1 class IssuesController < ApplicationController
4 before_action :authorize_web
5 before_action :require_user
6 before_action :check_permission, only: [:index, :show, :resolve,:open,:ignore,:comment]
7 before_action :find_issue, only: [:show, :resolve, :reopen, :ignore]
11 if @user.administrator?
12 @user_role = "administrator"
14 @user_role = "moderator"
18 if params[:search_by_user]
19 @find_user = User.find_by_display_name(params[:search_by_user])
21 @issues = Issue.where(reported_user_id: @find_user.id, issue_type: @user_role).order(:status)
23 @issues = Issue.where(issue_type: @user_role).order(:status)
24 notice = t('issues.index.search.user_not_found')
27 if @find_user !=nil and @issues.first == nil
28 @issues = Issue.where(issue_type: @user_role).order(:status)
29 notice = t('issues.index.search.issues_not_found')
33 redirect_to issues_path, notice: notice
37 @issues = Issue.where(issue_type: @user_role).order(:status)
42 @read_reports = @issue.read_reports
43 @unread_reports = @issue.unread_reports
44 @comments = @issue.comments
45 @related_issues = @issue.user.issues
47 @updated_by_admin = User.find(@issue.updated_by)
52 unless create_new_issue_params.blank?
53 @issue = Issue.find_or_initialize_by(create_new_issue_params)
54 path = 'issues.report_strings.' + @issue.reportable.class.name.to_s
55 @report_strings_yaml = t(path)
61 # TODO: Find better place to add these
62 admin_issues = [ 'DiaryEntry', 'DiaryComment', 'User']
66 @issue = Issue.find_by_reportable_id_and_reportable_type(params[:reportable_id],params[:reportable_type])
67 # Check if Issue alrwady exists
69 @issue = Issue.find_or_initialize_by(issue_params)
70 @issue.updated_by = nil
71 @admins = UserRole.where(role: "administrator")
72 @admins.each do |admin|
73 Notifier.new_issue_notification(User.find(admin.user_id)).deliver_now
76 # Reassign to moderators if it is a moderator issue
77 @issue.issue_type = "administrator"
78 if moderator_issues.include? @issue.reportable.class.name
83 # Check if details provided are sufficient
84 if check_report_params
85 @report = @issue.reports.build(report_params)
86 details = get_report_details
87 @report.reporter_user_id = @user.id
88 @report.details = details
90 # Checking if instance has been updated since last report
91 @last_report = @issue.reports.order(updated_at: :desc).last
99 redirect_to root_path, notice: t('issues.create.successful_report')
102 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')
107 @issue = Issue.find_by(issue_params)
108 # Check if details provided are sufficient
109 if check_report_params
110 @report = @issue.reports.where(reporter_user_id: @user.id).first
113 @report = @issue.reports.build(report_params)
114 @report.reporter_user_id = @user.id
115 notice = t('issues.update.new_report')
118 details = get_report_details
119 @report.details = details
121 # Checking if instance has been updated since last report
122 @last_report = @issue.reports.order(updated_at: :desc).last
129 notice = t('issues.update.successful_update')
133 redirect_to root_path, notice: notice
136 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')
141 @issue = Issue.find(params[:id])
142 if issue_comment_params.blank?
143 notice = t('issues.comment.provide_details')
145 @issue_comment = @issue.comments.build(issue_comment_params)
146 @issue_comment.commenter_user_id = @user.id
149 @issue_comment.reassign = true
152 @issue.updated_by = @user.id
154 notice = t('issues.comment.comment_created')
156 redirect_to @issue, notice: notice
159 # Status Transistions
163 redirect_to @issue, notice: t('issues.resolved')
171 @issue.updated_by = @user.id
173 redirect_to @issue, notice: t('issues.ignored')
181 @issue.updated_by = @user.id
183 redirect_to @issue, notice: t('issues.reopened')
189 # Reassign Issues between Administrators and Moderators
191 if @issue.issue_type == "moderator"
192 @issue.issue_type = "administrator"
194 @issue.issue_type = "moderator"
202 if @issue.reportable and (@issue.ignored? or @issue.resolved?) and @issue.reportable.updated_at > @last_report.updated_at
209 def get_report_details
210 details = params[:report][:details] + "--||--"
211 details = details + params[:report_type].to_s + "--||--"
215 def check_report_params
216 if params[:report] and params[:report][:details] and params[:report_type]
223 @issue = Issue.find(params[:id])
227 unless @user.administrator? or @user.moderator?
228 flash[:error] = t('application.require_admin.not_an_admin')
229 redirect_to root_path
233 def create_new_issue_params
234 params.permit(:reportable_id, :reportable_type, :reported_user_id)
238 params[:issue].permit(:reportable_id, :reportable_type,:reported_user_id)
242 params[:report].permit(:details)
245 def issue_comment_params
246 params.require(:issue_comment).permit(:body)