From 86a50a4f6df9ece982743a3b7ca510846d248909 Mon Sep 17 00:00:00 2001 From: leonoverweel Date: Tue, 24 Jan 2017 12:05:15 +0100 Subject: Initial commit --- opendc/models/room.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 opendc/models/room.py (limited to 'opendc/models/room.py') diff --git a/opendc/models/room.py b/opendc/models/room.py new file mode 100644 index 00000000..b8be88f9 --- /dev/null +++ b/opendc/models/room.py @@ -0,0 +1,34 @@ +from opendc.models.model import Model +from opendc.models.datacenter import Datacenter +from opendc.util import database, exceptions + +class Room(Model): + + JSON_TO_PYTHON_DICT = { + 'room': { + 'id': 'id', + 'datacenterId': 'datacenter_id', + 'name': 'name', + 'roomType': 'type' + } + } + + PATH = '/v1/simulations/{simulationId}/datacenters/{datacenterId}/rooms' + + TABLE_NAME = 'rooms' + COLUMNS = ['id', 'name', 'datacenter_id', 'type'] + COLUMNS_PRIMARY_KEY = ['id'] + + def google_id_has_at_least(self, google_id, authorization_level): + """Return True if the user has at least the given auth level over this Room.""" + + # Get the Datacenter + + try: + datacenter = Datacenter.from_primary_key((self.datacenter_id,)) + except exceptions.RowNotFoundError: + return False + + # Check the Datacenter's Authorization + + return datacenter.google_id_has_at_least(google_id, authorization_level) -- cgit v1.2.3