def get_members_data(application): members_data = [] for member in application.members: permission_sets = filter_perm_sets_data(member) roles = EnvironmentRoles.get_for_application_member(member.id) environment_roles = filter_env_roles_data(roles) env_roles_form_data = filter_env_roles_form_data( member, application.environments) form = UpdateMemberForm(environment_roles=env_roles_form_data, **permission_sets) update_invite_form = (MemberForm( obj=member.latest_invitation) if member.latest_invitation and member.latest_invitation.can_resend else MemberForm()) members_data.append({ "role_id": member.id, "user_name": member.user_name, "permission_sets": permission_sets, "environment_roles": environment_roles, "role_status": member.display_status, "form": form, "update_invite_form": update_invite_form, }) return sorted(members_data, key=lambda member: member["user_name"])
def get_members_data(application): members_data = [] for member in application.members: permission_sets = filter_perm_sets_data(member) roles = EnvironmentRoles.get_for_application_member(member.id) environment_roles = filter_env_roles_data(roles) env_roles_form_data = filter_env_roles_form_data( member, application.environments ) form = UpdateMemberForm( environment_roles=env_roles_form_data, **permission_sets ) update_invite_form = None if member.latest_invitation and member.latest_invitation.can_resend: update_invite_form = MemberForm(obj=member.latest_invitation) else: update_invite_form = MemberForm() members_data.append( { "role_id": member.id, "user_name": member.user_name, "permission_sets": permission_sets, "environment_roles": environment_roles, "role_status": member.status.value, "form": form, "update_invite_form": update_invite_form, } ) return members_data
def test_get_for_application_member_does_not_return_deleted( application_role, environment): EnvironmentRoleFactory.create(application_role=application_role, environment=environment, deleted=True) roles = EnvironmentRoles.get_for_application_member(application_role.id) assert len(roles) == 0
def test_get_for_application_member(application_role, environment): EnvironmentRoleFactory.create(application_role=application_role, environment=environment) roles = EnvironmentRoles.get_for_application_member(application_role.id) assert len(roles) == 1 assert roles[0].environment == environment assert roles[0].application_role == application_role