--- /dev/null
+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
@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
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
</div>
<br/>
<div class="comment">
- <%= form_for :issue_comment, :url => { :action => 'comment', :id => @issue.id } do |f| %>
+ <%= form_for @new_comment, url: issue_comments_path(@issue) do |f| %>
<%= richtext_area :issue_comment, :body, :cols => 10, :rows => 8, :required => true %>
<%= label_tag t('issues.show.comments.reassign_param') %> <%= check_box_tag :reassign, true %>
<br/>
# issues and reports
resources :issues do
+ resources :comments, :controller => :issue_comments
member do
post "resolve"
post "assign"
resources :reports
- post "/comment" => "issues#comment"
-
# redactions
resources :redactions
end
--- /dev/null
+require "test_helper"
+
+class IssuesTest < Capybara::Rails::TestCase
+ def test_view_issues_normal_user
+ sign_in_as(create(:user))
+
+ visit issues_path
+ assert page.has_content?(I18n.t("application.require_admin.not_an_admin"))
+ end
+
+ def test_view_no_issues
+ sign_in_as(create(:moderator_user))
+
+ visit issues_path
+ assert page.has_content?(I18n.t(".issues.index.search.issues_not_found"))
+ end
+
+ def test_view_issues
+ sign_in_as(create(:moderator_user))
+ issues = create_list(:issue, 3, :issue_type => "moderator")
+
+ visit issues_path
+ assert page.has_content?(issues.first.reported_user.display_name)
+ end
+
+ def test_commenting
+ issue = create(:issue)
+ sign_in_as(create(:moderator_user))
+
+ visit issue_path(issue)
+
+ fill_in :issue_comment_body, :with => "test comment"
+ click_on "Submit"
+ assert page.has_content?(I18n.t(".issues.comment.comment_created"))
+ assert page.has_content?("test comment")
+
+ issue.reload
+ assert_equal issue.comments.first.body, "test comment"
+ end
+end