mirror of
https://gitee.com/nocobase/nocobase.git
synced 2024-11-29 18:58:26 +08:00
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,
|
||||
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 () => {
|
||||
const role = await db.getRepository('roles').create({
|
||||
values: {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Database, Model } from '@nocobase/database';
|
||||
import { ACL, ACLRole } from '@nocobase/acl';
|
||||
import { ACL, ACLResource, ACLRole } from '@nocobase/acl';
|
||||
import { RoleResourceActionModel } from './RoleResourceActionModel';
|
||||
import { AssociationFieldsActions, GrantHelper } from '../server';
|
||||
|
||||
@ -43,6 +43,13 @@ export class RoleResourceModel extends Model {
|
||||
return;
|
||||
}
|
||||
|
||||
const resource = new ACLResource({
|
||||
role,
|
||||
name: resourceName,
|
||||
});
|
||||
|
||||
role.resources.set(resourceName, resource);
|
||||
|
||||
// @ts-ignore
|
||||
const actions: RoleResourceActionModel[] = await this.getActions({
|
||||
transaction: options.transaction,
|
||||
|
Loading…
Reference in New Issue
Block a user