Beispiel #1
0
def DELETE(request):
    """Delete this Project."""

    request.check_required_parameters(path={'projectId': 'string'})

    project = Project.from_id(request.params_path['projectId'])

    project.check_exists()
    project.check_user_access(request.google_id, True)

    for topology_id in project.obj['topologyIds']:
        topology = Topology.from_id(topology_id)
        topology.delete()

    for portfolio_id in project.obj['portfolioIds']:
        portfolio = Portfolio.from_id(portfolio_id)
        portfolio.delete()

    user = User.from_google_id(request.google_id)
    user.obj['authorizations'] = list(
        filter(lambda x: x['projectId'] != project.get_id(),
               user.obj['authorizations']))
    user.update()

    old_object = project.delete()

    return Response(200, 'Successfully deleted project.', old_object)
Beispiel #2
0
def POST(request):
    """Add a new Portfolio for this Project."""

    request.check_required_parameters(path={'projectId': 'string'},
                                      body={
                                          'portfolio': {
                                              'name': 'string',
                                              'targets': {
                                                  'enabledMetrics': 'list',
                                                  'repeatsPerScenario': 'int',
                                              },
                                          }
                                      })

    project = Project.from_id(request.params_path['projectId'])

    project.check_exists()
    project.check_user_access(request.google_id, True)

    portfolio = Portfolio(request.params_body['portfolio'])

    portfolio.set_property('projectId', project.get_id())
    portfolio.set_property('scenarioIds', [])

    portfolio.insert()

    project.obj['portfolioIds'].append(portfolio.get_id())
    project.update()

    return Response(200, 'Successfully added Portfolio.', portfolio.obj)
Beispiel #3
0
def POST(request):
    """Add a new Topology to the specified project and return it"""

    request.check_required_parameters(path={'projectId': 'string'},
                                      body={'topology': {
                                          'name': 'string'
                                      }})

    project = Project.from_id(request.params_path['projectId'])

    project.check_exists()
    project.check_user_access(request.google_id, True)

    topology = Topology({
        'projectId': project.get_id(),
        'name': request.params_body['topology']['name'],
        'rooms': request.params_body['topology']['rooms'],
    })

    topology.insert()

    project.obj['topologyIds'].append(topology.get_id())
    project.set_property('datetimeLastEdited',
                         Database.datetime_to_string(datetime.now()))
    project.update()

    return Response(200, 'Successfully inserted topology.', topology.obj)
Beispiel #4
0
def GET(request):
    """Get this Project."""

    request.check_required_parameters(path={'projectId': 'string'})

    project = Project.from_id(request.params_path['projectId'])

    project.check_exists()
    project.check_user_access(request.google_id, False)

    return Response(200, 'Successfully retrieved project', project.obj)
Beispiel #5
0
def GET(request):
    """Find all authorizations for a Project."""

    request.check_required_parameters(path={'projectId': 'string'})

    project = Project.from_id(request.params_path['projectId'])

    project.check_exists()
    project.check_user_access(request.google_id, False)

    authorizations = project.get_all_authorizations()

    return Response(200, 'Successfully retrieved project authorizations', authorizations)
Beispiel #6
0
def PUT(request):
    """Update a project's name."""

    request.check_required_parameters(body={'project': {
        'name': 'name'
    }},
                                      path={'projectId': 'string'})

    project = Project.from_id(request.params_path['projectId'])

    project.check_exists()
    project.check_user_access(request.google_id, True)

    project.set_property('name', request.params_body['project']['name'])
    project.set_property('datetime_last_edited',
                         Database.datetime_to_string(datetime.now()))
    project.update()

    return Response(200, 'Successfully updated project.', project.obj)
Beispiel #7
0
def DELETE(request):
    """Delete this User."""

    request.check_required_parameters(path={'userId': 'string'})

    user = User.from_id(request.params_path['userId'])

    user.check_exists()
    user.check_correct_user(request.google_id)

    for authorization in user.obj['authorizations']:
        if authorization['authorizationLevel'] != 'OWN':
            continue

        project = Project.from_id(authorization['projectId'])
        project.delete()

    old_object = user.delete()

    return Response(200, 'Successfully deleted user.', old_object)
Beispiel #8
0
def DELETE(request):
    """Delete this topology"""
    request.check_required_parameters(path={'topologyId': 'string'})

    topology = Topology.from_id(request.params_path['topologyId'])

    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 topology_id in project.obj['topologyIds']:
        project.obj['topologyIds'].remove(topology_id)
    project.update()

    old_object = topology.delete()

    return Response(200, 'Successfully deleted topology.', old_object)
Beispiel #9
0
def DELETE(request):
    """Delete this Portfolio."""

    request.check_required_parameters(path={'portfolioId': 'string'})

    portfolio = Portfolio.from_id(request.params_path['portfolioId'])

    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 portfolio_id in project.obj['portfolioIds']:
        project.obj['portfolioIds'].remove(portfolio_id)
    project.update()

    old_object = portfolio.delete()

    return Response(200, 'Successfully deleted portfolio.', old_object)
Beispiel #10
0
def POST(request):
    """Create a new project, and return that new project."""

    request.check_required_parameters(body={'project': {'name': 'string'}})

    topology = Topology({'name': 'Default topology', 'rooms': []})
    topology.insert()

    project = Project(request.params_body['project'])
    project.set_property('datetimeCreated',
                         Database.datetime_to_string(datetime.now()))
    project.set_property('datetimeLastEdited',
                         Database.datetime_to_string(datetime.now()))
    project.set_property('topologyIds', [topology.get_id()])
    project.set_property('portfolioIds', [])
    project.insert()

    topology.set_property('projectId', project.get_id())
    topology.update()

    user = User.from_google_id(request.google_id)
    user.obj['authorizations'].append({
        'projectId': project.get_id(),
        'authorizationLevel': 'OWN'
    })
    user.update()

    return Response(200, 'Successfully created project.', project.obj)