Add ClubRole (ADMIN / MEMBER / EDITOR, one per member per club) and complete club/services/access.py — the single module all authorisation routes through: - teams_managed_by / can_edit_event -> authority: a *management* StaffAssignment in the *current season*; ADMIN overrides club-wide. A StaffAssignment is per-season, so a former coach's authority expires with it. - teams_staffed_by -> visibility: *any* staff position, so support staff (physio, kit manager) can see the roster they work with without gaining authority. - members_visible_to -> ADMIN sees everyone linked to the club; otherwise self + children (family graph) + the current-season players and staff of the teams they're staffed on. - can_edit_event -> ADMIN/EDITOR, the event's owner, or a manager of one of its teams for that event's season. - can_manage_shop -> ADMIN. Fix roles_in_club, which called .unique() — not a QuerySet method, so it would have raised AttributeError on first use. Keep ClubRole in sync with membership status: an active ClubMembership grants the MEMBER role and losing it withdraws that role — but an elevated role (ADMIN/EDITOR) is never downgraded or removed, so a lapsed membership or a season rollover can never lock an admin out. Validate ClubMembership.season against the membership's club. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
from django.contrib import admin
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from .models import Club, ClubMembership, ClubRole, Season
|
|
|
|
|
|
@admin.register(Club)
|
|
class ClubAdmin(admin.ModelAdmin):
|
|
list_display = ["name", "slug"]
|
|
search_fields = ["name", "slug"]
|
|
prepopulated_fields = {"slug": ["name"]}
|
|
ordering = ["name"]
|
|
|
|
|
|
@admin.register(Season)
|
|
class SeasonAdmin(admin.ModelAdmin):
|
|
list_display = ["__str__", "club", "start_date", "end_date"]
|
|
list_filter = ["club"]
|
|
search_fields = ["club__name"]
|
|
ordering = ["club", "-start_date"]
|
|
|
|
|
|
@admin.register(ClubMembership)
|
|
class ClubMembershipAdmin(admin.ModelAdmin):
|
|
list_display = ["club__name", "member__last_name", "member__first_name", "season", "status", "fee_status", "license"]
|
|
search_fields = ["club__name", "member__last_name", "member__first_name", "license"]
|
|
list_filter = ["club", "season", "status", "fee_status"]
|
|
raw_id_fields = ["member"]
|
|
fieldsets = [
|
|
[None, {"fields": ["club", "season", "member"]}],
|
|
[_("Membership"), {"fields": ["license", "status", "fee_status"]}],
|
|
[_("Dates"), {"fields": ["signed_up_at", "activated_at"]}],
|
|
]
|
|
|
|
|
|
@admin.register(ClubRole)
|
|
class ClubRoleAdmin(admin.ModelAdmin):
|
|
list_display = ["club__name", "member__last_name", "member__first_name", "role"]
|
|
search_fields = ["club__name", "member__last_name", "member__first_name"]
|
|
list_filter = ["club", "role"]
|
|
raw_id_fields = ["member"]
|