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