refactor: use boolean value instead of null (#74)
This commit is contained in:
parent
214b227a6c
commit
f6dcfae28c
@ -84,7 +84,7 @@ export type CollectionPermissions = {
|
||||
tabs: any[]
|
||||
};
|
||||
|
||||
export type PermissionParams = true | null | {
|
||||
export type PermissionParams = boolean | {
|
||||
filter: any,
|
||||
fields: any[]
|
||||
};
|
||||
@ -175,7 +175,7 @@ export default class AccessController<T extends typeof AccessController = typeof
|
||||
if (!actionPermissions.length) {
|
||||
// 如果找不到可用的 action 记录
|
||||
// 则认为没有权限
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
|
||||
const filters = actionPermissions
|
||||
@ -195,7 +195,7 @@ export default class AccessController<T extends typeof AccessController = typeof
|
||||
async one(resourceKey): Promise<PermissionParams> {
|
||||
const any = await this.any();
|
||||
|
||||
if (!any || any === true) {
|
||||
if (typeof any === 'boolean') {
|
||||
return any;
|
||||
}
|
||||
|
||||
@ -209,7 +209,7 @@ export default class AccessController<T extends typeof AccessController = typeof
|
||||
}
|
||||
});
|
||||
|
||||
return existed ? any : null;
|
||||
return existed ? any : false;
|
||||
}
|
||||
|
||||
async getPermissions(): Promise<any> {
|
||||
@ -338,12 +338,11 @@ export default class AccessController<T extends typeof AccessController = typeof
|
||||
};
|
||||
|
||||
if (this.roles) {
|
||||
if ((this.constructor as T).isRoot(this.roles)) {
|
||||
return this.roles;
|
||||
}
|
||||
for (const role of this.roles) {
|
||||
role.permissions = await role.getPermissions(permissionOptions);
|
||||
role.set('permissions', role.permissions);
|
||||
if (!(this.constructor as T).isRoot(this.roles)) {
|
||||
for (const role of this.roles) {
|
||||
role.permissions = await role.getPermissions(permissionOptions);
|
||||
role.set('permissions', role.permissions);
|
||||
}
|
||||
}
|
||||
return this.roles;
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import { Application } from '@nocobase/server';
|
||||
import { Operator } from '@nocobase/database';
|
||||
import * as collectionsRolesActions from './actions/collections.roles';
|
||||
import * as rolesCollectionsActions from './actions/roles.collections';
|
||||
import AccessController from './AccessController';
|
||||
import AccessController, { PermissionParams } from './AccessController';
|
||||
|
||||
// API
|
||||
// const permissions = ctx.app.getPluginInstance('permissions');
|
||||
@ -105,7 +105,7 @@ export class Permissions {
|
||||
actionName
|
||||
} = ctx.action.params;
|
||||
|
||||
let result = null;
|
||||
let result: PermissionParams = false;
|
||||
|
||||
// 关系数据的权限
|
||||
if (associatedName && resourceField) {
|
||||
|
Loading…
Reference in New Issue
Block a user