1. Germano Gabbianelli
  2. django-acl

Commits

tyrion  committed 441048d

removed the useless _permissions_for_model

  • Participants
  • Parent commits a69037e
  • Branches default

Comments (0)

Files changed (1)

File acl/utils.py

View file
 from django.contrib.contenttypes.models import ContentType
 from acl.models import Role, RoleData, ACL, ACL_YES, ACL_NEVER, ACL_NO
 
+
 qn = connection.ops.quote_name
 
 def get_model_label_and_name(model):
         app_label, model = model.split('.')
     return app_label, model
 
+
 def get_model_contenttype(model):
     return '%s.%s' % (get_model_label_and_name(model))
 get_model_path = get_model_contenttype
 
+
 def permissions_for_groups(groups=None):
     raise NotImplementedError('will I really implement this?')
 
+
 def permissions_for_roles(roles=None):
     permissions = dict()
     cached_roles = dict()
     return permissions
 
 
-
-# XXX deprecated, should be removed. I am keeping it here only for the SQL
-# que.
-def _permissions_for_model(user, model):
-    cursor = connection.cursor()
-    permissions = dict()
-
-    app_label, model = get_model_label_and_name(model)
-
-    def set_perm(object, label, codename, setting):
-        # we're assuming that ACL_NO are not stored.
-        p_name = '%s.%s' % (label, codename)
-        p_dict = permissions.setdefault(object, dict())
-        if p_dict.get(p_name) != ACL_NEVER:
-            p_dict[p_name] = setting
-
-    query = ACL.objects.values_list('role_id', 'group_id', 'object_id',
-                                    'permission__content_type__app_label',
-                                    'permission__codename', 'setting',
-                                    flat=True
-            ).filter(Q(user=user) | Q(group__user_id=user)
-            ).filter(content_type__app_label=app_label,
-                     content_type__model=model)
-    
-    sql = """
-        SELECT acl.%s, acl.%s, acl.%s,
-            pct.%s, p.%s, acl.%s
-        FROM %s acl
-        INNER JOIN %s act ON (acl.%s = act.%s)
-        LEFT OUTER JOIN %s p ON (acl.%s = p.%s)
-        LEFT OUTER JOIN %s pct ON (p.%s = pct.%s)
-        LEFT OUTER JOIN %s ug ON (acl.%s = ug.%s)
-        WHERE (acl.%s = %%s OR ug.%s = %%s)
-            AND act.%s = %%s
-            AND act.%s = %%s;
-        """ % tuple(qn(param) for param in (
-                'role_id', 'group_id', 'object_id', 'app_label', 'codename',
-                'setting', 'acl_acl', 'django_content_type', 'content_type_id',
-                'id', 'auth_permission', 'permission_id', 'id',
-                'django_content_type',  'content_type_id', 'id',
-                'auth_user_groups', 'group_id', 'group_id', 'user_id',
-                'user_id', 'app_label', 'model'))
-    
-    cursor.execute(sql, [user.id, user.id, app_label, model])
-    res = cursor.fetchall()
-    roles = set([row[0] for row in res if row[0]])
-    """
-    for row in res:
-        if not row[0]:
-            permissions.setdefault(row[2], list()).append(row[3:])
-        else:
-            roles.append(
-    """
-
-    if roles:
-        roles_permissions = permissions_for_roles(roles)
-    
-    for role, group, object, label, codename, setting in res:
-        if role:
-            for perm in roles_permissions[role]:
-                set_perm(object, *perm)
-        else:
-            set_perm(object, label, codename, setting)
-
-    return permissions
-
 def get_permissions(user, model=None, all=True):
-    cursor = connection.cursor()
     permissions = dict()
 
     def set_perm(path, perm, setting):
         if s_perm == ACL_NO or g_perm == ACL_NEVER:
             return bool(g_perm)   
     return bool(s_perm)
-# u.set_perm('pybb.view_forum', forum)