1 class IssuesController < ApplicationController
4 before_action :authorize_web
5 before_action :require_user
6 before_action :set_issues
7 before_action :check_permission, :only => [:index, :show, :resolve, :open, :ignore, :comment]
8 before_action :find_issue, :only => [:show, :resolve, :reopen, :ignore]
9 before_action :setup_user_role, :only => [:show, :index]
11 helper_method :sort_column, :sort_direction
14 if current_user.moderator?
15 @issue_types = @moderator_issues
16 @users = User.joins(:roles).where(:user_roles => { :role => "moderator" })
18 @issue_types = @admin_issues
19 @users = User.joins(:roles).where(:user_roles => { :role => "administrator" })
22 @issues = Issue.where(:issue_type => @user_role).order(sort_column + " " + sort_direction)
25 if params[:search_by_user] && params[:search_by_user].present?
26 @find_user = User.find_by(:display_name => params[:search_by_user])
28 @issues = @issues.where(:reported_user_id => @find_user.id)
30 notice = t("issues.index.search.user_not_found")
34 if params[:status] && params[:status][0].present?
35 @issues = @issues.where(:status => params[:status][0].to_i)
38 if params[:issue_type] && params[:issue_type][0].present?
39 @issues = @issues.where(:reportable_type => params[:issue_type][0])
43 if params[:last_updated_by] && params[:last_updated_by][0].present?
44 last_updated_by = params[:last_updated_by][0].to_s == "nil" ? nil : params[:last_updated_by][0].to_i
45 @issues = @issues.where(:updated_by => last_updated_by)
48 notice = t("issues.index.search.issues_not_found") if @issues.first.nil?
50 if params[:last_reported_by] && params[:last_reported_by][0].present?
51 last_reported_by = params[:last_reported_by][0].to_s == "nil" ? nil : params[:last_reported_by][0].to_i
52 @issues = @issues.where(:updated_by => last_reported_by)
55 redirect_to issues_path, :notice => notice if notice
59 @read_reports = @issue.read_reports
60 @unread_reports = @issue.unread_reports
61 @comments = @issue.comments
62 @related_issues = @issue.reported_user.issues.where(:issue_type => @user_role)
66 @issue = Issue.find_by(issue_params)
67 # Check if details provided are sufficient
68 if check_report_params
69 @report = @issue.reports.where(:reporter_user_id => current_user.id).first
72 @report = @issue.reports.build(report_params)
73 @report.reporter_user_id = current_user.id
74 notice = t("issues.update.new_report")
77 details = report_details
78 @report.details = details
80 # Checking if instance has been updated since last report
81 @last_report = @issue.reports.order(:updated_at => :desc).last
87 notice = t("issues.update.successful_update") if notice.nil?
90 @issue.report_count = @issue.reports.count
92 redirect_back :fallback_location => "/", :notice => notice
95 redirect_to new_issue_path(:reportable_type => @issue.reportable_type, :reportable_id => @issue.reportable_id), :notice => t("issues.update.provide_details")
100 @issue = Issue.find(params[:id])
101 if issue_comment_params.blank?
102 notice = t("issues.comment.provide_details")
104 @issue_comment = @issue.comments.build(issue_comment_params)
105 @issue_comment.commenter_user_id = current_user.id
108 @issue_comment.reassign = true
111 @issue.updated_by = current_user.id
113 notice = t("issues.comment.comment_created")
115 redirect_to @issue, :notice => notice
118 # Status Transistions
122 redirect_to @issue, :notice => t("issues.resolved")
130 @issue.updated_by = current_user.id
132 redirect_to @issue, :notice => t("issues.ignored")
140 @issue.updated_by = current_user.id
142 redirect_to @issue, :notice => t("issues.reopened")
148 # Reassign Issues between Administrators and Moderators
150 @issue.issue_type = upgrade_issue(@issue.issue_type)
156 def upgrade_issue(type)
157 if type == "moderator"
165 @admin_issues = %w[DiaryEntry DiaryComment User]
166 @moderator_issues = %w[Changeset Note]
171 @user_role = current_user.administrator? ? "administrator" : "moderator"
175 if @issue.reportable && (@issue.ignored? || @issue.resolved?) && @issue.reportable.has_attribute?(:updated_by) && @issue.reportable.updated_at > @last_report.updated_at
183 params[:report][:details] + "--||--" + params[:report_type].to_s + "--||--"
186 def check_report_params
187 params[:report] && params[:report][:details] && params[:report_type]
191 @issue = Issue.find(params[:id])
195 unless current_user.administrator? || current_user.moderator?
196 flash[:error] = t("application.require_admin.not_an_admin")
197 redirect_to root_path
202 params[:issue].permit(:reportable_id, :reportable_type)
206 params[:report].permit(:details)
209 def issue_comment_params
210 params.require(:issue_comment).permit(:body)
214 Issue.column_names.include?(params[:sort]) ? params[:sort] : "status"
218 %w[asc desc].include?(params[:direction]) ? params[:direction] : "asc"