Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow reporting of abusive users to moderators or admins #1576

Merged
merged 158 commits into from Jun 16, 2018
Merged
Show file tree
Hide file tree
Changes from 146 commits
Commits
Show all changes
158 commits
Select commit Hold shift + click to select a range
5add3cf
Basic models set up
sbagroy986 May 16, 2015
453f758
Controllers + a few tests + new notification added. Work pending on t…
sbagroy986 May 20, 2015
d49922e
Added authorization + issues dashboard
sbagroy986 May 26, 2015
683722e
Added IssueComments + ForeignKeys + Indexes
sbagroy986 May 28, 2015
bdc6add
basic UI for reporting diary entries,diary entry comments and user pr…
sbagroy986 May 28, 2015
d1d4f81
DB changes + Related issues added
sbagroy986 Jun 1, 2015
faf4c5a
Fixed tests + Added new ones
sbagroy986 Jun 1, 2015
d5f0296
Fixed tests + Altered migration file + Added reporting strings + Adde…
sbagroy986 Jun 4, 2015
cf4cfc5
Moved strings to locales + Added 'Issues' button + Fixed typo in tests
sbagroy986 Jun 7, 2015
c7bc136
Issue reopens on Reports coming in after instance update
sbagroy986 Jun 10, 2015
0a3dd82
Added search for issues
sbagroy986 Jun 10, 2015
fb78544
Proper implementation of report strings + cleaning up
sbagroy986 Jun 11, 2015
f72c34a
Added Issue Type + Issue Reassigning + Last updated_by
sbagroy986 Jun 13, 2015
dc17388
Small changes
sbagroy986 Jun 13, 2015
e74163d
Replaced check_box_tags with radio_button
sbagroy986 Jun 15, 2015
965f32d
Fixed existing tests
sbagroy986 Jun 18, 2015
25737ce
Added a few tests
sbagroy986 Jun 19, 2015
cf63920
Added a few more tests
sbagroy986 Jun 19, 2015
b68b29b
Added support for reporting Changesets + Deleting issues from the CLI
sbagroy986 Jun 19, 2015
b17f9a6
Fixed an error + Added email notifications for moderators
sbagroy986 Jun 20, 2015
4b4b67a
Added report strings for Changesets and Notes + minor controller changes
sbagroy986 Jun 21, 2015
732e1ab
Fixed link to DiaryComments
sbagroy986 Jul 16, 2015
206e130
Added report icon + changes to admin UI + changes to report form + fe…
sbagroy986 Jul 18, 2015
69c1f6d
Added sortable headers + search + reportable Notes
sbagroy986 Jul 20, 2015
b598979
Changed report button + Added disclaimer on report page + Added searc…
sbagroy986 Jul 21, 2015
eb79b15
Fixed error
sbagroy986 Aug 1, 2015
ed84930
UI changes + Redirection after creating report fixed
sbagroy986 Aug 13, 2015
81b6599
Fixed related issues positioning
sbagroy986 Aug 13, 2015
916f2c9
Added helper + minor UI changes
sbagroy986 Aug 14, 2015
788d9c1
Update en.yml
emacsen Aug 18, 2015
4905046
Update en-GB.yml
sbagroy986 Aug 19, 2015
f3519e9
fix build on wily; fix some moderation branch language constants
woodpeck Feb 28, 2016
5cc0eba
Reordered migrations to make them the latest.
zerebubuth Aug 22, 2016
757a1aa
Made rubocop happy by formatting and minor syntax tweaks.
zerebubuth Aug 22, 2016
c3ad6aa
More whitespace fixes. Attempting to get tests to pass.
zerebubuth Aug 22, 2016
82ac68a
Revert changes to old migration.
zerebubuth Aug 22, 2016
1190162
More cleanup after tests.
zerebubuth Aug 22, 2016
2278aec
Revert changes to Vagrantfile
gravitystorm Jul 5, 2017
26210d6
Remove unused files
gravitystorm Jul 5, 2017
d56b140
Whitespace fixes.
gravitystorm Jul 5, 2017
9046b5b
Revert unrelated changes from db/structure.sql
gravitystorm Jul 5, 2017
dbd88d8
Merge branch 'master' into moderation
gravitystorm Jul 12, 2017
6f375ef
Get tests passing. Use factories instead of fixtures.
gravitystorm Jul 12, 2017
99df5f6
Rename association to reported_user, for clarity
gravitystorm Jul 12, 2017
65e1dbb
Rubocop autofixes.
gravitystorm Jul 12, 2017
506c0b5
Set the reported_user in a callback
gravitystorm Jul 12, 2017
9c1c696
Remove indirection.
gravitystorm Jul 12, 2017
c1cdddf
Use rails 5 version of redirect_back.
gravitystorm Jul 12, 2017
e31376e
Merge branch 'master' into moderation
gravitystorm Aug 2, 2017
3e4255e
Use current_user instead of @user.
gravitystorm Aug 2, 2017
9804225
Avoid passing the current_user.id when commenting
gravitystorm Aug 2, 2017
47d8d79
Add minitest-rails-capybara
gravitystorm Sep 6, 2017
2b617b7
Add a basic feature test for reporting diary entries.
gravitystorm Sep 6, 2017
4ff6027
Check that the flag is not show when not logged in
gravitystorm Sep 6, 2017
b578cee
Remove the border around the radio boxes
gravitystorm Sep 6, 2017
948fd8c
Use reports_count so that counter_cache works automatically.
gravitystorm Sep 6, 2017
d7612f4
Refactor creating a new report to use a ReportsController
gravitystorm Sep 6, 2017
c00c515
Ensure report details are not blank.
gravitystorm Sep 6, 2017
67a95ac
Remove created_at / updated_at column definitions since these duplica…
gravitystorm Sep 13, 2017
a0b665f
Add missing structure.sql changes from 948fd8c8faf1016d
gravitystorm Sep 13, 2017
33c43ab
Ensure that issue comments have associated issues and users.
gravitystorm Sep 13, 2017
659270d
The link is to the list of issues, not of reports, and there's no nee…
gravitystorm Sep 13, 2017
7ffec2e
Rework the 'issues not found' notice slightly.
gravitystorm Sep 13, 2017
f0e3a41
Fix parameter spacing
gravitystorm Sep 13, 2017
8cf16fe
Create an IssueCommentsController for managing IssueComments
gravitystorm Sep 13, 2017
dd619fb
Remove some more of the structured-details stuff
gravitystorm Sep 13, 2017
effb1b7
Merge branch 'master' into moderation
gravitystorm Nov 29, 2017
3115fd4
Remove minitest-rails-capybara and convert feature tests to system tests
gravitystorm Nov 29, 2017
f522865
Refactor factories to use FactoryBot
gravitystorm Nov 29, 2017
fc00962
Annotate models.
gravitystorm Nov 29, 2017
68213e3
Adjust for rails5 convention on migrations.
gravitystorm Nov 29, 2017
2dd8f09
Remove the reassign column from issue_comments
gravitystorm Nov 29, 2017
1d24228
Combine migrations into one
gravitystorm Nov 29, 2017
1956ab5
Use a simple user_id for tables with one owning user
gravitystorm Nov 29, 2017
546d13c
Remove the reassign boolean display
gravitystorm Nov 29, 2017
9f65820
Rubocop fixes.
gravitystorm Nov 29, 2017
3276063
Remove column sorting
gravitystorm Nov 29, 2017
a09e3f3
Move and amend the issue comment controller tests.
gravitystorm Nov 29, 2017
8e859b0
Index page no longer redirects when there's no issues.
gravitystorm Nov 29, 2017
1766c32
Move controller tests for new reports into seperate file, and adapt t…
gravitystorm Nov 29, 2017
f0bcdae
Put the expected value first in assert_equal
gravitystorm Nov 29, 2017
9ce0060
Remove the test around missing report_type, since we're not currently…
gravitystorm Nov 29, 2017
ca032e0
Convert issue search tests to system tests
gravitystorm Nov 29, 2017
c40ad9d
Remove the hardcoded pixel width for columns.
gravitystorm Dec 6, 2017
0df788d
Rename 'issue_type' to 'assigned_role', set defaults in the model and…
gravitystorm Dec 6, 2017
cbe707b
Validate the assigned role, and remove the :type activrecord enum
gravitystorm Dec 6, 2017
8dc8479
Re-enable issue reassigning.
gravitystorm Dec 6, 2017
875e588
Show issues based on all the users roles
gravitystorm Dec 6, 2017
63992d8
Store the report category.
gravitystorm Dec 13, 2017
a79d951
Remove a couple of unused style rules.
gravitystorm Dec 13, 2017
e0faf68
Remove new issue notifications for now
gravitystorm Dec 13, 2017
3d0c905
Revert en-GB.yml to master.
gravitystorm Dec 13, 2017
02c9806
Remove unused update method from issues_controller.
gravitystorm Dec 13, 2017
e3054fc
Fix some reporting links.
gravitystorm Dec 13, 2017
cba08bb
Simplify permissions check.
gravitystorm Dec 13, 2017
e23ff48
Revert whitespace changes.
gravitystorm Dec 13, 2017
3a386f1
Reopen issues if necessary when creating a report.
gravitystorm Jan 21, 2018
ae44879
Merge branch 'master' into moderation
gravitystorm Jan 21, 2018
79bd177
Fully internationalise the issues and reports interfaces.
gravitystorm Jan 22, 2018
7b5e0d9
resolve last_reported_by vs last_updated_by duplication
gravitystorm Feb 23, 2018
2d915b0
Avoid submit_tag to avoid 'Save changes' default
gravitystorm Feb 23, 2018
0366c2e
Rework status search to avoid relying on the enum ids, and also to al…
gravitystorm Feb 28, 2018
75e178e
Allow the status to be translated in the table of results
gravitystorm Feb 28, 2018
b955a7e
Link to diary comments using anchors, rather than showing them alone
gravitystorm Feb 28, 2018
38efcc2
Remove the report_type helper and use the model_name.human to look up…
gravitystorm Feb 28, 2018
2a89bf2
Refactor reportable_url helper to focus on just the title choices.
gravitystorm Feb 28, 2018
3bd0652
Refactor reportable_url to just return the url
gravitystorm Feb 28, 2018
80a241f
Allow reporting of anonymous notes
gravitystorm Feb 28, 2018
3006ce9
Remove reporting of changesets
gravitystorm Feb 28, 2018
05ae075
Rearrange issues table and combine some columns.
gravitystorm Feb 28, 2018
8587c2a
Rework the new report form text and layout
gravitystorm Feb 28, 2018
7821bf4
Reposition the note and user report flags
gravitystorm Feb 28, 2018
424b6ef
Merge branch 'master' into moderation
gravitystorm Feb 28, 2018
a20e288
Merge branch 'master' into moderation
gravitystorm Feb 28, 2018
1c04af4
Update tests for new link text
gravitystorm Feb 28, 2018
04a87bb
Rubocop fixes
gravitystorm Feb 28, 2018
508bb04
Remove unused code
gravitystorm Mar 5, 2018
0737c4f
Fix grammar
gravitystorm Mar 14, 2018
36970bc
Use underscore versions of model names for translation keys.
gravitystorm Mar 14, 2018
59ca99d
Use lower case to refer to reportable objects
gravitystorm Mar 14, 2018
e851109
Remove vandalism as an option for reporting notes.
gravitystorm Mar 14, 2018
13e7a4b
Increase padding around report disclaimer
gravitystorm Mar 14, 2018
e44f856
Combine category and reporting user
gravitystorm Mar 14, 2018
aaaeb21
Combine last_updated_by and last_updated_at columns on issues index
gravitystorm Mar 14, 2018
05b871d
Avoid wrapping in the reports count column
gravitystorm Mar 14, 2018
9e46754
User user_path to generate links to users
gravitystorm Mar 14, 2018
e41751f
Use th instead of td and b
gravitystorm Mar 14, 2018
0490186
Apply list styling to list of related reports
gravitystorm Mar 14, 2018
870a497
Remove unnecessary div
gravitystorm Mar 14, 2018
c1bb412
Fix class name
gravitystorm Mar 14, 2018
5e7abf6
Remove nonsense has_one relationship
gravitystorm Mar 14, 2018
3e5a4a1
Ensure reports have an issue id and a user id
gravitystorm Mar 14, 2018
5310c70
Remove cascading deletes, add another foreign key, and switch index a…
gravitystorm Mar 14, 2018
e7e12a3
Create a more accurate permissions check message
gravitystorm Mar 14, 2018
6bcffbf
Unwind the set_issues method
gravitystorm Mar 14, 2018
283cffd
Handle current_user being both an admin and a moderator for building …
gravitystorm Mar 14, 2018
85bf9ad
Handle issue_types properly if current_user is both and admin and a m…
gravitystorm Mar 14, 2018
2fc70be
Add a redirect and error message if user ends up trying to report som…
gravitystorm Mar 14, 2018
696bbd1
Redirect to the reportable after creating a report.
gravitystorm Mar 14, 2018
facce9d
Refactor set_default_assigned_role to be more easily read.
gravitystorm Mar 14, 2018
ee1a863
Convert issue status to an enum
gravitystorm Mar 21, 2018
32d1afb
Create a report_link helper, and use text instead of a flag icon
gravitystorm Mar 21, 2018
918a382
Use options_for_select to set the selected items in the search form
gravitystorm Mar 21, 2018
c71fd54
Avoid sending a commit value from from the search button
gravitystorm Mar 21, 2018
ab31506
Update system tests for report link changes
gravitystorm Mar 28, 2018
46c183f
Add more tests
gravitystorm Mar 28, 2018
7dbf8d8
Merge branch 'master' into moderation
gravitystorm Apr 11, 2018
f227804
Add some extra indexes on issues
tomhughes Jun 10, 2018
e894243
Use select_tag for issue filter fields instead of abusing select
tomhughes Jun 10, 2018
5effa0a
Avoid losing filter settings when an invalid user is entered
tomhughes Jun 10, 2018
2aca692
Use lazy lookups for translations in issues
tomhughes Jun 10, 2018
d3700e6
Merge branch 'master' into next
tomhughes Jun 10, 2018
f7d0a60
Make reportable item titles translatable
tomhughes Jun 10, 2018
5e2c567
Make report type a required field
tomhughes Jun 10, 2018
22385c1
Improve controller tests for issues
tomhughes Jun 10, 2018
518cf69
Improve model tests for issues
tomhughes Jun 10, 2018
29f12c4
Improve system tests for issues
tomhughes Jun 10, 2018
2767935
Default to only showing open issues
tomhughes Jun 10, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Expand Up @@ -67,7 +67,7 @@ Metrics/AbcSize:
# Offense count: 41
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
Max: 240
Max: 250

