1 class IssuesController < ApplicationController
4 before_action :authorize_web
5 before_action :require_user
6 before_action :set_issues
7 before_action :check_permission, :only => [:index, :show, :resolve, :open, :ignore, :comment]
8 before_action :find_issue, :only => [:show, :resolve, :reopen, :ignore]
11 if current_user.moderator?
12 @issue_types = @moderator_issues
13 @users = User.joins(:roles).where(:user_roles => { :role => "moderator" })
15 @issue_types = @admin_issues
16 @users = User.joins(:roles).where(:user_roles => { :role => "administrator" })
19 @issues = Issue.where(:assigned_role => current_user.roles.map(&:role))
22 if params[:search_by_user] && params[:search_by_user].present?
23 @find_user = User.find_by(:display_name => params[:search_by_user])
25 @issues = @issues.where(:reported_user_id => @find_user.id)
27 notice = t("issues.index.search.user_not_found")
31 if params[:status] && params[:status][0].present?
32 @issues = @issues.where(:status => params[:status][0].to_i)
35 if params[:issue_type] && params[:issue_type][0].present?
36 @issues = @issues.where(:reportable_type => params[:issue_type][0])
40 if params[:last_updated_by] && params[:last_updated_by][0].present?
41 last_updated_by = params[:last_updated_by][0].to_s == "nil" ? nil : params[:last_updated_by][0].to_i
42 @issues = @issues.where(:updated_by => last_updated_by)
45 if params[:last_reported_by] && params[:last_reported_by][0].present?
46 last_reported_by = params[:last_reported_by][0].to_s == "nil" ? nil : params[:last_reported_by][0].to_i
47 @issues = @issues.where(:updated_by => last_reported_by)
50 redirect_to issues_path, :notice => notice if notice
54 @read_reports = @issue.read_reports
55 @unread_reports = @issue.unread_reports
56 @comments = @issue.comments
57 @related_issues = @issue.reported_user.issues.where(:assigned_role => current_user.roles.map(&:role))
58 @new_comment = IssueComment.new(:issue => @issue)
65 redirect_to @issue, :notice => t("issues.resolved")
73 @issue.updated_by = current_user.id
75 redirect_to @issue, :notice => t("issues.ignored")
83 @issue.updated_by = current_user.id
85 redirect_to @issue, :notice => t("issues.reopened")
94 @admin_issues = %w[DiaryEntry DiaryComment User]
95 @moderator_issues = %w[Changeset Note]
99 if @issue.reportable && (@issue.ignored? || @issue.resolved?) && @issue.reportable.has_attribute?(:updated_by) && @issue.reportable.updated_at > @last_report.updated_at
107 @issue = Issue.find(params[:id])
111 unless current_user.administrator? || current_user.moderator?
112 flash[:error] = t("application.require_admin.not_an_admin")
113 redirect_to root_path
118 params[:issue].permit(:reportable_id, :reportable_type)
122 params[:report].permit(:details)
125 def issue_comment_params
126 params.require(:issue_comment).permit(:body)
130 Issue.column_names.include?(params[:sort]) ? params[:sort] : "status"
134 %w[asc desc].include?(params[:direction]) ? params[:direction] : "asc"