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

Finer add permission check for displaying the "Add site tree Item" button #277

Open
romaricpascal opened this issue May 15, 2020 · 3 comments

Comments

@romaricpascal
Copy link

Hello,

When editing a Site Tree, it'd be great if there was a specific permission check deciding whether to show the "Add site tree item", say "has_add_tree_item_permission". This would allow to remove the control for adding new Trees in the admin, but allow adding new Tree item.

Ran into the issue trying to allow admins to just edit pre-configured menus, without risking them adding new ones for nothing.

@idlesign
Copy link
Owner

Hi,

Thank you for the idea.

Have you tried overriding ModelAdmin.has_add_permission() approach?
It seem rather easy and flexible. Possibly more flexible than restrictions per-user.

You see, I'm afraid there's no convenient way to support that out of the box in sitetree. Since if we simply add a permission admin users will stil need to override the method mentioned above; and if we override it out-of-box, new users won't have it automatically and manual assignment will be required (that'll be not backward compatible).

What do you think?

@romaricpascal
Copy link
Author

Hi,

I'm not sure I understand what you're proposing, and I realise I was not super detailed with my suggestion and the use case leading to it.

What I was trying to achieve is the following:

  1. Remove the possibility to add new Site Trees, by removing the buttons from the admin UI
  2. Maintain the possibility to add new Site Tree Items

Overriding ModelAdmin.has_add_permission() took care of #1, as expected. The unfortunate side effect, because the value is also used to decide the rendering of the button to a Site Tree Item, was to remove the "Add Site Tree Item" button too.

This is due to this if in the template:

Rather than overriding the whole template to adapt the check (which might lead to discrepancies as the library gets update), it would have been ideal that the check was made on a separate context variable (the has_add_tree_item_permission I mentioned).

Its value could be overridden in the ModelAdmin, say by overriding a had_add_tree_item_permission() method. That method default implementation would return ModelAdmin.has_add_permission(), to keep its behaviour in line with what happens currently. Or maybe it could pull whatever has_add_permission the admin registered for SiteTreeItem, but that sounds lots of work for a marginal gain.

How does that sound?

@idlesign
Copy link
Owner

Ah, I see. Thank you for the clarification.

Adding new has_add_tree_item_permission() with backward compatible implementation sounds quite reasonable.

Pull request is welcome, if you will.

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

2 participants