# Offense count: 12
# Configuration parameters: CountBlocks.
Expand Down
3 changes: 3 additions & 0 deletions Gemfile
Expand Up @@ -70,6 +70,9 @@ gem "omniauth-windowslive"
# Markdown formatting support
gem "redcarpet"

# For status transitions of Issues
gem "aasm"

# Load libxml support for XML parsing and generation
gem "libxml-ruby", ">= 2.0.5", :require => "libxml"

Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Expand Up @@ -2,6 +2,7 @@ GEM
remote: https://rubygems.org/
specs:
SystemTimer (1.2.3)
aasm (4.1.0)
actioncable (5.1.5)
actionpack (= 5.1.5)
nio4r (~> 2.0)
Expand Down Expand Up @@ -354,6 +355,7 @@ PLATFORMS

DEPENDENCIES
SystemTimer (>= 1.1.3)
aasm
actionpack-page_caching
annotate
autoprefixer-rails
Expand Down
56 changes: 56 additions & 0 deletions app/assets/stylesheets/common.scss
Expand Up @@ -2818,3 +2818,59 @@ input.richtext_title[type="text"] {
display: none;
}
}

.read-reports {
background: #eee;
opacity: 0.7;
}

.report-related-block {
display:inline-block;
}

.report-block {
width:475px;
float:left;
margin-right:100px;
}

