diff options
Diffstat (limited to 'opendc-web/opendc-web-api/opendc/api/v2/projects/endpoint.py')
| -rw-r--r-- | opendc-web/opendc-web-api/opendc/api/v2/projects/endpoint.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/projects/endpoint.py b/opendc-web/opendc-web-api/opendc/api/v2/projects/endpoint.py index dacbe6a4..b381d689 100644 --- a/opendc-web/opendc-web-api/opendc/api/v2/projects/endpoint.py +++ b/opendc-web/opendc-web-api/opendc/api/v2/projects/endpoint.py @@ -2,15 +2,22 @@ from datetime import datetime from opendc.models.project import Project from opendc.models.topology import Topology -from opendc.models.user import User from opendc.util.database import Database from opendc.util.rest import Response +def GET(request): + """Get the authorized projects of the user""" + user_id = request.current_user['sub'] + projects = Project.get_for_user(user_id) + return Response(200, 'Successfully retrieved projects', projects) + + def POST(request): """Create a new project, and return that new project.""" request.check_required_parameters(body={'project': {'name': 'string'}}) + user_id = request.current_user['sub'] topology = Topology({'name': 'Default topology', 'rooms': []}) topology.insert() @@ -20,13 +27,10 @@ def POST(request): project.set_property('datetimeLastEdited', Database.datetime_to_string(datetime.now())) project.set_property('topologyIds', [topology.get_id()]) project.set_property('portfolioIds', []) + project.set_property('authorizations', [{'userId': user_id, 'authorizationLevel': 'OWN'}]) project.insert() topology.set_property('projectId', project.get_id()) topology.update() - user = User.from_google_id(request.current_user['sub']) - user.obj['authorizations'].append({'projectId': project.get_id(), 'authorizationLevel': 'OWN'}) - user.update() - return Response(200, 'Successfully created project.', project.obj) |
