question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jbazikcommented, 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.

0reactions
czpythoncommented, Aug 16, 2016
Read more comments on GitHub >

github_iconTop Results From Across the Web

cms.utils.permissions - get_user_permission_level - GitHub
cms.utils.permissions - get_user_permission_level - AttributeError 'Page' has no attribute 'level' #4928.
Read more >
Django CMS Link - AttributeError 'Page' object has no attribute ...
But when I double click on that link for edit It throws me this error - [AttributeError 'Page' object has no attribute 'site']...
Read more >
Unable to get scheduler to start correctly. Fails with ...
I am trying to instantiate an instance of the apscheduler. but It's constantly failing with the above error about a NoneType Object having...
Read more >
3.10a5 regression: AttributeError: 'NoneType' object has no ...
3.10a5 regression: AttributeError: 'NoneType' object has no attribute '__suppress_context__' in traceback.py ; behavior ; Library (Lib) ...
Read more >
AttributeError: 'Meta' object has no attribute 'permissions'
When I create item variant I get the following error Traceback (most recent call last): File ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found