summaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
Diffstat (limited to 'api')
-rw-r--r--api/opendc/api/v2/portfolios/portfolioId/endpoint.py6
-rw-r--r--api/opendc/api/v2/portfolios/portfolioId/scenarios/endpoint.py2
-rw-r--r--api/opendc/api/v2/projects/projectId/endpoint.py2
-rw-r--r--api/opendc/api/v2/projects/projectId/portfolios/endpoint.py2
-rw-r--r--api/opendc/api/v2/projects/projectId/topologies/endpoint.py2
-rw-r--r--api/opendc/api/v2/scenarios/scenarioId/endpoint.py6
-rw-r--r--api/opendc/api/v2/topologies/topologyId/endpoint.py6
-rw-r--r--api/opendc/models/model.py2
8 files changed, 17 insertions, 11 deletions
diff --git a/api/opendc/api/v2/portfolios/portfolioId/endpoint.py b/api/opendc/api/v2/portfolios/portfolioId/endpoint.py
index c0ca64e0..0ba61a13 100644
--- a/api/opendc/api/v2/portfolios/portfolioId/endpoint.py
+++ b/api/opendc/api/v2/portfolios/portfolioId/endpoint.py
@@ -54,10 +54,12 @@ def DELETE(request):
portfolio.check_exists()
portfolio.check_user_access(request.google_id, True)
+ portfolio_id = portfolio.get_id()
+
project = Project.from_id(portfolio.obj['projectId'])
project.check_exists()
- if request.params_path['portfolioId'] in project.obj['portfolioIds']:
- project.obj['portfolioIds'].remove(request.params_path['portfolioId'])
+ if portfolio_id in project.obj['portfolioIds']:
+ project.obj['portfolioIds'].remove(portfolio_id)
project.update()
old_object = portfolio.delete()
diff --git a/api/opendc/api/v2/portfolios/portfolioId/scenarios/endpoint.py b/api/opendc/api/v2/portfolios/portfolioId/scenarios/endpoint.py
index ca1db36a..fc2cab16 100644
--- a/api/opendc/api/v2/portfolios/portfolioId/scenarios/endpoint.py
+++ b/api/opendc/api/v2/portfolios/portfolioId/scenarios/endpoint.py
@@ -32,7 +32,7 @@ def POST(request):
scenario = Scenario(request.params_body['scenario'])
- scenario.set_property('portfolioId', request.params_path['portfolioId'])
+ scenario.set_property('portfolioId', portfolio.get_id())
scenario.set_property('simulation', {'state': 'QUEUED'})
scenario.insert()
diff --git a/api/opendc/api/v2/projects/projectId/endpoint.py b/api/opendc/api/v2/projects/projectId/endpoint.py
index 77b66d75..caac37ca 100644
--- a/api/opendc/api/v2/projects/projectId/endpoint.py
+++ b/api/opendc/api/v2/projects/projectId/endpoint.py
@@ -58,7 +58,7 @@ def DELETE(request):
user = User.from_google_id(request.google_id)
user.obj['authorizations'] = list(
- filter(lambda x: str(x['projectId']) != request.params_path['projectId'], user.obj['authorizations']))
+ filter(lambda x: x['projectId'] != project.get_id(), user.obj['authorizations']))
user.update()
old_object = project.delete()
diff --git a/api/opendc/api/v2/projects/projectId/portfolios/endpoint.py b/api/opendc/api/v2/projects/projectId/portfolios/endpoint.py
index 0bc65565..2cdb1194 100644
--- a/api/opendc/api/v2/projects/projectId/portfolios/endpoint.py
+++ b/api/opendc/api/v2/projects/projectId/portfolios/endpoint.py
@@ -24,7 +24,7 @@ def POST(request):
portfolio = Portfolio(request.params_body['portfolio'])
- portfolio.set_property('projectId', request.params_path['projectId'])
+ portfolio.set_property('projectId', project.get_id())
portfolio.set_property('scenarioIds', [])
portfolio.insert()
diff --git a/api/opendc/api/v2/projects/projectId/topologies/endpoint.py b/api/opendc/api/v2/projects/projectId/topologies/endpoint.py
index 211dc15d..44a0d575 100644
--- a/api/opendc/api/v2/projects/projectId/topologies/endpoint.py
+++ b/api/opendc/api/v2/projects/projectId/topologies/endpoint.py
@@ -17,7 +17,7 @@ def POST(request):
project.check_user_access(request.google_id, True)
topology = Topology({
- 'projectId': request.params_path['projectId'],
+ 'projectId': project.get_id(),
'name': request.params_body['topology']['name'],
'rooms': request.params_body['topology']['rooms'],
})
diff --git a/api/opendc/api/v2/scenarios/scenarioId/endpoint.py b/api/opendc/api/v2/scenarios/scenarioId/endpoint.py
index 02d39063..88a74e9c 100644
--- a/api/opendc/api/v2/scenarios/scenarioId/endpoint.py
+++ b/api/opendc/api/v2/scenarios/scenarioId/endpoint.py
@@ -46,10 +46,12 @@ def DELETE(request):
scenario.check_exists()
scenario.check_user_access(request.google_id, True)
+ scenario_id = scenario.get_id()
+
portfolio = Portfolio.from_id(scenario.obj['portfolioId'])
portfolio.check_exists()
- if request.params_path['scenarioId'] in portfolio.obj['scenarioIds']:
- portfolio.obj['scenarioIds'].remove(request.params_path['scenarioId'])
+ if scenario_id in portfolio.obj['scenarioIds']:
+ portfolio.obj['scenarioIds'].remove(scenario_id)
portfolio.update()
old_object = scenario.delete()
diff --git a/api/opendc/api/v2/topologies/topologyId/endpoint.py b/api/opendc/api/v2/topologies/topologyId/endpoint.py
index 512b050a..ea82b2e2 100644
--- a/api/opendc/api/v2/topologies/topologyId/endpoint.py
+++ b/api/opendc/api/v2/topologies/topologyId/endpoint.py
@@ -45,10 +45,12 @@ def DELETE(request):
topology.check_exists()
topology.check_user_access(request.google_id, True)
+ topology_id = topology.get_id()
+
project = Project.from_id(topology.obj['projectId'])
project.check_exists()
- if request.params_path['topologyId'] in project.obj['topologyIds']:
- project.obj['topologyIds'].remove(request.params_path['topologyId'])
+ if topology_id in project.obj['topologyIds']:
+ project.obj['topologyIds'].remove(topology_id)
project.update()
old_object = topology.delete()
diff --git a/api/opendc/models/model.py b/api/opendc/models/model.py
index bcb833ae..32159ca3 100644
--- a/api/opendc/models/model.py
+++ b/api/opendc/models/model.py
@@ -25,7 +25,7 @@ class Model:
def get_id(self):
"""Returns the ID of the enclosed object."""
- return str(self.obj['_id'])
+ return self.obj['_id']
def check_exists(self):
"""Raises an error if the enclosed object does not exist."""