-
Beta Was this translation helpful? Give feedback.
Answered by
denolfe
Jul 20, 2022
Replies: 2 comments 2 replies
-
same request |
Beta Was this translation helpful? Give feedback.
0 replies
-
Yes, this can be done w/ hooks and access control. Here is an example collection: const Posts: CollectionConfig = {
slug: 'posts',
hooks: {
beforeChange: [
({ req, operation, data }) => {
if (req.user) {
if (operation === 'create') {
data.updatedBy = req.user.id;
data.createdBy = req.user.id;
} else if (operation === 'update') {
data.updatedBy = req.user.id;
}
return data;
}
},
],
},
fields: [
{
name: 'createdBy',
type: 'relationship',
relationTo: 'users',
access: {
update: () => false,
},
admin: {
readOnly: true,
position: 'sidebar',
condition: (data) => !!data?.createdBy,
},
},
{
name: 'createdBy',
type: 'relationship',
relationTo: 'users',
access: {
update: () => false,
},
admin: {
readOnly: true,
position: 'sidebar',
condition: (data) => !!data?.createdBy,
},
},
// Other fields
],
};
export default Posts; This will now show in the admin sidebar |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
denolfe
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, this can be done w/ hooks and access control. Here is an example collection: