1 class IssuesController < ApplicationController
4 before_action :authorize_web
5 before_action :require_user
6 before_action :set_issues
7 before_action :check_permission
8 before_action :find_issue, :only => [:show, :resolve, :reopen, :ignore]
13 if current_user.moderator?
14 @issue_types = @moderator_issues
15 @users = User.joins(:roles).where(:user_roles => { :role => "moderator" })
17 @issue_types = @admin_issues
18 @users = User.joins(:roles).where(:user_roles => { :role => "administrator" })
21 @issues = Issue.where(:assigned_role => current_user.roles.map(&:role))
24 if params[:search_by_user] && params[:search_by_user].present?
25 @find_user = User.find_by(:display_name => params[:search_by_user])
27 @issues = @issues.where(:reported_user_id => @find_user.id)
29 notice = t("issues.index.user_not_found")
33 if params[:status] && params[:status][0].present?
34 @issues = @issues.where(:status => params[:status][0].to_i)
37 if params[:issue_type] && params[:issue_type][0].present?
38 @issues = @issues.where(:reportable_type => params[:issue_type][0])
42 if params[:last_updated_by] && params[:last_updated_by][0].present?
43 last_updated_by = params[:last_updated_by][0].to_s == "nil" ? nil : params[:last_updated_by][0].to_i
44 @issues = @issues.where(:updated_by => last_updated_by)
47 if params[:last_reported_by] && params[:last_reported_by][0].present?
48 last_reported_by = params[:last_reported_by][0].to_s == "nil" ? nil : params[:last_reported_by][0].to_i
49 @issues = @issues.where(:updated_by => last_reported_by)
52 redirect_to issues_path, :notice => notice if notice
56 @read_reports = @issue.read_reports
57 @unread_reports = @issue.unread_reports
58 @comments = @issue.comments
59 @related_issues = @issue.reported_user.issues.where(:assigned_role => current_user.roles.map(&:role))
60 @new_comment = IssueComment.new(:issue => @issue)
67 redirect_to @issue, :notice => t("issues.resolved")
75 @issue.updated_by = current_user.id
77 redirect_to @issue, :notice => t("issues.ignored")
85 @issue.updated_by = current_user.id
87 redirect_to @issue, :notice => t("issues.reopened")
96 @admin_issues = %w[DiaryEntry DiaryComment User]
97 @moderator_issues = %w[Changeset Note]
101 if @issue.reportable && (@issue.ignored? || @issue.resolved?) && @issue.reportable.has_attribute?(:updated_by) && @issue.reportable.updated_at > @last_report.updated_at
109 @issue = Issue.find(params[:id])
113 unless current_user.administrator? || current_user.moderator?
114 flash[:error] = t("application.require_admin.not_an_admin")
115 redirect_to root_path
120 params[:issue].permit(:reportable_id, :reportable_type)
124 params[:report].permit(:details)
127 def issue_comment_params
128 params.require(:issue_comment).permit(:body)
132 Issue.column_names.include?(params[:sort]) ? params[:sort] : "status"
136 %w[asc desc].include?(params[:direction]) ? params[:direction] : "asc"