]> git.openstreetmap.org Git - rails.git/blob - app/controllers/issues_controller.rb
Merge pull request #1558 from plarus/master
[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 Transistions
51   def resolve
52     if @issue.resolve
53       @issue.save!
54       redirect_to @issue, :notice => t(".resolved")
55     else
56       render :show
57     end
58   end
59
60   def ignore
61     if @issue.ignore
62       @issue.updated_by = current_user.id
63       @issue.save!
64       redirect_to @issue, :notice => t(".ignored")
65     else
66       render :show
67     end
68   end
69
70   def reopen
71     if @issue.reopen
72       @issue.updated_by = current_user.id
73       @issue.save!
74       redirect_to @issue, :notice => t(".reopened")
75     else
76       render :show
77     end
78   end
79
80   private
81
82   def find_issue
83     @issue = Issue.visible_to(current_user).find(params[:id])
84   rescue ActiveRecord::RecordNotFound
85     redirect_to :controller => "errors", :action => "not_found"
86   end
87 end