Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

django-polymorphic questions #462

Closed
BenDevelopment opened this issue Sep 20, 2016 · 5 comments
Closed

django-polymorphic questions #462

BenDevelopment opened this issue Sep 20, 2016 · 5 comments

Comments

@BenDevelopment
Copy link

BenDevelopment commented Sep 20, 2016

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?)?
@ad-m
Copy link
Member

ad-m commented Sep 20, 2016

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

@ad-m
Copy link
Member

ad-m commented Sep 20, 2016

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.

@benkonrath
Copy link
Contributor

@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

@benkonrath
Copy link
Contributor

@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.

@BenDevelopment
Copy link
Author

Thank you guys! All works well 👍 💯 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants