fix: acl write (#280)
This commit is contained in:
parent
571b077840
commit
2f6aeacbd8
@ -7,6 +7,7 @@ describe('role resource api', () => {
|
|||||||
let app: MockServer;
|
let app: MockServer;
|
||||||
let db: Database;
|
let db: Database;
|
||||||
let role: Model;
|
let role: Model;
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
await app.destroy();
|
await app.destroy();
|
||||||
});
|
});
|
||||||
@ -30,6 +31,46 @@ describe('role resource api', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should grant resource by createRepository', async () => {
|
||||||
|
const collectionManager = db.getRepository('collections') as CollectionRepository;
|
||||||
|
await collectionManager.create({
|
||||||
|
values: {
|
||||||
|
name: 'c1',
|
||||||
|
title: 'table1',
|
||||||
|
},
|
||||||
|
context: {},
|
||||||
|
});
|
||||||
|
|
||||||
|
await collectionManager.create({
|
||||||
|
values: {
|
||||||
|
name: 'c2',
|
||||||
|
title: 'table2',
|
||||||
|
},
|
||||||
|
context: {},
|
||||||
|
});
|
||||||
|
|
||||||
|
await db.getRepository('roles').create({
|
||||||
|
values: {
|
||||||
|
name: 'testRole',
|
||||||
|
resources: [
|
||||||
|
{
|
||||||
|
name: 'c1',
|
||||||
|
actions: [
|
||||||
|
{
|
||||||
|
name: 'create',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const acl = app.acl;
|
||||||
|
const testRole = acl.getRole('testRole');
|
||||||
|
const resource = testRole.getResource('c1');
|
||||||
|
expect(resource).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
it('should grant resource action', async () => {
|
it('should grant resource action', async () => {
|
||||||
const collectionManager = db.getRepository('collections') as CollectionRepository;
|
const collectionManager = db.getRepository('collections') as CollectionRepository;
|
||||||
|
|
||||||
|
@ -127,13 +127,17 @@ export class PluginACL extends Plugin {
|
|||||||
|
|
||||||
this.app.resourcer.registerActionHandler('roles:check', checkAction);
|
this.app.resourcer.registerActionHandler('roles:check', checkAction);
|
||||||
|
|
||||||
this.app.db.on('roles.afterSave', async (model, options) => {
|
this.app.db.on('roles.afterSaveWithAssociations', async (model, options) => {
|
||||||
const { transaction } = options;
|
const { transaction } = options;
|
||||||
|
|
||||||
model.writeToAcl({
|
model.writeToAcl({
|
||||||
acl: this.acl,
|
acl: this.acl,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
for (const resource of (await model.getResources({ transaction })) as RoleResourceModel[]) {
|
||||||
|
await this.writeResourceToACL(resource, transaction);
|
||||||
|
}
|
||||||
|
|
||||||
// model is default
|
// model is default
|
||||||
if (model.get('default')) {
|
if (model.get('default')) {
|
||||||
await this.app.db.getRepository('roles').update({
|
await this.app.db.getRepository('roles').update({
|
||||||
|
Loading…
Reference in New Issue
Block a user