summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-api/opendc/api/projects.py
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-07-07 20:45:06 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-07-08 10:53:25 +0200
commit5ec19973eb3d23046d874b097275857a58c23082 (patch)
treea601cd975f8917fb2d4af28e8a3fb228e0cb769e /opendc-web/opendc-web-api/opendc/api/projects.py
parent02a2f0f89cb1f39a5f8856bca1971a4e1b12374f (diff)
api: Add endpoints for accessing project relations
This change adds additional endpoints to the REST API to access the project relations, the portfolios and topologies that belong to a project.
Diffstat (limited to 'opendc-web/opendc-web-api/opendc/api/projects.py')
-rw-r--r--opendc-web/opendc-web-api/opendc/api/projects.py27
1 files changed, 26 insertions, 1 deletions
diff --git a/opendc-web/opendc-web-api/opendc/api/projects.py b/opendc-web/opendc-web-api/opendc/api/projects.py
index 05f02a84..2b47c12e 100644
--- a/opendc-web/opendc-web-api/opendc/api/projects.py
+++ b/opendc-web/opendc-web-api/opendc/api/projects.py
@@ -132,6 +132,18 @@ class ProjectTopologies(Resource):
"""
method_decorators = [requires_auth]
+ def get(self, project_id):
+ """Get all topologies belonging to the project."""
+ project = ProjectModel.from_id(project_id)
+
+ project.check_exists()
+ project.check_user_access(current_user['sub'], True)
+
+ topologies = Topology.get_for_project(project_id)
+ data = TopologySchema().dump(topologies, many=True)
+
+ return {'data': data}
+
def post(self, project_id):
"""Add a new Topology to the specified project and return it"""
schema = ProjectTopologies.PutSchema()
@@ -170,6 +182,18 @@ class ProjectPortfolios(Resource):
"""
method_decorators = [requires_auth]
+ def get(self, project_id):
+ """Get all portfolios belonging to the project."""
+ project = ProjectModel.from_id(project_id)
+
+ project.check_exists()
+ project.check_user_access(current_user['sub'], True)
+
+ portfolios = Portfolio.get_for_project(project_id)
+ data = PortfolioSchema().dump(portfolios, many=True)
+
+ return {'data': data}
+
def post(self, project_id):
"""Add a new Portfolio for this Project."""
schema = ProjectPortfolios.PutSchema()
@@ -190,7 +214,8 @@ class ProjectPortfolios(Resource):
project.obj['portfolioIds'].append(portfolio.get_id())
project.update()
- return {'data': portfolio.obj}
+ data = PortfolioSchema().dump(portfolio.obj)
+ return {'data': data}
class PutSchema(Schema):
"""