mirror of
https://github.com/pds-nest/nest.git
synced 2024-11-22 04:54:18 +00:00
Change repository page authentications url
This commit is contained in:
parent
b4206d6e75
commit
5eeb33b69f
2 changed files with 29 additions and 20 deletions
|
@ -69,7 +69,7 @@ app.add_url_rule(
|
||||||
app.add_url_rule(
|
app.add_url_rule(
|
||||||
"/api/v1/repositories/<int:rid>/authorizations/",
|
"/api/v1/repositories/<int:rid>/authorizations/",
|
||||||
view_func=routes.page_repository_authorizations,
|
view_func=routes.page_repository_authorizations,
|
||||||
methods=["GET", "POST", "DELETE"],
|
methods=["GET", "POST", "PUT"],
|
||||||
)
|
)
|
||||||
app.add_url_rule(
|
app.add_url_rule(
|
||||||
"/api/v1/repositories/<int:rid>/tweets/",
|
"/api/v1/repositories/<int:rid>/tweets/",
|
||||||
|
@ -77,7 +77,7 @@ app.add_url_rule(
|
||||||
methods=["GET"]
|
methods=["GET"]
|
||||||
)
|
)
|
||||||
app.add_url_rule(
|
app.add_url_rule(
|
||||||
"/api/v1/authorization/<int:rid>/<string:email>",
|
"/api/v1/repositories/<int:rid>/authorizations/<string:email>",
|
||||||
view_func=routes.page_authorization,
|
view_func=routes.page_authorization,
|
||||||
methods=["DELETE"]
|
methods=["DELETE"]
|
||||||
)
|
)
|
||||||
|
|
|
@ -70,7 +70,7 @@ def page_repository_authorizations(rid):
|
||||||
schema: Error
|
schema: Error
|
||||||
tags:
|
tags:
|
||||||
- repository-related
|
- repository-related
|
||||||
delete:
|
put:
|
||||||
summary: Delete an authorization.
|
summary: Delete an authorization.
|
||||||
parameters:
|
parameters:
|
||||||
- in: path
|
- in: path
|
||||||
|
@ -83,8 +83,16 @@ def page_repository_authorizations(rid):
|
||||||
application/json:
|
application/json:
|
||||||
schema: CreateAuthorization
|
schema: CreateAuthorization
|
||||||
responses:
|
responses:
|
||||||
'204':
|
'200':
|
||||||
description: The deletion was successful.
|
description: The authorization already existed
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema: Authorization
|
||||||
|
'201':
|
||||||
|
description: The authorization has been created successfully.
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema: Authorization
|
||||||
'401':
|
'401':
|
||||||
description: The user is not logged in.
|
description: The user is not logged in.
|
||||||
content:
|
content:
|
||||||
|
@ -115,27 +123,28 @@ def page_repository_authorizations(rid):
|
||||||
return json_success([a.to_json() for a in repository.authorizations])
|
return json_success([a.to_json() for a in repository.authorizations])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return json_error("Unknown error:" + str(e), GENERIC_UFO), 400
|
return json_error("Unknown error:" + str(e), GENERIC_UFO), 400
|
||||||
|
if request.json is None:
|
||||||
|
return json_error("Missing json content.", GENERIC_NO_JSON), 400
|
||||||
|
if not request.json.get("email"):
|
||||||
|
return json_error("Missing user email.", GENERIC_MISSING_FIELDS), 400
|
||||||
|
target = User.query.filter_by(email=request.json.get('email')).first()
|
||||||
|
if not target:
|
||||||
|
return json_error("User could not be located", USER_NOT_FOUND), 400
|
||||||
|
if target == user:
|
||||||
|
return json_error("Owner cannot be a spectator", GENERIC_ALREADY_EXISTS), 406
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
if request.json is None:
|
|
||||||
return json_error("Missing json content.", GENERIC_NO_JSON), 400
|
|
||||||
if not request.json.get("email"):
|
|
||||||
return json_error("Missing user email.", GENERIC_MISSING_FIELDS), 400
|
|
||||||
target = User.query.filter_by(email=request.json.get('email')).first()
|
|
||||||
if not target:
|
|
||||||
return json_error("User could not be located", USER_NOT_FOUND), 400
|
|
||||||
if target == user:
|
|
||||||
return json_error("Owner cannot be a spectator", GENERIC_ALREADY_EXISTS), 406
|
|
||||||
|
|
||||||
authorization = Authorization(email=request.json.get('email'), rid=repository.id)
|
authorization = Authorization(email=request.json.get('email'), rid=repository.id)
|
||||||
ext.session.add(authorization)
|
ext.session.add(authorization)
|
||||||
ext.session.commit()
|
ext.session.commit()
|
||||||
|
|
||||||
return json_success(authorization.to_json()), 201
|
return json_success(authorization.to_json()), 201
|
||||||
|
|
||||||
if request.method == "DELETE":
|
if request.method == "PUT":
|
||||||
authorization = Authorization.query.filter_by(rid=rid, email=request.json.get('email')).first()
|
authorization = Authorization.query.filter_by(rid=rid, email=request.json.get('email')).first()
|
||||||
if not authorization:
|
if not authorization:
|
||||||
return json_error("Could not find the authorization", AUTHORIZATION_NOT_FOUND), 404
|
authorization = Authorization(email=request.json.get('email'), rid=repository.id)
|
||||||
ext.session.delete(authorization)
|
ext.session.add(authorization)
|
||||||
ext.session.commit()
|
ext.session.commit()
|
||||||
return json_success("Deleted."), 204
|
return json_success(authorization.to_json()), 201
|
||||||
|
|
||||||
|
return json_success(authorization.to_json()), 200
|
||||||
|
|
Loading…
Reference in a new issue