]> git.openstreetmap.org Git - rails.git/blob - app/controllers/issues_controller.rb
Unwind the set_issues method
[rails.git] / app / controllers / issues_controller.rb
1 class IssuesController < ApplicationController
2   layout "site"
3
4   before_action :authorize_web
5   before_action :require_user
6   before_action :check_permission
7   before_action :find_issue, :only => [:show, :resolve, :reopen, :ignore]
8
9   def index
10     @title = t ".title"
11
12     if current_user.moderator?
13       @issue_types = %w[Note]
14       @users = User.joins(:roles).where(:user_roles => { :role => "moderator" })
15     else
16       @issue_types = %w[DiaryEntry DiaryComment User]
17       @users = User.joins(:roles).where(:user_roles => { :role => "administrator" })
18     end
19
20     @issues = Issue.where(:assigned_role => current_user.roles.map(&:role))
21
22     # If search
23     if params[:search_by_user] && params[:search_by_user].present?
24       @find_user = User.find_by(:display_name => params[:search_by_user])
25       if @find_user
26         @issues = @issues.where(:reported_user_id => @find_user.id)
27       else
28         notice = t("issues.index.user_not_found")
29       end
30     end
31
32     @issues = @issues.where(:status => params[:status][0]) if params[:status] && params[:status][0].present?
33
34     @issues = @issues.where(:reportable_type => params[:issue_type][0]) if params[:issue_type] && params[:issue_type][0].present?
35
36     if params[:last_updated_by] && params[:last_updated_by][0].present?
37       last_updated_by = params[:last_updated_by][0].to_s == "nil" ? nil : params[:last_updated_by][0].to_i
38       @issues = @issues.where(:updated_by => last_updated_by)
39     end
40
41     redirect_to issues_path, :notice => notice if notice
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 Transistions
53   def resolve
54     if @issue.resolve
55       @issue.save!
56       redirect_to @issue, :notice => t("issues.resolved")
57     else
58       render :show
59     end
60   end
61
62   def ignore
63     if @issue.ignore
64       @issue.updated_by = current_user.id
65       @issue.save!
66       redirect_to @issue, :notice => t("issues.ignored")
67     else
68       render :show
69     end
70   end
71
72   def reopen
73     if @issue.reopen
74       @issue.updated_by = current_user.id
75       @issue.save!
76       redirect_to @issue, :notice => t("issues.reopened")
77     else
78       render :show
79     end
80   end
81
82   private
83
84   def find_issue
85     @issue = Issue.find(params[:id])
86   end
87
88   def check_permission
89     unless current_user.administrator? || current_user.moderator?
90       flash[:error] = t("application.require_moderator_or_admin.not_a_moderator_or_admin")
91       redirect_to root_path
92     end
93   end
94 end