Django-guardian: django-polymorphic questions

Created on 20 Sep 2016  路  5Comments  路  Source: django-guardian/django-guardian

I've seen many discussions about django-guardian use with django-polymorphic, but it's verry confusing for me.
Imagine this case:

class FeedPost(PolymorphicModel):  
    class Meta: 
        default_permissions = ('add', 'change', 'delete', 'view')  


class ArticleFeedPost(FeedPost):
    class Meta: 
        default_permissions = ('add', 'change', 'delete', 'view')

With django-guardian 1.4.6, when you set permisssions to ArticleFeedPost, these permissions doesn't apply to FeedPost.
In the doc, there is this about polymorphic objects:
http://django-guardian.readthedocs.io/en/stable/configuration.html?highlight=polymorph#guardian-get-content-type
But there is no example describing how to use get_default_content_type.
My questions are (by the way, I'm sorry to ask these questions here, but I have a better chance to have a reply here than elsewhere):

  • How can we propagate permissions to "parent" polymorph object?
  • How can we get the guardian 1.5 version (I'm not realy familiar with django package versionning. Is the 1.5 version allready released ? When I run "pip install --upgrade django-guardian", pip say that 1.4.6 is the last version. Is it a good idea to upgrade manually by downloading this repo?)?

All 5 comments

Hello,

It is a django-polymorphic issue specific. django-polymorphic contains code for support django-guardian, so look for django-polymorphic docs about support.

Greetings,

CC: @benkonrath

Regarding issues of versioning is pleased to announce that it accepts the attention. In the next releases will be corrected. GUARDIAN_GET_CONTENT_TYPE was released in django 1.4.6.

@BenDevelopment The function to retrieve the base model content type was only recently merged into django-polymorphic. Using the base model content type will make the guardian permissions work on the base model. You just need to add this setting if you're using the latest released version of django-guardian and the latest version of django-polymorphic from git:

 GUARDIAN_GET_CONTENT_TYPE = 'polymorphic.contrib.get_polymorphic_base_content_type'

You can also copy & paste the get_polymorphic_base_content_type code into your own project if you don't want to use the latest git version of django-polymorphic.

Here are the unreleased docs:

https://django-polymorphic.readthedocs.io/en/latest/third-party.html#django-guardian-support

@BenDevelopment Correction, the setting should be:

GUARDIAN_GET_CONTENT_TYPE = 'polymorphic.contrib.guardian.get_polymorphic_base_content_type'

I'm going to make a PR to polymorphic to fix this in the docs.

Thank you guys! All works well 馃憤 馃挴 !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Dzejkob picture Dzejkob  路  28Comments

g-as picture g-as  路  10Comments

David-OConnor picture David-OConnor  路  6Comments

brianmay picture brianmay  路  16Comments

xuhcc picture xuhcc  路  10Comments