.related-reports {
width: 280px;
float: right;

ul {
padding-left: $lineheight;
margin-bottom: 0;

li {
list-style: disc;
}
}
}

.issue-comments {
width:475px;
}

.issues-list {
td:nth-child(2) {
white-space: nowrap;
}
}

.report-disclaimer {
background: #fff1f0;
color: #d85030;
border-color: rgba(216, 80, 48, 0.3);
padding: 10px 20px;
margin-bottom: $lineheight;

ul {
padding-left: $lineheight;
margin-bottom: 0;

li {
list-style: disc;
}
}
}
37 changes: 37 additions & 0 deletions app/controllers/issue_comments_controller.rb
@@ -0,0 +1,37 @@
class IssueCommentsController < ApplicationController
layout "site"

before_action :authorize_web
before_action :require_user
before_action :check_permission

def create
@issue = Issue.find(params[:issue_id])
comment = @issue.comments.build(issue_comment_params)
comment.user = current_user
comment.save!
notice = t("issues.comment.comment_created")
reassign_issue(@issue) if params[:reassign]
redirect_to @issue, :notice => notice
end

private

def issue_comment_params
params.require(:issue_comment).permit(:body)
end

def check_permission
unless current_user.administrator? || current_user.moderator?
flash[:error] = t("application.require_moderator_or_admin.not_a_moderator_or_admin")
redirect_to root_path
end
end

