diff options
Diffstat (limited to 'opendc/api/v2/simulations/simulationId/endpoint.py')
| -rw-r--r-- | opendc/api/v2/simulations/simulationId/endpoint.py | 40 |
1 files changed, 12 insertions, 28 deletions
diff --git a/opendc/api/v2/simulations/simulationId/endpoint.py b/opendc/api/v2/simulations/simulationId/endpoint.py index b08cf8be..b8ae9a38 100644 --- a/opendc/api/v2/simulations/simulationId/endpoint.py +++ b/opendc/api/v2/simulations/simulationId/endpoint.py @@ -10,10 +10,7 @@ from opendc.util.rest import Response def GET(request): """Get this Simulation.""" - try: - request.check_required_parameters(path={'simulationId': 'string'}) - except exceptions.ParameterError as e: - return Response(400, str(e)) + request.check_required_parameters(path={'simulationId': 'string'}) simulation = Simulation.from_id(request.params_path['simulationId']) validation_error = simulation.validate() @@ -30,10 +27,7 @@ def GET(request): def PUT(request): """Update a simulation's name.""" - try: - request.check_required_parameters(body={'simulation': {'name': 'name'}}, path={'simulationId': 'string'}) - except exceptions.ParameterError as e: - return Response(400, str(e)) + request.check_required_parameters(body={'simulation': {'name': 'name'}}, path={'simulationId': 'string'}) simulation = Simulation.from_id(request.params_path['simulationId']) @@ -55,30 +49,20 @@ def PUT(request): def DELETE(request): """Delete this Simulation.""" - # Make sure required parameters are there + request.check_required_parameters(path={'simulationId': 'string'}) - try: - request.check_required_parameters(path={'simulationId': 'string'}) - - except exceptions.ParameterError as e: - return Response(400, str(e)) - - # Instantiate a Simulation and make sure it exists - - simulation = Simulation.from_primary_key((request.params_path['simulationId'], )) - - if not simulation.exists(): - return Response(404, '{} not found.'.format(simulation)) + simulation = Simulation.from_id(request.params_path['simulationId']) - # Make sure this User is allowed to delete this Simulation + validation_error = simulation.validate() + if validation_error is not None: + return validation_error - if not simulation.google_id_has_at_least(request.google_id, 'OWN'): - return Response(403, 'Forbidden from deleting {}.'.format(simulation)) + access_error = simulation.validate_user_access(request.google_id, True) + if access_error is not None: + return access_error - # Delete this Simulation from the database + # FIXME cascading simulation.delete() - # Return this Simulation - - return Response(200, 'Successfully deleted {}.'.format(simulation), simulation.to_JSON()) + return Response(200, f'Successfully deleted simulation.', simulation.obj) |
