in src/olympia/reviewers/utils.py [0:0]
def auto_reject_multiple_versions(self):
"""Immediately reject a list of versions, either from previously
delayed rejections or from versions being blocked.
Note: this is not accessible through reviewer tools UI, but because it
is triggered for rejections coming from a block being created,
self.human_review can be True."""
# self.version and self.file won't point to the versions we want to
# modify in this action, so set them to None before finding the right
# versions.
channel = self.version.channel if self.version else None
self.version = None
self.file = None
now = datetime.now()
action_id = (
amo.LOG.REJECT_CONTENT if self.content_review else amo.LOG.REJECT_VERSION
)
log.info(
'Making %s versions %s disabled'
% (self.addon, ', '.join(str(v.pk) for v in self.data['versions']))
)
# For an immediate rejection we record a single action, but for
# applying a delayed rejection, we need to split by type (content
# review or not) and by original user to match the original user(s)
# and action(s).
actions_to_record = defaultdict(lambda: defaultdict(list))
for version in self.data['versions']:
file = version.file
self.set_file(amo.STATUS_DISABLED, file)
if (
not self.human_review
and (flags := getattr(version, 'reviewerflags', None))
and flags.pending_rejection
):
action_id = (
amo.LOG.AUTO_REJECT_CONTENT_AFTER_DELAY_EXPIRED
if flags.pending_content_rejection
else amo.LOG.AUTO_REJECT_VERSION_AFTER_DELAY_EXPIRED
)
if self.human_review:
# Clear needs human review flags on rejected versions, we
# consider that the reviewer looked at them before rejecting.
self.clear_specific_needs_human_review_flags(version)
# Reset pending_rejection.
VersionReviewerFlags.objects.update_or_create(
version=version,
defaults={
'pending_rejection': None,
'pending_rejection_by': None,
'pending_content_rejection': None,
},
)
self.set_human_review_date(version)
actions_to_record[action_id][self.user].append(version)
else:
actions_to_record[action_id][version.pending_rejection_by].append(
version
)
addonreviewerflags = {}
# A human rejection (delayed or not) implies the next version in the
# same channel should be manually reviewed.
if self.human_review:
auto_approval_disabled_until_next_approval_flag = (
'auto_approval_disabled_until_next_approval'
if channel == amo.CHANNEL_LISTED
else 'auto_approval_disabled_until_next_approval_unlisted'
)
addonreviewerflags[auto_approval_disabled_until_next_approval_flag] = True
# The versions rejected might require the add-on status to change.
self.addon.update_status()
if addonreviewerflags:
AddonReviewerFlags.objects.update_or_create(
addon=self.addon,
defaults=addonreviewerflags,
)
keys = [
'is_addon_being_blocked',
'is_addon_being_disabled',
]
extra_details = {key: self.data[key] for key in keys if key in self.data}
for action_id, user_and_versions in actions_to_record.items():
for user, versions in user_and_versions.items():
log.info('Sending email for %s' % (self.addon))
self.record_decision(
action_id,
versions=versions,
decision_metadata=extra_details,
log_action_kw={
'timestamp': now,
'user': user,
'extra_details': extra_details,
},
)