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)
42 @issue = Issue.find_by_reportable_id_and_reportable_type(params[:reportable_id],params[:reportable_type])
44 # Check if Issue alrwady exists
46 @issue = Issue.find_or_initialize_by(issue_params)
47 @admins = UserRole.where(role: "administrator")
48 @admins.each do |admin|
49 Notifier.new_issue_notification(User.find(admin.user_id)).deliver_now
53 # Check if details provided are sufficient
54 if params[:report][:details] and (params[:spam] or params[:offensive] or params[:threat] or params[:vandal] or params[:other])
55 @report = @issue.reports.build(report_params)
56 details = params[:report][:details].to_s + "||" + params[:spam].to_s + "||" + params[:offensive].to_s + "||" + params[:threat].to_s + "||" + params[:vandal].to_s + "||" + params[:other].to_s
57 @report.reporter_user_id = @user.id
58 @report.details = details
60 # Checking if instance has been updated since last report
61 @last_report = @issue.reports.order(updated_at: :desc).last
62 if @issue.reportable.updated_at.present? and (@issue.ignored? or @issue.resolved?) and @issue.reportable.updated_at > @last_report.updated_at
69 redirect_to root_path, notice: t('issues.create.successful_report')
72 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')
77 @issue = Issue.find_by(issue_params)
79 # Check if details provided are sufficient
80 if params[:report][:details] and (params[:spam] or params[:offensive] or params[:threat] or params[:vandal] or params[:other])
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 = params[:report][:details].to_s + "||" + params[:spam].to_s + "||" + params[:offensive].to_s + "||" + params[:threat].to_s + "||" + params[:vandal].to_s + "||" + params[:other].to_s
90 @report.details = details
92 # Checking if instance has been updated since last report
93 @last_report = @issue.reports.order(updated_at: :desc).last
94 if @issue.reportable.updated_at.present? and (@issue.ignored? or @issue.resolved?) and @issue.reportable.updated_at > @last_report.updated_at
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')
150 @issue = Issue.find(params[:id])
154 unless @user.administrator?
155 flash[:error] = t("application.require_admin.not_an_admin")
156 redirect_to root_path
160 def create_new_issue_params
161 params.permit(:reportable_id, :reportable_type, :reported_user_id)
165 params[:issue].permit(:reportable_id, :reportable_type,:reported_user_id)
169 params[:report].permit(:details)
172 def issue_comment_params
173 params.require(:issue_comment).permit(:body)