Replace clear admin review button with an action (#21003)

* Replace clear admin review button with an action

Still for the entire add-on, still only clearable by admins, but now
an explicit action that logs an activity.
This commit is contained in:
Mathieu Pillard 2023-07-17 14:56:13 +02:00 коммит произвёл GitHub
Родитель 8fb3222659
Коммит db087002d2
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 51 добавлений и 35 удалений

Просмотреть файл

@ -943,6 +943,16 @@ class BLOCKLIST_VERSION_UNBLOCKED(_LOG):
short = _('Version Unblocked')
class CLEAR_ADMIN_REVIEW_THEME(_LOG):
id = 181
format = _('{addon} {version} admin add-on-review cleared.')
short = _('Admin add-on-review cleared')
keep = True
review_queue = True
reviewer_review_action = True
admin_event = True
LOGS = [x for x in vars().values() if isclass(x) and issubclass(x, _LOG) and x != _LOG]
# Make sure there's no duplicate IDs.
assert len(LOGS) == len({log.id for log in LOGS})

Просмотреть файл

@ -46,7 +46,6 @@ class AddonReviewerFlagsSerializer(AMOModelSerializer):
'auto_approval_disabled_unlisted',
'auto_approval_disabled_until_next_approval',
'auto_approval_disabled_until_next_approval_unlisted',
'needs_admin_theme_review',
)
def update(self, instance, validated_data):

Просмотреть файл

@ -383,15 +383,6 @@
</li>
{% endif %}
{% endif %}
{% if addon.needs_admin_theme_review %}
<li>
<button data-api-url="{{ drf_url('reviewers-addon-flags', addon.pk) }}"
data-api-method="patch"
data-api-data="{&quot;needs_admin_theme_review&quot;: false}"
id="clear_admin_theme_review" class="oneoff" type="button">Clear Admin Static Theme Review Flag</button>
</li>
{% endif %}
{% endif %}
<li>

Просмотреть файл

@ -393,7 +393,7 @@ class TestReviewHelper(TestReviewHelperBase):
'reject_multiple_versions',
'set_needs_human_review_multiple_versions',
'reply',
'super',
'request_admin_review',
'comment',
]
assert (
@ -1939,12 +1939,29 @@ class TestReviewHelper(TestReviewHelperBase):
AutoApprovalSummary.objects.create(
version=self.addon.current_version, verdict=amo.AUTO_APPROVED
)
self.helper.handler.process_super_review()
self.helper.handler.request_admin_review()
assert self.addon.needs_admin_theme_review
assert self.check_log_count(amo.LOG.REQUEST_ADMIN_REVIEW_THEME.id) == 1
assert getattr(amo.LOG.REQUEST_ADMIN_REVIEW_THEME, 'sanitize', '')
def test_clear_admin_review(self):
self.setup_data(
amo.STATUS_APPROVED,
file_status=amo.STATUS_APPROVED,
type=amo.ADDON_STATICTHEME,
)
AddonReviewerFlags.objects.create(
addon=self.addon, needs_admin_theme_review=True
)
AutoApprovalSummary.objects.create(
version=self.addon.current_version, verdict=amo.AUTO_APPROVED
)
self.helper.handler.clear_admin_review()
assert not self.addon.reviewerflags.reload().needs_admin_theme_review
assert self.check_log_count(amo.LOG.CLEAR_ADMIN_REVIEW_THEME.id) == 1
def test_operating_system_present(self):
self.setup_data(amo.STATUS_APPROVED)
self.helper.handler.reject_latest_version()

Просмотреть файл

@ -3264,19 +3264,6 @@ class TestReview(ReviewBase):
self.addon.delete()
self.test_admin_block_actions()
def test_unflag_theme_option_forflagged_as_admin(self):
self.login_as_admin()
AddonReviewerFlags.objects.create(
addon=self.addon,
needs_admin_theme_review=True,
)
response = self.client.get(self.url)
assert response.status_code == 200
doc = pq(response.content)
assert doc('#clear_admin_code_review').length == 0
assert doc('#clear_admin_content_review').length == 0
assert doc('#clear_admin_theme_review').length == 1
def test_disable_auto_approval_as_admin(self):
self.login_as_admin()
response = self.client.get(self.url)
@ -5076,7 +5063,7 @@ class TestReview(ReviewBase):
'reject_multiple_versions',
'set_needs_human_review_multiple_versions',
'reply',
'super',
'request_admin_review',
'comment',
]
assert [
@ -5093,7 +5080,7 @@ class TestReview(ReviewBase):
'reject_multiple_versions',
'set_needs_human_review_multiple_versions',
'reply',
'super',
'request_admin_review',
'comment',
]
# we don't show files, reasons, and tested with for any static theme actions
@ -6449,7 +6436,6 @@ class TestAddonReviewerViewSet(TestCase):
'auto_approval_disabled_until_next_approval_unlisted': True,
'auto_approval_delayed_until': None,
'auto_approval_delayed_until_unlisted': None,
'needs_admin_theme_review': True,
}
response = self.client.patch(self.flags_url, data)
assert response.status_code == 200
@ -6463,7 +6449,6 @@ class TestAddonReviewerViewSet(TestCase):
)
assert reviewer_flags.auto_approval_delayed_until is None
assert reviewer_flags.auto_approval_delayed_until_unlisted is None
assert reviewer_flags.needs_admin_theme_review is True
def test_deny_resubmission(self):
self.grant_permission(self.user, 'Reviews:Admin')

Просмотреть файл

@ -781,8 +781,8 @@ class ReviewHelper:
'allows_reasons': not is_static_theme,
'requires_reasons': False,
}
actions['super'] = {
'method': self.handler.process_super_review,
actions['request_admin_review'] = {
'method': self.handler.request_admin_review,
'label': 'Request review from admin',
'details': (
'If you have concerns about this add-on that '
@ -793,6 +793,14 @@ class ReviewHelper:
'minimal': True,
'available': (self.version is not None and is_reviewer and is_static_theme),
}
actions['clear_admin_review'] = {
'method': self.handler.clear_admin_review,
'label': 'Clear admin review',
'details': ('Clear needs admin review flag on the add-on.'),
'minimal': True,
'comments': False,
'available': is_appropriate_admin_reviewer and is_static_theme,
}
actions['comment'] = {
'method': self.handler.process_comment,
'label': 'Comment',
@ -1126,17 +1134,23 @@ class ReviewBase:
self.log_sandbox_message()
log.info('Sending email for %s' % (self.addon))
def process_super_review(self):
def request_admin_review(self):
"""Mark an add-on as needing admin theme review."""
addon_type = self.addon.type
if addon_type == amo.ADDON_STATICTHEME:
if self.addon.type == amo.ADDON_STATICTHEME:
AddonReviewerFlags.objects.update_or_create(
addon=self.addon, defaults={'needs_admin_theme_review': True}
)
self.log_action(amo.LOG.REQUEST_ADMIN_REVIEW_THEME)
log.info(f'{amo.LOG.REQUEST_ADMIN_REVIEW_THEME.short} for {self.addon}')
def clear_admin_review(self):
if self.addon.type == amo.ADDON_STATICTHEME:
AddonReviewerFlags.objects.update_or_create(
addon=self.addon, defaults={'needs_admin_theme_review': False}
)
self.log_action(amo.LOG.CLEAR_ADMIN_REVIEW_THEME)
log.info(f'{amo.LOG.CLEAR_ADMIN_REVIEW_THEME.short} for {self.addon}')
def approve_content(self):
"""Approve content of an add-on."""
channel = self.version.channel