Skip to content
Snippets Groups Projects

WS-31: Viewing and creating capability requests

Merged Nathan Hertz requested to merge WS-31-create-capability-request-view into main
1 unresolved thread
5 files
+ 144
12
Compare changes
  • Side-by-side
  • Inline
Files
5
@@ -26,7 +26,8 @@ def view_capability(request: Request) -> Response:
URL: capability/{capability_name}
:param request: GET request
:return: Response with JSON-formatted capability info if found or 404 response (HTTPNotFound)
:return: Response with JSON-formatted capability info if found
or 404 response (HTTPNotFound)
"""
capability = request.capability_info.lookup_capability(request.matchdict["capability_name"])
if capability:
@@ -44,8 +45,8 @@ def create_capability(request: Request) -> Response:
:param request: POST request, expecting JSON parameters ["capability_name", "steps", "max_jobs"]
optionally, accepts a boolean "enabled" parameter
:return: Response with JSON-formatted capability info of newly created capability
or 400 response (HTTPBadRequest) if expected parameters not given
or 412 response (HTTPPreconditionFailed) if capability with given name already exists
or 400 response (HTTPBadRequest) if expected parameters not given
or 412 response (HTTPPreconditionFailed) if capability with given name already exists
"""
expected_params = ["capability_name", "steps", "max_jobs"]
params = request.json_body
@@ -82,8 +83,9 @@ def edit_capability(request: Request) -> Response:
:param request: POST request, expecting JSON parameters ["capability_name", "steps", "max_jobs"]
:return: Response with JSON-formatted capability info of newly created capability
or 400 response (HTTPBadRequest) if expected parameters not given
or 412 response (HTTPPreconditionFailed) if capability with given name does not exist
or 400 response (HTTPBadRequest) if expected parameters not given
or 412 response (HTTPPreconditionFailed) if capability with given name does not exist
or 417 response (HTTPExpectationFailed) if the capability was unable to be edited
TODO: In the future, we should check if there are any active requests for the capability being edited and
disallow its editing until they are finished
@@ -117,6 +119,14 @@ def edit_capability(request: Request) -> Response:
@view_config(route_name="enable_capability", renderer="json")
def enable_capability(request: Request) -> Response:
"""
Pyramid view that enables a capability
:param request: POST request
:return: HTTP 200 response
or 412 response (HTTPPreconditionFailed) if capability with given name does not exist
or 417 response (HTTPExpectationFailed) if the capability was unable to be enabled
"""
capability_name = request.matchdict["capability_name"]
if not request.capability_info.lookup_capability(capability_name):
@@ -133,6 +143,14 @@ def enable_capability(request: Request) -> Response:
@view_config(route_name="disable_capability", renderer="json")
def disable_capability(request: Request) -> Response:
"""
Pyramid view that disables a capability
:param request: POST request
:return: HTTP 200 response
or 412 response (HTTPPreconditionFailed) if capability with given name does not exist
or 417 response (HTTPExpectationFailed) if the capability was unable to be disabled
"""
capability_name = request.matchdict["capability_name"]
if not request.capability_info.lookup_capability(capability_name):
Loading