Beispiel #1
0
def test_get_application():
    app = ApplicationFactory.create()
    assert Applications.get(app.id) == app
    assert Applications.get(app.id, portfolio_id=app.portfolio_id) == app
    with pytest.raises(NotFoundError):
        # make the uuid a string like you'd get from a route
        rando_id = str(uuid4())
        Applications.get(app.id, portfolio_id=rando_id)
Beispiel #2
0
def test_can_only_update_name_and_description():
    owner = UserFactory.create()
    portfolio = PortfolioFactory.create(
        owner=owner,
        applications=[{
            "name": "Application 1",
            "description": "a application",
            "environments": [{
                "name": "dev"
            }],
        }],
    )
    application = Applications.get(portfolio.applications[0].id)
    env_name = application.environments[0].name
    Applications.update(
        application,
        {
            "name": "New Name",
            "description": "a new application",
            "environment_name": "prod",
        },
    )

    assert application.name == "New Name"
    assert application.description == "a new application"
    assert len(application.environments) == 1
    assert application.environments[0].name == env_name
Beispiel #3
0
def handle_create_member(application_id, form_data):
    application = Applications.get(application_id)
    form = NewMemberForm(form_data)

    if form.validate():
        try:
            invite = Applications.invite(
                application=application,
                inviter=g.current_user,
                user_data=form.user_data.data,
                permission_sets_names=form.data["permission_sets"],
                environment_roles_data=form.environment_roles.data,
            )

            send_application_invitation(
                invitee_email=invite.email,
                inviter_name=g.current_user.full_name,
                token=invite.token,
            )

            flash("new_application_member", user_name=invite.first_name)

        except AlreadyExistsError:
            return render_template(
                "error.html",
                message="There was an error processing your request.")
    else:
        pass
Beispiel #4
0
def handle_update_member(application_id, application_role_id, form_data):
    app_role = ApplicationRoles.get_by_id(application_role_id)
    application = Applications.get(application_id)
    existing_env_roles_data = filter_env_roles_form_data(
        app_role, application.environments)
    form = UpdateMemberForm(formdata=form_data,
                            environment_roles=existing_env_roles_data)

    if form.validate():
        try:
            ApplicationRoles.update_permission_sets(
                app_role, form.data["permission_sets"])

            for env_role in form.environment_roles:
                environment = Environments.get(env_role.environment_id.data)
                new_role = None if env_role.disabled.data else env_role.data[
                    "role"]
                Environments.update_env_role(environment, app_role, new_role)

            flash("application_member_updated", user_name=app_role.user_name)

        except GeneralCSPException as exc:
            log_error(exc)
            flash(
                "application_member_update_error",
                user_name=app_role.user_name,
            )
    else:
        pass
Beispiel #5
0
def create_or_update_new_application_step_1(portfolio_id=None,
                                            application_id=None):
    form = get_new_application_form({**http_request.form},
                                    NameAndDescriptionForm, application_id)

    if form.validate():
        application = None
        if application_id:
            application = Applications.get(application_id)
            application = Applications.update(application, form.data)
            flash("application_updated", application_name=application.name)
        else:
            portfolio = Portfolios.get_for_update(portfolio_id)
            application = Applications.create(g.current_user, portfolio,
                                              **form.data)
            flash("application_created", application_name=application.name)
        return redirect(
            url_for(
                "applications.update_new_application_step_2",
                application_id=application.id,
            ))
    else:
        return (
            render_new_application_form(
                "applications/new/step_1.html",
                NameAndDescriptionForm,
                portfolio_id,
                application_id,
                form,
            ),
            400,
        )
Beispiel #6
0
def settings(application_id):
    application = Applications.get(application_id)

    return render_settings_page(
        application=application,
        active_toggler=http_request.args.get("active_toggler"),
        active_toggler_section=http_request.args.get("active_toggler_section"),
    )
Beispiel #7
0
def delete(application_id):
    application = Applications.get(application_id)
    Applications.delete(application)

    flash("application_deleted", application_name=application.name)

    return redirect(
        url_for("applications.portfolio_applications",
                portfolio_id=application.portfolio_id))
Beispiel #8
0
def view_new_application_step_3(application_id):
    application = Applications.get(application_id)
    members = get_members_data(application)
    new_member_form = get_new_member_form(application)

    return render_template(
        "applications/new/step_3.html",
        application_id=application_id,
        application=application,
        members=members,
        new_member_form=new_member_form,
    )
