]> git.openstreetmap.org Git - rails.git/blob - app/controllers/reports_controller.rb
Store the report category.
[rails.git] / app / controllers / reports_controller.rb
1 class ReportsController < ApplicationController
2   layout "site"
3
4   before_action :authorize_web
5   before_action :require_user
6
7   def new
8     if create_new_report_params.present?
9       @report = Report.new
10       @report.issue = Issue.find_or_initialize_by(create_new_report_params)
11     end
12   end
13
14   def create
15     @report = current_user.reports.new(report_params)
16     @report.issue = Issue.find_or_initialize_by(:reportable_id => params[:report][:issue][:reportable_id], :reportable_type => params[:report][:issue][:reportable_type])
17
18     if @report.save
19       @report.issue.save
20       # FIXME: reopen issue if necessary
21       # FIXME: new issue notification (or via model observer)
22       redirect_to root_path, :notice => t("issues.create.successful_report")
23     else
24       redirect_to new_report_path(:reportable_type => @report.issue.reportable_type, :reportable_id => @report.issue.reportable_id), :notice => t("issues.create.provide_details")
25     end
26   end
27
28   private
29
30   def create_new_report_params
31     params.permit(:reportable_id, :reportable_type)
32   end
33
34   def report_params
35     params[:report].permit(:details, :category)
36   end
37 end