Add an explicit target_versions attribute on ContentAction classes#24789
Add an explicit target_versions attribute on ContentAction classes#24789diox wants to merge 1 commit intomozilla:masterfrom
Conversation
Having an actual target_versions attribute rather than a property depending on the decision will allow us to have logic that depends on the target versions inside the action class but still allow the target versions considered for that logic to be set by the caller before a decision has been made. A set_target_versions() method is provided to keep the decision target versions in sync with the ContentAction.
|
The end goal I'm after here is being able to add a def should_be_skipped_by_automation(self):
return ContentDecision.objects.filter(self.addon, action=self.action).exists()But then def should_be_skipped_by_automation(self):
return ContentDecision.objects.filter(
addon=self.target, versions__in=self.target_versions, action=self.action
).exists()The problem is, I need to perform this check before the scanner decision has actually taken place. So I'm instantiating the relevant class without a saved ContentActionClass = CONTENT_ACTION_FROM_DECISION_ACTION[action]
action_helper = ContentActionClass(ContentDecision(addon=addon))
action_helper.target_versions = Version.unfiltered.filter(pk=version.pk)
if not action_helper.should_be_skipped_by_automation():
# Proceed ...This is done in a loop for one or more actions, the Alternatively, I could give up on using |
Having an actual target_versions attribute rather than a property depending on the decision will allow us to have logic that depends on the target versions inside the action class but still allow the target versions considered for that logic to be set by the caller before a decision has been made.
A
set_target_versions()method is provided to keep the decision target versions in sync with the ContentAction.Split from #24785
Helps mozilla/addons#16123