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

process jobs from legal escalations with no abuse reports #23024

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

eviljeff
Copy link
Member

@eviljeff eviljeff commented Jan 27, 2025

Fixes: mozilla/addons#15278

Description

Handles jobs from Cinder that have no abuse report attached. Also correctly clears NHR from the add-on when the legal escalation is made (the other problem noted in the issue)

Context

CinderJobs in general don't have any target information directly fk'd to them - the information is on the AbuseReport, or appealed decision, that led to the job being created. A legal forward doesn't (necessarily) have any appeals or abuse reports associated with it. But for add-on, we do set target_addon, so we can use that instead (which we did already as an optimization, but then failed because there was no abuse report or appeal to reference .rating, etc , which would always have been None for an addon abuse report/appeal anyway).

Testing

  • Forward an add-on with some NHRs (manually create them in django shell if it's easier)
  • see them cleared with the "review" (i.e. the add-on is no longer in the manual review queue)
  • see the job in Cinder legal escalations queue
  • resolve the job in Cinder with an action that would disable the add-on (AUP, etc)
  • playback the webhook response locally
  • see the add-on is disabled

Checklist

  • Add #ISSUENUM at the top of your PR to an existing open issue in the mozilla/addons repository.
  • Successfully verified the change locally.
  • The change is covered by automated tests, or otherwise indicated why doing so is unnecessary/impossible.
  • Add before and after screenshots (Only for changes that impact the UI).
  • Add or update relevant docs reflecting the changes made.

Copy link

sentry-io bot commented Jan 27, 2025

🔍 Existing Issues For Review

Your pull request is modifying functions with the following pre-existing issues:

📄 File: src/olympia/abuse/models.py

Function Unhandled Issue
process_decision AttributeError: 'NoneType' object has no attribute 'rating' /api/v5/abus...
Event Count: 26

Did you find this useful? React with a 👍 or 👎

@eviljeff eviljeff marked this pull request as ready for review January 27, 2025 12:22
@eviljeff eviljeff requested review from a team and KevinMind and removed request for a team January 27, 2025 12:23
contain any attached abuse reports (i.e. if an add-on was forwared without a
job)."""
target = addon_factory()
cinder_job = CinderJob.objects.create(job_id='1234', target_addon=target)
Copy link
Contributor

@KevinMind KevinMind Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to explicitly set "None" to the values that we are testing are in fact None?

That's probably the default but it helps clarify the intentions of the test and protects against any weird scenario where those values are defined internally.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the fields aren't on CinderJob - they're on AbuseReport and ContentDecision - it's that there aren't any AbuseReports or ContentDecisions (both have a foreign key to the CinderJob)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both of those models have database constraints to ensure that addon, collection, rating, user have exactly one non-None value (AbuseReport uses guid rather than an addon foreign key, but same restriction)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it would be inverted like

assert AbuseReport.objects.filter(cinder_job=cinder_job).count() == 0

Would that make sense?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's impossible for that assertion ever to fail, but as requested c88399c

rating=abuse_report_or_decision.rating,
collection=abuse_report_or_decision.collection,
user=abuse_report_or_decision.user,
rating=getattr(abuse_report_or_decision, 'rating', None),
Copy link
Contributor

@KevinMind KevinMind Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this patch, would calling this method just raise if any of those fields were None? Or how would it have behaved before. That would be good to add to the context as well as testing to know how you'd expect it to behave outside of this patchl.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It raised because abuse_report_or_decision was None (there were no abuse reports or appealed decisions). I already wrote about in the PR context section, or did you mean write it as code comments?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I read it wrong then, I interpreted "failed" as the approach failed not the code.

@eviljeff eviljeff requested a review from KevinMind January 27, 2025 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants