]> git.openstreetmap.org Git - rails.git/blob - app/controllers/issues_controller.rb
Create a report_link helper, and use text instead of a flag icon
[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         notice = t("issues.index.user_not_found")
26       end
27     end
28
29     @issues = @issues.where(:status => params[:status][0]) if params[:status] && params[:status][0].present?
30
31     @issues = @issues.where(:reportable_type => params[:issue_type][0]) if params[:issue_type] && params[:issue_type][0].present?
32
33     if params[:last_updated_by] && params[:last_updated_by][0].present?
34       last_updated_by = params[:last_updated_by][0].to_s == "nil" ? nil : params[:last_updated_by][0].to_i
35       @issues = @issues.where(:updated_by => last_updated_by)
36     end
37
38     redirect_to issues_path, :notice => notice if notice
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("issues.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("issues.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("issues.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