1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-25 06:24:19 +00:00

Add delete method to repository_authorization

This commit is contained in:
Lorenzo Balugani 2021-05-24 13:32:12 +02:00
parent 8c38d1a65a
commit b4206d6e75
2 changed files with 41 additions and 1 deletions

View file

@ -69,7 +69,7 @@ app.add_url_rule(
app.add_url_rule(
"/api/v1/repositories/<int:rid>/authorizations/",
view_func=routes.page_repository_authorizations,
methods=["GET", "POST"],
methods=["GET", "POST", "DELETE"],
)
app.add_url_rule(
"/api/v1/repositories/<int:rid>/tweets/",

View file

@ -70,6 +70,38 @@ def page_repository_authorizations(rid):
schema: Error
tags:
- repository-related
delete:
summary: Delete an authorization.
parameters:
- in: path
schema: IntegerParameterSchema
security:
- jwt: []
requestBody:
required: true
content:
application/json:
schema: CreateAuthorization
responses:
'204':
description: The deletion was successful.
'401':
description: The user is not logged in.
content:
application/json:
schema: Error
'403':
description: The user is not authorized.
content:
application/json:
schema: Error
'404':
description: Something could not be found.
content:
application/json:
schema: Error
tags:
- repository-related
"""
repository = Repository.query.filter_by(id=rid).first()
@ -99,3 +131,11 @@ def page_repository_authorizations(rid):
ext.session.commit()
return json_success(authorization.to_json()), 201
if request.method == "DELETE":
authorization = Authorization.query.filter_by(rid=rid, email=request.json.get('email')).first()
if not authorization:
return json_error("Could not find the authorization", AUTHORIZATION_NOT_FOUND), 404
ext.session.delete(authorization)
ext.session.commit()
return json_success("Deleted."), 204