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]
10 if params[:search_by_user].present?
11 @user = User.find_by_display_name(params[:search_by_user])
13 @issues = Issue.where(reported_user_id: @user.id).order(:status)
15 @issues = Issue.all.order(:status)
16 redirect_to issues_path, notice: t('issues.index.search.user_not_found')
19 if @user.present? and not @issues.present?
20 @issues = Issue.all.order(:status)
21 redirect_to issues_path, notice: t('issues.index.search.issues_not_found')
24 @issues = Issue.all.order(:status)
29 @read_reports = @issue.read_reports
30 @unread_reports = @issue.unread_reports
31 @comments = @issue.comments
32 @related_issues = @issue.user.issues
36 unless create_new_issue_params.blank?
37 @issue = Issue.find_or_initialize_by(create_new_issue_params)
38 path = 'issues.report_strings.' + @issue.reportable.class.name.to_s
39 @report_strings_yaml = t( path)
44 @issue = Issue.find_by_reportable_id_and_reportable_type(params[:reportable_id],params[:reportable_type])
45 # Check if Issue alrwady exists
47 @issue = Issue.find_or_initialize_by(issue_params)
48 @admins = UserRole.where(role: "administrator")
49 @admins.each do |admin|
50 Notifier.new_issue_notification(User.find(admin.user_id)).deliver_now
54 # Check if details provided are sufficient
55 if check_report_params
56 @report = @issue.reports.build(report_params)
57 details = get_report_details
58 @report.reporter_user_id = @user.id
59 @report.details = details
61 # Checking if instance has been updated since last report
62 @last_report = @issue.reports.order(updated_at: :desc).last
70 redirect_to root_path, notice: t('issues.create.successful_report')
73 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')
78 @issue = Issue.find_by(issue_params)
79 # Check if details provided are sufficient
80 if check_report_params
81 @report = @issue.reports.where(reporter_user_id: @user.id).first
84 @report = @issue.reports.build(report_params)
85 @report.reporter_user_id = @user.id
86 notice = t('issues.update.new_report')
89 details = get_report_details
90 @report.details = details
92 # Checking if instance has been updated since last report
93 @last_report = @issue.reports.order(updated_at: :desc).last
100 notice = t('issues.update.successful_update')
104 redirect_to root_path, notice: notice
107 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')
112 @issue = Issue.find(params[:id])
113 @issue_comment = @issue.comments.build(issue_comment_params)
114 @issue_comment.commenter_user_id = @user.id
119 # Status Transistions
123 redirect_to @issue, notice: t('issues.resolved')
132 redirect_to @issue, notice: t('issues.ignored')
141 redirect_to @issue, notice: t('issues.reopened')
151 if @issue.reportable and (@issue.ignored? or @issue.resolved?) and @issue.reportable.updated_at > @last_report.updated_at
158 def get_report_details
159 details = params[:report][:details] + "--||--"
160 path = 'issues.report_strings.' + @issue.reportable.class.name.to_s
161 @report_strings_yaml = t( path)
162 @report_strings_yaml.each do |k,v|
164 details = details + params[k.to_sym] + "--||--"
170 def check_report_params
171 path = 'issues.report_strings.' + @issue.reportable.class.name.to_s
172 @report_strings_yaml = t( path)
173 if params[:report] and params[:report][:details]
174 @report_strings_yaml.each do |k,v|
184 @issue = Issue.find(params[:id])
188 unless @user.administrator?
189 flash[:error] = t('application.require_admin.not_an_admin')
190 redirect_to root_path
194 def create_new_issue_params
195 params.permit(:reportable_id, :reportable_type, :reported_user_id)
199 params[:issue].permit(:reportable_id, :reportable_type,:reported_user_id)
203 params[:report].permit(:details)
206 def issue_comment_params
207 params.require(:issue_comment).permit(:body)