diff options
| author | leonoverweel <l.overweel@gmail.com> | 2017-01-24 12:05:15 +0100 |
|---|---|---|
| committer | leonoverweel <l.overweel@gmail.com> | 2017-01-24 12:05:15 +0100 |
| commit | 86a50a4f6df9ece982743a3b7ca510846d248909 (patch) | |
| tree | 79edc0478908b7fee9e5dca2088e562c7a62038b /opendc/models/room.py | |
Initial commit
Diffstat (limited to 'opendc/models/room.py')
| -rw-r--r-- | opendc/models/room.py | 34 |
1 files changed, 34 insertions, 0 deletions
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) |
