一些ActionAuth,以及将一些状态的联动改变置root权限

This commit is contained in:
Xu Chang 2024-06-11 12:40:50 +08:00
parent 699fbbc480
commit 00275166db
5 changed files with 77 additions and 5 deletions

View File

@ -40,7 +40,30 @@ const actionAuths: ActionAuth[] = [
id: 'user-account-withdraw',
pathId: 'user-account-withdraw',
deActions: ['select'],
}
},
//account
{
id: 'account-user',
pathId: 'user-acc',
deActions: ['select', 'deposit', 'withdraw', 'consume', 'loan'],
},
//deposit
{
id: 'deposit-creator',
pathId: 'creator-deposit',
deActions: ['create'],
},
{
id: 'deposit-account-user',
pathId: 'user-account-deposit',
deActions: ['fail'],
},
// accountOper
{
id: 'user-acc-oper',
pathId: 'user-acc-oper',
deActions: ['select', 'create'],
},
];
export default actionAuths;

View File

@ -70,6 +70,34 @@ const paths: Path[] = [
destEntity: 'withdraw',
value: 'account.user',
recursive: false,
},
{
id: 'user-acc',
sourceEntity: 'user',
destEntity: 'account',
value: 'user',
recursive: false,
},
{
id: 'user-acc-oper',
sourceEntity: 'user',
destEntity: 'accountOper',
value: 'account.user',
recursive: false,
},
{
id: 'creator-deposit',
sourceEntity: 'user',
destEntity: 'deposit',
value: 'creator',
recursive: false,
},
{
id: 'user-account-deposit',
sourceEntity: 'user',
destEntity: 'deposit',
value: 'account.user',
recursive: false,
}
];

View File

@ -166,6 +166,7 @@ const triggers: Trigger<EntityDict, 'pay', BRC>[] = [
entity: 'pay',
action: 'create',
when: 'after',
asRoot: true,
fn: async ({ operation }, context, option) => {
const { data } = operation;
assert(!(data instanceof Array));
@ -189,6 +190,7 @@ const triggers: Trigger<EntityDict, 'pay', BRC>[] = [
action: ['startPaying', 'succeedPaying', 'continuePaying', 'startClosing', 'succeedClosing', 'startRefunding',
'refundAll', 'refundPartially'],
when: 'after',
asRoot: true,
fn: async ({ operation }, context, option) => {
const { data, filter, action, id } = operation as EntityDict['pay']['Update'];
assert(typeof filter!.id === 'string');
@ -309,6 +311,7 @@ const triggers: Trigger<EntityDict, 'pay', BRC>[] = [
action: 'close',
when: 'before',
priority: 99,
asRoot: true,
fn: async ({ operation }, context, option) => {
const { data, filter } = operation;
const pays = await context.select('pay', {
@ -404,6 +407,7 @@ const triggers: Trigger<EntityDict, 'pay', BRC>[] = [
entity: 'pay',
action: 'succeedPaying',
when: 'after',
asRoot: true,
fn: async ({ operation }, context) => {
const { data, filter } = operation;
@ -479,6 +483,7 @@ const triggers: Trigger<EntityDict, 'pay', BRC>[] = [
{
name: '当account类型的pay的paid达到price改为支付成功',
entity: 'pay',
asRoot: true,
action: ['startPaying', 'continuePaying'],
check(operation: UpdateOperation) {
return (!!operation.data.paid) && operation.data.paid > 0;

View File

@ -134,6 +134,7 @@ const triggers: Trigger<EntityDict, 'refund', BRC>[] = [
entity: 'refund',
action: 'succeedRefunding',
when: 'after',
asRoot: true,
name: '退款成功时更新对应的pay状态以及对应的withdraw状态',
fn: async ({ operation }, context) => {
const { filter } = operation;
@ -232,6 +233,7 @@ const triggers: Trigger<EntityDict, 'refund', BRC>[] = [
entity: 'refund',
action: 'failRefunding',
when: 'after',
asRoot: true,
name: '退款失败时更新对应的pay状态以及对应的withdraw状态',
fn: async ({ operation }, context) => {
const { filter } = operation;
@ -278,6 +280,7 @@ const triggers: Trigger<EntityDict, 'refund', BRC>[] = [
entity: 'refund',
name: '当发起退款时将对应的pay置退款中状态',
action: 'create',
asRoot: true,
when: 'before',
fn: async ({ operation }, context) => {
const { data } = operation;

View File

@ -8,6 +8,7 @@ import Offline from './Offline';
import Account from './Account';
import { WebConfig, WechatMpConfig, WechatPublicConfig } from 'oak-general-business/lib/entities/Application';
import WechatPay from './WechatPay';
import { StorageSchema } from 'oak-domain/lib/types/Storage';
type PayClazzConstructor = (applicationId: string, entityId: string, context: BRC) => Promise<PayClazz>;
@ -121,15 +122,25 @@ const PayClazzEntityDict: Record<string, {
// 这里用一个flag来表达先后顺序如果有registerPayClazzEntity框架应保证register在get之前
// 目前因为没有registerPayClazzEntity所以没测可能不对。by Xc 20240608
let MODULE_USED = false;
export function registerPayClazzEntity<ED extends EntityDict & BaseEntityDict>(entity: keyof ED, def: {
export function registerPayClazzEntity<ED extends EntityDict & BaseEntityDict, T extends keyof ED>(entity: T, def: {
clazzConstructor: PayClazzConstructor;
accountEntity: keyof ED;
}) {
assert(!MODULE_USED);
}, schema: StorageSchema<ED>) {
if (!MODULE_USED) {
assert(!MODULE_USED);
}
PayClazzEntityDict[entity as string] = {
accountEntity: def.accountEntity as string,
clazzConstructor: def.clazzConstructor,
};
// 检查此entity是否符合注册要求
const { attributes } = schema[entity];
const { attributes: payAttr } = schema.pay;
const { attributes: accountAttr } = schema[def.accountEntity];
assert(payAttr.entity.enumeration?.includes(entity as string));
assert(accountAttr.price && accountAttr.price.type === 'decimal');
}
export function getPayClazzAccountEntities<ED extends EntityDict & BaseEntityDict>() {
@ -141,7 +152,9 @@ export function getPayClazzAccountEntities<ED extends EntityDict & BaseEntityDic
export async function getPayClazz(applicationId: string, entity: EntityDict['pay']['OpSchema']['entity'], entityId: string, context: BRC) {
MODULE_USED = true;
if (!MODULE_USED) {
assert(!MODULE_USED);
}
const key = entity === 'account' ? entity : `${entity}.${entityId}`;
if (PayChannelDict.hasOwnProperty(key)) {
return PayChannelDict[key]!;