From 61cf27a9529e503d3c56854c9d664f2d9520213a Mon Sep 17 00:00:00 2001 From: jc0b Date: Thu, 25 Jun 2020 22:11:25 +0200 Subject: GET for topologies with tests --- opendc/models/topology.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'opendc/models') diff --git a/opendc/models/topology.py b/opendc/models/topology.py index a5f53bbb..b01d5f41 100644 --- a/opendc/models/topology.py +++ b/opendc/models/topology.py @@ -1,5 +1,16 @@ from opendc.models.model import Model +from opendc.models.user import User +from opendc.util.rest import Response class Topology(Model): collection_name = 'topologies' + + def validate_user_access(self, google_id, edit_access): + user = User.from_google_id(google_id) + authorizations = list( + filter(lambda x: str(x['topologyId']) == str(self.obj['_id']), user.obj['authorizations'])) + if len(authorizations) == 0 or (edit_access and authorizations[0]['authorizationLevel'] == 'VIEW'): + return Response(403, "Forbidden from retrieving topology.") + + return None \ No newline at end of file -- cgit v1.2.3