Esempio n. 1
0
def test_update_env_role_no_access():
    env_role = EnvironmentRoleFactory.create(role=CSPRole.BASIC_ACCESS.value)

    assert Environments.update_env_role(env_role.environment,
                                        env_role.application_role, None)

    assert not EnvironmentRoles.get(env_role.application_role.id,
                                    env_role.environment.id)
Esempio n. 2
0
def test_get(application_role, environment):
    EnvironmentRoleFactory.create(application_role=application_role,
                                  environment=environment)

    environment_role = EnvironmentRoles.get(application_role.id,
                                            environment.id)
    assert environment_role
    assert environment_role.application_role == application_role
    assert environment_role.environment == environment
Esempio n. 3
0
def test_get_members_data(app, client, user_session):
    user = UserFactory.create()
    application = ApplicationFactory.create(environments=[{
        "name":
        "testing",
        "members": [{
            "user": user,
            "role_name": CSPRole.BASIC_ACCESS.value
        }],
    }])
    environment = application.environments[0]
    app_role = ApplicationRoles.get(user_id=user.id,
                                    application_id=application.id)
    env_role = EnvironmentRoles.get(application_role_id=app_role.id,
                                    environment_id=environment.id)

    user_session(application.portfolio.owner)

    with captured_templates(app) as templates:
        response = app.test_client().get(
            url_for("applications.settings", application_id=application.id))

        assert response.status_code == 200
        _, context = templates[-1]

        member = context["members"][0]
        assert member["role_id"] == app_role.id
        assert member["user_name"] == user.full_name
        assert member["permission_sets"] == {
            "perms_team_mgmt": False,
            "perms_env_mgmt": False,
            "perms_del_env": False,
        }
        assert member["environment_roles"] == [{
            "environment_id":
            str(environment.id),
            "environment_name":
            environment.name,
            "role":
            env_role.role,
        }]
        assert member["role_status"]
        assert isinstance(member["form"], UpdateMemberForm)
Esempio n. 4
0
    def update_env_role(cls, environment, application_role, new_role):
        updated = False

        if new_role is None:
            updated = EnvironmentRoles.delete(application_role.id, environment.id)
        else:
            env_role = EnvironmentRoles.get(application_role.id, environment.id)
            if env_role and env_role.role != new_role:
                env_role.role = new_role
                updated = True
                db.session.add(env_role)
            elif not env_role:
                env_role = EnvironmentRoles.create(
                    application_role=application_role,
                    environment=environment,
                    role=new_role,
                )
                updated = True
                db.session.add(env_role)

        if updated:
            db.session.commit()

        return updated