Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/olympia/devhub/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1650,11 +1650,11 @@ def __init__(self, *args, **kwargs):
if not self.listed_count and self.unlisted_count:
# if there is no listed option, we default to unlisted
channel.initial = amo.CHANNEL_UNLISTED
channel.widget.attrs = {'disabled': True}
channel.disabled = True
elif not self.unlisted_count and self.listed_count:
# if there is a listed option, we default to that channel
channel.initial = amo.CHANNEL_LISTED
channel.widget.attrs = {'disabled': True}
channel.disabled = True
elif self.listed_count or self.unlisted_count:
# otherwise we default to the most recently used channel
channel.initial = self.addon.versions.first().channel
Expand Down
32 changes: 24 additions & 8 deletions src/olympia/devhub/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,7 @@ def test_clean_new_version_string_for_listed_greater_than_existing(self):
)
assert form.is_valid()

def test_clean_adds_version(self):
def test_clean_adds_version_for_listed(self):
addon = addon_factory()
lv1 = addon.current_version
version_factory(addon=addon)
Expand All @@ -1588,27 +1588,43 @@ def test_clean_adds_version(self):
assert form.is_valid(), form.errors
# the listed version is added, and as the chosen version
assert form.clean() == {
**data,
'channel': amo.CHANNEL_LISTED,
'new_version_string': '111111',
'unlisted_version': uv1,
'listed_version': lv1,
'version': lv1,
}

# repeat with unlisted
data['channel'] = amo.CHANNEL_UNLISTED
def test_clean_adds_version_for_unlisted(self):
addon = addon_factory()
lv1 = addon.current_version
version_factory(addon=addon)
uv1 = version_factory(addon=addon, channel=amo.CHANNEL_UNLISTED)
version_factory(addon=addon, channel=amo.CHANNEL_UNLISTED)
data = {
'channel': amo.CHANNEL_UNLISTED,
'unlisted_version': uv1.id,
'new_version_string': '111111',
}
form = forms.RollbackVersionForm(data, addon=addon)
assert form.is_valid(), form.errors
# the selected unlisted version is added as the chosen version
assert form.clean() == {
**data,
'channel': amo.CHANNEL_UNLISTED,
'new_version_string': '111111',
'unlisted_version': uv1,
'listed_version': lv1,
'version': uv1,
}

# and when we select listed but there is no listed version availble: error
data['channel'] = amo.CHANNEL_LISTED
lv1.delete()
def test_clean_errors_when_no_version_for_channel(self):
addon = addon_factory()
version_factory(addon=addon, channel=amo.CHANNEL_UNLISTED)
version_factory(addon=addon, channel=amo.CHANNEL_UNLISTED)
data = {
'channel': amo.CHANNEL_LISTED,
'new_version_string': '111111',
}
form = forms.RollbackVersionForm(data, addon=addon)
assert not form.is_valid()
assert form.errors == {
Expand Down
15 changes: 13 additions & 2 deletions static/js/zamboni/devhub.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,8 @@ function initVersions() {
});

if ($('#modal-rollback-version').length) {
const CHANNEL_UNLISTED = '1',
CHANNEL_LISTED = '2';
let $modalRollback = $('#modal-rollback-version').modal('.version-rollback', {
width: 600
});
Expand All @@ -616,6 +618,7 @@ function initVersions() {
}

let $channelInputs = $('#id_channel input'),
$hiddenChannelInput = $('input[name="channel"][type="hidden"]'),
$listedVersionRow = $('#listed-version-row'),
$unlistedVersionRow = $('#unlisted-version-row'),
$listedVersionSelect = $('#id_listed_version'),
Expand All @@ -641,17 +644,25 @@ function initVersions() {
$unlistedVersionRow.hide();
$channelInputs.each(function (index, element) {
const $radio = $(element);
if ($radio.val() == '2' && $radio.prop('checked')) {
if ($radio.val() == CHANNEL_LISTED && $radio.prop('checked')) {
$listedVersionRow.show();
$listedVersionSelect.trigger('change');
}
if ($radio.val() == '1' && $radio.prop('checked')) {
if ($radio.val() == CHANNEL_UNLISTED && $radio.prop('checked')) {
$unlistedVersionRow.show();
$unlistedVersionSelect.trigger('change');
}
});
})
.trigger('change');

if ($hiddenChannelInput) {
if ($hiddenChannelInput.val() == CHANNEL_UNLISTED) {
$unlistedVersionSelect.trigger('change');
} else if ($hiddenChannelInput.val() == CHANNEL_LISTED) {
$listedVersionSelect.trigger('change');
}
}
}

function addToReviewHistory(json, historyContainer, reverseOrder) {
Expand Down