Skip to content

Allow policies to be selected directly for reviewer tools actions #23437

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

Merged

Conversation

eviljeff
Copy link
Member

@eviljeff eviljeff commented May 9, 2025

Fixes: mozilla/addons#15513

Description

Allow CinderPolicy to be selected directly for reviewer tools actions, rather then ReviewActionReasons (which were associated with a policy). placeholder values for policies can be filled in by the reviewer. With the waffle switch enabled, policies are available everywhere ReviewActionReasons were - except reviewer Reply action which has it's own email template and code path (it will be addressed in follow-ups)

Screenshot 2025-05-12 170500

Context

The (in theory) last piece of the work to replace ReviewActionReason - this took more work than expected as I didn't really consider the extra changes to show some policies for some actions and not others (e.g. we don't want the Approve policy shown for the Reject action).

Testing

First check that with the waffle switch off everything is as before:

  • (You may have to create some ReviewActionReason instances in django admin)
  • review action reasons can be selected for rejections, disables, and approves; cinder policies available for resolve abuse reports
  • reasons are required for rejections and disables; not for approves
  • the comment field is always visible; 4 rows high, and required

The enable the waffle switch

  • in django admin sync the policies (needs Cinder API key in settings)
  • in django enable expose in reviewer tools for some policies
    • the policies will need to have enforcement actions defined in Cinder. And text too to be useful.
    • policy text can have {PLACEHOLDER} values in them
    • if you decide to edit some, bear in mind you can't define AMO_REJECT_VERSION_ADDON for any policy that's used by moderators directly in Cinder - it has to be DISABLE_ADDON)
    • I already edited Sources -> Testing information required, so you can just expose that one in the reviewer tools
  • CinderPolicy instances should be shown for approve, reject, disable, as well as resolve abuse reports as before.
  • Any policies with text containing {XXX} should have an input field to fill in a value for XXX
  • Comments should be optional
  • If you check the email (in fake mail) it should contain the policy texts, with the placeholder values filled in.
  • the policy text should also be shown in the reviewer tools addon/version history

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.

@eviljeff eviljeff changed the title Allow policies to selected directly for reviewer tools actions Allow policies to be selected directly for reviewer tools actions May 9, 2025
@eviljeff eviljeff force-pushed the 15513-reviewer-tools-cinder-policies branch from 8fb3367 to c7fd3b5 Compare May 12, 2025 15:08
@eviljeff eviljeff marked this pull request as ready for review May 12, 2025 16:28
@eviljeff eviljeff force-pushed the 15513-reviewer-tools-cinder-policies branch from c7fd3b5 to 3761403 Compare May 12, 2025 16:35
@eviljeff eviljeff force-pushed the 15513-reviewer-tools-cinder-policies branch from 3761403 to e0befef Compare May 12, 2025 17:48
@eviljeff eviljeff requested review from a team and KevinMind and removed request for a team May 12, 2025 18:48
Copy link
Contributor

@KevinMind KevinMind left a comment

Choose a reason for hiding this comment

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

Some comments on the code. I will try to verify tomorrow.

def create_option(
self, name, value, label, selected, index, subindex=None, attrs=None
):
obj = label
Copy link
Contributor

Choose a reason for hiding this comment

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

This is breaking by brain... label is an argument, that is set to obj and then the stringified version of that is set back to label?

Copy link
Member Author

Choose a reason for hiding this comment

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

hah, yeah - we use the same trick for a number of fields/widgets for reviewer forms - the field knows about the instances, but by the time it's passed to create_option in the widget the instance is unavailable, so we can't render html based on it. The trick is in WidgetRenderedModelMultipleChoiceField where rather than returning a string for the label that represents the instance, we return the instance object as the label; so we can then use it in create_option.

@KevinMind
Copy link
Contributor

Merge conflicts?

@eviljeff
Copy link
Member Author

Merge conflicts?

undoubtedly

@eviljeff eviljeff requested a review from KevinMind May 16, 2025 12:40
@KevinMind
Copy link
Contributor

Not directly related to this PR but still a bit of an annoying behavior. If you have an invalid form state and submit, the form refreshes and cinder placeholder fields are cleared. Would be great if they were persisted on reload.

image

Copy link
Contributor

@KevinMind KevinMind left a comment

Choose a reason for hiding this comment

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

LGTM 🚢

@eviljeff
Copy link
Member Author

eviljeff commented May 19, 2025

Not directly related to this PR but still a bit of an annoying behavior. If you have an invalid form state and submit, the form refreshes and cinder placeholder fields are cleared. Would be great if they were persisted on reload.

mmm, I didn't notice that, but I can see why that'd happen (they're not django form fields) I'll file a follow-up.

--edit mozilla/addons#15612

@eviljeff eviljeff merged commit 98c7bc2 into mozilla:master May 19, 2025
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task]: Allow dynamic (placeholder) values for policies to be entered in the reviewer tools
2 participants