mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 19:04:38 +00:00
Fix error not ignored getPlugins
This commit is contained in:
parent
649df34583
commit
4a21a75d53
@ -13,7 +13,7 @@ module.exports = {
|
|||||||
createRole: async params => {
|
createRole: async params => {
|
||||||
if (!strapi.plugins['content-manager']) {
|
if (!strapi.plugins['content-manager']) {
|
||||||
return new Error(
|
return new Error(
|
||||||
'This feature requires to install the Content Manager plugin',
|
'This feature requires to install the Content Manager plugin'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,7 +21,8 @@ module.exports = {
|
|||||||
params.type = _.snakeCase(_.deburr(_.toLower(params.name)));
|
params.type = _.snakeCase(_.deburr(_.toLower(params.name)));
|
||||||
}
|
}
|
||||||
|
|
||||||
const role = await strapi.plugins['users-permissions'].queries('role', 'users-permissions')
|
const role = await strapi.plugins['users-permissions']
|
||||||
|
.queries('role', 'users-permissions')
|
||||||
.create(_.omit(params, ['users', 'permissions']));
|
.create(_.omit(params, ['users', 'permissions']));
|
||||||
|
|
||||||
const arrayOfPromises = Object.keys(params.permissions).reduce(
|
const arrayOfPromises = Object.keys(params.permissions).reduce(
|
||||||
@ -29,24 +30,26 @@ module.exports = {
|
|||||||
Object.keys(params.permissions[type].controllers).forEach(
|
Object.keys(params.permissions[type].controllers).forEach(
|
||||||
controller => {
|
controller => {
|
||||||
Object.keys(
|
Object.keys(
|
||||||
params.permissions[type].controllers[controller],
|
params.permissions[type].controllers[controller]
|
||||||
).forEach(action => {
|
).forEach(action => {
|
||||||
acc.push(
|
acc.push(
|
||||||
strapi.plugins['users-permissions'].queries('permission', 'users-permissions').addPermission({
|
strapi.plugins['users-permissions']
|
||||||
role: role._id || role.id,
|
.queries('permission', 'users-permissions')
|
||||||
type,
|
.addPermission({
|
||||||
controller,
|
role: role._id || role.id,
|
||||||
action: action.toLowerCase(),
|
type,
|
||||||
...params.permissions[type].controllers[controller][action],
|
controller,
|
||||||
}),
|
action: action.toLowerCase(),
|
||||||
|
...params.permissions[type].controllers[controller][action],
|
||||||
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
},
|
},
|
||||||
[],
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
// Use Content Manager business logic to handle relation.
|
// Use Content Manager business logic to handle relation.
|
||||||
@ -59,15 +62,16 @@ module.exports = {
|
|||||||
{
|
{
|
||||||
users: params.users,
|
users: params.users,
|
||||||
},
|
},
|
||||||
'users-permissions',
|
'users-permissions'
|
||||||
),
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
return await Promise.all(arrayOfPromises);
|
return await Promise.all(arrayOfPromises);
|
||||||
},
|
},
|
||||||
|
|
||||||
deleteRole: async (roleID, publicRoleID) => {
|
deleteRole: async (roleID, publicRoleID) => {
|
||||||
const role = await strapi.plugins['users-permissions'].queries('role', 'users-permissions')
|
const role = await strapi.plugins['users-permissions']
|
||||||
|
.queries('role', 'users-permissions')
|
||||||
.findOne({ id: roleID }, ['users', 'permissions']);
|
.findOne({ id: roleID }, ['users', 'permissions']);
|
||||||
|
|
||||||
if (!role) {
|
if (!role) {
|
||||||
@ -77,14 +81,16 @@ module.exports = {
|
|||||||
// Move users to guest role.
|
// Move users to guest role.
|
||||||
const arrayOfPromises = role.users.reduce((acc, user) => {
|
const arrayOfPromises = role.users.reduce((acc, user) => {
|
||||||
acc.push(
|
acc.push(
|
||||||
strapi.plugins['users-permissions'].queries('user', 'users-permissions').update(
|
strapi.plugins['users-permissions']
|
||||||
{
|
.queries('user', 'users-permissions')
|
||||||
id: user._id || user.id,
|
.update(
|
||||||
},
|
{
|
||||||
{
|
id: user._id || user.id,
|
||||||
role: publicRoleID,
|
},
|
||||||
},
|
{
|
||||||
),
|
role: publicRoleID,
|
||||||
|
}
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
@ -93,17 +99,21 @@ module.exports = {
|
|||||||
// Remove permissions related to this role.
|
// Remove permissions related to this role.
|
||||||
role.permissions.forEach(permission => {
|
role.permissions.forEach(permission => {
|
||||||
arrayOfPromises.push(
|
arrayOfPromises.push(
|
||||||
strapi.plugins['users-permissions'].queries('permission', 'users-permissions').delete({
|
strapi.plugins['users-permissions']
|
||||||
id: permission._id || permission.id,
|
.queries('permission', 'users-permissions')
|
||||||
}),
|
.delete({
|
||||||
|
id: permission._id || permission.id,
|
||||||
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Delete the role.
|
// Delete the role.
|
||||||
arrayOfPromises.push(
|
arrayOfPromises.push(
|
||||||
strapi.plugins['users-permissions'].queries('role', 'users-permissions').delete({
|
strapi.plugins['users-permissions']
|
||||||
id: roleID,
|
.queries('role', 'users-permissions')
|
||||||
}),
|
.delete({
|
||||||
|
id: roleID,
|
||||||
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
return await Promise.all(arrayOfPromises);
|
return await Promise.all(arrayOfPromises);
|
||||||
@ -120,12 +130,12 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
(err, response, body) => {
|
(err, response, body) => {
|
||||||
if (err) {
|
if (response.statusCode !== 200 || err) {
|
||||||
return resolve([]);
|
return resolve([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve(body);
|
resolve(body);
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -146,13 +156,13 @@ module.exports = {
|
|||||||
(acc, key) => {
|
(acc, key) => {
|
||||||
Object.keys(strapi.api[key].controllers).forEach(controller => {
|
Object.keys(strapi.api[key].controllers).forEach(controller => {
|
||||||
acc.controllers[controller] = generateActions(
|
acc.controllers[controller] = generateActions(
|
||||||
strapi.api[key].controllers[controller],
|
strapi.api[key].controllers[controller]
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
},
|
},
|
||||||
{ controllers: {} },
|
{ controllers: {} }
|
||||||
);
|
);
|
||||||
|
|
||||||
const pluginsPermissions = Object.keys(strapi.plugins).reduce(
|
const pluginsPermissions = Object.keys(strapi.plugins).reduce(
|
||||||
@ -169,17 +179,17 @@ module.exports = {
|
|||||||
acc[key] = Object.keys(strapi.plugins[key].controllers).reduce(
|
acc[key] = Object.keys(strapi.plugins[key].controllers).reduce(
|
||||||
(obj, k) => {
|
(obj, k) => {
|
||||||
obj.controllers[k] = generateActions(
|
obj.controllers[k] = generateActions(
|
||||||
strapi.plugins[key].controllers[k],
|
strapi.plugins[key].controllers[k]
|
||||||
);
|
);
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
},
|
},
|
||||||
initialState,
|
initialState
|
||||||
);
|
);
|
||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
},
|
},
|
||||||
{},
|
{}
|
||||||
);
|
);
|
||||||
|
|
||||||
const permissions = {
|
const permissions = {
|
||||||
@ -192,7 +202,8 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
getRole: async (roleID, plugins) => {
|
getRole: async (roleID, plugins) => {
|
||||||
const role = await strapi.plugins['users-permissions'].queries('role', 'users-permissions')
|
const role = await strapi.plugins['users-permissions']
|
||||||
|
.queries('role', 'users-permissions')
|
||||||
.findOne({ id: roleID }, ['users', 'permissions']);
|
.findOne({ id: roleID }, ['users', 'permissions']);
|
||||||
|
|
||||||
if (!role) {
|
if (!role) {
|
||||||
@ -209,7 +220,7 @@ module.exports = {
|
|||||||
{
|
{
|
||||||
enabled: _.toNumber(permission.enabled) == true,
|
enabled: _.toNumber(permission.enabled) == true,
|
||||||
policy: permission.policy,
|
policy: permission.policy,
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@ -227,13 +238,15 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
getRoles: async () => {
|
getRoles: async () => {
|
||||||
const roles = await strapi.plugins['users-permissions'].queries('role', 'users-permissions')
|
const roles = await strapi.plugins['users-permissions']
|
||||||
|
.queries('role', 'users-permissions')
|
||||||
.find({ _sort: 'name' }, []);
|
.find({ _sort: 'name' }, []);
|
||||||
|
|
||||||
for (let i = 0; i < roles.length; ++i) {
|
for (let i = 0; i < roles.length; ++i) {
|
||||||
roles[i].id = roles[i].id || roles[i]._id;
|
roles[i].id = roles[i].id || roles[i]._id;
|
||||||
|
|
||||||
roles[i].nb_users = await strapi.plugins['users-permissions'].queries('user', 'users-permissions')
|
roles[i].nb_users = await strapi.plugins['users-permissions']
|
||||||
|
.queries('user', 'users-permissions')
|
||||||
.count({ role: roles[i].id });
|
.count({ role: roles[i].id });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,7 +263,7 @@ module.exports = {
|
|||||||
const routes = _.get(
|
const routes = _.get(
|
||||||
clonedPlugins,
|
clonedPlugins,
|
||||||
[current, 'config', 'routes'],
|
[current, 'config', 'routes'],
|
||||||
[],
|
[]
|
||||||
).reduce((acc, curr) => {
|
).reduce((acc, curr) => {
|
||||||
const prefix = curr.config.prefix;
|
const prefix = curr.config.prefix;
|
||||||
const path =
|
const path =
|
||||||
@ -266,7 +279,7 @@ module.exports = {
|
|||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
},
|
},
|
||||||
{},
|
{}
|
||||||
);
|
);
|
||||||
|
|
||||||
return _.merge({ application: routes }, pluginsRoutes);
|
return _.merge({ application: routes }, pluginsRoutes);
|
||||||
@ -274,11 +287,12 @@ module.exports = {
|
|||||||
|
|
||||||
async updatePermissions() {
|
async updatePermissions() {
|
||||||
// fetch all the current permissions from the database, and format them into an array of actions.
|
// fetch all the current permissions from the database, and format them into an array of actions.
|
||||||
const databasePermissions = await strapi.plugins['users-permissions'].queries('permission', 'users-permissions')
|
const databasePermissions = await strapi.plugins['users-permissions']
|
||||||
|
.queries('permission', 'users-permissions')
|
||||||
.find({ _limit: -1 });
|
.find({ _limit: -1 });
|
||||||
const actions = databasePermissions.map(
|
const actions = databasePermissions.map(
|
||||||
permission =>
|
permission =>
|
||||||
`${permission.type}.${permission.controller}.${permission.action}`,
|
`${permission.type}.${permission.controller}.${permission.action}`
|
||||||
);
|
);
|
||||||
|
|
||||||
// Aggregate first level actions.
|
// Aggregate first level actions.
|
||||||
@ -287,12 +301,12 @@ module.exports = {
|
|||||||
controller => {
|
controller => {
|
||||||
const actions = Object.keys(strapi.api[api].controllers[controller])
|
const actions = Object.keys(strapi.api[api].controllers[controller])
|
||||||
.filter(action =>
|
.filter(action =>
|
||||||
_.isFunction(strapi.api[api].controllers[controller][action]),
|
_.isFunction(strapi.api[api].controllers[controller][action])
|
||||||
)
|
)
|
||||||
.map(action => `application.${controller}.${action.toLowerCase()}`);
|
.map(action => `application.${controller}.${action.toLowerCase()}`);
|
||||||
|
|
||||||
acc = acc.concat(actions);
|
acc = acc.concat(actions);
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
@ -302,12 +316,10 @@ module.exports = {
|
|||||||
const pluginsActions = Object.keys(strapi.plugins).reduce((acc, plugin) => {
|
const pluginsActions = Object.keys(strapi.plugins).reduce((acc, plugin) => {
|
||||||
Object.keys(strapi.plugins[plugin].controllers).forEach(controller => {
|
Object.keys(strapi.plugins[plugin].controllers).forEach(controller => {
|
||||||
const actions = Object.keys(
|
const actions = Object.keys(
|
||||||
strapi.plugins[plugin].controllers[controller],
|
strapi.plugins[plugin].controllers[controller]
|
||||||
)
|
)
|
||||||
.filter(action =>
|
.filter(action =>
|
||||||
_.isFunction(
|
_.isFunction(strapi.plugins[plugin].controllers[controller][action])
|
||||||
strapi.plugins[plugin].controllers[controller][action],
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.map(action => `${plugin}.${controller}.${action.toLowerCase()}`);
|
.map(action => `${plugin}.${controller}.${action.toLowerCase()}`);
|
||||||
|
|
||||||
@ -394,7 +406,9 @@ module.exports = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Retrieve roles
|
// Retrieve roles
|
||||||
const roles = await strapi.plugins['users-permissions'].queries('role', 'users-permissions').find();
|
const roles = await strapi.plugins['users-permissions']
|
||||||
|
.queries('role', 'users-permissions')
|
||||||
|
.find();
|
||||||
|
|
||||||
// We have to know the difference to add or remove
|
// We have to know the difference to add or remove
|
||||||
// the permissions entries in the database.
|
// the permissions entries in the database.
|
||||||
@ -412,31 +426,36 @@ module.exports = {
|
|||||||
toAdd
|
toAdd
|
||||||
.map(action => defaultPolicy(action, role))
|
.map(action => defaultPolicy(action, role))
|
||||||
.map(action =>
|
.map(action =>
|
||||||
strapi.plugins['users-permissions'].queries('permission', 'users-permissions')
|
strapi.plugins['users-permissions']
|
||||||
|
.queries('permission', 'users-permissions')
|
||||||
.addPermission(
|
.addPermission(
|
||||||
Object.assign(action, { role: role.id || role._id }),
|
Object.assign(action, { role: role.id || role._id })
|
||||||
),
|
)
|
||||||
),
|
)
|
||||||
),
|
)
|
||||||
)
|
)
|
||||||
.concat([
|
.concat([
|
||||||
Promise.all(
|
Promise.all(
|
||||||
toRemove.map(action =>
|
toRemove.map(action =>
|
||||||
strapi.plugins['users-permissions'].queries('permission', 'users-permissions')
|
strapi.plugins['users-permissions']
|
||||||
.removePermission(action),
|
.queries('permission', 'users-permissions')
|
||||||
),
|
.removePermission(action)
|
||||||
|
)
|
||||||
),
|
),
|
||||||
]),
|
])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
removeDuplicate: async function() {
|
removeDuplicate: async function() {
|
||||||
const primaryKey = strapi.plugins['users-permissions'].queries('permission', 'users-permissions')
|
const primaryKey = strapi.plugins['users-permissions'].queries(
|
||||||
.primaryKey;
|
'permission',
|
||||||
|
'users-permissions'
|
||||||
|
).primaryKey;
|
||||||
|
|
||||||
// Retrieve permissions by creation date (ID or ObjectID).
|
// Retrieve permissions by creation date (ID or ObjectID).
|
||||||
const permissions = await strapi.plugins['users-permissions'].queries('permission', 'users-permissions')
|
const permissions = await strapi.plugins['users-permissions']
|
||||||
|
.queries('permission', 'users-permissions')
|
||||||
.find({
|
.find({
|
||||||
_sort: `${primaryKey}`,
|
_sort: `${primaryKey}`,
|
||||||
_limit: -1,
|
_limit: -1,
|
||||||
@ -449,14 +468,14 @@ module.exports = {
|
|||||||
element ===
|
element ===
|
||||||
`${permission.type}.controllers.${permission.controller}.${
|
`${permission.type}.controllers.${permission.controller}.${
|
||||||
permission.action
|
permission.action
|
||||||
}.${permission.role[primaryKey]}`,
|
}.${permission.role[primaryKey]}`
|
||||||
);
|
);
|
||||||
|
|
||||||
if (index === -1) {
|
if (index === -1) {
|
||||||
acc.toKeep.push(
|
acc.toKeep.push(
|
||||||
`${permission.type}.controllers.${permission.controller}.${
|
`${permission.type}.controllers.${permission.controller}.${
|
||||||
permission.action
|
permission.action
|
||||||
}.${permission.role[primaryKey]}`,
|
}.${permission.role[primaryKey]}`
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
acc.toRemove.push(permission[primaryKey]);
|
acc.toRemove.push(permission[primaryKey]);
|
||||||
@ -467,16 +486,20 @@ module.exports = {
|
|||||||
{
|
{
|
||||||
toKeep: [],
|
toKeep: [],
|
||||||
toRemove: [],
|
toRemove: [],
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return strapi.plugins['users-permissions'].queries('permission', 'users-permissions').deleteMany({
|
return strapi.plugins['users-permissions']
|
||||||
[primaryKey]: value.toRemove,
|
.queries('permission', 'users-permissions')
|
||||||
});
|
.deleteMany({
|
||||||
|
[primaryKey]: value.toRemove,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
async initialize(cb) {
|
async initialize(cb) {
|
||||||
const roleCount = await strapi.plugins['users-permissions'].queries('role', 'users-permissions').count();
|
const roleCount = await strapi.plugins['users-permissions']
|
||||||
|
.queries('role', 'users-permissions')
|
||||||
|
.count();
|
||||||
|
|
||||||
// It has already been initialized.
|
// It has already been initialized.
|
||||||
if (roleCount > 0) {
|
if (roleCount > 0) {
|
||||||
@ -491,26 +514,30 @@ module.exports = {
|
|||||||
|
|
||||||
// Create two first default roles.
|
// Create two first default roles.
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
strapi.plugins['users-permissions'].queries('role', 'users-permissions').create({
|
strapi.plugins['users-permissions']
|
||||||
name: 'Authenticated',
|
.queries('role', 'users-permissions')
|
||||||
description: 'Default role given to authenticated user.',
|
.create({
|
||||||
type: 'authenticated',
|
name: 'Authenticated',
|
||||||
}),
|
description: 'Default role given to authenticated user.',
|
||||||
strapi.plugins['users-permissions'].queries('role', 'users-permissions').create({
|
type: 'authenticated',
|
||||||
name: 'Public',
|
}),
|
||||||
description: 'Default role given to unauthenticated user.',
|
strapi.plugins['users-permissions']
|
||||||
type: 'public',
|
.queries('role', 'users-permissions')
|
||||||
}),
|
.create({
|
||||||
|
name: 'Public',
|
||||||
|
description: 'Default role given to unauthenticated user.',
|
||||||
|
type: 'public',
|
||||||
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
this.updatePermissions().then(() => cb(), err => cb(err));
|
this.updatePermissions().then(() => cb(), err => cb(err));
|
||||||
},
|
},
|
||||||
|
|
||||||
updateRole: async function(roleID, body) {
|
updateRole: async function(roleID, body) {
|
||||||
const [role, authenticated] = await Promise.all([
|
const [role, authenticated] = await Promise.all([
|
||||||
this.getRole(roleID, []),
|
this.getRole(roleID, []),
|
||||||
strapi.plugins['users-permissions'].queries('role', 'users-permissions')
|
strapi.plugins['users-permissions']
|
||||||
|
.queries('role', 'users-permissions')
|
||||||
.findOne({ type: 'authenticated' }, []),
|
.findOne({ type: 'authenticated' }, []),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -524,38 +551,42 @@ module.exports = {
|
|||||||
const currentAction = _.get(
|
const currentAction = _.get(
|
||||||
role.permissions,
|
role.permissions,
|
||||||
`${type}.controllers.${controller}.${action}`,
|
`${type}.controllers.${controller}.${action}`,
|
||||||
{},
|
{}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (_.differenceWith([bodyAction], [currentAction]).length > 0) {
|
if (_.differenceWith([bodyAction], [currentAction]).length > 0) {
|
||||||
acc.push(
|
acc.push(
|
||||||
strapi.plugins['users-permissions'].queries('permission', 'users-permissions').update(
|
strapi.plugins['users-permissions']
|
||||||
{
|
.queries('permission', 'users-permissions')
|
||||||
role: roleID,
|
.update(
|
||||||
type,
|
{
|
||||||
controller,
|
role: roleID,
|
||||||
action: action.toLowerCase(),
|
type,
|
||||||
},
|
controller,
|
||||||
bodyAction,
|
action: action.toLowerCase(),
|
||||||
),
|
},
|
||||||
|
bodyAction
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
},
|
},
|
||||||
[],
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
arrayOfPromises.push(
|
arrayOfPromises.push(
|
||||||
strapi.plugins['users-permissions'].queries('role', 'users-permissions').update(
|
strapi.plugins['users-permissions']
|
||||||
{
|
.queries('role', 'users-permissions')
|
||||||
id: roleID,
|
.update(
|
||||||
},
|
{
|
||||||
_.pick(body, ['name', 'description']),
|
id: roleID,
|
||||||
),
|
},
|
||||||
|
_.pick(body, ['name', 'description'])
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
// stringify mongoDB _id for add/remove matching
|
// stringify mongoDB _id for add/remove matching
|
||||||
@ -572,30 +603,32 @@ module.exports = {
|
|||||||
_.differenceBy(body.users, role.users, role._id ? '_id' : 'id').forEach(
|
_.differenceBy(body.users, role.users, role._id ? '_id' : 'id').forEach(
|
||||||
user => {
|
user => {
|
||||||
arrayOfPromises.push(this.updateUserRole(user, roleID));
|
arrayOfPromises.push(this.updateUserRole(user, roleID));
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// Remove user to this role and link him to authenticated.
|
// Remove user to this role and link him to authenticated.
|
||||||
_.differenceBy(role.users, body.users, role._id ? '_id' : 'id').forEach(
|
_.differenceBy(role.users, body.users, role._id ? '_id' : 'id').forEach(
|
||||||
user => {
|
user => {
|
||||||
arrayOfPromises.push(
|
arrayOfPromises.push(
|
||||||
this.updateUserRole(user, authenticated._id || authenticated.id),
|
this.updateUserRole(user, authenticated._id || authenticated.id)
|
||||||
);
|
);
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return Promise.all(arrayOfPromises);
|
return Promise.all(arrayOfPromises);
|
||||||
},
|
},
|
||||||
|
|
||||||
updateUserRole: async (user, role) => {
|
updateUserRole: async (user, role) => {
|
||||||
return strapi.plugins['users-permissions'].queries('user', 'users-permissions').update(
|
return strapi.plugins['users-permissions']
|
||||||
{
|
.queries('user', 'users-permissions')
|
||||||
id: user._id || user.id,
|
.update(
|
||||||
},
|
{
|
||||||
{
|
id: user._id || user.id,
|
||||||
role: role.toString(),
|
},
|
||||||
},
|
{
|
||||||
);
|
role: role.toString(),
|
||||||
|
}
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
template: (layout, data) => {
|
template: (layout, data) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user