Skip to content

Commit

Permalink
Do not allow edits on updates for archived releases
Browse files Browse the repository at this point in the history
Signed-off-by: Mattia Verga <mattia.verga@tiscali.it>
  • Loading branch information
mattiaverga authored and mergify[bot] committed Sep 8, 2021
1 parent 08a3702 commit 7f9df9d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
6 changes: 0 additions & 6 deletions bodhi/server/services/updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
ContentType,
UpdateRequest,
UpdateStatus,
ReleaseState,
Build,
Package,
Release,
Expand Down Expand Up @@ -200,11 +199,6 @@ def set_request(request):
"Can't change request on a locked update")
return

if update.release.state is ReleaseState.archived:
request.errors.add('body', 'request',
"Can't change request for an archived release")
return

if update.status == UpdateStatus.stable and action == UpdateRequest.testing:
request.errors.add('body', 'request',
"Pushing back to testing a stable update is not allowed")
Expand Down
3 changes: 3 additions & 0 deletions bodhi/server/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,9 @@ def validate_acls(request, **kwargs):
builds = request.validated['builds']

if 'update' in request.validated:
if request.validated['update'].release.state == ReleaseState.archived:
request.errors.add('body', 'update', 'cannot edit Update for an archived Release')
return
builds = request.validated['update'].builds

if not builds:
Expand Down
4 changes: 2 additions & 2 deletions bodhi/tests/server/services/test_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ def test_set_request_archived_release(self, *args):

assert res.json_body['status'] == 'error'
assert res.json_body['errors'][0]['description'] == (
"Can't change request for an archived release"
"cannot edit Update for an archived Release"
)

@mock.patch(**mock_valid_requirements)
Expand Down Expand Up @@ -4096,7 +4096,7 @@ def test_request_to_archived_release(self, *args):

assert resp.json['status'] == 'error'
assert resp.json['errors'][0]['description'] == (
"Can't change request for an archived release"
"cannot edit Update for an archived Release"
)

@mock.patch(**mock_failed_taskotron_results)
Expand Down
14 changes: 14 additions & 0 deletions bodhi/tests/server/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,20 @@ def test_validate_acls_dummy_committer(self):
validators.validate_acls(mock_request)
assert not len(mock_request.errors)

@mock.patch.dict('bodhi.server.validators.config', {'acl_system': 'dummy'})
def test_validate_acls_archived_release(self):
""" Test validate_acls when trying to edit an Update for an archived Release.
"""
mock_request = self.get_mock_request()
mock_request.validated['update'].release.state = models.ReleaseState.archived
validators.validate_acls(mock_request)
error = [{
'location': 'body',
'name': 'update',
'description': 'cannot edit Update for an archived Release'
}]
assert mock_request.errors == error

@mock.patch.dict('bodhi.server.validators.config', {'acl_system': 'nonexistent'})
def test_validate_acls_invalid_acl_system(self):
""" Test validate_acls when the acl system is invalid.
Expand Down
1 change: 1 addition & 0 deletions news/PR4236.bug
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Updates for archived releases cannot be edited anymore

0 comments on commit 7f9df9d

Please sign in to comment.