Fixed error when non-superuser tries to create a top-level page #3200
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
cmscodebase.cms_toolbar.pyadd_page_menu()method ofPageToolbar. Where the URL is being generated for the 'New Page' linktargetis set toself.page.parent_id or '', which at the top level means''empty string.Then in
utils/permissions.pyhas_page_add_permission()function,targetgets extracted fromrequest.GETso
targetis an empty string. It's notNoneso passes theifstatement test. Then it tries to get aPageobject using empty string as thepk:Which gives the error
invalid literal for int() with base 10: ''. Being less strict about the checking oftargetmeans cms doesn't try to make it a sub-page.