diff --git a/smash/web/decorators.py b/smash/web/decorators.py index 9d15f7d8782b2ed5d25ab7ac5ba10f51e717b4b0..2aafa5324e5a7319cbd91ae7c86d7dd2a98042ac 100644 --- a/smash/web/decorators.py +++ b/smash/web/decorators.py @@ -62,7 +62,7 @@ class PermissionDecorator: @staticmethod def get_permissions(): - if PermissionDecorator.permissions_queryset is None and len(PermissionDecorator.codenames) > 0: + if PermissionDecorator.permissions_queryset is None or len(PermissionDecorator.codenames) > len(PermissionDecorator.permissions_queryset): PermissionDecorator.permissions_queryset = Permission.objects.filter(codename__in=PermissionDecorator.codenames) return PermissionDecorator.permissions_queryset @@ -81,21 +81,6 @@ class PermissionDecorator: #variables to be used on decorator call self.perm_codename = perm_codename - # since the decorators are executed during code interpretation, we need to avoid executing - # the rest of the code if we are in the process of ./manage migrate or makemigrations - # since Permission won't be already migrated - if is_django_migrating(): - return - - query_result = Permission.objects.filter(codename=perm_codename) - if len(query_result) < 0: - logger.warn('Codename {} used in PermissionDecorator does not exist.'.format(perm_codename)) - raise ValueError - - if query_result[0].id not in PermissionDecorator.permission_ids: #avoid re-query if the permissions remain the same - PermissionDecorator.permission_ids.add(query_result[0].id) - PermissionDecorator.permissions_queryset = Permission.objects.filter(id__in=PermissionDecorator.permission_ids).all() - def __call__(self, func): ''' This method is also called when the function is decorated