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

update:更新应用权限服务

上级 9cba1e72
...@@ -32,6 +32,42 @@ export interface IAppAuthService { ...@@ -32,6 +32,42 @@ export interface IAppAuthService {
*/ */
setAppData(opt: IParam): void; 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 { ...@@ -22,6 +22,22 @@ export abstract class AppAuthServiceBase implements IAppAuthService {
*/ */
private appData: IParam = {}; 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 { ...@@ -39,9 +55,20 @@ export abstract class AppAuthServiceBase implements IAppAuthService {
* @memberof AppAuthServiceBase * @memberof AppAuthServiceBase
*/ */
public setAppData(opt: IParam = {}): void { public setAppData(opt: IParam = {}): void {
console.log(opt);
this.appData = 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 { ...@@ -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 { ...@@ -241,4 +365,21 @@ export abstract class AppAuthServiceBase implements IAppAuthService {
return tempViewParam; 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 { ...@@ -27,6 +27,15 @@ export class UIServiceBase {
*/ */
protected appDeKeyFieldName: string = ''; protected appDeKeyFieldName: string = '';
/**
* 是否启用主状态
*
* @protected
* @type {boolean}
* @memberof UIServiceBase
*/
protected isEnableDEMainState: boolean = false;
/** /**
* 主状态属性集合 * 主状态属性集合
* *
...@@ -39,14 +48,14 @@ export class UIServiceBase { ...@@ -39,14 +48,14 @@ export class UIServiceBase {
* *
* @memberof UIServiceBase * @memberof UIServiceBase
*/ */
protected allDeMainStateMap: Map<string, string> = new Map(); protected allDeMainStateMap: Map<string, string> = new Map();
/** /**
* 主状态操作标识Map * 主状态操作标识Map
* *
* @memberof UIServiceBase * @memberof UIServiceBase
*/ */
protected allDeMainStateOPPrivsMap: Map<string, any> = new Map(); protected allDeMainStateOPPrivsMap: Map<string, any> = new Map();
/** /**
* *
...@@ -61,20 +70,20 @@ export class UIServiceBase { ...@@ -61,20 +70,20 @@ export class UIServiceBase {
* 获取数据对象所有的操作标识 * 获取数据对象所有的操作标识
* *
* @param data 当前数据 * @param data 当前数据
* @param dataaccaction 数据操作标识 * @param dataAccAction 数据操作标识
* @memberof UIServiceBase * @memberof UIServiceBase
*/ */
protected getAllOPPrivs(data: any, dataaccaction: string) { protected getAllOPPrivs(data: any, dataAccAction: string) {
if (!Environment.enablePermissionValid) { if (!Environment.enablePermissionValid) {
return 1; return 1;
} }
if (data && (Object.keys(data).length > 0)) { if (data && (Object.keys(data).length > 0)) {
const curActiveKey: string = `${data[this.appDeKeyFieldName?.toLowerCase()]}`; const key: string = `${data[this.appDeKeyFieldName?.toLowerCase()]}`;
//const result = this.authService.getOPPrivs(curActiveKey, dataaccaction, this.getDEMainStateOPPrivs(data)); const result = App.getAppAuthService().getOPEnableAuth(this.context, dataAccAction, key, this.getDEMainStateOPPrivs(data));
return 1; return result[dataAccAction];
} else { } else {
// const result = this.authService.getOPPrivs(undefined, dataaccaction, undefined); const result = App.getAppAuthService().getOPEnableAuth(this.context, dataAccAction);
return 1; return result[dataAccAction];
} }
} }
...@@ -92,7 +101,7 @@ export class UIServiceBase { ...@@ -92,7 +101,7 @@ export class UIServiceBase {
return null; return null;
} }
} }
/** /**
* 获取数据对象的主状态标识 * 获取数据对象的主状态标识
* *
...@@ -100,7 +109,7 @@ export class UIServiceBase { ...@@ -100,7 +109,7 @@ export class UIServiceBase {
* @memberof UIServiceBase * @memberof UIServiceBase
*/ */
protected getDEMainStateTag(data: IParam) { protected getDEMainStateTag(data: IParam) {
const mainStateFields: string[] = []; const mainStateFields: string[] = this.mainStateFields;
if (mainStateFields.length === 0) return null; if (mainStateFields.length === 0) return null;
mainStateFields.forEach((singleMainField: any) => { mainStateFields.forEach((singleMainField: any) => {
if (!(singleMainField in data)) { 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 ...@@ -17,6 +17,33 @@ export class AppAuthService extends AppAuthServiceBase implements IAppAuthServic
*/ */
private static readonly instance = new AppAuthService(); 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 ...@@ -28,6 +28,8 @@ export class {{pascalCase appEntity.codeName}}UIServiceBase extends UIServiceBas
public initBasicData() { public initBasicData() {
// 应用实体主键属性 // 应用实体主键属性
this.appDeKeyFieldName = '{{lowerCase appEntity.pSDataEntity.keyPSDEField.codeName}}'; this.appDeKeyFieldName = '{{lowerCase appEntity.pSDataEntity.keyPSDEField.codeName}}';
// 是否启用主状态
this.isEnableDEMainState = {{#if appEntity.allPSDEMainStates}}true{{else}}false{{/if}};
{{#if appEntity.pSDataEntity.dEMainStateDEFields}} {{#if appEntity.pSDataEntity.dEMainStateDEFields}}
// 主状态属性集合 // 主状态属性集合
this.mainStateFields = [ this.mainStateFields = [
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册