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

Modify Button Behaviour When enable-submissions Flag is Disabled #22779

Merged
merged 16 commits into from
Oct 31, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ <h3>{{ _('Upload Version') }}</h3>
{% endif %}
{% endif %}
data-max-upload-size="{{ max_upload_size }}"
data-submissions-enabled="{{ submissions_enabled|json }}"
>
{{ new_addon_form.theme_specific }}
{{ new_addon_form.non_field_errors() }}
Expand Down Expand Up @@ -95,7 +94,7 @@ <h3>{{ _('Create a Theme Version') }}</h3>
</p>
{% endif %}

<div class="submission-buttons addon-submission-field">
<div id="submission-field" class="submission-buttons addon-submission-field" data-submissions-enabled="{{ submissions_enabled|json }}">
<button class="addon-upload-dependant" id="submit-upload-file-finish" disabled=disabled type="submit">
{{ _('Continue') }}
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ <h3>{{ _('Browser preview') }}</h3>
{{ new_addon_form.compatible_apps.errors }}
{{ new_addon_form.upload.errors }}
{{ new_addon_form.non_field_errors() }}
<div class="submission-buttons addon-submission-field">
<div id="submission-field" class="submission-buttons addon-submission-field" data-submissions-enabled="{{ submissions_enabled|json }}">
<button class="button upload"
{% if addon %}
formaction="{{ url('devhub.upload_for_version', addon.slug, channel_param) }}"
Expand Down
40 changes: 33 additions & 7 deletions src/olympia/devhub/tests/test_views_submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3016,20 +3016,36 @@ def setUp(self):
addon = self.get_addon()
self.version = version_factory(addon=addon)

def _test_submissions_disabled(self, viewname, args=None):
def _test_submissions_disabled(self, viewname, *, assert_status=True, args=None):
args = args or []
self.create_flag('enable-submissions', note=':-(', everyone=False)
url = reverse(viewname, args=args)

self.create_flag('enable-submissions', note=':-(', everyone=False)
response = self.client.post(url)
if assert_status:
assert response.status_code == 503
doc = pq(response.content)
assert 'Add-on uploads are temporarily unavailable' in doc.text()
assert ':-(' in doc.html()

self.create_flag('enable-submissions', note='', everyone=False)
response = self.client.post(url)
assert response.status_code == 503
if assert_status:
assert response.status_code == 503
doc = pq(response.content)
assert 'Add-on uploads are temporarily unavailable.' in doc.text()
assert ':-(' in doc.text()
assert ':-(' not in doc.html()

def _test_submissions_disabled_by_list_type(self, viewname, args=None):
def _test_submissions_disabled_by_list_type(
self, viewname, assert_status=True, args=None
):
args = args or []
self._test_submissions_disabled(viewname, args=args + ['listed'])
self._test_submissions_disabled(viewname, args=args + ['unlisted'])
self._test_submissions_disabled(
viewname, assert_status=assert_status, args=args + ['listed']
)
self._test_submissions_disabled(
viewname, assert_status=assert_status, args=args + ['unlisted']
)

def test_submissions_disabled_submit_details(self):
self._test_submissions_disabled('devhub.submit.details', args=['a3615'])
Expand All @@ -3046,3 +3062,13 @@ def test_submissions_disabled_version_finish(self):
self._test_submissions_disabled(
'devhub.submit.version.finish', args=[self.addon.slug, self.version.pk]
)

def test_submissions_disabled_upload(self):
self._test_submissions_disabled_by_list_type(
'devhub.submit.upload', assert_status=False
)

def test_submissions_disabled_wizard(self):
self._test_submissions_disabled_by_list_type(
'devhub.submit.wizard', assert_status=False
)
12 changes: 10 additions & 2 deletions src/olympia/devhub/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1574,7 +1574,15 @@ def _submit_upload(
if existing_properties
else []
)
submit_notification_warning = get_config('submit_notification_warning')
flag = waffle.get_waffle_flag_model().get('enable-submissions')
warning = gettext('Add-on uploads are temporarily unavailable') + (
': ' + flag.note if getattr(flag, 'note', None) else '.'
)
submit_notification_warning = (
warning
if not flag.is_active(request)
else get_config('submit_notification_warning')
)
if not submit_notification_warning and addon:
# If we're not showing the generic submit notification warning, show
# one specific to pre review if the developer would be affected because
Expand Down Expand Up @@ -1612,7 +1620,7 @@ def _submit_upload(
'version_number': get_next_version_number(addon) if wizard else None,
'wizard_url': wizard_url,
'max_upload_size': settings.MAX_UPLOAD_SIZE,
'submissions_enabled': waffle.flag_is_active(request, 'enable-submissions'),
'submissions_enabled': flag.is_active(request),
},
)

Expand Down
13 changes: 3 additions & 10 deletions static/js/common/upload-addon.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
getErrors: getErrors,
cancel: $(),
maxSize: null, // Dynamically set by devhub.js
submissionsDisabled: false,
};

if (options) {
Expand Down Expand Up @@ -79,16 +80,8 @@
text: gettext('Your add-on should end with .zip, .xpi or .crx'),
});

const submissionsDisabled = !$(this).data('submissions-enabled');
ui_link.toggleClass('disabled', submissionsDisabled);
$upload_field.prop('disabled', submissionsDisabled);

$upload_field.attr(
'title',
submissionsDisabled
? gettext('Add-on uploads are temporarily unavailable.')
: $upload_field.attr('title'),
);
ui_link.toggleClass('disabled', settings.submissionsDisabled);
$upload_field.prop('disabled', settings.submissionsDisabled);

$upload_field.wrap(ui_parent);
$upload_field.before(ui_link);
Expand Down
7 changes: 7 additions & 0 deletions static/js/zamboni/devhub.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,19 @@ $(document).ready(function () {
initUploadPreview();
});

// disable buttons if submission is disabled
const submissionField = $('#submission-field');
const submissionsDisabled =
submissionField && !submissionField.data('submissions-enabled');
$('.submission-buttons .button').toggleClass('disabled', submissionsDisabled);

// Add-on uploader
var $uploadAddon = $('#upload-addon');
if ($('#upload-addon').length) {
var opt = {
cancel: $('.upload-file-cancel'),
maxSize: $uploadAddon.data('max-upload-size'),
submissionsDisabled,
};
opt.appendFormData = function (formData) {
if ($('#addon-compat-upload').length) {
Expand Down
Loading