filtering documents that show up in admin panel (without limiting public read access).

default discord avatar
ryoheiw
last week

For collection level access, you can limit which users can read or provide a where query to allow only specific documents to be read. I'd like to keep public read access to the entire collection, but provide a where query for the documents that show up in the admin panel for the collection. Specifically, I want to be able to limit the documents based on a field on the user and document, kind of like a filterOptions from a relationship field but for the admin panel's documents (not overall collection reads). Is there a way to do this?



you can do this with JS if statements 🤦‍♂️ just filter when the user is signed in and return

true

for whatever web client you're using.



if (user && user.role === "user") {
        return {
          id: { equals: user.company.id },
        };
      }
      if (user && user.role === "admin") {
        return true;
      }
      return true;
    Open the post
    Continue the discussion in Discord
    Like what we're doing?
    Star us on GitHub!

    Star

    Connect with the Payload Community on Discord

    Discord

    online

    Can't find what you're looking for?

    Get help straight from the Payload team with an Enterprise License.