Skip to content

Conversation

@damianmoore
Copy link
Contributor

When a non-superuser that had the correct page-level permissions tried to create a 'New Page' from the CMS toolbar, I was getting the error invalid literal for int() with base 10: '' appear in the sidebar. The user could, however, create a new top-level page from within the admin.

I tracked the problem down to 2 places in the cms codebase. cms_toolbar.py add_page_menu() method of PageToolbar. Where the URL is being generated for the 'New Page' link target is set to self.page.parent_id or '', which at the top level means '' empty string.

url="%s?language=%s&edit=1&target=%s&position=last-child" % (
    reverse("admin:cms_page_add"),
    self.toolbar.language,
    self.page.parent_id or ''
)

Then in utils/permissions.py has_page_add_permission() function, target gets extracted from request.GET

target = request.GET.get('target', None)

so target is an empty string. It's not None so passes the if statement test. Then it tries to get a Page object using empty string as the pk:

page = Page.objects.get(pk=target)

Which gives the error invalid literal for int() with base 10: ''. Being less strict about the checking of target means cms doesn't try to make it a sub-page.

@coveralls
Copy link

coveralls commented May 26, 2014

Coverage Status

Coverage decreased (-0.1%) to 87.997% when pulling dea80fe on damianmoore:fix_for_non_superuser_adding_top_level_page into 99c0a1e on divio:develop.

digi604 added a commit that referenced this pull request May 26, 2014
…g_top_level_page

Fixed error when non-superuser tries to create a top-level page
@digi604 digi604 merged commit 61146de into django-cms:develop May 26, 2014
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

Successfully merging this pull request may close these issues.

3 participants