payload icon indicating copy to clipboard operation
payload copied to clipboard

Folders + Multi-Tenant lacks filtering by tenant

Open bratvanov opened this issue 10 months ago • 1 comments

Describe the Bug

I'm testing the new folders feature together with the Multi-Tenant plugin and I noticed that when on the folder view of my Pages collection, per-tenant docs filtering doesn't get applied, and all docs for all tenants are being shown (unlike the default list view, where filtering works as expected – due to the useBaseListFilter: true default setting of the Multi-Tenant plugin).

CC @JarrodMFlesch

Link to the code that reproduces this issue

https://github.com/payloadcms/payload/tree/main/examples/multi-tenant

Reproduction Steps

  1. A simple multi-tenanant install with a Pages collection and existing docs for multiple tenants
  2. Go to http://localhost:3000/admin/collections/pages - the default list view ("All Pages") properly filters docs by tenant
  3. If you click on "By Folder" - the folder view shows all folders/docs, even though we've selected a tenant in the tenant selector

Which area(s) are affected? (Select all that apply)

plugin: multi-tenant, area: core

Environment Info

payload: 3.40.0
next: 15.3.3

bratvanov avatar May 30 '25 12:05 bratvanov

I am running to a similar issue with a manual multi tenant set up, expect it throws an error saying 'relationTo cannot be queried'. Only happens when I have multiple collections with folders: true

cgilly2fast avatar May 31 '25 06:05 cgilly2fast

On that note, it would be great if the config supported granular folder access control by tenant. For example, I may want some folders or subfolders to be global, while others are visible only to specific tenants (or user roles) based on certain conditions. Is that possible?

My use case involves building a multi-tenant DAM (Digital Asset Management) system using a Payload “media” upload-enabled collection. Tenants belong to the same brand umbrella and should all have access to folders under a primary “master” folder. Beyond that, tenants are grouped into departments—each with its own shared folders and subfolders. Some departments are further divided into sub-departments and have their own media/branding assets, with access limited to fewer tenants. Hopefully that gives you a clear picture.

bratvanov avatar Jun 02 '25 11:06 bratvanov

This has been at the forefront of my mind for a while. I am aware of the inability to do the things mentioned in this thread. It is... tricky... but I think I have ideas for how to solve. Might take a little bit tbh. The hardest part is that I need to move the folder grid/list views to be server rendered via server functions bc the multi-tenant plugin relies on that paradigm.

JarrodMFlesch avatar Jun 04 '25 18:06 JarrodMFlesch

I should mention that in the next release - baseListFilters for documents will be respected. It was grouped into this PR, for reference.

JarrodMFlesch avatar Jun 04 '25 18:06 JarrodMFlesch

#12710 was just merged, so the first step towards paving the way for eventually integrating folders and multi-tenant seems to be complete. Good stuff!

bratvanov avatar Jun 11 '25 09:06 bratvanov

@bratvanov could we pass access control functions folder collection override, so user cant view folder from a different tenant? Then you just manage the folders, like all folders for a tenant go in a root tenant folder. Maybe I a miss understanding the current implementation. I haven't read though the code in detail

cgilly2fast avatar Jun 17 '25 04:06 cgilly2fast

Great work guys.

Just out of curiosity, is this being actively looked into with a target date in mind?

This is unrelated to admin folders but in the meantime, I've been using a limitied workaround to nest documents in storage that appears to work well for now: I am using the beforeOperation hook on my media collection to manipulate the prefix field of media documents before uploading. Very basic example below

Image

hassanthegooner avatar Jun 17 '25 08:06 hassanthegooner

@hassanthegooner I haven't done it, but yes that is what I would do too. And that is also what I do for my media as wel

cgilly2fast avatar Jun 20 '25 01:06 cgilly2fast

I wasn’t able to reproduce the filtering issue in Payload 3.52.0, so this issue may be safe to close.

That said, I did encounter a different problem: folders cannot currently be scoped to tenants via the multi-tenant plugin. I opened a separate issue for that here: #13518.

@bratvanov I also referenced your comment (https://github.com/payloadcms/payload/issues/12617#issuecomment-2930078929) in the new issue regarding granular folder access control.

jhb-dev avatar Aug 20 '25 07:08 jhb-dev

Closing this as the filtering has been addressed. The Multi-tenant folders feature request can be tracked in https://github.com/payloadcms/payload/issues/13518. TY @jhb-dev

JarrodMFlesch avatar Aug 21 '25 12:08 JarrodMFlesch

This issue has been automatically locked. Please open a new issue if this issue persists with any additional detail.

github-actions[bot] avatar Aug 29 '25 05:08 github-actions[bot]