提交 dedcd2e4 编写于 作者: tony001's avatar tony001

update:更新应用权限服务

上级 9cba1e72
......@@ -32,6 +32,42 @@ export interface IAppAuthService {
*/
setAppData(opt: IParam): void;
/**
* 获取指定数据操作标识是否鉴权
*
* @param {IParam} context 应用上下文
* @param {string} dataAccAction 操作标识
* @param {string} [key] 数据主键
* @param {IParam} [mainSateOPPrivs] 指定数据主状态操作标识
* @param {IParam} [param] 额外参数
* @return {*} {IParam}
* @memberof IAppAuthService
*/
getOPEnableAuth(context: IParam, dataAccAction: string, key?: string, mainSateOPPrivs?: IParam, param?: IParam): IParam;
/**
* 获取应用权限
*
* @param {string | undefined} dataAccAction 操作标识
* @param {('RESOURCE'|'RT'|'MINIX')} [mode='RESOURCE'] RT(RT模式),RESOURCE(资源模式),MINIX(混合模式),默认值RESOURCE
* @return {*} {boolean}
* @memberof IAppAuthService
*/
getAppAuth(dataAccAction: string | undefined, mode: 'RESOURCE' | 'RT' | 'MINIX'): boolean;
/**
* 获取实体级权限
*
* @param {IParam} context 应用上下文
* @param {string} key 数据主键标识
* @param {string} dataAccAction 操作标识
* @param {IParam} [param] 额外参数
* @return {*} {boolean}
* @memberof IAppAuthService
*/
getDEAuth(context: IParam, key: string, dataAccAction: string, param?: IParam): boolean;
/**
* 登录
*
......
......@@ -22,6 +22,22 @@ export abstract class AppAuthServiceBase implements IAppAuthService {
*/
private appData: IParam = {};
/**
* 系统默认操作标识
*
* @protected
* @type {IParam}
* @memberof AppAuthServiceBase
*/
protected sysOPPrivs: IParam = {};
/**
* @description 系统操作标识映射统一资源映射表
* @type {Map<string, string>}
* @memberof AppAuthServiceBase
*/
protected sysOPPrivsMap: Map<string, string> = new Map();
/**
* 获取应用数据
*
......@@ -39,9 +55,20 @@ export abstract class AppAuthServiceBase implements IAppAuthService {
* @memberof AppAuthServiceBase
*/
public setAppData(opt: IParam = {}): void {
console.log(opt);
this.appData = opt;
}
/**
* 应用是否启用权限
*
* @return {boolean}
* @memberof AppAuthServiceBase
*/
public getEnablePermission(): boolean {
return this.appData.enablepermissionvalid && Environment.enablePermissionValid;
}
/**
* 初始化应用权限
*
......@@ -108,6 +135,103 @@ export abstract class AppAuthServiceBase implements IAppAuthService {
}
}
/**
* 获取指定数据操作标识是否鉴权
*
* @param {IParam} context 应用上下文
* @param {{ key: string, dataAccAction: string, mainSateOPPrivs: IParam }} { key, dataAccAction, mainSateOPPrivs } {数据主键,操作标识,指定数据主状态操作标识 }
* @param {IParam} [param] 额外参数
* @return {*} {IParam}
* @memberof AppAuthServiceBase
*/
/**
* 获取指定数据操作标识是否鉴权
*
* @param {IParam} context 应用上下文
* @param {string} dataAccAction 操作标识
* @param {string} [key] 数据主键
* @param {IParam} [mainSateOPPrivs] 指定数据主状态操作标识
* @param {IParam} [param] 额外参数
* @return {*} {IParam}
* @memberof IAppAuthService
*/
public getOPEnableAuth(context: IParam, dataAccAction: string, key?: string, mainSateOPPrivs?: IParam, param?: IParam): IParam {
let result: IParam = { [dataAccAction]: 1 };
// 统一资源权限
const curDefaultOPPrivs: any = this.handleSysOPPrivs();
if (curDefaultOPPrivs && (Object.keys(curDefaultOPPrivs).length > 0) && (curDefaultOPPrivs[dataAccAction] === 0)) {
result[dataAccAction] = 0;
}
// 主状态权限
if (mainSateOPPrivs && (Object.keys(mainSateOPPrivs).length > 0) && mainSateOPPrivs.hasOwnProperty(dataAccAction)) {
result[dataAccAction] = result[dataAccAction] && mainSateOPPrivs[dataAccAction];
}
// 实体级权限
if (key && !this.getDEAuth(context, key, dataAccAction, param)) {
result[dataAccAction] = 0;
}
return result;
}
/**
* 获取应用权限
*
* @param {string | undefined} dataAccAction 操作标识
* @param {('RESOURCE'|'RT'|'MINIX')} [mode='RESOURCE'] RT(RT模式),RESOURCE(资源模式),MINIX(混合模式),默认值RESOURCE
* @return {*} {boolean}
* @memberof AppAuthServiceBase
*/
public getAppAuth(dataAccAction: string | undefined, mode: 'RESOURCE' | 'RT' | 'MINIX' = 'RESOURCE'): boolean {
if (!this.getEnablePermission() || !dataAccAction) {
return true;
}
const computeAuth = (authData: string[]) => {
if (!authData || (authData.length == 0)) {
return false;
}
const index = authData.findIndex((item: string) => {
return item === dataAccAction;
})
if (index === -1) {
return false;
} else {
return true;
}
}
// 统一资源数据
const resourceData: string[] = this.getAppData().unires;
// 菜单数据
const menuData: string[] = this.getAppData().appmenu;
// 资源模式
if (Object.is(mode, 'RESOURCE')) {
return computeAuth(resourceData);
}
// RT模式(菜单)
if (Object.is(mode, 'RT')) {
return computeAuth(menuData);
}
// 混合模式
if (Object.is(mode, 'MINIX')) {
return computeAuth(resourceData) && computeAuth(menuData);
}
return false;
}
/**
* 获取实体级权限
*
* @param {IParam} context 应用上下文
* @param {string} key 数据主键标识
* @param {string} dataAccAction 操作标识
* @param {IParam} [param] 额外参数
* @return {*} {boolean}
* @memberof AppAuthServiceBase
*/
public getDEAuth(context: IParam, key: string, dataAccAction: string, param?: IParam): boolean {
// TODO 暂未实现
return true;
}
/**
* 通过租户获取组织数据
*
......@@ -241,4 +365,21 @@ export abstract class AppAuthServiceBase implements IAppAuthService {
return tempViewParam;
}
/**
* 处理统一资源与系统操作标识映射
*
* @return {IParam}
* @memberof AppAuthServiceBase
*/
public handleSysOPPrivs() {
let copySysOPPrivs: IParam = JSON.parse(JSON.stringify(this.sysOPPrivs));
if (Object.keys(copySysOPPrivs).length === 0) return {};
Object.keys(copySysOPPrivs).forEach((name: any) => {
if (this.sysOPPrivsMap.get(name)) {
copySysOPPrivs[name] = this.getAppAuth(this.sysOPPrivsMap.get(name)) ? 1 : 0;
}
})
return copySysOPPrivs;
}
}
\ No newline at end of file
......@@ -27,6 +27,15 @@ export class UIServiceBase {
*/
protected appDeKeyFieldName: string = '';
/**
* 是否启用主状态
*
* @protected
* @type {boolean}
* @memberof UIServiceBase
*/
protected isEnableDEMainState: boolean = false;
/**
* 主状态属性集合
*
......@@ -61,20 +70,20 @@ export class UIServiceBase {
* 获取数据对象所有的操作标识
*
* @param data 当前数据
* @param dataaccaction 数据操作标识
* @param dataAccAction 数据操作标识
* @memberof UIServiceBase
*/
protected getAllOPPrivs(data: any, dataaccaction: string) {
protected getAllOPPrivs(data: any, dataAccAction: string) {
if (!Environment.enablePermissionValid) {
return 1;
}
if (data && (Object.keys(data).length > 0)) {
const curActiveKey: string = `${data[this.appDeKeyFieldName?.toLowerCase()]}`;
//const result = this.authService.getOPPrivs(curActiveKey, dataaccaction, this.getDEMainStateOPPrivs(data));
return 1;
const key: string = `${data[this.appDeKeyFieldName?.toLowerCase()]}`;
const result = App.getAppAuthService().getOPEnableAuth(this.context, dataAccAction, key, this.getDEMainStateOPPrivs(data));
return result[dataAccAction];
} else {
// const result = this.authService.getOPPrivs(undefined, dataaccaction, undefined);
return 1;
const result = App.getAppAuthService().getOPEnableAuth(this.context, dataAccAction);
return result[dataAccAction];
}
}
......@@ -100,7 +109,7 @@ export class UIServiceBase {
* @memberof UIServiceBase
*/
protected getDEMainStateTag(data: IParam) {
const mainStateFields: string[] = [];
const mainStateFields: string[] = this.mainStateFields;
if (mainStateFields.length === 0) return null;
mainStateFields.forEach((singleMainField: any) => {
if (!(singleMainField in data)) {
......
import { AppAuthServiceBase, IAppAuthService, IParam } from "@core";
import { AppAuthServiceBase, IAppAuthService } from "@core";
/**
* 应用权限服务
......@@ -17,6 +17,33 @@ export class AppAuthService extends AppAuthServiceBase implements IAppAuthServic
*/
private static readonly instance = new AppAuthService();
/**
* Creates an instance of AppAuthService.
* @memberof AppAuthService
*/
public constructor() {
super();
this.initBaseData();
}
/**
* 初始化基础数据
*
* @memberof AppAuthService
*/
public initBaseData() {
// 系统默认操作标识
this.sysOPPrivs = {
{{~#each app.psSystem.allPSDEOPPrivs as | psDEOPPriv |~}}
{{psDEOPPriv.name}}:1{{#unless @last}},{{/unless}}
{{~/each~}}
};
{{#each app.psSystem.allPSDEOPPrivs as | psDEOPPriv |}}
// 系统操作标识映射统一资源映射表
this.sysOPPrivsMap.set('{{psDEOPPriv.name}}', '{{psDEOPPriv.mapPSSysUniRes.resCode}}');
{{/each}}
}
/**
* 获取唯一实例
*
......
......@@ -28,6 +28,8 @@ export class {{pascalCase appEntity.codeName}}UIServiceBase extends UIServiceBas
public initBasicData() {
// 应用实体主键属性
this.appDeKeyFieldName = '{{lowerCase appEntity.pSDataEntity.keyPSDEField.codeName}}';
// 是否启用主状态
this.isEnableDEMainState = {{#if appEntity.allPSDEMainStates}}true{{else}}false{{/if}};
{{#if appEntity.pSDataEntity.dEMainStateDEFields}}
// 主状态属性集合
this.mainStateFields = [
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册