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 :get_user_role, only: [:show, :index]
11 helper_method :sort_column, :sort_direction
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] and !params[:search_by_user].blank?
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')
35 if params[:status] and !params[:status][0].blank?
36 @issues = @issues.where(status: params[:status][0].to_i)
39 if params[:issue_type] and !params[:issue_type][0].blank?
40 @issues = @issues.where(reportable_type: params[:issue_type][0])
43 if @issues.first == nil
44 notice = t('issues.index.search.issues_not_found')
47 if params[:last_reported_by] and !params[:last_reported_by][0].blank?
48 last_reported_by = params[:last_reported_by][0].to_s == "nil" ? nil : params[:last_reported_by][0].to_i
49 @issues = @issues.where(updated_by: last_reported_by)
53 redirect_to issues_path, notice: notice
58 @read_reports = @issue.read_reports
59 @unread_reports = @issue.unread_reports
60 @comments = @issue.comments
61 @related_issues = @issue.user.issues.where(issue_type: @user_role)
63 @updated_by_admin = User.find(@issue.updated_by)
68 unless create_new_issue_params.blank?
69 @issue = Issue.find_or_initialize_by(create_new_issue_params)
70 path = 'issues.report_strings.' + @issue.reportable.class.name.to_s
71 @report_strings_yaml = t(path)
76 @issue = Issue.find_by_reportable_id_and_reportable_type(params[:reportable_id],params[:reportable_type])
77 # Check if Issue already exists
79 @issue = Issue.find_or_initialize_by(issue_params)
80 @issue.updated_by = nil
82 # Reassign to moderators if it is a moderator issue
83 @issue.issue_type = "administrator"
84 if @moderator_issues.include? @issue.reportable.class.name
88 @admins_or_mods = UserRole.where(role: @issue.issue_type)
89 @admins_or_mods.each do |user|
90 Notifier.new_issue_notification(User.find(user.user_id)).deliver_now
95 # Check if details provided are sufficient
96 if check_report_params
97 @report = @issue.reports.build(report_params)
98 details = get_report_details
99 @report.reporter_user_id = @user.id
100 @report.details = details
101 # Checking if instance has been updated since last report
102 @last_report = @issue.reports.order(updated_at: :desc).last
110 @issue.report_count = @issue.reports.count
112 redirect_to root_path, notice: t('issues.create.successful_report')
115 redirect_to new_issue_path(reportable_type: @issue.reportable_type,reportable_id: @issue.reportable_id, reported_user_id: @issue.reported_user_id), notice: t('issues.create.provide_details')
120 @issue = Issue.find_by(issue_params)
121 # Check if details provided are sufficient
122 if check_report_params
123 @report = @issue.reports.where(reporter_user_id: @user.id).first
126 @report = @issue.reports.build(report_params)
127 @report.reporter_user_id = @user.id
128 notice = t('issues.update.new_report')
131 details = get_report_details
132 @report.details = details
134 # Checking if instance has been updated since last report
135 @last_report = @issue.reports.order(updated_at: :desc).last
142 notice = t('issues.update.successful_update')
147 @issue.report_count = @issue.reports.count
149 redirect_to root_path, notice: notice
152 redirect_to new_issue_path(reportable_type: @issue.reportable_type,reportable_id: @issue.reportable_id, reported_user_id: @issue.reported_user_id), notice: t('issues.update.provide_details')
157 @issue = Issue.find(params[:id])
158 if issue_comment_params.blank?
159 notice = t('issues.comment.provide_details')
161 @issue_comment = @issue.comments.build(issue_comment_params)
162 @issue_comment.commenter_user_id = @user.id
165 @issue_comment.reassign = true
168 @issue.updated_by = @user.id
170 notice = t('issues.comment.comment_created')
172 redirect_to @issue, notice: notice
175 # Status Transistions
179 redirect_to @issue, notice: t('issues.resolved')
187 @issue.updated_by = @user.id
189 redirect_to @issue, notice: t('issues.ignored')
197 @issue.updated_by = @user.id
199 redirect_to @issue, notice: t('issues.reopened')
205 # Reassign Issues between Administrators and Moderators
207 if @issue.issue_type == "moderator"
208 @issue.issue_type = "administrator"
210 @issue.issue_type = "moderator"
218 @admin_issues = [ 'DiaryEntry', 'DiaryComment', 'User']
219 @moderator_issues = [ 'Changeset', 'Note' ]
224 if @user.administrator?
225 @user_role = "administrator"
227 @user_role = "moderator"
232 if @issue.reportable and (@issue.ignored? or @issue.resolved?) and @issue.reportable.has_attribute?(:updated_by) and @issue.reportable.updated_at > @last_report.updated_at
239 def get_report_details
240 details = params[:report][:details] + "--||--"
241 details = details + params[:report_type].to_s + "--||--"
245 def check_report_params
246 if params[:report] and params[:report][:details] and params[:report_type]
253 @issue = Issue.find(params[:id])
257 unless @user.administrator? or @user.moderator?
258 flash[:error] = t('application.require_admin.not_an_admin')
259 redirect_to root_path
263 def create_new_issue_params
264 params.permit(:reportable_id, :reportable_type, :reported_user_id)
268 params[:issue].permit(:reportable_id, :reportable_type,:reported_user_id)
272 params[:report].permit(:details)
275 def issue_comment_params
276 params.require(:issue_comment).permit(:body)
280 Issue.column_names.include?(params[:sort]) ? params[:sort] : "status"
284 %w[asc desc].include?(params[:direction]) ? params[:direction] : "asc"