This commit is contained in:
xiaojunnuo
2024-10-01 23:52:44 +08:00
parent f8f3e8b43f
commit b09acfb4dc
9 changed files with 47 additions and 26 deletions
@@ -1,13 +1,12 @@
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
import { Constants } from '../../../basic/constants.js';
import {
accessRegistry,
AccessRequestHandleContext,
AccessRequestHandleReq,
http,
ITaskPlugin,
logger,
mergeUtils,
newAccess,
pluginRegistry,
PluginRequestHandleReq,
TaskInstanceContext,
@@ -28,15 +27,6 @@ export class HandleController extends BaseController {
@Post('/access', { summary: Constants.per.authOnly })
async accessRequest(@Body(ALL) body: AccessRequestHandleReq) {
const accessItem = accessRegistry.get(body.typeName);
const accessCls = accessItem.target;
if (accessCls == null) {
throw new Error(`access ${body.typeName} not found`);
}
//实例化access
//@ts-ignore
const access = new accessCls();
let inputAccess = body.input.access;
if (body.input.id > 0) {
const oldEntity = await this.accessService.info(body.input.id);
@@ -49,14 +39,10 @@ export class HandleController extends BaseController {
inputAccess = this.accessService.decryptAccessEntity(param);
}
}
mergeUtils.merge(access, inputAccess);
const ctx: AccessRequestHandleContext = {
http: http,
logger: logger,
utils,
};
const res = await access.onRequest(body, ctx);
const access = newAccess(body.typeName, inputAccess);
const res = await access.onRequest(body);
return this.ok(res);
}
@@ -3,7 +3,7 @@ import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository } from 'typeorm';
import { BaseService } from '../../../basic/base-service.js';
import { AccessEntity } from '../entity/access.js';
import { AccessDefine, accessRegistry, IAccessService } from '@certd/pipeline';
import { AccessDefine, accessRegistry, IAccessService, newAccess } from '@certd/pipeline';
import { EncryptService } from './encrypt-service.js';
import { ValidateException } from '../../../basic/exception/validation-exception.js';
@@ -109,10 +109,11 @@ export class AccessService extends BaseService<AccessEntity> implements IAccessS
}
// const access = accessRegistry.get(entity.type);
const setting = this.decryptAccessEntity(entity);
return {
const input = {
id: entity.id,
...setting,
};
return newAccess(entity.type, input);
}
decryptAccessEntity(entity: AccessEntity): any {