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