Skip to content

Commit

Permalink
fix(rest): fix workflow sharing endpoints after rebase (reanahub#658)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonadoni committed Aug 29, 2024
1 parent 0148633 commit f66d666
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 145 deletions.
109 changes: 42 additions & 67 deletions docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1332,9 +1332,7 @@
"application/json": {
"users_shared_with_you": [
{
"email": "[email protected]",
"full_name": "John Doe",
"username": "jdoe"
"email": "[email protected]"
}
]
}
Expand All @@ -1346,12 +1344,6 @@
"properties": {
"email": {
"type": "string"
},
"full_name": {
"type": "string"
},
"username": {
"type": "string"
}
},
"type": "object"
Expand Down Expand Up @@ -1437,9 +1429,7 @@
"application/json": {
"users_you_shared_with": [
{
"email": "[email protected]",
"full_name": "John Doe",
"username": "jdoe"
"email": "[email protected]"
}
]
}
Expand All @@ -1451,12 +1441,6 @@
"properties": {
"email": {
"type": "string"
},
"full_name": {
"type": "string"
},
"username": {
"type": "string"
}
},
"type": "object"
Expand Down Expand Up @@ -1610,14 +1594,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 @@ -1790,7 +1774,10 @@
"type": "string"
},
"shared_with": {
"type": "string"
"items": {
"type": "string"
},
"type": "array"
},
"size": {
"properties": {
Expand Down Expand Up @@ -3351,7 +3338,15 @@
}
},
"400": {
"description": "Request failed. The incoming data seems malformed."
"description": "Request failed. The incoming data seems malformed.",
"schema": {
"properties": {
"message": {
"type": "string"
}
},
"type": "object"
}
},
"401": {
"description": "Request failed. User not signed in.",
Expand Down Expand Up @@ -3391,6 +3386,14 @@
"application/json": {
"message": "Workflow cdcf48b1-c2f3-4693-8230-b066e088c6ac does not exist"
}
},
"schema": {
"properties": {
"message": {
"type": "string"
}
},
"type": "object"
}
},
"409": {
Expand All @@ -3399,6 +3402,14 @@
"application/json": {
"message": "The workflow is already shared with the user."
}
},
"schema": {
"properties": {
"message": {
"type": "string"
}
},
"type": "object"
}
},
"500": {
Expand All @@ -3407,6 +3418,14 @@
"application/json": {
"message": "Internal controller error."
}
},
"schema": {
"properties": {
"message": {
"type": "string"
}
},
"type": "object"
}
}
},
Expand Down Expand Up @@ -4397,20 +4416,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 @@ -4422,19 +4432,11 @@
"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": {
"properties": {
"errors": {
"items": {
"type": "string"
},
"type": "array"
},
"message": {
"type": "string"
}
Expand All @@ -4446,20 +4448,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 @@ -4471,20 +4464,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 @@ -4496,20 +4480,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
41 changes: 4 additions & 37 deletions reana_server/rest/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,18 +392,12 @@ def get_users_shared_with_you(user):
properties:
email:
type: string
full_name:
type: string
username:
type: string
examples:
application/json:
{
"users_shared_with_you": [
{
"email": "[email protected]",
"full_name": "John Doe",
"username": "jdoe"
}
]
}
Expand Down Expand Up @@ -457,27 +451,16 @@ def get_users_shared_with_you(user):
shared_workflow_owners_ids = (
Session.query(Workflow.owner_id)
.filter(Workflow.id_.in_(shared_workflows_ids))
.distinct()
.subquery()
)

users = (
Session.query(User.email, User.full_name, User.username)
Session.query(User.email)
.filter(User.id_.in_(shared_workflow_owners_ids))
.all()
)

response = {"users_shared_with_you": []}

for email, full_name, username in users:
response["users_shared_with_you"].append(
{
"email": email,
"full_name": full_name,
"username": username,
}
)

response = {"users_shared_with_you": [{"email": user.email} for user in users]}
return jsonify(response), 200
except HTTPError as e:
logging.error(traceback.format_exc())
Expand Down Expand Up @@ -524,18 +507,12 @@ def get_users_you_shared_with(user):
properties:
email:
type: string
full_name:
type: string
username:
type: string
examples:
application/json:
{
"users_you_shared_with": [
{
"email": "[email protected]",
"full_name": "John Doe",
"username": "jdoe"
}
]
}
Expand Down Expand Up @@ -592,22 +569,12 @@ def get_users_you_shared_with(user):
)

users = (
Session.query(User.email, User.full_name, User.username)
Session.query(User.email)
.filter(User.id_.in_(users_you_shared_with_ids))
.all()
)

response = {"users_you_shared_with": []}

for email, full_name, username in users:
response["users_you_shared_with"].append(
{
"email": email,
"full_name": full_name,
"username": username,
}
)

response = {"users_you_shared_with": [{"email": user.email} for user in users]}
return jsonify(response), 200
except HTTPError as e:
logging.error(traceback.format_exc())
Expand Down
Loading

0 comments on commit f66d666

Please sign in to comment.