summaryrefslogtreecommitdiff
path: root/opendc/models
diff options
context:
space:
mode:
authorjc0b <j@jc0b.computer>2020-06-25 22:11:25 +0200
committerjc0b <j@jc0b.computer>2020-06-25 22:11:25 +0200
commit61cf27a9529e503d3c56854c9d664f2d9520213a (patch)
tree77b32f3dfd56af806520ed481450f6d3c2f33412 /opendc/models
parent00597ec99f587557b88b9982a2c41a2cb8db8112 (diff)
GET for topologies with tests
Diffstat (limited to 'opendc/models')
-rw-r--r--opendc/models/topology.py11
1 files changed, 11 insertions, 0 deletions
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