From: Andy Allan Date: Wed, 13 Dec 2017 16:02:55 +0000 (+0000) Subject: Store the report category. X-Git-Tag: live~2953^2~69 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/63992d83bdf3c2489e10504957bb57ed29976803?ds=sidebyside Store the report category. --- diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index 6c62deb30..781c3af66 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -8,8 +8,6 @@ class ReportsController < ApplicationController 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 @@ -34,6 +32,6 @@ class ReportsController < ApplicationController end def report_params - params[:report].permit(:details) + params[:report].permit(:details, :category) end end diff --git a/app/models/report.rb b/app/models/report.rb index e32e09721..eda70f865 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -6,6 +6,7 @@ # issue_id :integer # user_id :integer # details :text not null +# category :string not null # created_at :datetime not null # updated_at :datetime not null # @@ -25,4 +26,16 @@ class Report < ActiveRecord::Base belongs_to :user validates :details, :presence => true + validates :category, :presence => true + + def self.categories_for(reportable) + case reportable.class.name + when "DiaryEntry" then %w[spam offensive threat other] + when "DiaryComment" then %w[spam offensive threat other] + when "User" then %w[spam offensive threat vandal other] + when "Changeset" then %w[undiscussed_import mechanical_edit edit_error spam vandalism other] + when "Note" then %w[spam vandalism personal abusive other] + else %w[other] + end + end end diff --git a/app/views/issues/_reports.html.erb b/app/views/issues/_reports.html.erb index 68e69ee72..9f180d1c0 100644 --- a/app/views/issues/_reports.html.erb +++ b/app/views/issues/_reports.html.erb @@ -8,6 +8,10 @@ On <%= l report.updated_at.to_datetime, :format => :friendly %>
+ + Category: <%= report.category %> + +
<%= report.details %>
diff --git a/app/views/reports/new.html.erb b/app/views/reports/new.html.erb index 6dad7aa43..a39b5b151 100644 --- a/app/views/reports/new.html.erb +++ b/app/views/reports/new.html.erb @@ -23,10 +23,10 @@

<%= t('issues.new.select') %>:

