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