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])
44 if params[:last_updated_by] and !params[:last_updated_by][0].blank?
45 last_reported_by = params[:last_updated_by][0].to_s == "nil" ? nil : params[:last_updated_by][0].to_i
46 @issues = @issues.where(updated_by: last_updated_by)
49 if @issues.first == nil
50 notice = t('issues.index.search.issues_not_found')
53 if params[:last_reported_by] and !params[:last_reported_by][0].blank?
54 last_reported_by = params[:last_reported_by][0].to_s == "nil" ? nil : params[:last_reported_by][0].to_i
55 @issues = @issues.where(updated_by: last_reported_by)
59 redirect_to issues_path, notice: notice
64 @read_reports = @issue.read_reports
65 @unread_reports = @issue.unread_reports
66 @comments = @issue.comments
67 @related_issues = @issue.user.issues.where(issue_type: @user_role)
69 @updated_by_admin = User.find(@issue.updated_by)
74 unless create_new_issue_params.blank?
75 @issue = Issue.find_or_initialize_by(create_new_issue_params)
76 path = 'issues.report_strings.' + @issue.reportable.class.name.to_s
77 @report_strings_yaml = t(path)
82 @issue = Issue.find_by_reportable_id_and_reportable_type(params[:reportable_id],params[:reportable_type])
83 # Check if Issue already exists
85 @issue = Issue.find_or_initialize_by(issue_params)
86 @issue.updated_by = nil
88 # Reassign to moderators if it is a moderator issue
89 @issue.issue_type = "administrator"
90 if @moderator_issues.include? @issue.reportable.class.name
94 @admins_or_mods = UserRole.where(role: @issue.issue_type)
95 @admins_or_mods.each do |user|
96 Notifier.new_issue_notification(User.find(user.user_id)).deliver_now
101 # Check if details provided are sufficient
102 if check_report_params
103 @report = @issue.reports.build(report_params)
104 details = get_report_details
105 @report.reporter_user_id = @user.id
106 @report.details = details
107 # Checking if instance has been updated since last report
108 @last_report = @issue.reports.order(updated_at: :desc).last
116 @issue.report_count = @issue.reports.count
118 redirect_to root_path, notice: t('issues.create.successful_report')
121 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')
126 @issue = Issue.find_by(issue_params)
127 # Check if details provided are sufficient
128 if check_report_params
129 @report = @issue.reports.where(reporter_user_id: @user.id).first
132 @report = @issue.reports.build(report_params)
133 @report.reporter_user_id = @user.id
134 notice = t('issues.update.new_report')
137 details = get_report_details
138 @report.details = details
140 # Checking if instance has been updated since last report
141 @last_report = @issue.reports.order(updated_at: :desc).last
148 notice = t('issues.update.successful_update')
153 @issue.report_count = @issue.reports.count
155 redirect_to root_path, notice: notice
158 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')
163 @issue = Issue.find(params[:id])
164 if issue_comment_params.blank?
165 notice = t('issues.comment.provide_details')
167 @issue_comment = @issue.comments.build(issue_comment_params)
168 @issue_comment.commenter_user_id = @user.id
171 @issue_comment.reassign = true
174 @issue.updated_by = @user.id
176 notice = t('issues.comment.comment_created')
178 redirect_to @issue, notice: notice
181 # Status Transistions
185 redirect_to @issue, notice: t('issues.resolved')
193 @issue.updated_by = @user.id
195 redirect_to @issue, notice: t('issues.ignored')
203 @issue.updated_by = @user.id
205 redirect_to @issue, notice: t('issues.reopened')
211 # Reassign Issues between Administrators and Moderators
213 if @issue.issue_type == "moderator"
214 @issue.issue_type = "administrator"
216 @issue.issue_type = "moderator"
224 @admin_issues = [ 'DiaryEntry', 'DiaryComment', 'User']
225 @moderator_issues = [ 'Changeset', 'Note' ]
230 if @user.administrator?
231 @user_role = "administrator"
233 @user_role = "moderator"
238 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
245 def get_report_details
246 details = params[:report][:details] + "--||--"
247 details = details + params[:report_type].to_s + "--||--"
251 def check_report_params
252 if params[:report] and params[:report][:details] and params[:report_type]
259 @issue = Issue.find(params[:id])
263 unless @user.administrator? or @user.moderator?
264 flash[:error] = t('application.require_admin.not_an_admin')
265 redirect_to root_path
269 def create_new_issue_params
270 params.permit(:reportable_id, :reportable_type, :reported_user_id)
274 params[:issue].permit(:reportable_id, :reportable_type,:reported_user_id)
278 params[:report].permit(:details)
281 def issue_comment_params
282 params.require(:issue_comment).permit(:body)
286 Issue.column_names.include?(params[:sort]) ? params[:sort] : "status"
290 %w[asc desc].include?(params[:direction]) ? params[:direction] : "asc"