statamic / ideas

💡Discussions on ideas and feature requests for Statamic
https://statamic.dev
31 stars 1 forks source link

Protect Scheme "order of precedence" #888

Open binoclard opened 1 year ago

binoclard commented 1 year ago

I wonder if it could be a decent feature, that the protect scheme has some king of "order of precedence": Site > Collection > Entry So if a global protect scheme is set, it could still be overridden at a more specific level.

My question comes from my current project, where it makes sense to set up a site-wide protection with password, but I still would like to exclude some limited pages. Currently, if I understand things correctly, the only option is to define a protect scheme for each and all Collections/Entries, except the ones I would like to be less restricted.

So I think it could be nice to be able to specify "protect: null" at the entry level to exclude it, or to be able to set 'logged_in" as the default, but 'password' for selected items, or vice-versa.

Hope it makes sense, and that others might find it useful.

jacksleight commented 1 year ago

Just run into this as well. Set a default protection scheme and then tried to override the default for a specific collection, but the default one takes priority.

If there's interest in changing this behaviour it might make sense for v4, since it could be breaking.

jasonvarga commented 1 year ago

This could be added at any time with an additional config option to swap the behavior. We wouldn't need to wait for a breaking release. (Especially after v4 since breaking releases are planned to only be once a year)

Something like:

// config/statamic/protect.php

'precedence' => 'default', // or 'content'
jacksleight commented 1 year ago

Oh yeah good point, just make it configurable! 🤦‍♂️

jasonvarga commented 1 year ago

Quickly looking at it, it should be simple to change.

https://github.com/statamic/cms/blob/cd21c8863c7233f452708b3d0d0078986ecb51a4/src/Auth/Protect/Protection.php#L31-L42

In here, you should be able to switch the order of the default/data protection depending on the new config option.