# This sort of assumes there are only two roles
def reassign_issue(issue)
role = (Issue::ASSIGNED_ROLES - [issue.assigned_role]).first
issue.assigned_role = role
issue.save!
end
end
91 changes: 91 additions & 0 deletions app/controllers/issues_controller.rb
@@ -0,0 +1,91 @@
class IssuesController < ApplicationController
layout "site"

before_action :authorize_web
before_action :require_user
before_action :check_permission
before_action :find_issue, :only => [:show, :resolve, :reopen, :ignore]

def index
@title = t ".title"

@issue_types = []
@issue_types.concat %w[Note] if current_user.moderator?
@issue_types.concat %w[DiaryEntry DiaryComment User] if current_user.administrator?

@users = User.joins(:roles).where(:user_roles => { :role => current_user.roles.map(&:role) }).distinct
@issues = Issue.where(:assigned_role => current_user.roles.map(&:role))

# If search
if params[:search_by_user] && params[:search_by_user].present?
@find_user = User.find_by(:display_name => params[:search_by_user])
if @find_user
@issues = @issues.where(:reported_user_id => @find_user.id)
else
notice = t("issues.index.user_not_found")
end
end

@issues = @issues.where(:status => params[:status][0]) if params[:status] && params[:status][0].present?

@issues = @issues.where(:reportable_type => params[:issue_type][0]) if params[:issue_type] && params[:issue_type][0].present?

