]> git.openstreetmap.org Git - rails.git/blob - app/controllers/issue_comments_controller.rb
Merge remote-tracking branch 'upstream/pull/3791'
[rails.git] / app / controllers / issue_comments_controller.rb
1 class IssueCommentsController < ApplicationController
2   layout "site"
3
4   before_action :authorize_web
5   before_action :set_locale
6
7   authorize_resource
8
9   def create
10     @issue = Issue.find(params[:issue_id])
11     comment = @issue.comments.build(issue_comment_params)
12     comment.user = current_user
13     comment.save!
14
15     if params[:reassign]
16       reassign_issue(@issue)
17       flash[:notice] = t ".issue_reassigned"
18
19       if current_user.has_role? @issue.assigned_role
20         redirect_to @issue
21       else
22         redirect_to issues_path(:status => "open")
23       end
24     else
25       flash[:notice] = t(".comment_created")
26       redirect_to @issue
27     end
28   end
29
30   private
31
32   def issue_comment_params
33     params.require(:issue_comment).permit(:body)
34   end
35
36   # This sort of assumes there are only two roles
37   def reassign_issue(issue)
38     role = (Issue::ASSIGNED_ROLES - [issue.assigned_role]).first
39     issue.assigned_role = role
40     issue.save!
41   end
42 end