joas8211 / payload-tenancy

Multi-tenancy plugin for Payload CMS
MIT License
122 stars 6 forks source link

Add option to limit tenant hierarchy depth #13

Open PhotoshopLOL opened 1 year ago

PhotoshopLOL commented 1 year ago

Hello! Thank you for making this very useful plugin!

Some use cases such as mine only need 1-2 layers of tenancy. Restricting this to a certain depth also patches up the "infinite subtenants" possibility.

With that, I suggest adding a depth setting for creating tenants.

PhotoshopLOL commented 1 year ago

For my case, I only needed 1 depth of tenancy. A hack I found was to explicitly filter access to create documents by doing if (user?.tenant?.slug === 'rootTenant') in the Tenant collection.

I'm not quite sure how else to do this for 2 layers of depth though. I will keep searching for it!

joas8211 commented 1 year ago

I'm pretty sure it can also be done by manipulating tenant collection and it's parent field as a user of the plugin. At least when I get improvements to the field override system properly implemented and released (started from #8).

Adding an option might not hurt either since it requires quite extensive modifications to be made by the user of this plugin if done that way. I'm thinking it might be benefitial for other / future users also.

All things considered, I think the game plan is that I'll add the option to limit tenant hirarchy depth.