]> git.openstreetmap.org Git - rails.git/blob - app/controllers/issues_controller.rb
Rubocop autofix: ambiguous operator precedence
[rails.git] / app / controllers / issues_controller.rb
1 class IssuesController < ApplicationController
2   layout "site"
3
4   before_action :authorize_web
5   before_action :set_locale
6
7   authorize_resource
8
9   before_action :find_issue, :only => [:show, :resolve, :reopen, :ignore]
10
11   def index
12     @title = t ".title"
13
14     @issue_types = []
15     @issue_types.concat %w[Note] if current_user.moderator?
16     @issue_types.concat %w[DiaryEntry DiaryComment User] if current_user.administrator?
17
18     @users = User.joins(:roles).where(:user_roles => { :role => current_user.roles.map(&:role) }).distinct
19     @issues = Issue.visible_to(current_user)
20
21     # If search
22     if params[:search_by_user]&.present?
23       @find_user = User.find_by(:display_name => params[:search_by_user])
24       if @find_user
25         @issues = @issues.where(:reported_user_id => @find_user.id)
26       else
27         @issues = @issues.none
28         flash.now[:warning] = t(".user_not_found")
29       end
30     end
31
32     @issues = @issues.where(:status => params[:status]) if params[:status]&.present?
33
34     @issues = @issues.where(:reportable_type => params[:issue_type]) if params[:issue_type]&.present?
35
36     if params[:last_updated_by]&.present?
37       last_updated_by = params[:last_updated_by].to_s == "nil" ? nil : params[:last_updated_by].to_i
38       @issues = @issues.where(:updated_by => last_updated_by)
39     end
40   end
41
42   def show
43     @read_reports = @issue.read_reports
44     @unread_reports = @issue.unread_reports
45     @comments = @issue.comments
46     @related_issues = @issue.reported_user.issues.where(:assigned_role => current_user.roles.map(&:role)) if @issue.reported_user
47     @new_comment = IssueComment.new(:issue => @issue)
48   end
49
50   # Status Transitions
51   def resolve
52     if @issue.resolve
53       @issue.updated_by = current_user.id
54       @issue.save!
55       redirect_to @issue, :notice => t(".resolved")
56     else
57       render :show
58     end
59   end
60
61   def ignore
62     if @issue.ignore
63       @issue.updated_by = current_user.id
64       @issue.save!
65       redirect_to @issue, :notice => t(".ignored")
66     else
67       render :show
68     end
69   end
70
71   def reopen
72     if @issue.reopen
73       @issue.updated_by = current_user.id
74       @issue.save!
75       redirect_to @issue, :notice => t(".reopened")
76     else
77       render :show
78     end
79   end
80
81   private
82
83   def find_issue
84     @issue = Issue.visible_to(current_user).find(params[:id])
85   rescue ActiveRecord::RecordNotFound
86     redirect_to :controller => "errors", :action => "not_found"
87   end
88 end