mirror of
https://github.com/strapi/strapi.git
synced 2025-11-10 23:29:33 +00:00
use new condition format
Signed-off-by: Pierre Noël <petersg83@gmail.com>
This commit is contained in:
parent
6ab7669365
commit
dd88c00514
@ -1,7 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
conditions: {
|
|
||||||
isOwner: () => true, // to be modified
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@ -102,7 +102,7 @@ const createRolesIfNeeded = async () => {
|
|||||||
|
|
||||||
const authorPermissions = _.cloneDeep(editorPermissions).map(p => ({
|
const authorPermissions = _.cloneDeep(editorPermissions).map(p => ({
|
||||||
...p,
|
...p,
|
||||||
conditions: ['isOwner'],
|
conditions: ['admin::is-creator'],
|
||||||
}));
|
}));
|
||||||
|
|
||||||
await strapi.admin.services.permission.assign(editorRole.id, editorPermissions);
|
await strapi.admin.services.permission.assign(editorRole.id, editorPermissions);
|
||||||
|
|||||||
@ -131,7 +131,7 @@ describe('Role controller', () => {
|
|||||||
admin: {
|
admin: {
|
||||||
services: {
|
services: {
|
||||||
role: { getSuperAdmin: jest.fn(() => undefined) },
|
role: { getSuperAdmin: jest.fn(() => undefined) },
|
||||||
permission: { conditionProvider: { conditions: jest.fn(() => []) } },
|
permission: { conditionProvider: { getAll: jest.fn(() => []) } },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -157,7 +157,7 @@ describe('Role controller', () => {
|
|||||||
action: 'test',
|
action: 'test',
|
||||||
subject: 'model1',
|
subject: 'model1',
|
||||||
fields: ['title'],
|
fields: ['title'],
|
||||||
conditions: ['someCondition'],
|
conditions: ['admin::is-creator'],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -178,7 +178,7 @@ describe('Role controller', () => {
|
|||||||
permission: {
|
permission: {
|
||||||
assign: assignPermissions,
|
assign: assignPermissions,
|
||||||
conditionProvider: {
|
conditionProvider: {
|
||||||
conditions: jest.fn(() => ['someCondition']),
|
getAll: jest.fn(() => [{ id: 'admin::is-creator' }]),
|
||||||
},
|
},
|
||||||
actionProvider: {
|
actionProvider: {
|
||||||
getAllByMap: jest.fn(),
|
getAllByMap: jest.fn(),
|
||||||
|
|||||||
@ -112,7 +112,7 @@ module.exports = {
|
|||||||
input.permissions
|
input.permissions
|
||||||
.filter(p => existingPermissions.get(p.action).section === 'contentTypes')
|
.filter(p => existingPermissions.get(p.action).section === 'contentTypes')
|
||||||
.forEach(p => {
|
.forEach(p => {
|
||||||
p.conditions = role.code === AUTHOR_CODE ? ['isOwner'] : [];
|
p.conditions = role.code === AUTHOR_CODE ? ['admin::is-creator'] : [];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -52,7 +52,7 @@ describe('Permission Service', () => {
|
|||||||
permission: {
|
permission: {
|
||||||
actionProvider: { getAll },
|
actionProvider: { getAll },
|
||||||
conditionProvider: {
|
conditionProvider: {
|
||||||
conditions: jest.fn(() => ['someCondition']),
|
getAll: jest.fn(() => [{ id: 'admin::is-creator' }]),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@ -69,7 +69,7 @@ describe('Role CRUD End to End', () => {
|
|||||||
data.editorRole = res.body.data.find(r => r.code === 'strapi-editor');
|
data.editorRole = res.body.data.find(r => r.code === 'strapi-editor');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Author have isOwner condition for every permission', async () => {
|
test('Author have admin::is-creator condition for every permission', async () => {
|
||||||
const res = await rq({
|
const res = await rq({
|
||||||
url: `/admin/roles/${data.authorRole.id}/permissions`,
|
url: `/admin/roles/${data.authorRole.id}/permissions`,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
@ -79,7 +79,7 @@ describe('Role CRUD End to End', () => {
|
|||||||
expect(Array.isArray(res.body.data)).toBe(true);
|
expect(Array.isArray(res.body.data)).toBe(true);
|
||||||
expect(res.body.data).toHaveLength(4);
|
expect(res.body.data).toHaveLength(4);
|
||||||
res.body.data.forEach(permission => {
|
res.body.data.forEach(permission => {
|
||||||
expect(permission.conditions).toEqual(['isOwner']);
|
expect(permission.conditions).toEqual(['admin::is-creator']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ describe('Role CRUD End to End', () => {
|
|||||||
action: 'plugins::content-manager.explorer.create',
|
action: 'plugins::content-manager.explorer.create',
|
||||||
subject: 'plugins::users-permissions.user',
|
subject: 'plugins::users-permissions.user',
|
||||||
fields: ['username'],
|
fields: ['username'],
|
||||||
conditions: ['isOwner'],
|
conditions: ['admin::is-creator'],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ describe('Role CRUD End to End', () => {
|
|||||||
action: 'plugins::content-manager.explorer.create',
|
action: 'plugins::content-manager.explorer.create',
|
||||||
subject: 'plugins::users-permissions.user',
|
subject: 'plugins::users-permissions.user',
|
||||||
fields: ['username'],
|
fields: ['username'],
|
||||||
conditions: ['isOwner'],
|
conditions: ['admin::is-creator'],
|
||||||
}),
|
}),
|
||||||
]),
|
]),
|
||||||
});
|
});
|
||||||
@ -152,7 +152,7 @@ describe('Role CRUD End to End', () => {
|
|||||||
action: 'plugins::content-manager.explorer.create',
|
action: 'plugins::content-manager.explorer.create',
|
||||||
subject: 'plugins::users-permissions.user',
|
subject: 'plugins::users-permissions.user',
|
||||||
fields: ['username'],
|
fields: ['username'],
|
||||||
conditions: ['isOwner'],
|
conditions: ['admin::is-creator'],
|
||||||
}),
|
}),
|
||||||
]),
|
]),
|
||||||
});
|
});
|
||||||
@ -164,31 +164,31 @@ describe('Role CRUD End to End', () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
action: 'plugins::users-permissions.roles.read',
|
action: 'plugins::users-permissions.roles.read',
|
||||||
conditions: ['isOwner'],
|
conditions: ['admin::is-creator'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
action: 'plugins::content-manager.explorer.create',
|
action: 'plugins::content-manager.explorer.create',
|
||||||
subject: 'plugins::users-permissions.user',
|
subject: 'plugins::users-permissions.user',
|
||||||
fields: ['username'],
|
fields: ['username'],
|
||||||
conditions: ['isOwner'],
|
conditions: ['admin::is-creator'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
action: 'plugins::content-manager.explorer.update',
|
action: 'plugins::content-manager.explorer.update',
|
||||||
subject: 'plugins::users-permissions.user',
|
subject: 'plugins::users-permissions.user',
|
||||||
fields: ['username'],
|
fields: ['username'],
|
||||||
conditions: ['isOwner'],
|
conditions: ['admin::is-creator'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
action: 'plugins::content-manager.explorer.delete',
|
action: 'plugins::content-manager.explorer.delete',
|
||||||
subject: 'plugins::users-permissions.user',
|
subject: 'plugins::users-permissions.user',
|
||||||
fields: ['username'],
|
fields: ['username'],
|
||||||
conditions: ['isOwner'],
|
conditions: ['admin::is-creator'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
action: 'plugins::content-manager.explorer.read',
|
action: 'plugins::content-manager.explorer.read',
|
||||||
subject: 'plugins::users-permissions.user',
|
subject: 'plugins::users-permissions.user',
|
||||||
fields: ['username'],
|
fields: ['username'],
|
||||||
conditions: ['isOwner'],
|
conditions: ['admin::is-creator'],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -222,7 +222,7 @@ describe('Role CRUD End to End', () => {
|
|||||||
data: expect.arrayContaining(
|
data: expect.arrayContaining(
|
||||||
newPermissions
|
newPermissions
|
||||||
.slice(3, 6)
|
.slice(3, 6)
|
||||||
.map(p => ({ ...p, conditions: ['isOwner'] }))
|
.map(p => ({ ...p, conditions: ['admin::is-creator'] }))
|
||||||
.map(expect.objectContaining)
|
.map(expect.objectContaining)
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|||||||
@ -35,7 +35,7 @@ const arrayOfConditionNames = yup
|
|||||||
.array()
|
.array()
|
||||||
.of(yup.string())
|
.of(yup.string())
|
||||||
.test('is-an-array-of-conditions', 'is not a plugin name', function(value) {
|
.test('is-an-array-of-conditions', 'is not a plugin name', function(value) {
|
||||||
const ids = strapi.admin.services.permission.conditionProvider.conditions();
|
const ids = strapi.admin.services.permission.conditionProvider.getAll().map(c => c.id);
|
||||||
return _.isUndefined(value) || _.difference(value, ids).length === 0
|
return _.isUndefined(value) || _.difference(value, ids).length === 0
|
||||||
? true
|
? true
|
||||||
: this.createError({ path: this.path, message: `contains conditions that don't exist` });
|
: this.createError({ path: this.path, message: `contains conditions that don't exist` });
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user