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 @issues = Issue.all.order(:status)
14 @read_reports = @issue.read_reports
15 @unread_reports = @issue.unread_reports
16 @comments = @issue.comments
17 @related_issues = @issue.user.issues
21 unless create_new_issue_params.blank?
22 @issue = Issue.find_or_initialize_by(create_new_issue_params)
27 @issue = Issue.find_by_reportable_id_and_reportable_type(params[:reportable_id],params[:reportable_type])
29 # Check if Issue alrwady exists
31 @issue = Issue.find_or_initialize_by(issue_params)
32 @admins = UserRole.where(role: "administrator")
33 @admins.each do |admin|
34 Notifier.new_issue_notification(User.find(admin.user_id)).deliver_now
38 # Check if details provided are sufficient
39 if params[:report][:details] and (params[:spam] or params[:offensive] or params[:threat] or params[:vandal] or params[:other])
40 @report = @issue.reports.build(report_params)
41 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
42 @report.reporter_user_id = @user.id
43 @report.details = details
45 # Checking if instance has been updated since last report
46 @last_report = @issue.reports.order(updated_at: :desc).last
47 if @issue.reportable.updated_at.present? and (@issue.ignored? or @issue.resolved?) and @issue.reportable.updated_at > @last_report.updated_at
54 redirect_to root_path, notice: t('issues.create.successful_report')
57 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')
62 @issue = Issue.find_by(issue_params)
64 # Check if details provided are sufficient
65 if params[:report][:details] and (params[:spam] or params[:offensive] or params[:threat] or params[:vandal] or params[:other])
66 @report = @issue.reports.where(reporter_user_id: @user.id).first
69 @report = @issue.reports.build(report_params)
70 @report.reporter_user_id = @user.id
71 notice = t('issues.update.new_report')
74 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
75 @report.details = details
77 # Checking if instance has been updated since last report
78 @last_report = @issue.reports.order(updated_at: :desc).last
79 if @issue.reportable.updated_at.present? and (@issue.ignored? or @issue.resolved?) and @issue.reportable.updated_at > @last_report.updated_at
85 notice = t('issues.update.successful_update')
89 redirect_to root_path, notice: notice
92 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')
97 @issue = Issue.find(params[:id])
98 @issue_comment = @issue.comments.build(issue_comment_params)
99 @issue_comment.commenter_user_id = @user.id
104 # Status Transistions
108 redirect_to @issue, notice: t('issues.resolved')
117 redirect_to @issue, notice: t('issues.ignored')
126 redirect_to @issue, notice: t('issues.reopened')
135 @issue = Issue.find(params[:id])
139 unless @user.administrator?
140 flash[:error] = t("application.require_admin.not_an_admin")
141 redirect_to root_path
145 def create_new_issue_params
146 params.permit(:reportable_id, :reportable_type, :reported_user_id)
150 params[:issue].permit(:reportable_id, :reportable_type,:reported_user_id)
154 params[:report].permit(:details)
157 def issue_comment_params
158 params.require(:issue_comment).permit(:body)