if params[:last_updated_by] && params[:last_updated_by][0].present?
last_updated_by = params[:last_updated_by][0].to_s == "nil" ? nil : params[:last_updated_by][0].to_i
@issues = @issues.where(:updated_by => last_updated_by)
end

redirect_to issues_path, :notice => notice if notice
end

def show
@read_reports = @issue.read_reports
@unread_reports = @issue.unread_reports
@comments = @issue.comments
@related_issues = @issue.reported_user.issues.where(:assigned_role => current_user.roles.map(&:role)) if @issue.reported_user
@new_comment = IssueComment.new(:issue => @issue)
end

# Status Transistions
def resolve
if @issue.resolve
@issue.save!
redirect_to @issue, :notice => t("issues.resolved")
else
render :show
end
end

def ignore
if @issue.ignore
@issue.updated_by = current_user.id
@issue.save!
redirect_to @issue, :notice => t("issues.ignored")
else
render :show
end
end

def reopen
if @issue.reopen
@issue.updated_by = current_user.id
@issue.save!
redirect_to @issue, :notice => t("issues.reopened")
else
render :show
end
end

private

def find_issue
@issue = Issue.find(params[:id])
end

def check_permission
unless current_user.administrator? || current_user.moderator?
flash[:error] = t("application.require_moderator_or_admin.not_a_moderator_or_admin")
redirect_to root_path
end
end
end
42 changes: 42 additions & 0 deletions app/controllers/reports_controller.rb
@@ -0,0 +1,42 @@
class ReportsController < ApplicationController
layout "site"

before_action :authorize_web
before_action :require_user

def new
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

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
@report.issue.reopen! unless @report.issue.open?
redirect_to helpers.reportable_url(@report.issue.reportable), :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 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

def report_params
params[:report].permit(:details, :category)
end
end
27 changes: 27 additions & 0 deletions app/helpers/issues_helper.rb
@@ -0,0 +1,27 @@
module IssuesHelper
def reportable_url(reportable)
case reportable
when DiaryEntry
url_for(:controller => reportable.class.name.underscore, :action => :view, :display_name => reportable.user.display_name, :id => reportable.id)
when User
url_for(:controller => reportable.class.name.underscore, :action => :view, :display_name => reportable.display_name)
when DiaryComment
url_for(:controller => reportable.diary_entry.class.name.underscore, :action => :view, :display_name => reportable.diary_entry.user.display_name, :id => reportable.diary_entry.id, :anchor => "comment#{reportable.id}")
when Note
url_for(:controller => :browse, :action => :note, :id => reportable.id)
end
end

def reportable_title(reportable)
case reportable
when DiaryEntry
reportable.title
when User
reportable.display_name
when DiaryComment
"#{reportable.diary_entry.title}, Comment id ##{reportable.id}"
when Note
"Note ##{reportable.id}"
end
end
end
5 changes: 5 additions & 0 deletions app/helpers/reports_helper.rb
@@ -0,0 +1,5 @@
module ReportsHelper
def report_link(name, reportable)
link_to name, new_report_url(:reportable_id => reportable.id, :reportable_type => reportable.class.name)
end
end