diff options
| author | Georgios Andreadis <info@gandreadis.com> | 2020-07-01 14:02:06 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2020-08-24 19:47:20 +0200 |
| commit | 85901acea556c69891b13ab7299cd62445292c7a (patch) | |
| tree | 3daffa1a9600df8471a78db719b7964b0bc5c9ef | |
| parent | de8f12d74faef5fa3f9e38d1340948cab2d06ea3 (diff) | |
Fix simulation interface
| -rw-r--r-- | frontend/src/components/simulations/SimulationActionButtons.js | 2 | ||||
| -rw-r--r-- | frontend/src/components/simulations/SimulationAuthList.js | 2 | ||||
| -rw-r--r-- | frontend/src/components/simulations/SimulationAuthRow.js | 2 | ||||
| -rw-r--r-- | frontend/src/reducers/objects.js | 2 | ||||
| -rw-r--r-- | frontend/src/sagas/simulations.js | 3 | ||||
| -rw-r--r-- | frontend/src/sagas/users.js | 7 | ||||
| -rw-r--r-- | web-server/opendc/api/v2/experiments/experimentId/endpoint.py | 4 | ||||
| -rw-r--r-- | web-server/opendc/api/v2/simulations/endpoint.py | 2 | ||||
| -rw-r--r-- | web-server/opendc/api/v2/simulations/simulationId/endpoint.py | 4 | ||||
| -rw-r--r-- | web-server/opendc/api/v2/topologies/topologyId/endpoint.py | 4 | ||||
| -rw-r--r-- | web-server/opendc/api/v2/users/userId/endpoint.py | 4 | ||||
| -rw-r--r-- | web-server/opendc/models/model.py | 7 | ||||
| -rw-r--r-- | web-server/opendc/util/database.py | 8 |
13 files changed, 26 insertions, 25 deletions
diff --git a/frontend/src/components/simulations/SimulationActionButtons.js b/frontend/src/components/simulations/SimulationActionButtons.js index 6d2e5831..515047c4 100644 --- a/frontend/src/components/simulations/SimulationActionButtons.js +++ b/frontend/src/components/simulations/SimulationActionButtons.js @@ -29,7 +29,7 @@ const SimulationActionButtons = ({ simulationId, onViewUsers, onDelete }) => ( ) SimulationActionButtons.propTypes = { - simulationId: PropTypes.number.isRequired, + simulationId: PropTypes.string.isRequired, onViewUsers: PropTypes.func, onDelete: PropTypes.func, } diff --git a/frontend/src/components/simulations/SimulationAuthList.js b/frontend/src/components/simulations/SimulationAuthList.js index dce7fb5c..c760d08f 100644 --- a/frontend/src/components/simulations/SimulationAuthList.js +++ b/frontend/src/components/simulations/SimulationAuthList.js @@ -26,7 +26,7 @@ const SimulationAuthList = ({ authorizations }) => { {authorizations.map(authorization => ( <SimulationAuthRow simulationAuth={authorization} - key={authorization.simulation.id} + key={authorization.simulation._id} /> ))} </tbody> diff --git a/frontend/src/components/simulations/SimulationAuthRow.js b/frontend/src/components/simulations/SimulationAuthRow.js index b647db69..0e9c36da 100644 --- a/frontend/src/components/simulations/SimulationAuthRow.js +++ b/frontend/src/components/simulations/SimulationAuthRow.js @@ -21,7 +21,7 @@ const SimulationAuthRow = ({ simulationAuth }) => ( /> {AUTH_DESCRIPTION_MAP[simulationAuth.authorizationLevel]} </td> - <SimulationActions simulationId={simulationAuth.simulation.id}/> + <SimulationActions simulationId={simulationAuth.simulation._id}/> </tr> ) diff --git a/frontend/src/reducers/objects.js b/frontend/src/reducers/objects.js index 2e9644d0..1dc1e7e8 100644 --- a/frontend/src/reducers/objects.js +++ b/frontend/src/reducers/objects.js @@ -35,7 +35,7 @@ export const objects = combineReducers({ }) function object(type) { - return objectWithId(type, object => object.id) + return objectWithId(type, object => object._id) } function objectWithId(type, getId) { diff --git a/frontend/src/sagas/simulations.js b/frontend/src/sagas/simulations.js index 9e914b85..b57fac95 100644 --- a/frontend/src/sagas/simulations.js +++ b/frontend/src/sagas/simulations.js @@ -21,9 +21,10 @@ export function* onSimulationAdd(action) { yield put(addToStore('simulation', simulation)) const authorization = { - simulationId: simulation.id, + simulationId: simulation._id, userId: action.userId, authorizationLevel: 'OWN', + simulation, } yield put(addToStore('authorization', authorization)) yield put( diff --git a/frontend/src/sagas/users.js b/frontend/src/sagas/users.js index fb5197d1..a10887a0 100644 --- a/frontend/src/sagas/users.js +++ b/frontend/src/sagas/users.js @@ -13,7 +13,7 @@ export function* onFetchLoggedInUser(action) { performTokenSignIn, action.payload.authToken, ) - console.log(tokenResponse) + let userId = tokenResponse.userId if (tokenResponse.isNewUser) { @@ -33,14 +33,13 @@ export function* onFetchAuthorizationsOfCurrentUser(action) { const user = yield call(fetchAndStoreUser, action.userId) for (const authorization of user.authorizations) { + authorization.userId = action.userId yield put(addToStore('authorization', authorization)) - yield fetchAndStoreSimulation(authorization.simulationId) - yield fetchAndStoreUser(authorization.userId) } const authorizationIds = user.authorizations.map(authorization => [ - authorization.userId, + action.userId, authorization.simulationId, ]) diff --git a/web-server/opendc/api/v2/experiments/experimentId/endpoint.py b/web-server/opendc/api/v2/experiments/experimentId/endpoint.py index 103c24ac..5120368e 100644 --- a/web-server/opendc/api/v2/experiments/experimentId/endpoint.py +++ b/web-server/opendc/api/v2/experiments/experimentId/endpoint.py @@ -60,6 +60,6 @@ def DELETE(request): simulation.obj['experimentIds'].remove(request.params_path['experimentId']) simulation.update() - experiment.delete() + old_object = experiment.delete() - return Response(200, 'Successfully deleted experiment.', experiment.obj) + return Response(200, 'Successfully deleted experiment.', old_object) diff --git a/web-server/opendc/api/v2/simulations/endpoint.py b/web-server/opendc/api/v2/simulations/endpoint.py index c978fad7..bcdea650 100644 --- a/web-server/opendc/api/v2/simulations/endpoint.py +++ b/web-server/opendc/api/v2/simulations/endpoint.py @@ -15,7 +15,7 @@ def POST(request): topology = Topology({'name': 'Default topology', 'rooms': []}) topology.insert() - simulation = Simulation({'simulation': request.params_body['simulation']}) + simulation = Simulation(request.params_body['simulation']) simulation.set_property('datetimeCreated', Database.datetime_to_string(datetime.now())) simulation.set_property('datetimeLastEdited', Database.datetime_to_string(datetime.now())) simulation.set_property('topologyIds', [topology.get_id()]) diff --git a/web-server/opendc/api/v2/simulations/simulationId/endpoint.py b/web-server/opendc/api/v2/simulations/simulationId/endpoint.py index 05b38686..93617ea8 100644 --- a/web-server/opendc/api/v2/simulations/simulationId/endpoint.py +++ b/web-server/opendc/api/v2/simulations/simulationId/endpoint.py @@ -55,6 +55,6 @@ def DELETE(request): experiment = Experiment.from_id(experiment_id) experiment.delete() - simulation.delete() + old_object = simulation.delete() - return Response(200, 'Successfully deleted simulation.', simulation.obj) + return Response(200, 'Successfully deleted simulation.', old_object) diff --git a/web-server/opendc/api/v2/topologies/topologyId/endpoint.py b/web-server/opendc/api/v2/topologies/topologyId/endpoint.py index 84f20903..1dcccb3e 100644 --- a/web-server/opendc/api/v2/topologies/topologyId/endpoint.py +++ b/web-server/opendc/api/v2/topologies/topologyId/endpoint.py @@ -51,6 +51,6 @@ def DELETE(request): simulation.obj['topologyIds'].remove(request.params_path['topologyId']) simulation.update() - topology.delete() + old_object = topology.delete() - return Response(200, 'Successfully deleted topology.', topology.obj) + return Response(200, 'Successfully deleted topology.', old_object) diff --git a/web-server/opendc/api/v2/users/userId/endpoint.py b/web-server/opendc/api/v2/users/userId/endpoint.py index 660083b6..eedb2e3c 100644 --- a/web-server/opendc/api/v2/users/userId/endpoint.py +++ b/web-server/opendc/api/v2/users/userId/endpoint.py @@ -46,6 +46,6 @@ def DELETE(request): user.check_exists() user.check_correct_user(request.google_id) - user.delete() + old_object = user.delete() - return Response(200, 'Successfully deleted user.', user.obj) + return Response(200, 'Successfully deleted user.', old_object) diff --git a/web-server/opendc/models/model.py b/web-server/opendc/models/model.py index f42134bf..cab283c9 100644 --- a/web-server/opendc/models/model.py +++ b/web-server/opendc/models/model.py @@ -46,5 +46,10 @@ class Model: DB.update(self.get_id(), self.obj, self.collection_name) def delete(self): - """Deletes the enclosed object in the database.""" + """Deletes the enclosed object in the database, if it existed.""" + if self.obj is None: + return None + + old_object = self.obj.copy() DB.delete_one({'_id': self.get_id()}, self.collection_name) + return old_object diff --git a/web-server/opendc/util/database.py b/web-server/opendc/util/database.py index 0402c2e1..80cdcbab 100644 --- a/web-server/opendc/util/database.py +++ b/web-server/opendc/util/database.py @@ -63,18 +63,14 @@ class Database: The query needs to be in json format, i.e.: `{'name': prefab_name}`. """ - bson = getattr(self.opendc_db, collection).delete_one(query) - - return self.convert_bson_to_json(bson) + getattr(self.opendc_db, collection).delete_one(query) def delete_all(self, query, collection): """Deletes all objects matching the given query. The query needs to be in json format, i.e.: `{'name': prefab_name}`. """ - bson = getattr(self.opendc_db, collection).delete_many(query) - - return self.convert_bson_to_json(bson) + getattr(self.opendc_db, collection).delete_many(query) @staticmethod def convert_bson_to_json(bson): |
