]> git.openstreetmap.org Git - rails.git/blob - app/controllers/issue_comments_controller.rb
Fix right sidebar background
[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   before_action :check_database_readable
7
8   authorize_resource
9
10   before_action :check_database_writable, :only => [:create]
11
12   def create
13     @issue = Issue.find(params[:issue_id])
14     comment = @issue.comments.build(issue_comment_params)
15     comment.user = current_user
16     comment.save!
17
18     if params[:reassign]
19       reassign_issue(@issue)
20       flash[:notice] = t ".issue_reassigned"
21
22       if current_user.role? @issue.assigned_role
23         redirect_to @issue
24       else
25         redirect_to issues_path(:status => "open")
26       end
27     else
28       flash[:notice] = t(".comment_created")
29       redirect_to @issue
30     end
31   end
32
33   private
34
35   def issue_comment_params
36     params.require(:issue_comment).permit(:body)
37   end
38
39   # This sort of assumes there are only two roles
40   def reassign_issue(issue)
41     role = (Issue::ASSIGNED_ROLES - [issue.assigned_role]).first
42     issue.assigned_role = role
43     issue.save!
44   end
45 end