diff options
Diffstat (limited to 'opendc-web/opendc-web-api/opendc/api')
| -rw-r--r-- | opendc-web/opendc-web-api/opendc/api/portfolios.py | 14 | ||||
| -rw-r--r-- | opendc-web/opendc-web-api/opendc/api/projects.py | 27 |
2 files changed, 40 insertions, 1 deletions
diff --git a/opendc-web/opendc-web-api/opendc/api/portfolios.py b/opendc-web/opendc-web-api/opendc/api/portfolios.py index eea82289..4d8f54fd 100644 --- a/opendc-web/opendc-web-api/opendc/api/portfolios.py +++ b/opendc-web/opendc-web-api/opendc/api/portfolios.py @@ -103,6 +103,20 @@ class PortfolioScenarios(Resource): """ method_decorators = [requires_auth] + def get(self, portfolio_id): + """ + Get all scenarios belonging to a portfolio. + """ + portfolio = PortfolioModel.from_id(portfolio_id) + + portfolio.check_exists() + portfolio.check_user_access(current_user['sub'], True) + + scenarios = Scenario.get_for_portfolio(portfolio_id) + + data = ScenarioSchema().dump(scenarios, many=True) + return {'data': data} + def post(self, portfolio_id): """ Add a new scenario to this portfolio 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): """ |
