fix(acl): issue with repeated createdById field (#1871)
This commit is contained in:
parent
fbbd90ca3c
commit
f5d6dd7d09
@ -1,3 +1,4 @@
|
|||||||
|
import { Context } from '@nocobase/actions';
|
||||||
import { ACL } from '..';
|
import { ACL } from '..';
|
||||||
|
|
||||||
describe('acl', () => {
|
describe('acl', () => {
|
||||||
@ -354,4 +355,26 @@ describe('acl', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should clone can result deeply', () => {
|
||||||
|
jest.spyOn(acl, 'can').mockReturnValue({
|
||||||
|
role: 'root',
|
||||||
|
resource: 'Test',
|
||||||
|
action: 'test',
|
||||||
|
params: {
|
||||||
|
fields: [],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const newConext = () => ({
|
||||||
|
state: {},
|
||||||
|
action: {},
|
||||||
|
throw: () => {},
|
||||||
|
});
|
||||||
|
const ctx1 = newConext() as Context;
|
||||||
|
const ctx2 = newConext() as Context;
|
||||||
|
acl.getActionParams(ctx1);
|
||||||
|
acl.getActionParams(ctx2);
|
||||||
|
ctx1.permission.can.params.fields.push('createdById');
|
||||||
|
expect(ctx2.permission.can.params.fields).toEqual([]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -376,7 +376,11 @@ export class ACL extends EventEmitter {
|
|||||||
const { resourceName, actionName } = ctx.action;
|
const { resourceName, actionName } = ctx.action;
|
||||||
|
|
||||||
ctx.can = (options: Omit<CanArgs, 'role'>) => {
|
ctx.can = (options: Omit<CanArgs, 'role'>) => {
|
||||||
return this.can({ role: roleName, ...options });
|
const can = this.can({ role: roleName, ...options });
|
||||||
|
if (!can) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return lodash.cloneDeep(can);
|
||||||
};
|
};
|
||||||
|
|
||||||
ctx.permission = {
|
ctx.permission = {
|
||||||
|
Loading…
Reference in New Issue
Block a user