Ejemplo n.º 1
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
Ejemplo n.º 2
0
def update_member(application_id, application_role_id):
    app_role = ApplicationRoles.get_by_id(application_role_id)
    form = UpdateMemberForm(http_request.form)

    if form.validate():
        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)
            Environments.update_env_role(environment, app_role, env_role.data["role"])

        flash("application_member_updated", user_name=app_role.user_name)
    else:
        pass
        # TODO: flash error message

    return redirect(
        url_for(
            "applications.settings",
            application_id=application_id,
            fragment="application-members",
            _anchor="application-members",
        )
    )