-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Description
I am trying to set the find
and findOne
permissions for the public
role for some new content types using the migration plugin.
If I run the script below using the strap console
the commands works as intended, but when migration plugin runs the script, the strapi.entityService.findMany(...)
returns an empty array []
.
Not sure what is causing this, but I guess it is related to if the user-permissions
is ready or not at the time the migrations
plugin is running.
// Based on https://forum.strapi.io/t/set-permissions-programmatically-6294/1774/10
module.exports = async () => {
const r1 = await strapi.entityService.findMany('plugin::users-permissions.role', {filters: {type:'public'}})
const _public = await strapi
.service("plugin::users-permissions.role")
.findOne(r1[0].id);
for (const permission of Object.keys(_public.permissions)) {
if (permission.startsWith("api::content-type")) {
for (const controller of Object.keys(
_public.permissions[permission].controllers
)) {
_public.permissions[permission]
.controllers[controller]
.find.enabled = true;
_public.permissions[permission]
.controllers[controller]
.findOne.enabled = true;
}
}
}
await strapi
.service("plugin::users-permissions.role")
.updateRole(_public.id, _public)
}
Metadata
Metadata
Assignees
Labels
No labels