Skip to content

Add notes to abuse report model

What does this MR do and why?

  • Resolves sub-task 1 of https://gitlab.com/gitlab-org/modelops/anti-abuse/team-tasks/-/issues/168
  • Creates a has-many relationship from the AbuseReport model to the Note model
  • Creates Abuse::Reports::UserMention model & abuse_report_user_mentions table
  • Skips namespace & project validation in Note model if the note is for an abuse report
  • Adds AbuseReport as a noteable type

Database

  • Output of db:migrate
main: == 20231003073437 CreateAbuseReportUserMentions: migrating ====================
main: -- create_table(:abuse_report_user_mentions)
main:    -> 0.0057s
main: == 20231003073437 CreateAbuseReportUserMentions: migrated (0.0136s) ===========

main: == 20231003073505 AddAbuseReportsForeignKeyToAbuseReportUserMentions: migrating 
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- execute("ALTER TABLE abuse_report_user_mentions ADD CONSTRAINT fk_088018ecd8 FOREIGN KEY (abuse_report_id) REFERENCES abuse_reports (id) ON DELETE CASCADE NOT VALID;")
main:    -> 0.0013s
main: -- execute("ALTER TABLE abuse_report_user_mentions VALIDATE CONSTRAINT fk_088018ecd8;")
main:    -> 0.0012s
main: == 20231003073505 AddAbuseReportsForeignKeyToAbuseReportUserMentions: migrated (0.0360s) 

main: == 20231003073526 AddNotesForeignKeyToAbuseReportUserMentions: migrating ======
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- execute("ALTER TABLE abuse_report_user_mentions ADD CONSTRAINT fk_a4bd02b7df FOREIGN KEY (note_id) REFERENCES notes (id) ON DELETE CASCADE NOT VALID;")
main:    -> 0.0010s
main: -- execute("ALTER TABLE abuse_report_user_mentions VALIDATE CONSTRAINT fk_a4bd02b7df;")
main:    -> 0.0010s
main: == 20231003073526 AddNotesForeignKeyToAbuseReportUserMentions: migrated (0.0313s) 
  • Output of db:rollback
main: == [advisory_lock_connection] object_id: 222340, pg_backend_pid: 109
main: == 20231003073526 AddNotesForeignKeyToAbuseReportUserMentions: reverting ======
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- remove_foreign_key(:abuse_report_user_mentions, {:column=>:note_id})
main:    -> 0.0209s
main: == 20231003073526 AddNotesForeignKeyToAbuseReportUserMentions: reverted (0.0398s) 

main: == 20231003073505 AddAbuseReportsForeignKeyToAbuseReportUserMentions: reverting 
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- remove_foreign_key(:abuse_report_user_mentions, {:column=>:abuse_report_id})
main:    -> 0.0046s
main: == 20231003073505 AddAbuseReportsForeignKeyToAbuseReportUserMentions: reverted (0.0125s) 

main: == 20231003073437 CreateAbuseReportUserMentions: reverting ====================
main: -- drop_table(:abuse_report_user_mentions, {:if_exists=>true})
main:    -> 0.0016s
main: == 20231003073437 CreateAbuseReportUserMentions: reverted (0.0070s) ===========

How to set up and validate locally

  1. Create an abuse report
> report = AbuseReport.create(user: User.last, reporter: User.first, message: "test")
  1. Create a note and user-mention for the abuse report
> note = Note.create(noteable_type: "AbuseReport", noteable: report, note: "Test note", author: User.first)
> Abuse::Reports::UserMention.create(abuse_report: report, note: note, mentioned_users_ids: [1])
  1. Test that the note and user-mention can be retrieved for the abuse report
> report.notes
> report.user_mentions

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Hinam Mehra

Merge request reports

Loading