From 4f9a40abdc7836345113c047f27fcc96800cb3f5 Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Mon, 29 Jun 2020 16:05:23 +0200 Subject: Prepare web-server repository for monorepo This change prepares the web-server Git repository for the monorepo residing at https://github.com/atlarge-research.com/opendc. To accomodate for this, we move all files into a web-server subdirectory. --- opendc/models/__init__.py | 0 opendc/models/model.py | 30 ------------------------------ opendc/models/simulation.py | 15 --------------- opendc/models/topology.py | 15 --------------- opendc/models/user.py | 26 -------------------------- 5 files changed, 86 deletions(-) delete mode 100644 opendc/models/__init__.py delete mode 100644 opendc/models/model.py delete mode 100644 opendc/models/simulation.py delete mode 100644 opendc/models/topology.py delete mode 100644 opendc/models/user.py (limited to 'opendc/models') diff --git a/opendc/models/__init__.py b/opendc/models/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/opendc/models/model.py b/opendc/models/model.py deleted file mode 100644 index 2505ae61..00000000 --- a/opendc/models/model.py +++ /dev/null @@ -1,30 +0,0 @@ -from opendc.util.database import DB -from opendc.util.exceptions import ClientError -from opendc.util.rest import Response - - -class Model: - collection_name = '' - - @classmethod - def from_id(cls, _id): - return cls(DB.fetch_one({'_id': _id}, Model.collection_name)) - - def __init__(self, obj): - self.obj = obj - - def check_exists(self): - if self.obj is None: - raise ClientError(Response(404, 'Not found.')) - - def set_property(self, key, value): - self.obj[key] = value - - def insert(self): - self.obj = DB.insert(self.obj, self.collection_name) - - def update(self): - self.obj = DB.update(self.obj['_id'], self.obj, self.collection_name) - - def delete(self): - self.obj = DB.delete_one({'_id': self.obj['_id']}, self.collection_name) diff --git a/opendc/models/simulation.py b/opendc/models/simulation.py deleted file mode 100644 index 5cd3d49e..00000000 --- a/opendc/models/simulation.py +++ /dev/null @@ -1,15 +0,0 @@ -from opendc.models.model import Model -from opendc.models.user import User -from opendc.util.exceptions import ClientError -from opendc.util.rest import Response - - -class Simulation(Model): - collection_name = 'simulations' - - def check_user_access(self, google_id, edit_access): - user = User.from_google_id(google_id) - authorizations = list( - 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.")) diff --git a/opendc/models/topology.py b/opendc/models/topology.py deleted file mode 100644 index 6dde3e2a..00000000 --- a/opendc/models/topology.py +++ /dev/null @@ -1,15 +0,0 @@ -from opendc.models.model import Model -from opendc.models.user import User -from opendc.util.exceptions import ClientError -from opendc.util.rest import Response - - -class Topology(Model): - collection_name = 'topologies' - - def check_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'): - raise ClientError(Response(403, "Forbidden from retrieving topology.")) diff --git a/opendc/models/user.py b/opendc/models/user.py deleted file mode 100644 index cd314457..00000000 --- a/opendc/models/user.py +++ /dev/null @@ -1,26 +0,0 @@ -from opendc.models.model import Model -from opendc.util.database import DB -from opendc.util.exceptions import ClientError -from opendc.util.rest import Response - - -class User(Model): - collection_name = 'users' - - @classmethod - def from_email(cls, email): - return User(DB.fetch_one({'email': email}, User.collection_name)) - - @classmethod - def from_google_id(cls, google_id): - return User(DB.fetch_one({'googleId': google_id}, User.collection_name)) - - def check_correct_user(self, request_google_id): - if request_google_id is not None and self.obj['googleId'] != request_google_id: - raise ClientError(Response(403, f'Forbidden from editing user with ID {self.obj["_id"]}.')) - - def check_already_exists(self): - existing_user = DB.fetch_one({'googleId': self.obj['googleId']}, self.collection_name) - - if existing_user is not None: - raise ClientError(Response(409, 'User already exists.')) -- cgit v1.2.3