Access Control RBAC - get record ID / get collection #389
-
I'm trying to follow along with the docs and receive an ID with my access control functions. I'm expecting the Additionally, is there any way to figure out what collection I'm in on an access control method? I can see the user, but I'd also like to do more advanced checks depending on which collection I'm on. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hey @ryanlanciaux — I can give some insight here. The Also—you're seeing your access control function being called from the The Also, in regards to knowing what collection you're in, I would recommend abstracting your access control functions in a way that allows you to pass them the collection that you're on so you have full control. Like this: export const accessControl = ({ req }) => {
// how do we know what collection we're in?
return true; // simple example
} import { accessControl } from './access';
const pages = {
slug: 'pages',
access: {
read: accessControl,
}
} You're probably sharing a function like this through many collections, and within that function there is no way to know what collection you're on. Instead, you could do this: export const getAccessControl = (collectionSlug) => ({ req }) => {
// Now we know that our collection is `collectionSlug`
return true; // simple example
} import { getAccessControl } from './access';
const pages = {
slug: 'pages',
access: {
read: getAccessControl('pages'),
}
} Does that make sense? There are many other patterns of abstraction that can work here but this is the one we'd generally use. Also - can I ask what you need the ID of the document for? Are you familiar with the nature of how returning 👍 |
Beta Was this translation helpful? Give feedback.
Hey @ryanlanciaux — I can give some insight here.
The
id
parameter is optional and only going to be present in some access control methods, in certain cases. For example, there is noid
yet increate
access control.Also—you're seeing your access control function being called from the
access
operation, which goes through and calls all access control through all your collections and globals. But, while your access control functions are being called by theaccess
operation, there will be no ID present there either.The
access
operation is responsible for telling the admin UI what you can and can't do. You can hit it in your browser by going to/api/access
to see what it looks like.Also, in…