def test_get_by_id(): user = UserFactory.create() application = ApplicationFactory.create() app_role = ApplicationRoleFactory.create(user=user, application=application) assert ApplicationRoles.get_by_id(app_role.id) == app_role app_role.status = ApplicationRoleStatus.DISABLED with pytest.raises(NotFoundError): ApplicationRoles.get_by_id(app_role.id)
def resend_invite(application_id, application_role_id): app_role = ApplicationRoles.get_by_id(application_role_id) invite = app_role.latest_invitation form = MemberForm(http_request.form) if form.validate(): new_invite = ApplicationInvitations.resend(g.current_user, invite.token, form.data) send_application_invitation( invitee_email=new_invite.email, inviter_name=g.current_user.full_name, token=new_invite.token, ) flash( "application_invite_resent", user_name=new_invite.user_name, application_name=app_role.application.name, ) else: flash( "application_invite_error", user_name=app_role.user_name, application_name=g.application.name, ) return redirect( url_for( "applications.settings", application_id=application_id, fragment="application-members", _anchor="application-members", ))
def revoke_invite(application_id, application_role_id): app_role = ApplicationRoles.get_by_id(application_role_id) invite = app_role.latest_invitation if invite.is_pending: ApplicationInvitations.revoke(invite.token) flash( "application_invite_revoked", user_name=app_role.user_name, application_name=g.application.name, ) else: flash( "application_invite_error", user_name=app_role.user_name, application_name=g.application.name, ) return redirect( url_for( "applications.settings", application_id=application_id, fragment="application-members", _anchor="application-members", ))
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
def remove_member(application_id, application_role_id): application_role = ApplicationRoles.get_by_id(application_role_id) ApplicationRoles.disable(application_role) flash( "application_member_removed", user_name=application_role.user_name, application_name=g.application.name, ) return redirect( url_for( "applications.settings", _anchor="application-members", application_id=g.application.id, fragment="application-members", ))
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", ) )