#Hide Collection from admin sidebar

31 messages · Page 1 of 1 (latest)

mint lake
#

Is there a way to hide a particular collection from admin sidebar for certain users?

arctic cloak
mint lake
#

I just wanted to hide the collection from the admin, not restrict access. Didn't express myself correctly.

Just found the solution on another post. Just add css to hide that element, for example, here I'm hiding users collection:

indigo moon
#

Is there a way to achieve this dynamically, depending on the users role? I'd like specific collections to be only visible for admins

next verge
#

I think this is what you are looking for. https://www.youtube.com/watch?v=DoPLyXG26Dg&t=483s

Access control is one of Payload's killer features. It delivers a ton of power and flexibility, especially compared to other CMS' rigid RBAC patterns.

Payload's admin UI automatically responds to the access control that you define. For example, if a user can't edit a document, the "Publish" button will be automatically removed. If a user can't...

▶ Play video
indigo moon
#

Unfortunately not, I don't want to restrict access, just hide the collection from the dashboard and sidebar

next verge
#

I see 🤔

civic plover
#

It would be cool to see visibility controls on the admin config for a global/collection that would handle this by role

#
  admin: {
    group: "Pages",
    visibility: [Users] // or role property on a user collection?
  },
indigo moon
#

Yes 100%, I’d love to see a similar pattern as with access control, it’s super dope!

copper seal
#

You can dynamically hide collections and globals from the admin outside of access control also using admin.hidden as a function.

#
      admin: {
        hidden: ({ user }) => user.role !== 'admin',
      },
#

Something like that will work, assuming you have a role property on your users.

#

@indigo moon @civic plover @next verge @mint lake @arctic cloak
I'm tagging you because I am sad nobody knew this.

civic plover
#

Yoooo @copper seal the man saving the day

indigo moon
#

Haha maybe that’s the only disadvantage of a great community, you’re always tempted to just post a question in the forum instead of really getting your hands dirty first

obsidian scroll
#

Even easier: in the CollectionConfig, just add admin: { hidden: true }

indigo moon
copper seal
#

I do think the user should be the full user object. It's been this way for a long time, but it does seem like a bug.

summer turret
#

@copper seal would it be also possible to get the collection config within those function (access function and admin -> hidden) when loading a list?

The collections config is only available if I start editing an entry.

But I need it before to check if my user is allowed to access this colleciotn

copper seal
#

Also I didn't add the config because it's self referencing from the place in your code that it is defined anyways. It didn't seem likely to be useful. Maybe I'm not thinking of this in the right way. I'm not opposed to adding it off there something I am missing, of course.

velvet hare
summer turret
summer turret
#

@copper seal I'll try to explain:

I have a muli-site admin.

My user can have different roles for the sites (e. g. admin for site1 and editor for site2). But I need different post-collection for my sites. So maybe user1 should be able to access posts for site1 but not posts for site2. And so he should not be able to see collection for page2.

Within my collection I got a field called "site" where the id of the used site will be stored (otherwise I'd add a custom property within the collections config to check this)

So I'd like to set hidden and my access properties to false by checking the user and the collections properties.

Is this more clear for you?

Otherwise I can also add my complete collection config 😄

copper seal
# summer turret <@969226489549713438> I'll try to explain: I have a muli-site admin. My user c...

I'm still not following. You're saying your users have roles to sites and that the collection has a relationship to the site. These are both data driven values, not hard-coded in your collection config. The collection config itself isn't determining if it belongs to site1 or site2. That all tells me you need good access control methods on your posts collection.
A user needs to see posts in the admin UI. How is it going to work if admin.hidden is true? They can't navigate to the collection list at all if that is the case.
Whereas with access, you can return a query where posts are in the sites that the user has enabled roles.

summer turret
#

@copper seal okay 🙈
It seems that I'll have to investigate and test my request a bite more before answering you. I'll take a look and come back to you later on

clear oasis
copper seal
#

I'll see if we can improve the type for user from Payload. In the meantime you can do if ore the ts error or use (user as any).roles

velvet hare
#

@clear oasis the includes function takes a value, so you would want to do !user.roles.includes('admin')