Create an IssueCommentsController for managing IssueComments

This commit is contained in:
Andy Allan 2017-09-13 16:19:16 +01:00
parent f0e3a41726
commit 8cf16fe78b
5 changed files with 76 additions and 22 deletions

View file

@ -0,0 +1,33 @@
class IssueCommentsController < ApplicationController
layout "site"
before_action :authorize_web
before_action :require_user
before_action :check_permission
def create
@issue = Issue.find(params[:issue_id])
comment = @issue.comments.build(issue_comment_params)
comment.user = current_user
# if params[:reassign]
# reassign_issue
# @issue_comment.reassign = true
# end
comment.save!
notice = t("issues.comment.comment_created")
redirect_to @issue, :notice => notice
end
private
def issue_comment_params
params.require(:issue_comment).permit(:body)
end
def check_permission
unless current_user.administrator? || current_user.moderator?
flash[:error] = t("application.require_admin.not_an_admin")
redirect_to root_path
end
end
end

View file

@ -58,6 +58,7 @@ class IssuesController < ApplicationController
@unread_reports = @issue.unread_reports
@comments = @issue.comments
@related_issues = @issue.reported_user.issues.where(:issue_type => @user_role)
@new_comment = IssueComment.new(:issue => @issue)
end
def update
@ -94,25 +95,6 @@ class IssuesController < ApplicationController
end
end
def comment
@issue = Issue.find(params[:id])
if issue_comment_params.blank?
notice = t("issues.comment.provide_details")
else
@issue_comment = @issue.comments.build(issue_comment_params)
@issue_comment.commenter_user_id = current_user.id
if params[:reassign]
reassign_issue
@issue_comment.reassign = true
end
@issue_comment.save!
@issue.updated_by = current_user.id
@issue.save!
notice = t("issues.comment.comment_created")
end
redirect_to @issue, :notice => notice
end
# Status Transistions
def resolve
if @issue.resolve