]> git.openstreetmap.org Git - rails.git/blob - app/controllers/issues_controller.rb
Merge pull request #4587 from AntonKhorev/changeset-comment-routes
[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       if @find_user
31         @issues = @issues.where(:reported_user => @find_user)
32       else
33         @issues = @issues.none
34         flash.now[:warning] = t(".user_not_found")
35       end
36     end
37
38     @issues = @issues.where(:status => params[:status]) if params[:status].present?
39
40     @issues = @issues.where(:reportable_type => params[:issue_type]) if params[:issue_type].present?
41
42     if params[:last_updated_by].present?
43       last_updated_by = params[:last_updated_by].to_s == "nil" ? nil : params[:last_updated_by].to_i
44       @issues = @issues.where(:updated_by => last_updated_by)
45     end
46
47     @issues, @newer_issues_id, @older_issues_id = get_page_items(@issues, :limit => @params[:limit])
48     render :partial => "page" if turbo_frame_request_id == "pagination"
49   end
50
51   def show
52     @title = t ".title", :status => @issue.status.humanize, :issue_id => @issue.id
53     @read_reports = @issue.read_reports
54     @unread_reports = @issue.unread_reports
55     @comments = @issue.comments
56     @related_issues = @issue.reported_user.issues.where(:assigned_role => current_user.roles.map(&:role)) if @issue.reported_user
57     @new_comment = IssueComment.new(:issue => @issue)
58   end
59
60   # Status Transitions
61   def resolve
62     if @issue.resolve
63       @issue.updated_by = current_user.id
64       @issue.save!
65       redirect_to @issue, :notice => t(".resolved")
66     else
67       render :show
68     end
69   end
70
71   def ignore
72     if @issue.ignore
73       @issue.updated_by = current_user.id
74       @issue.save!
75       redirect_to @issue, :notice => t(".ignored")
76     else
77       render :show
78     end
79   end
80
81   def reopen
82     if @issue.reopen
83       @issue.updated_by = current_user.id
84       @issue.save!
85       redirect_to @issue, :notice => t(".reopened")
86     else
87       render :show
88     end
89   end
90
91   private
92
93   def find_issue
94     @issue = Issue.visible_to(current_user).find(params[:id])
95   rescue ActiveRecord::RecordNotFound
96     redirect_to :controller => "errors", :action => "not_found"
97   end
98 end