fix: empty resource acl error (#357)
This commit is contained in:
parent
90a58cc3cf
commit
914600209a
@ -175,6 +175,8 @@ export class ACL extends EventEmitter {
|
|||||||
action,
|
action,
|
||||||
params: actionParams,
|
params: actionParams,
|
||||||
};
|
};
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,6 +72,56 @@ describe('acl', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should deny when resource action has no resource', async () => {
|
||||||
|
const role = await db.getRepository('roles').create({
|
||||||
|
values: {
|
||||||
|
name: 'admin',
|
||||||
|
title: 'Admin User',
|
||||||
|
allowConfigure: true,
|
||||||
|
strategy: {
|
||||||
|
actions: ['update:own', 'destroy:own', 'create', 'view'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
changeMockRole('admin');
|
||||||
|
|
||||||
|
// create c1 collection
|
||||||
|
await db.getRepository('collections').create({
|
||||||
|
values: {
|
||||||
|
name: 'c1',
|
||||||
|
title: 'table1',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// create c2 collection
|
||||||
|
await db.getRepository('collections').create({
|
||||||
|
values: {
|
||||||
|
name: 'c2',
|
||||||
|
title: 'table2',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await app
|
||||||
|
.agent()
|
||||||
|
.resource('roles.resources', 'admin')
|
||||||
|
.create({
|
||||||
|
values: {
|
||||||
|
name: 'c1',
|
||||||
|
usingActionsConfig: true,
|
||||||
|
actions: [],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(
|
||||||
|
acl.can({
|
||||||
|
role: 'admin',
|
||||||
|
resource: 'c1',
|
||||||
|
action: 'list',
|
||||||
|
}),
|
||||||
|
).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
it('should works with resources actions', async () => {
|
it('should works with resources actions', async () => {
|
||||||
const role = await db.getRepository('roles').create({
|
const role = await db.getRepository('roles').create({
|
||||||
values: {
|
values: {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Database, Model } from '@nocobase/database';
|
import { Database, Model } from '@nocobase/database';
|
||||||
import { ACL, ACLRole } from '@nocobase/acl';
|
import { ACL, ACLResource, ACLRole } from '@nocobase/acl';
|
||||||
import { RoleResourceActionModel } from './RoleResourceActionModel';
|
import { RoleResourceActionModel } from './RoleResourceActionModel';
|
||||||
import { AssociationFieldsActions, GrantHelper } from '../server';
|
import { AssociationFieldsActions, GrantHelper } from '../server';
|
||||||
|
|
||||||
@ -43,6 +43,13 @@ export class RoleResourceModel extends Model {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const resource = new ACLResource({
|
||||||
|
role,
|
||||||
|
name: resourceName,
|
||||||
|
});
|
||||||
|
|
||||||
|
role.resources.set(resourceName, resource);
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const actions: RoleResourceActionModel[] = await this.getActions({
|
const actions: RoleResourceActionModel[] = await this.getActions({
|
||||||
transaction: options.transaction,
|
transaction: options.transaction,
|
||||||
|
Loading…
Reference in New Issue
Block a user