Skip to content

Commit

Permalink
fix(rest): clean up workflow sharing code after changes (#552)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonadoni authored and tiborsimko committed Sep 4, 2024
1 parent 894a99e commit e36c6a2
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 334 deletions.
85 changes: 9 additions & 76 deletions docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@
"type": "boolean"
},
{
"description": "Optional argument to list workflows shared by the specified user(s).",
"description": "Optional argument to list workflows shared by the specified user.",
"in": "query",
"name": "shared_by",
"required": false,
"type": "string"
},
{
"description": "Optional argument to list workflows shared with the specified user(s).",
"description": "Optional argument to list workflows shared with the specified user.",
"in": "query",
"name": "shared_with",
"required": false,
Expand Down Expand Up @@ -195,7 +195,10 @@
"type": "object"
},
"shared_with": {
"type": "string"
"items": {
"type": "string"
},
"type": "array"
},
"size": {
"properties": {
Expand Down Expand Up @@ -1133,7 +1136,7 @@
{
"description": "Required. UUID of workflow owner.",
"in": "query",
"name": "user_id",
"name": "user",
"required": true,
"type": "string"
},
Expand Down Expand Up @@ -1190,38 +1193,6 @@
"type": "object"
}
},
"401": {
"description": "Request failed. User not signed in.",
"examples": {
"application/json": {
"message": "User not signed in."
}
},
"schema": {
"properties": {
"message": {
"type": "string"
}
},
"type": "object"
}
},
"403": {
"description": "Request failed. Credentials are invalid or revoked.",
"examples": {
"application/json": {
"message": "Token not valid."
}
},
"schema": {
"properties": {
"message": {
"type": "string"
}
},
"type": "object"
}
},
"404": {
"description": "Request failed. Workflow does not exist.",
"examples": {
Expand Down Expand Up @@ -1500,7 +1471,7 @@
{
"description": "Required. UUID of workflow owner.",
"in": "query",
"name": "user_id",
"name": "user",
"required": true,
"type": "string"
},
Expand Down Expand Up @@ -1551,20 +1522,11 @@
"description": "Request failed. The incoming data specification seems malformed.",
"examples": {
"application/json": {
"errors": [
"Missing data for required field."
],
"message": "Malformed request."
}
},
"schema": {
"properties": {
"errors": {
"items": {
"type": "string"
},
"type": "array"
},
"message": {
"type": "string"
}
Expand All @@ -1576,9 +1538,7 @@
"description": "Request failed. User is not allowed to unshare the workflow.",
"examples": {
"application/json": {
"errors": [
"User is not allowed to unshare the workflow."
]
"message": "User is not allowed to unshare the workflow."
}
},
"schema": {
Expand All @@ -1594,20 +1554,11 @@
"description": "Request failed. Workflow does not exist or user does not exist.",
"examples": {
"application/json": {
"errors": [
"Workflow cdcf48b1-c2f3-4693-8230-b066e088c6ac does not exist"
],
"message": "Workflow cdcf48b1-c2f3-4693-8230-b066e088c6ac does not exist"
}
},
"schema": {
"properties": {
"errors": {
"items": {
"type": "string"
},
"type": "array"
},
"message": {
"type": "string"
}
Expand All @@ -1619,20 +1570,11 @@
"description": "Request failed. The workflow is not shared with the user.",
"examples": {
"application/json": {
"errors": [
"The workflow is not shared with the user."
],
"message": "The workflow is not shared with the user."
}
},
"schema": {
"properties": {
"errors": {
"items": {
"type": "string"
},
"type": "array"
},
"message": {
"type": "string"
}
Expand All @@ -1644,20 +1586,11 @@
"description": "Request failed. Internal controller error.",
"examples": {
"application/json": {
"errors": [
"Internal controller error."
],
"message": "Internal controller error."
}
},
"schema": {
"properties": {
"errors": {
"items": {
"type": "string"
},
"type": "array"
},
"message": {
"type": "string"
}
Expand Down
1 change: 1 addition & 0 deletions reana_workflow_controller/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,4 @@ def _parse_interactive_sessions_environments(env_var):
"""Prefixes that can be removed from container image references to generate valid image aliases."""

MAX_WORKFLOW_SHARING_MESSAGE_LENGTH = 5000
"""Maximum length of the user-provided message when sharing a workflow."""
13 changes: 9 additions & 4 deletions reana_workflow_controller/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,15 @@ def handle_args_validation_error(error: UnprocessableEntity):
exception = getattr(error, "exc", None)
if isinstance(exception, ValidationError):
validation_messages = []
for field, messages in exception.normalized_messages().items():
validation_messages.append(
"Field '{}': {}".format(field, ", ".join(messages))
)
# this is slightly different from r-server error handler due to different
# versions of webargs/marshmallow
# the format of normalized_messages() is:
# {"json": {"field name": ["error 1", "error 2"]}}
for field_messages in exception.normalized_messages().values():
for field, messages in field_messages.items():
validation_messages.append(
"Field '{}': {}".format(field, ", ".join(messages))
)
error_message = ". ".join(validation_messages)

return jsonify({"message": error_message}), 400
Expand Down
Loading

0 comments on commit e36c6a2

Please sign in to comment.