Disallow deleting the null version of a product
The null version is implicitly created with the product and should only be deleted if the product is deleted. This version is used when a user doesn't want to associate a test to an explicit version but just the product itself. This patch restricts users from explicitly deleting this null version. Change-Id: Ibb29940b5702f73cd50ed2a29e5a23a4d87ed887
This commit is contained in:
parent
ac472fe494
commit
701b1ed5f3
@ -115,6 +115,15 @@ class VersionsController(validation.BaseRestControllerWithValidation):
|
||||
|
||||
pecan.abort(403, 'Forbidden.')
|
||||
try:
|
||||
version = db.get_product_version(version_id,
|
||||
allowed_keys=['version'])
|
||||
if not version['version']:
|
||||
pecan.abort(400, 'Can not delete the empty version as it is '
|
||||
'used for basic product/test association. '
|
||||
'This version was implicitly created with '
|
||||
'the product, and so it cannot be deleted '
|
||||
'explicitly.')
|
||||
|
||||
db.delete_product_version(version_id)
|
||||
except DBReferenceError:
|
||||
pecan.abort(400, 'Unable to delete. There are still tests '
|
||||
|
@ -284,3 +284,9 @@ class TestProductVersionEndpoint(api.FunctionalTest):
|
||||
self.delete(self.URL + version_id)
|
||||
self.assertRaises(webtest.app.AppError, self.get_json,
|
||||
self.URL + 'version_id')
|
||||
|
||||
# Get the null version and ensure it can't be deleted.
|
||||
versions = self.get_json(self.URL)
|
||||
version_id = versions[0]['id']
|
||||
response = self.delete(self.URL + version_id, expect_errors=True)
|
||||
self.assertEqual(400, response.status_code)
|
||||
|
Loading…
Reference in New Issue
Block a user