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]
8 before_action :get_user_role, only: [:show, :index]
12 if params[:search_by_user]
13 @find_user = User.find_by_display_name(params[:search_by_user])
15 @issues = Issue.where(reported_user_id: @find_user.id, issue_type: @user_role).order(:status)
17 @issues = Issue.where(issue_type: @user_role).order(:status)
18 notice = t('issues.index.search.user_not_found')
21 if @find_user !=nil and @issues.first == nil
22 @issues = Issue.where(issue_type: @user_role).order(:status)
23 notice = t('issues.index.search.issues_not_found')
27 redirect_to issues_path, notice: notice
31 @issues = Issue.where(issue_type: @user_role).order(:status)
36 @read_reports = @issue.read_reports
37 @unread_reports = @issue.unread_reports
38 @comments = @issue.comments
39 @related_issues = @issue.user.issues.where(issue_type: @user_role)
41 @updated_by_admin = User.find(@issue.updated_by)
46 unless create_new_issue_params.blank?
47 @issue = Issue.find_or_initialize_by(create_new_issue_params)
48 path = 'issues.report_strings.' + @issue.reportable.class.name.to_s
49 @report_strings_yaml = t(path)
55 # TODO: Find better place to add these
56 admin_issues = [ 'DiaryEntry', 'DiaryComment', 'User']
57 moderator_issues = [ 'Changeset' ]
60 @issue = Issue.find_by_reportable_id_and_reportable_type(params[:reportable_id],params[:reportable_type])
61 # Check if Issue alrwady exists
63 @issue = Issue.find_or_initialize_by(issue_params)
64 @issue.updated_by = nil
66 # Reassign to moderators if it is a moderator issue
67 @issue.issue_type = "administrator"
68 if moderator_issues.include? @issue.reportable.class.name
72 @admins_or_mods = UserRole.where(role: @issue.issue_type)
73 @admins_or_mods.each do |user|
74 Notifier.new_issue_notification(User.find(user.user_id)).deliver_now
79 # Check if details provided are sufficient
80 if check_report_params
81 @report = @issue.reports.build(report_params)
82 details = get_report_details
83 @report.reporter_user_id = @user.id
84 @report.details = details
86 # Checking if instance has been updated since last report
87 @last_report = @issue.reports.order(updated_at: :desc).last
95 redirect_to root_path, notice: t('issues.create.successful_report')
98 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')
103 @issue = Issue.find_by(issue_params)
104 # Check if details provided are sufficient
105 if check_report_params
106 @report = @issue.reports.where(reporter_user_id: @user.id).first
109 @report = @issue.reports.build(report_params)
110 @report.reporter_user_id = @user.id
111 notice = t('issues.update.new_report')
114 details = get_report_details
115 @report.details = details
117 # Checking if instance has been updated since last report
118 @last_report = @issue.reports.order(updated_at: :desc).last
125 notice = t('issues.update.successful_update')
129 redirect_to root_path, notice: notice
132 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')
137 @issue = Issue.find(params[:id])
138 if issue_comment_params.blank?
139 notice = t('issues.comment.provide_details')
141 @issue_comment = @issue.comments.build(issue_comment_params)
142 @issue_comment.commenter_user_id = @user.id
145 @issue_comment.reassign = true
148 @issue.updated_by = @user.id
150 notice = t('issues.comment.comment_created')
152 redirect_to @issue, notice: notice
155 # Status Transistions
159 redirect_to @issue, notice: t('issues.resolved')
167 @issue.updated_by = @user.id
169 redirect_to @issue, notice: t('issues.ignored')
177 @issue.updated_by = @user.id
179 redirect_to @issue, notice: t('issues.reopened')
185 # Reassign Issues between Administrators and Moderators
187 if @issue.issue_type == "moderator"
188 @issue.issue_type = "administrator"
190 @issue.issue_type = "moderator"
199 if @user.administrator?
200 @user_role = "administrator"
202 @user_role = "moderator"
207 if @issue.reportable and (@issue.ignored? or @issue.resolved?) and @issue.reportable.updated_at > @last_report.updated_at
214 def get_report_details
215 details = params[:report][:details] + "--||--"
216 details = details + params[:report_type].to_s + "--||--"
220 def check_report_params
221 if params[:report] and params[:report][:details] and params[:report_type]
228 @issue = Issue.find(params[:id])
232 unless @user.administrator? or @user.moderator?
233 flash[:error] = t('application.require_admin.not_an_admin')
234 redirect_to root_path
238 def create_new_issue_params
239 params.permit(:reportable_id, :reportable_type, :reported_user_id)
243 params[:issue].permit(:reportable_id, :reportable_type,:reported_user_id)
247 params[:report].permit(:details)
250 def issue_comment_params
251 params.require(:issue_comment).permit(:body)