So I created a role through bootstrap with set permissions. The code ran fine until it came to a point where I need to update some permissions in the dashboard. Whenever I update the role, it show the success confirmation popup. But when i refresh the page, all the updates I made are gone and it reverts back to the original permissions. Below is my bootstrap code. Maybe I did something wrong there that’s causing this
"use strict";
/**
* An asynchronous bootstrap function that runs before
* your application gets started.
*
* This gives you an opportunity to set up your data model,
* run jobs, or perform some special logic.
*
* See more details here: https://strapi.io/documentation/developer-docs/latest/setup-deployment-guides/configurations.html#bootstrap
*/
async function isFirstRun() {
const pluginStore = strapi.store({
environment: strapi.config.environment,
type: "type",
name: "setup",
});
const initHasRun = await pluginStore.get({ key: "initHasRun" });
await pluginStore.set({ key: "initHasRun", value: true });
return !initHasRun;
}
async function setRoles() {
try {
const publicRole = await strapi
.query("role", "users-permissions")
.findOne({ type: "public" });
if (publicRole) {
await strapi.query("role", "users-permissions").update(
{ id: publicRole.id },
{
name: "Volunteer",
type: "volunteer",
description: "This user is the volunteer",
}
);
}
const organisationRole = await strapi
.query("role", "users-permissions")
.create({
name: "Organisation",
type: "organisation",
description: "This is the organnisation looking for volunteers",
});
await setPermissions(publicRole.permissions, organisationRole.id);
} catch (error) {
console.log({ error });
}
}
async function setPermissions(permissions, organisationRoleId) {
const permissionsToSet = permissions.map(async (permission) => {
const { id, role, controller, action, ...rest } = permission;
const input =
controller === "organisation" && action === "create"
? { ...rest, controller, action, enabled: true }
: { ...rest, controller, action };
await strapi.query("permission", "users-permissions").create({
...input,
role: organisationRoleId,
});
if (controller === "volunteer" && action === "create") {
await strapi
.query("permission", "users-permissions")
.update({ id }, { enabled: true });
}
});
await Promise.all(permissionsToSet);
}
module.exports = async () => {
const shouldImportSeedData = await isFirstRun();
if (shouldImportSeedData) {
try {
await setRoles();
} catch (error) {
console.log("Could not import seed data");
console.error(error);
}
}
};
Please let me know if you see anything wrong. I’m fairly new to strapi. Thank you