]> git.openstreetmap.org Git - rails.git/blob - app/controllers/issue_comments_controller.rb
Re-enable issue reassigning.
[rails.git] / app / controllers / issue_comments_controller.rb
1 class IssueCommentsController < ApplicationController
2   layout "site"
3
4   before_action :authorize_web
5   before_action :require_user
6   before_action :check_permission
7
8   def create
9     @issue = Issue.find(params[:issue_id])
10     comment = @issue.comments.build(issue_comment_params)
11     comment.user = current_user
12     comment.save!
13     notice = t("issues.comment.comment_created")
14     reassign_issue(@issue) if params[:reassign]
15     redirect_to @issue, :notice => notice
16   end
17
18   private
19
20   def issue_comment_params
21     params.require(:issue_comment).permit(:body)
22   end
23
24   def check_permission
25     unless current_user.administrator? || current_user.moderator?
26       flash[:error] = t("application.require_admin.not_an_admin")
27       redirect_to root_path
28     end
29   end
30
31   # This sort of assumes there are only two roles
32   def reassign_issue(issue)
33     role = (Issue::ASSIGNED_ROLES - [issue.assigned_role]).first
34     issue.assigned_role = role
35     issue.save!
36   end
37 end