]> git.openstreetmap.org Git - rails.git/commitdiff
Store the report category.
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 13 Dec 2017 16:02:55 +0000 (16:02 +0000)
committerAndy Allan <git@gravitystorm.co.uk>
Wed, 13 Dec 2017 16:02:55 +0000 (16:02 +0000)
app/controllers/reports_controller.rb
app/models/report.rb
app/views/issues/_reports.html.erb
app/views/reports/new.html.erb
config/locales/en.yml
db/migrate/20160822153055_create_issues_and_reports.rb
db/structure.sql
test/controllers/reports_controller_test.rb
test/factories/reports.rb
test/models/report_test.rb
test/system/report_diary_entry_test.rb

index 6c62deb30d677db8ae6ac55850c11900685fe996..781c3af66b87021405710388ec7c92f8a2d6a4f8 100644 (file)
@@ -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)
     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
 
     end
   end
 
@@ -34,6 +32,6 @@ class ReportsController < ApplicationController
   end
 
   def report_params
   end
 
   def report_params
-    params[:report].permit(:details)
+    params[:report].permit(:details, :category)
   end
 end
   end
 end
index e32e09721848e75fd8053488c1ef02c635b855f6..eda70f86516e2c65eb8ae4eba27bb2722ae9cdb4 100644 (file)
@@ -6,6 +6,7 @@
 #  issue_id   :integer
 #  user_id    :integer
 #  details    :text             not null
 #  issue_id   :integer
 #  user_id    :integer
 #  details    :text             not null
+#  category   :string           not null
 #  created_at :datetime         not null
 #  updated_at :datetime         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
   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
 end
index 68e69ee72570f83b9a81d1d15c7aa9523e9fbe1e..9f180d1c0ac82f4c9cf0c0128670092d47d64d6e 100644 (file)
@@ -8,6 +8,10 @@
       On <%= l report.updated_at.to_datetime, :format => :friendly %>
     </span>
     <br/>
       On <%= l report.updated_at.to_datetime, :format => :friendly %>
     </span>
     <br/>
+    <span class="deemphasize">
+      Category: <%= report.category %>
+    </span>
+    <br/>
     <%= report.details %>
     <br/>
   </div>
     <%= report.details %>
     <br/>
   </div>
index 6dad7aa43a314069ddbcd2f05a112aacd37ef467..a39b5b15115f7596ba5f56955970cdafa51a4e88 100644 (file)
       <p><%= t('issues.new.select') %>:</p>
 
       <div class="new-report-form">
       <p><%= t('issues.new.select') %>:</p>
 
       <div class="new-report-form">
-        <% @report_strings_yaml.each do |k,v| %>
+        <% Report.categories_for(@report.issue.reportable).each do |c| %>
           <div style="padding-left:5px">
           <div style="padding-left:5px">
-            <%= radio_button_tag :report_type, v[:type].to_s %>
-            <%= label_tag v[:details].to_s %> <br/>
+            <%= radio_button :report, :category, c %>
+            <%= label_tag "report_category_#{c}", t("reports.categories.#{@report.issue.reportable.class.name}.#{c}") %> <br/>
           </div>
         <% end %>
       </div>
           </div>
         <% end %>
       </div>
index f8ca248b1b069c560350052db4bc1497e666007e..7c127ffc7b273b9fa287c42acf7ca93748af2f66 100644 (file)
@@ -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'
     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:
       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:
       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:
       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:
       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:
       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 <title>
   layouts:
     project_name:
       # in <title>
index a9ba965544021d3eee70831c4ef5d06402231da4..4361c95285aa8bb2ed5687d8c41651c79111264d 100644 (file)
@@ -24,6 +24,7 @@ class CreateIssuesAndReports < ActiveRecord::Migration[5.0]
       t.integer :issue_id
       t.integer :user_id
       t.text :details, :null => false
       t.integer :issue_id
       t.integer :user_id
       t.text :details, :null => false
+      t.string :category, :null => false
       t.timestamps :null => false
     end
 
       t.timestamps :null => false
     end
 
index f01cbfbbc7e6bf65f865931d8fce149d0076cb71..c7613fca4051b77182f1ba7dd2f60593435b36f5 100644 (file)
@@ -1067,6 +1067,7 @@ CREATE TABLE reports (
     issue_id integer,
     user_id integer,
     details text NOT NULL,
     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
 );
     created_at timestamp without time zone NOT NULL,
     updated_at timestamp without time zone NOT NULL
 );
index d061e284a18db56a3276c6a3ac6cc88a61f19d33..206958ab88486c568444b90a5d7dee2d50235486 100644 (file)
@@ -20,10 +20,12 @@ class ReportsControllerTest < ActionController::TestCase
     assert_response :success
     assert_difference "Issue.count", 1 do
       details = "Details of a report"
     assert_response :success
     assert_difference "Issue.count", 1 do
       details = "Details of a report"
+      category = "other"
       post :create,
            :params => {
              :report => {
                :details => details,
       post :create,
            :params => {
              :report => {
                :details => details,
+               :category => category,
                :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
              }
            }
                :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"
     assert_response :success
     assert_difference "Issue.count", 1 do
       details = "Details of a report"
+      category = "other"
       post :create,
            :params => {
              :report => {
                :details => details,
       post :create,
            :params => {
              :report => {
                :details => details,
+               :category => category,
                :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
              }
            }
                :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
 
     # Report without details
     assert_no_difference "Issue.count" do
+      category = "other"
       post :create,
            :params => {
              :report => {
       post :create,
            :params => {
              :report => {
+               :category => category,
                :issue => { :reportable_id => 1, :reportable_type => "User" }
              }
            }
                :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"
     assert_response :success
     assert_difference "Issue.count", 1 do
       details = "Details of a report"
+      category = "other"
       post :create,
            :params => {
              :report => {
                :details => details,
       post :create,
            :params => {
              :report => {
                :details => details,
+               :category => category,
                :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
              }
            }
                :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"
     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,
       post :create,
            :params => {
              :report => {
                :details => details,
+               :category => category,
                :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
              }
            }
                :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
              }
            }
index 3945bfd3c89a85069355c27f4bd5e2956d2d3287..7936d46b2d3f4b619a75e9e6437e4d1c878154b3 100644 (file)
@@ -1,6 +1,7 @@
 FactoryBot.define do
   factory :report do
     sequence(:details) { |n| "Report details #{n}" }
 FactoryBot.define do
   factory :report do
     sequence(:details) { |n| "Report details #{n}" }
+    category "other"
     issue
     user
   end
     issue
     user
   end
index 2ababa9888d5c881c18ca04cfca9c8bbd14c4e4b..fad76297bf9f2a178323501a054849692519dbe1 100644 (file)
@@ -8,4 +8,12 @@ class ReportTest < ActiveSupport::TestCase
     report.details = ""
     assert !report.valid?
   end
     report.details = ""
     assert !report.valid?
   end
+
+  def test_category_required
+    report = create(:report)
+
+    assert report.valid?
+    report.category = ""
+    assert !report.valid?
+  end
 end
 end
index 36cd3603053de80f392d2b92d9d352a3ccc078bc..bf8d82986590e0bb3c4f14f48928e59093ebd75a 100644 (file)
@@ -22,7 +22,7 @@ class ReportDiaryEntryTest < ApplicationSystemTestCase
     assert page.has_content? "Report"
     assert page.has_content? I18n.t("issues.new.disclaimer.intro")
 
     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"
 
     fill_in "report_details", :with => "This is advertising"
     click_on "Save changes"