mirror of
https://github.com/strapi/strapi.git
synced 2025-11-01 10:23:34 +00:00
Merge pull request #14238 from strapi/api-token-v2/rename-api-token-permission
rename token-permission to api-token-permission
This commit is contained in:
commit
0213ee2e1a
@ -1,12 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
collectionName: 'strapi_token_permissions',
|
||||
collectionName: 'strapi_api_token_permissions',
|
||||
info: {
|
||||
name: 'API Token Permission',
|
||||
description: '',
|
||||
singularName: 'token-permission',
|
||||
pluralName: 'token-permissions',
|
||||
singularName: 'api-token-permission',
|
||||
pluralName: 'api-token-permissions',
|
||||
displayName: 'API Token Permission',
|
||||
},
|
||||
options: {},
|
||||
@ -55,7 +55,7 @@ module.exports = {
|
||||
},
|
||||
permissions: {
|
||||
type: 'relation',
|
||||
target: 'admin::token-permission',
|
||||
target: 'admin::api-token-permission',
|
||||
relation: 'oneToMany',
|
||||
mappedBy: 'token',
|
||||
configurable: false,
|
||||
|
||||
@ -5,5 +5,5 @@ module.exports = {
|
||||
user: { schema: require('./User') },
|
||||
role: { schema: require('./Role') },
|
||||
'api-token': { schema: require('./api-token') },
|
||||
'token-permission': { schema: require('./token-permission') },
|
||||
'api-token-permission': { schema: require('./api-token-permission') },
|
||||
};
|
||||
|
||||
@ -190,13 +190,13 @@ const create = async (attributes) => {
|
||||
// If this is a custom type token, create and the related permissions
|
||||
if (attributes.type === constants.API_TOKEN_TYPE.CUSTOM) {
|
||||
// TODO: createMany doesn't seem to create relation properly, implement a better way rather than a ton of queries
|
||||
// const permissionsCount = await strapi.query('admin::token-permission').createMany({
|
||||
// const permissionsCount = await strapi.query('admin::api-token-permission').createMany({
|
||||
// populate: POPULATE_FIELDS,
|
||||
// data: attributes.permissions.map(action => ({ action, token: apiToken })),
|
||||
// });
|
||||
await Promise.all(
|
||||
uniq(attributes.permissions).map((action) =>
|
||||
strapi.query('admin::token-permission').create({
|
||||
strapi.query('admin::api-token-permission').create({
|
||||
data: { action, token: apiToken },
|
||||
})
|
||||
)
|
||||
@ -373,7 +373,7 @@ const update = async (id, attributes) => {
|
||||
// method using a loop -- works but very inefficient
|
||||
await Promise.all(
|
||||
actionsToDelete.map((action) =>
|
||||
strapi.query('admin::token-permission').delete({
|
||||
strapi.query('admin::api-token-permission').delete({
|
||||
where: { action, token: id },
|
||||
})
|
||||
)
|
||||
@ -383,7 +383,7 @@ const update = async (id, attributes) => {
|
||||
// using a loop -- works but very inefficient
|
||||
await Promise.all(
|
||||
actionsToAdd.map((action) =>
|
||||
strapi.query('admin::token-permission').create({
|
||||
strapi.query('admin::api-token-permission').create({
|
||||
data: { action, token: id },
|
||||
})
|
||||
)
|
||||
@ -391,7 +391,7 @@ const update = async (id, attributes) => {
|
||||
}
|
||||
// if type is not custom, make sure any old permissions get removed
|
||||
else if (updatedToken.type !== constants.API_TOKEN_TYPE.CUSTOM) {
|
||||
await strapi.query('admin::token-permission').delete({
|
||||
await strapi.query('admin::api-token-permission').delete({
|
||||
where: { token: id },
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user