Make categories optional parameter
Change-Id: I5960de1b7e01db491046b89f08fd95324d24551d Closes-Bug: #1311033
This commit is contained in:
parent
45f002010a
commit
da8ee01b65
@ -249,8 +249,6 @@ Allowed operations:
|
||||
{ "op": "replace", "path": "/name", "value": "New name" }
|
||||
]
|
||||
|
||||
Note, that replacing categories with empty list is not allowed as well as the removing last category.
|
||||
|
||||
**Request 200 (application/murano-packages-json-patch)**
|
||||
|
||||
::
|
||||
@ -292,10 +290,6 @@ Note, that replacing categories with empty list is not allowed as well as the re
|
||||
* An attempt to perform operation that is not allowed on the specified path
|
||||
* An attempt to update non-public package by user whose tenant is not an owner of this package
|
||||
|
||||
**Response 400**
|
||||
|
||||
* An attempt to replace categories with empty list or remove last category
|
||||
|
||||
**Response 404**
|
||||
|
||||
* An attempt to update package that doesn't exist
|
||||
|
@ -91,12 +91,13 @@ def _validate_body(body):
|
||||
raise exc.HTTPBadRequest('Uploading file is too large.'
|
||||
' The limit is {0} Mb'.format(mb_limit))
|
||||
|
||||
if len(body.keys()) != 2:
|
||||
if len(body.keys()) > 2:
|
||||
msg = _("'multipart/form-data' request body should contain "
|
||||
"2 parts: json string and zip archive. Current body consist "
|
||||
"of {0} part(s)").format(len(body.keys()))
|
||||
"1 or 2 parts: json string and zip archive. Current body "
|
||||
"consists of {0} part(s)").format(len(body.keys()))
|
||||
LOG.error(msg)
|
||||
raise exc.HTTPBadRequest(msg)
|
||||
|
||||
file_obj = None
|
||||
package_meta = None
|
||||
for part in body.values():
|
||||
@ -110,10 +111,6 @@ def _validate_body(body):
|
||||
msg = _('There is no file package with application description')
|
||||
LOG.error(msg)
|
||||
raise exc.HTTPBadRequest(msg)
|
||||
if package_meta is None:
|
||||
msg = _('There is no json with meta information about package')
|
||||
LOG.error(msg)
|
||||
raise exc.HTTPBadRequest(msg)
|
||||
return file_obj, package_meta
|
||||
|
||||
|
||||
@ -128,6 +125,7 @@ class Controller(object):
|
||||
{ "op": "add", "path": "/tags", "value": [ "foo", "bar" ] }
|
||||
{ "op": "add", "path": "/categories", "value": [ "foo", "bar" ] }
|
||||
{ "op": "remove", "path": "/tags" }
|
||||
{ "op": "remove", "path": "/categories" }
|
||||
{ "op": "replace", "path": "/tags", "value": ["foo", "bar"] }
|
||||
{ "op": "replace", "path": "/is_public", "value": true }
|
||||
{ "op": "replace", "path": "/description",
|
||||
@ -185,11 +183,14 @@ class Controller(object):
|
||||
"""
|
||||
_check_content_type(req, 'multipart/form-data')
|
||||
file_obj, package_meta = _validate_body(body)
|
||||
if package_meta:
|
||||
try:
|
||||
jsonschema.validate(package_meta, schemas.PKG_UPLOAD_SCHEMA)
|
||||
except jsonschema.ValidationError as e:
|
||||
LOG.exception(e)
|
||||
raise exc.HTTPBadRequest(explanation=e.message)
|
||||
else:
|
||||
package_meta = {}
|
||||
|
||||
with tempfile.NamedTemporaryFile(delete=False) as tempf:
|
||||
LOG.debug("Storing package archive in a temporary file")
|
||||
|
@ -37,7 +37,7 @@ PKG_UPLOAD_SCHEMA = {
|
||||
},
|
||||
"categories": {
|
||||
"type": "array",
|
||||
"minItems": 1,
|
||||
"minItems": 0,
|
||||
"items": {"type": "string"},
|
||||
"uniqueItems": True
|
||||
},
|
||||
@ -46,7 +46,6 @@ PKG_UPLOAD_SCHEMA = {
|
||||
"is_public": {"type": "boolean"},
|
||||
"enabled": {"type": "boolean"}
|
||||
},
|
||||
"required": ["categories"],
|
||||
"additionalProperties": False
|
||||
}
|
||||
|
||||
@ -62,7 +61,6 @@ PKG_UPDATE_SCHEMA = {
|
||||
},
|
||||
"categories": {
|
||||
"type": "array",
|
||||
"minItems": 1,
|
||||
"items": {"type": "string"},
|
||||
"uniqueItems": True
|
||||
},
|
||||
|
@ -197,10 +197,6 @@ def _do_remove(package, change):
|
||||
"does not exist.").format(value, path)
|
||||
LOG.error(msg)
|
||||
raise exc.HTTPNotFound(msg)
|
||||
if path == 'categories' and len(current_values) == 1:
|
||||
msg = _("At least one category should be assigned to the package")
|
||||
LOG.error(msg)
|
||||
raise exc.HTTPBadRequest(msg)
|
||||
item_to_remove = find(current_values, lambda i: i.name == value)
|
||||
current_values.remove(item_to_remove)
|
||||
return package
|
||||
|
Loading…
Reference in New Issue
Block a user