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

cms.utils.permissions - get_user_permission_level - AttributeError 'Page' has no attribute 'level' #4928

Closed
benjhastings opened this issue Jan 18, 2016 · 5 comments
Assignees
Milestone

Comments

@benjhastings
Copy link

As the title suggests, the "get_user_permission_level" function in cms.utils.permissions tries to return the level of the page and falls over with an AttributeError. I don't think this is something that I have messed up (I am adding the CMS to an existing project that was on django 1.5, upgrading to django 1.8.8 in the process so I have to contend with the new migrations).
This is using version 3.2.0 and occurs on line 202.
I think that is is just a case of changing .level to .get_depth() but I don't know what knock on effects this will have.

Furthermore there are two lookups for __level in get_subordinate_users() and get_subordinate_groups() in the same file. (Let me know if you need new tickets raising for these)

def get_user_permission_level(user):
    """
    Returns highest user level from the page/permission hierarchy on which
    user haves can_change_permission. Also takes look into user groups. Higher
    level equals to lover number. Users on top of hierarchy have level 0. Level
    is the same like page.level attribute.

    Example:
                              A,W                    level 0
                            /    \
                          user    B,GroupE           level 1
                        /     \
                      C,X     D,Y,W                  level 2

        Users A, W have user level 0. GroupE and all his users have user level 1
        If user D is a member of GroupE, his user level will be 1, otherwise is
        2.

    """
    if (user.is_superuser or
            GlobalPagePermission.objects.with_can_change_permissions(user).exists()):
        # those
        return 0
    try:
        permission = PagePermission.objects.with_can_change_permissions(user).order_by('page__path')[0]
    except IndexError:
        # user isn't assigned to any node
        raise NoPermissionsException
    return permission.page.level #<----OFFENDING LINE
@jbazik
Copy link
Contributor

jbazik commented May 2, 2016

I just bumped into this. Treebeard MP_Node has a "depth" attribute, so it looks like the fix is to simply replace level with depth. What I can't understand is how this has escaped fixing all this time, and I see new code in develop that still references "level." Am I missing something?

The level attribute is also referenced in some templates, possibly elsewhere. I can provide a PR if someone can confirm that this hasn't been fixed some other way.

@FinalAngel
Copy link
Member

@divio/django-cms-core any feedback?

@czpython
Copy link
Contributor

Confirmed. Will need to be backported to 3.1

@czpython czpython added this to the 3.3.1 milestone Jun 21, 2016
@czpython
Copy link
Contributor

I'm currently working on a fix for this on 3.3.x

@czpython
Copy link
Contributor

Fixed by #5532

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

No branches or pull requests

4 participants