From 690818051d0c9768cdaf735acf77ea9e98f00b38 Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Tue, 30 Jun 2020 10:31:27 +0200 Subject: Implement authorizations endpoint --- web-server/opendc/models/simulation.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'web-server/opendc/models') diff --git a/web-server/opendc/models/simulation.py b/web-server/opendc/models/simulation.py index 5cd3d49e..a77697ab 100644 --- a/web-server/opendc/models/simulation.py +++ b/web-server/opendc/models/simulation.py @@ -1,5 +1,6 @@ from opendc.models.model import Model from opendc.models.user import User +from opendc.util.database import DB from opendc.util.exceptions import ClientError from opendc.util.rest import Response @@ -13,3 +14,10 @@ class Simulation(Model): filter(lambda x: str(x['simulationId']) == str(self.obj['_id']), user.obj['authorizations'])) if len(authorizations) == 0 or (edit_access and authorizations[0]['authorizationLevel'] == 'VIEW'): raise ClientError(Response(403, "Forbidden from retrieving simulation.")) + + def get_all_authorizations(self): + return [ + user['_id'] for user in DB.fetch_all({'authorizations': { + 'simulationId': self.obj['_id'] + }}, User.collection_name) + ] -- cgit v1.2.3