]> git.openstreetmap.org Git - rails.git/blob - app/controllers/issue_comments_controller.rb
Fix Style/NumericPredicate rubocop warnings
[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 :require_user
7   before_action :check_permission
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     notice = t(".comment_created")
15     reassign_issue(@issue) if params[:reassign]
16     redirect_to @issue, :notice => notice
17   end
18
19   private
20
21   def issue_comment_params
22     params.require(:issue_comment).permit(:body)
23   end
24
25   def check_permission
26     unless current_user.administrator? || current_user.moderator?
27       flash[:error] = t("application.require_moderator_or_admin.not_a_moderator_or_admin")
28       redirect_to root_path
29     end
30   end
31
32   # This sort of assumes there are only two roles
33   def reassign_issue(issue)
34     role = (Issue::ASSIGNED_ROLES - [issue.assigned_role]).first
35     issue.assigned_role = role
36     issue.save!
37   end
38 end