0

I'm trying to use Django-guardian to apply permissions to specific flatpages. we have a number of flatpages on our site, and in most cases the django-auth works for what we need. However, we want to add object level permissions to some of the flatpages and specific users.

for example, i have a user YOUNGTEMP and i want to give this user access to edit a subset of the total flatpages we have on the site.

I have installed Django-guardian, and using the shell given change_flatpage permissions to this user for the appropriate sites. this user has no other permissions at all, as i don't want them to see anything but this one site from the admin.

I can verify by looking at the DB that the permissions are there, as well as that they appear in the admin when i log in as a SU. Why then when i log in as this user YOUNGTEMP does the admin site tell me i have no permissions to edit anything?

I followed the excerpts from the readthedocs.io page here to assign permissions in the shell to make sure it wasn't a problem with my overridden admin, which looks like this:

imports*...

class FlatPageForm(FlatPageFormOld):
    content = forms.CharField(widget=CKEditorUploadingWidget())
    class Meta:
        model = FlatPage
        fields = '__all__'

class FlatPageCustomAdmin(GuardedModelAdmin):
    form = FlatPageForm
    list_display = ('url', 'title')
    search_fields = ('url', 'title')

im stuck, as everything appears to be working, but still doesnt work to accomplish my purpose...

re:@solarissmoke 's request:

$ python manage.py shell
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.contrib.flatpages.models import FlatPage
>>> from django.contrib.auth.models import User
>>> from guardian.shortcuts import assign_perm, get_users_with_perms
>>> user = User.objects.all().filter(id=758)
>>> print(user[0])
epss_student_worker  
>>> page_i_want_to_give_perms_for = FlatPage.objects.all().filter(id=27)
>>> print(page_i_want_to_give_perms_for[0])
/people/alumniawardwinners/ -- Student Alumni Award Winners
>>> assign_perm('change_flatpage', user[0], page_i_want_to_give_perms_for[0])
<UserObjectPermission: /people/alumniawardwinners/ -- Student Alumni Award Winners | epss_student_worker | change_flatpage>

results of get_users_with_perms >>> get_users_with_perms(page_i_want_to_give_perms_for[0],attach_perms=True) {<User: epss_student_worker>: [u'change_flatpage']}

Rod O'Connor
  • 33
  • 1
  • 8
  • Show us how you are assigning permissions in the shell please, and also the result of `get_users_with_perms` for the specific page object that you're testing the permissions on. – solarissmoke Nov 04 '17 at 08:33
  • @solarissmoke ok thanks for reading, i have added the requested lines and output. it appears that everything is assigned correctly, however, when i login to admin, the user gets a message saying: "you don't have permission to edit anything" This user has no Group or other Permissions from the regular admin. My mistake may be assuming that only this permission is required? – Rod O'Connor Nov 06 '17 at 19:33

0 Answers0