mirror of
https://github.com/ae-utbm/sith.git
synced 2026-03-31 15:59:42 +00:00
refactor: reorder conditions in ClubAddMemberForm.available_roles
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user