* feat: getRepository * getRepository return type * export action * add: acl * feat: setResourceAction * feat: action alias * chore: code struct * feat: removeResourceAction * chore: file name * ignorecase * remove ACL * feat: ACL * feat: role toJSON * using emit * chore: test * feat: plugin-acl * feat: acl with predicate * grant universal action test * grant action test * update resource action test * revoke resource action * usingActionsConfig switch * plugin-ui-schema-storage * remove global acl instance * fix: collection manager with sqlite * add own action listener * add acl middleware * add acl allowConfigure strategy option * add plugin-acl allowConfigure * change acl resourceName * add acl middleware merge params * bugfix * append fields on acl action params * acl middleware parse template * fix: collection-manager migrate Co-authored-by: chenos <chenlinxh@gmail.com>
67 lines
1.5 KiB
TypeScript
67 lines
1.5 KiB
TypeScript
import { MockServer } from '@nocobase/test';
|
|
import { CollectionRepository } from '@nocobase/plugin-collection-manager';
|
|
import { Database, Model } from '@nocobase/database';
|
|
|
|
import { prepareApp } from './prepare';
|
|
|
|
describe('role api', () => {
|
|
let app: MockServer;
|
|
let db: Database;
|
|
|
|
afterEach(async () => {
|
|
await app.destroy();
|
|
});
|
|
|
|
beforeEach(async () => {
|
|
app = await prepareApp();
|
|
db = app.db;
|
|
});
|
|
|
|
describe('grant', () => {
|
|
let role: Model;
|
|
|
|
beforeEach(async () => {
|
|
await db.getRepository('roles').create({
|
|
values: {
|
|
name: 'admin',
|
|
title: 'Admin User',
|
|
allowConfigure: true,
|
|
},
|
|
});
|
|
|
|
role = await db.getRepository('roles').findOne({
|
|
filter: {
|
|
name: 'admin',
|
|
},
|
|
});
|
|
});
|
|
|
|
it('should list actions', async () => {
|
|
const response = await app.agent().resource('availableActions').list();
|
|
expect(response.statusCode).toEqual(200);
|
|
});
|
|
|
|
it('should grant universal role actions', async () => {
|
|
// grant role actions
|
|
const response = await app
|
|
.agent()
|
|
.resource('roles')
|
|
.update({
|
|
values: {
|
|
strategy: {
|
|
actions: ['create:all', 'view:own'],
|
|
},
|
|
},
|
|
});
|
|
|
|
expect(response.statusCode).toEqual(200);
|
|
|
|
await role.reload();
|
|
|
|
expect(role.get('strategy')).toMatchObject({
|
|
actions: ['create:all', 'view:own'],
|
|
});
|
|
});
|
|
});
|
|
});
|