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