diff --git a/club/models.py b/club/models.py index 242250f5..cbec4872 100644 --- a/club/models.py +++ b/club/models.py @@ -139,10 +139,7 @@ class Club(models.Model): """ Method to see if that object can be edited by the given user """ - ms = self.get_membership_for(user) - if ms is not None and ms.role > settings.SITH_MAXIMUM_FREE_ROLE: - return True - return False + return self.has_rights_in_club(user) def can_be_viewed_by(self, user): """ @@ -170,6 +167,10 @@ class Club(models.Model): Club._memberships[self.id][user.id] = m return m + def has_rights_in_club(self, user): + m = self.get_membership_for(user) + return m is not None and m.role > settings.SITH_MAXIMUM_FREE_ROLE + class Membership(models.Model): """ diff --git a/core/models.py b/core/models.py index a0791c1b..00c5f684 100644 --- a/core/models.py +++ b/core/models.py @@ -300,7 +300,15 @@ class User(AbstractBaseUser): @cached_property def is_board_member(self): from club.models import Club - return Club.objects.filter(unix_name=settings.SITH_MAIN_CLUB['unix_name']).first().get_membership_for(self) + return Club.objects.filter(unix_name=settings.SITH_MAIN_CLUB['unix_name']).first().has_rights_in_club(self) + + @cached_property + def can_create_subscription(self): + from club.models import Club + for club in Club.objects.filter(id__in=settings.SITH_CAN_CREATE_SUBSCRIPTIONS).all(): + if club.has_rights_in_club(self): + return True + return False @cached_property def is_launderette_manager(self): @@ -504,6 +512,10 @@ class AnonymousUser(AuthAnonymousUser): def __init__(self, request): super(AnonymousUser, self).__init__() + @property + def can_create_subscription(self): + return False + @property def was_subscribed(self): return False diff --git a/core/templates/core/user_tools.jinja b/core/templates/core/user_tools.jinja index 1074e64e..4033f702 100644 --- a/core/templates/core/user_tools.jinja +++ b/core/templates/core/user_tools.jinja @@ -14,8 +14,10 @@