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