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