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