Use lazy lookups for translations in issues
[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(".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_moderator_or_admin.not_a_moderator_or_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