diff options
Diffstat (limited to 'web-server/opendc')
| -rw-r--r-- | web-server/opendc/api/v2/simulations/simulationId/topologies/endpoint.py | 7 | ||||
| -rw-r--r-- | web-server/opendc/api/v2/topologies/topologyId/endpoint.py | 6 | ||||
| -rw-r--r-- | web-server/opendc/models/experiment.py | 2 | ||||
| -rw-r--r-- | web-server/opendc/models/model.py | 11 | ||||
| -rw-r--r-- | web-server/opendc/models/simulation.py | 4 |
5 files changed, 14 insertions, 16 deletions
diff --git a/web-server/opendc/api/v2/simulations/simulationId/topologies/endpoint.py b/web-server/opendc/api/v2/simulations/simulationId/topologies/endpoint.py index ecf80353..09c84019 100644 --- a/web-server/opendc/api/v2/simulations/simulationId/topologies/endpoint.py +++ b/web-server/opendc/api/v2/simulations/simulationId/topologies/endpoint.py @@ -9,12 +9,7 @@ from opendc.util.database import Database def POST(request): """Add a new Topology to the specified simulation and return it""" - request.check_required_parameters(path={'simulationId': 'string'}, - body={ - 'topology': { - 'name': 'string' - } - }) + request.check_required_parameters(path={'simulationId': 'string'}, body={'topology': {'name': 'string'}}) simulation = Simulation.from_id(request.params_path['simulationId']) diff --git a/web-server/opendc/api/v2/topologies/topologyId/endpoint.py b/web-server/opendc/api/v2/topologies/topologyId/endpoint.py index a4f71ed6..84f20903 100644 --- a/web-server/opendc/api/v2/topologies/topologyId/endpoint.py +++ b/web-server/opendc/api/v2/topologies/topologyId/endpoint.py @@ -9,7 +9,7 @@ from opendc.util.rest import Response def GET(request): """Get this Topology.""" - request.check_required_parameters(path={'topologyId': 'int'}) + request.check_required_parameters(path={'topologyId': 'string'}) topology = Topology.from_id(request.params_path['topologyId']) @@ -21,7 +21,7 @@ def GET(request): def PUT(request): """Update this topology""" - request.check_required_parameters(path={'topologyId': 'int'}, body={'topology': {'name': 'string', 'rooms': {}}}) + request.check_required_parameters(path={'topologyId': 'string'}, body={'topology': {'name': 'string', 'rooms': {}}}) topology = Topology.from_id(request.params_path['topologyId']) topology.check_exists() @@ -38,7 +38,7 @@ def PUT(request): def DELETE(request): """Delete this topology""" - request.check_required_parameters(path={'topologyId': 'int'}) + request.check_required_parameters(path={'topologyId': 'string'}) topology = Topology.from_id(request.params_path['topologyId']) diff --git a/web-server/opendc/models/experiment.py b/web-server/opendc/models/experiment.py index ac606d64..36b5d415 100644 --- a/web-server/opendc/models/experiment.py +++ b/web-server/opendc/models/experiment.py @@ -21,4 +21,4 @@ class Experiment(Model): authorizations = list( filter(lambda x: str(x['simulationId']) == str(self.obj['simulationId']), user.obj['authorizations'])) if len(authorizations) == 0 or (edit_access and authorizations[0]['authorizationLevel'] == 'VIEW'): - raise ClientError(Response(403, "Forbidden from retrieving/editing experiment.")) + raise ClientError(Response(403, 'Forbidden from retrieving/editing experiment.')) diff --git a/web-server/opendc/models/model.py b/web-server/opendc/models/model.py index 1935638f..f42134bf 100644 --- a/web-server/opendc/models/model.py +++ b/web-server/opendc/models/model.py @@ -1,3 +1,5 @@ +from uuid import uuid4 + from opendc.util.database import DB from opendc.util.exceptions import ClientError from opendc.util.rest import Response @@ -23,7 +25,7 @@ class Model: def get_id(self): """Returns the ID of the enclosed object.""" - return self.obj['_id'] + return str(self.obj['_id']) def check_exists(self): """Raises an error if the enclosed object does not exist.""" @@ -35,12 +37,13 @@ class Model: self.obj[key] = value def insert(self): - """Inserts the enclosed object and updates the internal reference to the newly inserted object.""" - self.obj = DB.insert(self.obj, self.collection_name) + """Inserts the enclosed object and generates a UUID for it.""" + self.obj['_id'] = str(uuid4()) + DB.insert(self.obj, self.collection_name) def update(self): """Updates the enclosed object and updates the internal reference to the newly inserted object.""" - self.obj = DB.update(self.get_id(), self.obj, self.collection_name) + DB.update(self.get_id(), self.obj, self.collection_name) def delete(self): """Deletes the enclosed object in the database.""" diff --git a/web-server/opendc/models/simulation.py b/web-server/opendc/models/simulation.py index 86aa4726..9a2770cf 100644 --- a/web-server/opendc/models/simulation.py +++ b/web-server/opendc/models/simulation.py @@ -25,7 +25,7 @@ class Simulation(Model): def get_all_authorizations(self): """Get all user IDs having access to this simulation.""" return [ - user['_id'] for user in DB.fetch_all({'authorizations': { - 'simulationId': self.get_id() + str(user['_id']) for user in DB.fetch_all({'authorizations': { + 'simulationId': self.obj['_id'] }}, User.collection_name) ] |