- <% @report_strings_yaml.each do |k,v| %> + <% Report.categories_for(@report.issue.reportable).each do |c| %>
- <%= radio_button_tag :report_type, v[:type].to_s %> - <%= label_tag v[:details].to_s %>
+ <%= radio_button :report, :category, c %> + <%= label_tag "report_category_#{c}", t("reports.categories.#{@report.issue.reportable.class.name}.#{c}") %>
<% end %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index f8ca248b1..7c127ffc7 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -940,84 +940,37 @@ en: resolved: Issue status has been set to 'Resolved' ignored: Issue status has been set to 'Ignored' reopened: Issue status has been set to 'Open' - report_strings: + reports: + categories: DiaryEntry: - spam: - type: "[SPAM]" - details: This Diary Entry is/contains spam - offensive: - type: "[OFFENSIVE]" - details: This Diary Entry is obscene/offensive - threat: - type: "[THREAT]" - details: This Diary Entry contains a threat - other: - type: "[OTHER]" - details: Other + spam: This Diary Entry is/contains spam + offensive: This Diary Entry is obscene/offensive + threat: This Diary Entry contains a threat + other: Other DiaryComment: - spam: - type: "[SPAM]" - details: This Diary Comment is/contains spam - offensive: - type: "[OFFENSIVE]" - details: This Diary Comment is obscene/offensive - threat: - type: "[THREAT]" - details: This Diary Comment contains a threat - other: - type: "[OTHER]" - details: Other + spam: This Diary Comment is/contains spam + offensive: This Diary Comment is obscene/offensive + threat: This Diary Comment contains a threat + other: Other User: - spam: - type: "[SPAM]" - details: This User profile is/contains spam - offensive: - type: "[OFFENSIVE]" - details: This User profile is obscene/offensive - threat: - type: "[THREAT]" - details: This User profile contains a threat - vandal: - type: "[VANDAL]" - details: This User is a vandal - other: - type: "[OTHER]" - details: Other + spam: This User profile is/contains spam + offensive: This User profile is obscene/offensive + threat: This User profile contains a threat + vandal: This User is a vandal + other: Other Changeset: - undiscussed_import: - type: "[UNDISCUSSED-IMPORT]" - details: This changeset is an undiscussed import - mechanical_edit: - type: "[MECH-EDIT]" - details: This changeset is a mechanical edit - edit_error: - type: "[EDIT-ERROR]" - details: This changeset contains a newbie or an editor error - spam: - type: "[SPAM]" - details: This changeset is/contains spam - vandalism: - type: "[VANDALISM]" - details: This changeset is/contains vandalism - other: - type: "[OTHER]" - details: Other + undiscussed_import: This changeset is an undiscussed import + mechanical_edit: This changeset is a mechanical edit + edit_error: This changeset contains a newbie or an editor error + spam: This changeset is/contains spam + vandalism: This changeset is/contains vandalism + other: Other Note: - spam: - type: "[SPAM]" - details: This note is spam - vandalism: - type: "[VANDALISM]" - details: This note is vandalism - personal: - type: "[PERSONAL]" - details: This note contains personal data - abusive: - type: "[ABUSIVE]" - details: This note is abusive - other: - type: "[OTHER]" - details: Other + spam: This note is spam + vandalism: This note is vandalism + personal: This note contains personal data + abusive: This note is abusive + other: Other layouts: project_name: # in diff --git a/db/migrate/20160822153055_create_issues_and_reports.rb b/db/migrate/20160822153055_create_issues_and_reports.rb index a9ba96554..4361c9528 100644 --- a/db/migrate/20160822153055_create_issues_and_reports.rb +++ b/db/migrate/20160822153055_create_issues_and_reports.rb @@ -24,6 +24,7 @@ class CreateIssuesAndReports < ActiveRecord::Migration[5.0] t.integer :issue_id t.integer :user_id t.text :details, :null => false + t.string :category, :null => false t.timestamps :null => false end diff --git a/db/structure.sql b/db/structure.sql index f01cbfbbc..c7613fca4 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -1067,6 +1067,7 @@ CREATE TABLE reports ( issue_id integer, user_id integer, details text NOT NULL, + category character varying NOT NULL, created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL ); diff --git a/test/controllers/reports_controller_test.rb b/test/controllers/reports_controller_test.rb index d061e284a..206958ab8 100644 --- a/test/controllers/reports_controller_test.rb +++ b/test/controllers/reports_controller_test.rb @@ -20,10 +20,12 @@ class ReportsControllerTest < ActionController::TestCase assert_response :success assert_difference "Issue.count", 1 do details = "Details of a report" + category = "other" post :create, :params => { :report => { :details => details, + :category => category, :issue => { :reportable_id => target_user.id, :reportable_type => "User" } } } @@ -47,10 +49,12 @@ class ReportsControllerTest < ActionController::TestCase assert_response :success assert_difference "Issue.count", 1 do details = "Details of a report" + category = "other" post :create, :params => { :report => { :details => details, + :category => category, :issue => { :reportable_id => target_user.id, :reportable_type => "User" } } } @@ -64,9 +68,11 @@ class ReportsControllerTest < ActionController::TestCase # Report without details assert_no_difference "Issue.count" do + category = "other" post :create, :params => { :report => { + :category => category, :issue => { :reportable_id => 1, :reportable_type => "User" } } } @@ -89,10 +95,12 @@ class ReportsControllerTest < ActionController::TestCase assert_response :success assert_difference "Issue.count", 1 do details = "Details of a report" + category = "other" post :create, :params => { :report => { :details => details, + :category => category, :issue => { :reportable_id => target_user.id, :reportable_type => "User" } } } @@ -106,10 +114,12 @@ class ReportsControllerTest < ActionController::TestCase assert_response :success assert_no_difference "Issue.count" do details = "Details of another report under the same issue" + category = "other" post :create, :params => { :report => { :details => details, + :category => category, :issue => { :reportable_id => target_user.id, :reportable_type => "User" } } } diff --git a/test/factories/reports.rb b/test/factories/reports.rb index 3945bfd3c..7936d46b2 100644 --- a/test/factories/reports.rb +++ b/test/factories/reports.rb @@ -1,6 +1,7 @@ FactoryBot.define do factory :report do sequence(:details) { |n| "Report details #{n}" } + category "other" issue user end diff --git a/test/models/report_test.rb b/test/models/report_test.rb index 2ababa988..fad76297b 100644 --- a/test/models/report_test.rb +++ b/test/models/report_test.rb @@ -8,4 +8,12 @@ class ReportTest < ActiveSupport::TestCase report.details = "" assert !report.valid? end + + def test_category_required + report = create(:report) + + assert report.valid? + report.category = "" + assert !report.valid? + end end diff --git a/test/system/report_diary_entry_test.rb b/test/system/report_diary_entry_test.rb index 36cd36030..bf8d82986 100644 --- a/test/system/report_diary_entry_test.rb +++ b/test/system/report_diary_entry_test.rb @@ -22,7 +22,7 @@ class ReportDiaryEntryTest < ApplicationSystemTestCase assert page.has_content? "Report" assert page.has_content? I18n.t("issues.new.disclaimer.intro") - choose "report_type__SPAM" # FIXME: use label text when the radio button labels are working + choose I18n.t("reports.categories.DiaryEntry.spam") fill_in "report_details", :with => "This is advertising" click_on "Save changes"