Opened 7 years ago

Closed 7 years ago

Last modified 3 years ago

#7115 closed (fixed)

[Patch] django.contrib.auth Permissions ordering changed due to qsrf

Reported by: Matthew Flanagan <mattimustang@…> Owned by: nobody
Component: contrib.admin Version: master
Severity: Keywords:
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Hi,

With the merge of the QSRF branch to trunk the ordering of the Permissions model results have changed due to the new QSRF changes respecting the Meta: ordering = ... on related fields. The Permissions model has ordering = ('content_type', 'codename') and ContentType in turn has ordering= ('name',). In pre-QSRF the ordering of ContentType was not respected and so the resulting ordering of permissions was actually on the content_type.id and not content_type.name.

QSRF has fixed this and this is a good thing but I believe the original intent of the ordering of the Permission model was to group permissions belonging to the same app together so when they are displayed in the django admin they are also grouped in the multi-select list box.

The patch below restores the permissions ordering to what it was prior to the QSRF merge.

Index: django/contrib/auth/models.py
===================================================================
--- django/contrib/auth/models.py       (revision 7503)
+++ django/contrib/auth/models.py       (working copy)
@@ -78,7 +78,7 @@
         verbose_name = _('permission')
         verbose_name_plural = _('permissions')
         unique_together = (('content_type', 'codename'),)
-        ordering = ('content_type', 'codename')
+        ordering = ('content_type__app_label', 'codename')

     def __unicode__(self):
         return u"%s | %s | %s" % (self.content_type.app_label, self.content_type, self.name)

A little test case below shows the ordering issue. Run it on pre-QSRF rev [7476] and post-QSRF trunk rev [7503]:

from django.contrib.auth.models import Group, Permission
from django.core.serializers import serialize

# cleanup from previous test
Group.objects.filter(name='permordering').delete()

g = Group(name='permordering')
g.save()

perms = [1,2,16]
print 'Assigning permissions to group:'
for p in perms:
    #print the fields in ordering = ('content_type', 'codename')
    perm = Permission.objects.get(pk=p)
    print '\t%d (%d, %s, %s)' % (p, perm.content_type.id, perm.content_type, perm.codename)
g.permissions = perms
g.save()

print serialize('json', [g])

Change History (4)

comment:1 Changed 7 years ago by telenieko

  • Component changed from Contrib apps to Admin interface
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 7 years ago by ericholscher

  • milestone set to 1.0
  • Triage Stage changed from Unreviewed to Design decision needed

comment:3 Changed 7 years ago by jacob

  • Resolution set to fixed
  • Status changed from new to closed

(In [8246]) Fixed #7115: tweaked ordering on Permission to more closely match the pre-QSRF behavior, which was nice. Thanks, Matthew Flanagan.

comment:4 Changed 3 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

Note: See TracTickets for help on using tickets.
Back to Top