From 2cedabe3936f054a6271ed7228ec860645fd9de4 Mon Sep 17 00:00:00 2001 From: Xavier Fernandez Date: Mon, 16 Dec 2024 11:09:38 +0100 Subject: [PATCH] organizations: remove now unsed member_required method --- itou/common_apps/organizations/models.py | 14 +------------- tests/companies/test_models.py | 14 -------------- tests/institutions/tests.py | 16 ---------------- tests/prescribers/tests.py | 16 ---------------- 4 files changed, 1 insertion(+), 59 deletions(-) diff --git a/itou/common_apps/organizations/models.py b/itou/common_apps/organizations/models.py index 1776d52408..ca50c2b922 100644 --- a/itou/common_apps/organizations/models.py +++ b/itou/common_apps/organizations/models.py @@ -2,7 +2,7 @@ from django.conf import settings from django.db import models -from django.db.models import Exists, OuterRef, Prefetch, Q +from django.db.models import Prefetch, Q from django.forms import ValidationError from django.utils import timezone @@ -15,18 +15,6 @@ class OrganizationQuerySet(models.QuerySet): Common methods used by Company, PrescriberOrganization and Institution models query sets. """ - def member_required(self, user): - membership_model = self.model.members.through - # through_fields contains a tuple like ("company", "user") - structure_field, _user_field = self.model.members.rel.through_fields - return self.filter( - Exists( - membership_model.objects.filter( - user=user, is_active=True, user__is_active=True, **{structure_field: OuterRef("pk")} - ) - ) - ) - def prefetch_active_memberships(self): membership_model = self.model.members.through membership_set_related_name = membership_model.user.field.remote_field.get_accessor_name() diff --git a/tests/companies/test_models.py b/tests/companies/test_models.py index 5564173ee3..233b60f816 100644 --- a/tests/companies/test_models.py +++ b/tests/companies/test_models.py @@ -271,20 +271,6 @@ def test_add_or_activate_member(self): class TestCompanyQuerySet: - def test_member_required(self): - company = CompanyFactory() - user = EmployerFactory() - assert Company.objects.member_required(user).count() == 0 - - company.add_or_activate_member(user) - assert Company.objects.member_required(user).get() == company - - membership = company.memberships.get() - membership.is_active = False - membership.save(update_fields=("is_active",)) - - assert Company.objects.member_required(user).count() == 0 - def test_with_count_recent_received_job_applications(self): company = CompanyFactory() model = JobApplicationFactory._meta.model diff --git a/tests/institutions/tests.py b/tests/institutions/tests.py index 11bd9531fb..c45900e046 100644 --- a/tests/institutions/tests.py +++ b/tests/institutions/tests.py @@ -71,22 +71,6 @@ def test_add_or_activate_member(self): institution.add_or_activate_member(wrong_kind_user) -class TestInstitutionQuerySet: - def test_member_required(self): - institution = InstitutionFactory() - user = LaborInspectorFactory() - assert Institution.objects.member_required(user).count() == 0 - - institution.add_or_activate_member(user) - assert Institution.objects.member_required(user).get() == institution - - membership = institution.memberships.get() - membership.is_active = False - membership.save(update_fields=("is_active",)) - - assert Institution.objects.member_required(user).count() == 0 - - def test_deactivate_last_admin(admin_client, mailoutbox): institution = InstitutionWithMembershipFactory(department="") membership = institution.memberships.first() diff --git a/tests/prescribers/tests.py b/tests/prescribers/tests.py index 1298013a82..ecadbf7d5d 100644 --- a/tests/prescribers/tests.py +++ b/tests/prescribers/tests.py @@ -246,22 +246,6 @@ def test_update_prescriber_with_api_entreprise(self, settings): assert organization.is_head_office is True -class TestPrescriberOrganizationQuerySet: - def test_member_required(self): - organization = PrescriberOrganizationFactory() - user = PrescriberFactory() - assert PrescriberOrganization.objects.member_required(user).count() == 0 - - organization.add_or_activate_member(user) - assert PrescriberOrganization.objects.member_required(user).get() == organization - - membership = organization.memberships.get() - membership.is_active = False - membership.save(update_fields=("is_active",)) - - assert PrescriberOrganization.objects.member_required(user).count() == 0 - - class TestPrescriberOrganizationAdmin: ACCEPT_BUTTON_LABEL = "Valider l'habilitation" REFUSE_BUTTON_LABEL = "Refuser l'habilitation"