Store the report category.

This commit is contained in:
Andy Allan 2017-12-13 16:02:55 +00:00
parent 875e588348
commit 63992d83bd
11 changed files with 69 additions and 80 deletions

View 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)
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

View file

@ -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

View file

@ -8,6 +8,10 @@
On <%= l report.updated_at.to_datetime, :format => :friendly %>
</span>
<br/>
<span class="deemphasize">
Category: <%= report.category %>
</span>
<br/>
<%= report.details %>
<br/>
</div>

View file

@ -23,10 +23,10 @@
<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">
<%= 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>

View 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'
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 <title>

View 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.string :category, :null => false
t.timestamps :null => false
end

View file

@ -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
);

View file

@ -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" }
}
}

View file

@ -1,6 +1,7 @@
FactoryBot.define do
factory :report do
sequence(:details) { |n| "Report details #{n}" }
category "other"
issue
user
end

View file

@ -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

View file

@ -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"