Aggregate multiple abuse reports by the user & category (list-view)
What does this MR do and why?
- Resolves https://gitlab.com/gitlab-org/modelops/anti-abuse/team-tasks/-/issues/180
- It aggregates open abuse reports by user & abuse category, such as
User1 has been reported for spam by 10 users
. Earlier it would list each abuse report as it's own row.
Frontend:
- Adds a new sorting option,
Number of Reports
for open reports. This is the default sorting option for open reports. - Since, closed reports are not aggregated, their default sorting option is still
Created date
- Fixes a minor bug in the filter bar, so that
Status = X
always appears first.
Backend:
- Updates
AbuseReportsFinder
so it aggregates and sorts open reports. Closed reports don't get aggregated. Since, we get a lot of abuse reports, aggregating closed reports would have been not as performative. - Adds
count
to theAbuseReportEntity
with adefault = 1
.
Database
No changes have been made to the tables, but here are the query plans for the new query
Insert Data
# status = closed & category = 1 (10K)
exec INSERT INTO "abuse_reports" ("reporter_id", "user_id", "message", "created_at", "updated_at", "message_html", "cached_markdown_version") SELECT 9670031, user_id, 'spammer', '2023-02-07 09:51:12.678028', '2023-02-07 09:51:12.678028', 'spammer', 2097152 FROM generate_series(4038079, 4048079) as user_id;
# status = open & category = 1 (10K)
exec INSERT INTO "abuse_reports" ("reporter_id", "user_id", "message", "created_at", "updated_at", "message_html", "cached_markdown_version", "category", "status") SELECT 9670031, user_id, 'spammer', '2023-02-07 09:51:12.678028', '2023-02-07 09:51:12.678028', 'spammer', 2097152, 1, 2 FROM generate_series(4038079, 4048079) as user_id;
# status = open & category = 1 & user_id = 9670032 (1K)
exec INSERT INTO "abuse_reports" ("user_id", "reporter_id", "message", "created_at", "updated_at", "message_html", "cached_markdown_version") SELECT 9670032, reporter_id, 'spammer', '2023-02-07 09:51:12.678028', '2023-02-07 09:51:12.678028', 'spammer', 2097152 FROM generate_series(4038079, 4039079) as reporter_id;
- status = open
- status = open and category = spam
- status = open and user_id = 9670032
- status = open and reporter_id = 9670031
Screenshots or screen recordings
Before | After |
---|---|
before | after |
How to set up and validate locally
- In rails console
> Feature.enable(:abuse_reports_list)
# seed data
> AbuseReport.delete_all
# create 10 different reports for the same user & category
> User.limit(10).order_id_asc.pluck("id").each { |i| AbuseReport.create(reporter_id: i, user_id: User.last.id, status: "open", category: "spam", message: "test") }
# create another 10 for the same user but different category
> User.limit(10).order_id_asc.pluck("id").each { |i| AbuseReport.create(reporter_id: i, user_id: User.last.id, status: "open", category: "offensive", message: "test") }
# create 20 more for different users
> User.limit(20).order_id_asc.pluck("id").each { |i| AbuseReport.create(reporter_id: User.first.id, user_id: i, status: "open", category: "crypto", message: "test") }
- Log-in as
admin
and navigate to/admin/abuse_reports
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Hinam Mehra