Beispiel #9
0
def view_new_application_step_2(application_id):
    application = Applications.get(application_id)
    render_args = {
        "form":
        EnvironmentsForm(
            data={
                "environment_names":
                [environment.name for environment in application.environments]
            }),
        "application":
        application,
    }

    return render_template("applications/new/step_2.html", **render_args)
Beispiel #10
0
def render_new_application_form(template,
                                form_class,
                                portfolio_id=None,
                                application_id=None,
                                form=None):
    render_args = {"application_id": application_id}
    if application_id:
        application = Applications.get(application_id)
        render_args["form"] = form or form_class(obj=application)
        render_args["application"] = application
    else:
        render_args["form"] = form or form_class()

    return render_template(template, **render_args)
Beispiel #11
0
def update(application_id):
    application = Applications.get(application_id)
    form = NameAndDescriptionForm(http_request.form)
    if form.validate():
        application_data = form.data
        Applications.update(application, application_data)

        return redirect(
            url_for(
                "applications.portfolio_applications",
                portfolio_id=application.portfolio_id,
            ))
    else:
        return render_settings_page(application=application,
                                    application_form=form)
Beispiel #12
0
def test_portfolio_owner_can_view_environments():
    owner = UserFactory.create()
    portfolio = PortfolioFactory.create(
        owner=owner,
        applications=[{
            "environments": [{
                "name": "dev"
            }, {
                "name": "prod"
            }]
        }],
    )
    application = Applications.get(portfolio.applications[0].id)

    assert len(application.environments) == 2
Beispiel #13
0
def update(application_id):
    application = Applications.get(application_id)
    form = NameAndDescriptionForm(http_request.form)
    updated_application = handle_update_application(form, application_id)

    if updated_application:
        return redirect(
            url_for(
                "applications.portfolio_applications",
                portfolio_id=application.portfolio_id,
            ))
    else:
        return (
            render_settings_page(application=application, show_flash=True),
            400,
        )
Beispiel #14
0
def new_environment(application_id):
    application = Applications.get(application_id)
    env_form = EditEnvironmentForm(formdata=http_request.form)
    environment = handle_update_environment(form=env_form,
                                            application=application)

    if environment:
        return redirect(
            url_for(
                "applications.settings",
                application_id=application.id,
                fragment="application-environments",
                _anchor="application-environments",
            ))
    else:
        return (render_settings_page(application=application,
                                     show_flash=True), 400)
Beispiel #15
0
def handle_update_application(form, application_id=None, portfolio_id=None):
    if form.validate():
        application = None

        try:
            if application_id:
                application = Applications.get(application_id)
                application = Applications.update(application, form.data)
                flash("application_updated", application_name=application.name)
            else:
                portfolio = Portfolios.get_for_update(portfolio_id)
                application = Applications.create(g.current_user, portfolio,
                                                  **form.data)
                flash("application_created", application_name=application.name)

            return application

        except AlreadyExistsError:
            flash("application_name_error", name=form.data["name"])
            return False
Beispiel #16
0
def new_environment(application_id):
    application = Applications.get(application_id)
    env_form = EditEnvironmentForm(formdata=http_request.form)

    if env_form.validate():
        Environments.create(g.current_user,
                            application=application,
                            name=env_form.name.data)

        flash("environment_added", environment_name=env_form.data["name"])

        return redirect(
            url_for(
                "applications.settings",
                application_id=application.id,
                fragment="application-environments",
                _anchor="application-environments",
            ))
    else:
        return (render_settings_page(application=application), 400)
Beispiel #17
0
def update_new_application_step_2(application_id):
    form = get_new_application_form({**http_request.form}, EnvironmentsForm,
                                    application_id)
    if form.validate():
        application = Applications.get(application_id)
        application = Applications.update(application, form.data)
        flash("application_environments_updated")
        return redirect(
            url_for(
                "applications.update_new_application_step_3",
                application_id=application_id,
            ))
    else:
        return (
            render_new_application_form(
                "applications/new/step_2.html",
                EnvironmentsForm,
                application_id=application_id,
                form=form,
            ),
            400,
        )
Beispiel #18
0
def settings(application_id):
    application = Applications.get(application_id)

    return render_settings_page(application=application, )
Beispiel #19
0
def get_new_application_form(form_data, form_class, application_id=None):
    if application_id:
        application = Applications.get(application_id)
        return form_class(form_data, obj=application)
    else:
        return form_class(form_data)
Beispiel #20
0
def test_get_excludes_deleted():
    app = ApplicationFactory.create(deleted=True)
    with pytest.raises(NotFoundError):
        Applications.get(app.id)