mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 10:55:37 +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';
|
'use strict';
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
collectionName: 'strapi_token_permissions',
|
collectionName: 'strapi_api_token_permissions',
|
||||||
info: {
|
info: {
|
||||||
name: 'API Token Permission',
|
name: 'API Token Permission',
|
||||||
description: '',
|
description: '',
|
||||||
singularName: 'token-permission',
|
singularName: 'api-token-permission',
|
||||||
pluralName: 'token-permissions',
|
pluralName: 'api-token-permissions',
|
||||||
displayName: 'API Token Permission',
|
displayName: 'API Token Permission',
|
||||||
},
|
},
|
||||||
options: {},
|
options: {},
|
||||||
@ -55,7 +55,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
permissions: {
|
permissions: {
|
||||||
type: 'relation',
|
type: 'relation',
|
||||||
target: 'admin::token-permission',
|
target: 'admin::api-token-permission',
|
||||||
relation: 'oneToMany',
|
relation: 'oneToMany',
|
||||||
mappedBy: 'token',
|
mappedBy: 'token',
|
||||||
configurable: false,
|
configurable: false,
|
||||||
|
|||||||
@ -5,5 +5,5 @@ module.exports = {
|
|||||||
user: { schema: require('./User') },
|
user: { schema: require('./User') },
|
||||||
role: { schema: require('./Role') },
|
role: { schema: require('./Role') },
|
||||||
'api-token': { schema: require('./api-token') },
|
'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 this is a custom type token, create and the related permissions
|
||||||
if (attributes.type === constants.API_TOKEN_TYPE.CUSTOM) {
|
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
|
// 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,
|
// populate: POPULATE_FIELDS,
|
||||||
// data: attributes.permissions.map(action => ({ action, token: apiToken })),
|
// data: attributes.permissions.map(action => ({ action, token: apiToken })),
|
||||||
// });
|
// });
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
uniq(attributes.permissions).map((action) =>
|
uniq(attributes.permissions).map((action) =>
|
||||||
strapi.query('admin::token-permission').create({
|
strapi.query('admin::api-token-permission').create({
|
||||||
data: { action, token: apiToken },
|
data: { action, token: apiToken },
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@ -373,7 +373,7 @@ const update = async (id, attributes) => {
|
|||||||
// method using a loop -- works but very inefficient
|
// method using a loop -- works but very inefficient
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
actionsToDelete.map((action) =>
|
actionsToDelete.map((action) =>
|
||||||
strapi.query('admin::token-permission').delete({
|
strapi.query('admin::api-token-permission').delete({
|
||||||
where: { action, token: id },
|
where: { action, token: id },
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@ -383,7 +383,7 @@ const update = async (id, attributes) => {
|
|||||||
// using a loop -- works but very inefficient
|
// using a loop -- works but very inefficient
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
actionsToAdd.map((action) =>
|
actionsToAdd.map((action) =>
|
||||||
strapi.query('admin::token-permission').create({
|
strapi.query('admin::api-token-permission').create({
|
||||||
data: { action, token: id },
|
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
|
// if type is not custom, make sure any old permissions get removed
|
||||||
else if (updatedToken.type !== constants.API_TOKEN_TYPE.CUSTOM) {
|
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 },
|
where: { token: id },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user