openstreetmap-website/app/controllers/reports_controller.rb
Andy Allan d7612f42d0 Refactor creating a new report to use a ReportsController
It's really a report that the user is creating, the issue is created indirectly. Similar
refactoring will be required for issue comments.
2017-09-06 18:06:21 +01:00

39 lines
1.2 KiB
Ruby

class ReportsController < ApplicationController
layout "site"
before_action :authorize_web
before_action :require_user
def new
if create_new_report_params.present?
@report = Report.new
@report.issue = Issue.find_or_initialize_by(create_new_report_params)
path = "issues.report_strings." + @report.issue.reportable.class.name.to_s
@report_strings_yaml = t(path)
end
end
def create
@report = current_user.reports.new(report_params)
@report.issue = Issue.find_or_initialize_by(:reportable_id => params[:report][:issue][:reportable_id], :reportable_type => params[:report][:issue][:reportable_type])
if @report.save
@report.issue.save
# FIXME: reopen issue if necessary
# FIXME: new issue notification (or via model observer)
redirect_to root_path, :notice => t("issues.create.successful_report")
else
redirect_to new_report_path(:reportable_type => @report.issue.reportable_type, :reportable_id => @report.issue.reportable_id), :notice => t("issues.create.provide_details")
end
end
private
def create_new_report_params
params.permit(:reportable_id, :reportable_type)
end
def report_params
params[:report].permit(:details)
end
end