From: Andy Allan Date: Wed, 14 Mar 2018 09:09:57 +0000 (+0800) Subject: Add a redirect and error message if user ends up trying to report something without... X-Git-Tag: live~3005^2~20 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/2fc70be734fb6439b1eef340d396af62965817df Add a redirect and error message if user ends up trying to report something without the correct parameters --- diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index 5d0442731..4d2220a26 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -5,9 +5,11 @@ class ReportsController < ApplicationController before_action :require_user def new - if create_new_report_params.present? + if required_new_report_params_present? @report = Report.new @report.issue = Issue.find_or_initialize_by(create_new_report_params) + else + redirect_to root_path, :notice => t("reports.new.missing_params") end end @@ -26,6 +28,10 @@ class ReportsController < ApplicationController private + def required_new_report_params_present? + create_new_report_params['reportable_id'].present? && create_new_report_params['reportable_type'].present? + end + def create_new_report_params params.permit(:reportable_id, :reportable_type) end diff --git a/config/locales/en.yml b/config/locales/en.yml index d57bc65aa..afc100dc9 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1039,6 +1039,7 @@ en: reports: new: title_html: "Report %{link}" + missing_params: "Cannot create a new report" categories: diary_entry: spam: This diary entry is/contains spam diff --git a/test/system/report_diary_entry_test.rb b/test/system/report_diary_entry_test.rb index 3be8b3fd7..e9262388a 100644 --- a/test/system/report_diary_entry_test.rb +++ b/test/system/report_diary_entry_test.rb @@ -49,4 +49,10 @@ class ReportDiaryEntryTest < ApplicationSystemTestCase assert !issue.resolved? assert issue.open? end + + def test_missing_report_params + sign_in_as(create(:user)) + visit new_report_path + assert page.has_content? I18n.t("reports.new.missing_params") + end end