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