Exemplo n.º 1
0
 def get_all_permissions(self, user_obj, obj=None):
     if not user_obj.is_active or user_obj.is_anonymous:
         return set()
     disable_cache = getattr(settings, 'DISABLE_GENERIC_PERMISSION_CACHE', False)
     if user_obj.is_superuser:
         perms = getattr(self, '_all_permissions', None)
         if perms is None:
             perms = generate_perm_list(Permission.objects.all())
             if not disable_cache:
                 setattr(self, '_all_permissions', perms)
         return perms
     cache_field_name = get_cache_field_name(obj)
     # need this for testing purposes, do not enable this in production
     if not hasattr(user_obj, cache_field_name) or disable_cache:
         perms = get_all_user_permissions(user_obj, obj)
         setattr(user_obj, cache_field_name, perms)
     return getattr(user_obj, cache_field_name)
Exemplo n.º 2
0
 def get_all_permissions(self, user_obj, obj=None):
     if not user_obj.is_active or user_obj.is_anonymous:
         return set()
     disable_cache = getattr(settings, 'DISABLE_GENERIC_PERMISSION_CACHE',
                             False)
     if user_obj.is_superuser:
         perms = getattr(self, '_all_permissions', None)
         if perms is None:
             perms = generate_perm_list(Permission.objects.all())
             if not disable_cache:
                 setattr(self, '_all_permissions', perms)
         return perms
     cache_field_name = get_cache_field_name(obj)
     # need this for testing purposes, do not enable this in production
     if not hasattr(user_obj, cache_field_name) or disable_cache:
         perms = get_all_user_permissions(user_obj, obj)
         setattr(user_obj, cache_field_name, perms)
     return getattr(user_obj, cache_field_name)
Exemplo n.º 3
0
 def get_all_permissions(self, user_obj, obj=None):
     if not user_obj.is_active or user_obj.is_anonymous():
         return set()
     disable_cache = getattr(settings, 'DISABLE_GENERIC_PERMISSION_CACHE', False)
     if user_obj.is_superuser:
         perms = getattr(self, '_all_permissions', None)
         if perms is None:
             perms = generate_perm_list(Permission.objects.all())
             if not disable_cache:
                 setattr(self, '_all_permissions', perms)
         return perms
     # need this for testing purposes, do not enable this in production
     if obj is None:
         cache_field_name = ALL_PERMS_CACHE_FIELD
     else:
         cache_field_name = '%s_%s_%s' % (
             ALL_PERMS_CACHE_FIELD, obj.pk, ContentType.objects.get_for_model(obj).id
         )
     if not hasattr(user_obj, cache_field_name) or disable_cache:
         perms = get_all_user_permissions(user_obj, obj)
         setattr(user_obj, cache_field_name, perms)
     return getattr(user_obj, cache_field_name)
Exemplo n.º 4
0
 def get_all_permissions(self, user_obj, obj=None):
     if not user_obj.is_active or user_obj.is_anonymous():
         return set()
     disable_cache = getattr(settings, 'DISABLE_GENERIC_PERMISSION_CACHE', False)
     if user_obj.is_superuser:
         perms = getattr(self, '_all_permissions', None)
         if perms is None:
             perms = generate_perm_list(Permission.objects.all())
             if not disable_cache:
                 setattr(self, '_all_permissions', perms)
         return perms
     # need this for testing purposes, do not enable this in production
     if obj is None:
         cache_field_name = ALL_PERMS_CACHE_FIELD
     else:
         cache_field_name = '{field}_{pk}_{ctype_id}'.format(
             field=ALL_PERMS_CACHE_FIELD, pk=obj.pk,
             ctype_id=ContentType.objects.get_for_model(obj).id
         )
     if not hasattr(user_obj, cache_field_name) or disable_cache:
         perms = get_all_user_permissions(user_obj, obj)
         setattr(user_obj, cache_field_name, perms)
     return getattr(user_obj, cache_field_name)