refactor: reorder conditions in ClubAddMemberForm.available_roles

This commit is contained in:
imperosol
2026-03-31 17:08:13 +02:00
parent 11779231e1
commit 9bacf2c23d

View File

@@ -250,19 +250,20 @@ class ClubAddMemberForm(ClubMemberForm):
widgets = {"user": AutoCompleteSelectUser}
@cached_property
def available_roles(self):
"""The greatest role that will be obtainable with this form.
def available_roles(self) -> QuerySet[ClubRole]:
"""The roles that will be obtainable with this form.
Admins and the club president can attribute any role.
Board members can attribute roles lower than their own.
Other users cannot attribute roles with this form
"""
if self.request_user.has_perm("club.add_membership"):
return self.club.roles.all()
membership = self.request_user_membership
if membership is None or not membership.role.is_board:
return ClubRole.objects.none()
if membership.role.is_presidency:
if (
self.request_user.has_perm("club.add_membership")
or membership.role.is_presidency
):
return self.club.roles.all()
return self.club.roles.above_instance(membership.role)