anteo / redmine_custom_workflows

Allows to create custom workflows for Redmine
http://www.redmine.org/plugins/custom-workflows
GNU General Public License v2.0
182 stars 72 forks source link

Redirects #185

Closed spbdimka closed 1 year ago

spbdimka commented 4 years ago

Hi. It happens that I change in the workflow, for example, the assigned user and after saving the issue, the current user does not have enough rights. The user sees a 403 error. Is there any way to redress it, for example, on / issues?

picman commented 4 years ago

I think, that it's an error in your code. You shouldn't cut off yourself. If it's necessary, from whatever reason, you should detect yourself this case and redirect it as follows:

redirect_to: issues_path
spbdimka commented 4 years ago

I think, that it's an error in your code. You shouldn't cut off yourself. If it's necessary, from whatever reason, you should detect yourself this case and redirect it as follows:

redirect_to: issues_path

Processing by CustomWorkflowsController#create as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"sdfVhurcQtfg==", "custom_workflow"=>{"name"=>"redirz", "author"=>"", "observable"=>"issue", "description"=>"", "is_for_all"=>"0", "active"=>"1", "project_ids"=>["3", ""], "before_save"=>"", "after_save"=>"redirect_to: projects_path", "before_destroy"=>"", "after_destroy"=>""}, "commit"=>"Создать"} Current user: admin (id=1) = Running shared code for Issue (#) " #: " = Finished running shared code for Issue (#) " #: " Completed 500 Internal Server Error in 32ms (ActiveRecord: 3.9ms)

SyntaxError ((eval):1: syntax error, unexpected ':', expecting end-of-input redirect_to: issues_path ^):

plugins/redmine_custom_workflows/app/models/custom_workflow.rb:111:in instance_eval' plugins/redmine_custom_workflows/app/models/custom_workflow.rb:111:invalidate_syntax_for' plugins/redmine_custom_workflows/app/models/custom_workflow.rb:142:in block in validate_syntax' plugins/redmine_custom_workflows/app/models/custom_workflow.rb:142:ineach' plugins/redmine_custom_workflows/app/models/custom_workflow.rb:142:in validate_syntax' plugins/redmine_custom_workflows/app/controllers/custom_workflows_controller.rb:106:inblock in create' plugins/redmine_custom_workflows/app/controllers/custom_workflows_controller.rb:105:in create' lib/redmine/sudo_mode.rb:65:insudo_mode' plugins/redmine_dmsf/lib/redmine_dmsf/webdav/custom_middleware.rb:60:in `call'

picman commented 4 years ago
redirect_to issues_path
spbdimka commented 4 years ago
redirect_to issues_path

so i got undefined variable issues_path after defining it, i got undefined method redirect_to

redmine 4.1.1, i put clean code in after_save callback

picman commented 4 years ago

Hm, you're right. My advice was completely wrong. You can't use a redirection in a model. How about the following approach?

unless @issue.visible?
  raise WorkflowError.new("You've lost access to the issue")
end
spbdimka commented 4 years ago

@picman Yes, it is possible, but it is more of a temporary kludge Is it possible to write an internal function for workflows to implement redirects?

picman commented 2 years ago

I don't think so. The plugin works with models only.