#11154: Inconsistency with permissions for proxy models
------------------------------+------------------------------------
     Reporter:  etianen       |                    Owner:  nobody
         Type:  Bug           |                   Status:  new
    Component:  contrib.auth  |                  Version:  SVN
     Severity:  Normal        |               Resolution:
     Keywords:                |             Triage Stage:  Accepted
    Has patch:  0             |      Needs documentation:  0
  Needs tests:  0             |  Patch needs improvement:  0
Easy pickings:  0             |                    UI/UX:  0
------------------------------+------------------------------------
Changes (by danny.adair@…):

 * cc: danny.adair@… (added)


Comment:

 I also think that Proxy models should have their own permissions. The
 current problem seems to lie in the way that !ContentTypeManager
 determines the app_label of a model:

 !ModelBase will - proxy or not - report the app_label either as explicitly
 specified or from the parent's module name.
 
https://code.djangoproject.com/browser/django/trunk/django/db/models/base.py#L50

 {{{
 if getattr(meta, 'app_label', None) is None:
     # Figure out the app_label by looking one level up.
     # For 'django.contrib.sites.models', this would be 'sites'.
     model_module = sys.modules[new_class.__module__]
         kwargs = {"app_label": model_module.__name__.split('.')[-2]}
     else:
         kwargs = {}
 }}}

 However, !ContentTypeManager._get_opts() traverses proxies up to the non-
 proxy model and then uses the entire meta of that model, incl. app_label.
 
https://code.djangoproject.com/browser/django/trunk/django/contrib/contenttypes/models.py#L18

 {{{
 def _get_opts(self, model):
     opts = model._meta
     while opts.proxy:
         model = opts.proxy_for_model
         opts = model._meta
     return opts

 }}}

 This is where app_label needs to be preserved. Maybe just put it aside,
 traverse, then readjust:

 {{{
 def _get_opts(self, model):
     opts = model._meta
     # Preserve proxy model's attr_label
     attr_label = opts.attr_label
     while opts.proxy:
         model = opts.proxy_for_model
         opts = model._meta
     opts.attr_label = attr_label
     return opts

 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/11154#comment:23>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to