Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

admin: Clarifier les structures dont sont membres les utilisateurs #5281

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions itou/approvals/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
ItouTabularInline,
PkSupportRemarkInline,
get_admin_view_link,
get_company_view_link,
get_structure_view_link,
)
from itou.utils.templatetags.str_filters import pluralizefr

Expand Down Expand Up @@ -60,7 +60,7 @@ def has_add_permission(self, request, obj=None):

@admin.display(description="Entreprise destinataire")
def to_company_link(self, obj):
return get_company_view_link(obj.to_company)
return get_structure_view_link(obj.to_company, display_attr="display_name")

# Custom read-only fields as workaround :
# there is no direct relation between approvals and employee records
Expand Down
8 changes: 4 additions & 4 deletions itou/users/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
PkSupportRemarkInline,
add_support_remark_to_obj,
get_admin_view_link,
get_company_view_link,
get_structure_view_link,
)


Expand Down Expand Up @@ -106,7 +106,7 @@ def has_add_permission(self, request, obj=None):

@admin.display(description="Entreprise")
def company_siret_link(self, obj):
return get_company_view_link(obj.company)
return get_structure_view_link(obj.company)


class PrescriberMembershipInline(DisabledNotificationsMixin, ItouTabularInline):
Expand Down Expand Up @@ -134,7 +134,7 @@ def has_add_permission(self, request, obj=None):
return True

def organization_id_link(self, obj):
return get_admin_view_link(obj.organization)
return get_structure_view_link(obj.organization)


class InstitutionMembershipInline(ItouTabularInline):
Expand Down Expand Up @@ -165,7 +165,7 @@ def has_add_permission(self, request, obj=None):
return True

def institution_id_link(self, obj):
return get_admin_view_link(obj.institution)
return get_structure_view_link(obj.institution)


class JobApplicationInline(ItouTabularInline):
Expand Down
16 changes: 9 additions & 7 deletions itou/utils/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ def get_admin_view_link(obj, *, content=None, view="change"):
return format_html('<a href="{}">{}</a>', url, content or obj.pk)


def get_company_view_link(company):
return format_html(
"{} — SIRET : {} ({})",
get_admin_view_link(company, content=company.display_name),
company.siret,
company.kind,
)
def get_structure_view_link(structure, display_attr="name"):
francoisfreitag marked this conversation as resolved.
Show resolved Hide resolved
format_string = "{link}"
format_kwargs = {"link": get_admin_view_link(structure, content=getattr(structure, display_attr))}
if hasattr(structure, "siret"):
format_string += " — SIRET {siret}"
format_kwargs["siret"] = structure.siret
format_string += " ({kind})"
format_kwargs["kind"] = structure.kind
return format_html(format_string, **format_kwargs)


class AbstractSupportRemarkInline(GenericStackedInline):
Expand Down
20 changes: 20 additions & 0 deletions tests/users/test_admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import pytest
from django.urls import reverse

from itou.users import admin
from itou.users.models import JobSeekerProfile, User
from tests.companies.factories import CompanyMembershipFactory
from tests.institutions.factories import InstitutionMembershipFactory
from tests.prescribers.factories import PrescriberMembershipFactory
from tests.users.factories import JobSeekerFactory


Expand Down Expand Up @@ -108,3 +114,17 @@ def test_get_fields_to_transfer_for_job_seekers():
# - either an existing relation has been dropped (and the relation can be removed from the relevant list)
assert not fields_to_transfer & fields_to_ignore, fields_to_transfer & fields_to_ignore
assert {f.name for f in relation_fields} == fields_to_transfer | fields_to_ignore


@pytest.mark.parametrize(
"membership_factory",
[
PrescriberMembershipFactory,
CompanyMembershipFactory,
InstitutionMembershipFactory,
],
)
def test_admin_membership(admin_client, membership_factory):
membership = membership_factory()
response = admin_client.get(reverse("admin:users_user_change", args=(membership.user_id,)))
assert response.status_code == 200
Loading