oak-domain 2.3.0 → 2.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/store/CascadeStore.js +5 -0
- package/lib/store/checker.d.ts +2 -2
- package/lib/store/checker.js +38 -0
- package/lib/store/filter.js +2 -2
- package/lib/store/modi.js +39 -5
- package/package.json +1 -1
|
@@ -685,6 +685,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
685
685
|
Object.assign(data2, (_b = {},
|
|
686
686
|
_b[Entity_1.CreateAtAttribute] = now,
|
|
687
687
|
_b[Entity_1.UpdateAtAttribute] = now,
|
|
688
|
+
_b[Entity_1.DeleteAtAttribute] = null,
|
|
688
689
|
_b));
|
|
689
690
|
};
|
|
690
691
|
if (data instanceof Array) {
|
|
@@ -727,6 +728,8 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
727
728
|
case 1:
|
|
728
729
|
this.preProcessDataCreated(entity, data);
|
|
729
730
|
if (!(option.modiParentEntity && !['modi', 'modiEntity', 'oper', 'operEntity'].includes(entity))) return [3 /*break*/, 3];
|
|
731
|
+
// 变成对modi的插入
|
|
732
|
+
(0, assert_1.default)(option.modiParentId);
|
|
730
733
|
modiCreate = {
|
|
731
734
|
id: 'dummy',
|
|
732
735
|
action: 'create',
|
|
@@ -983,6 +986,8 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
983
986
|
action: {
|
|
984
987
|
$in: ['create', 'update'],
|
|
985
988
|
},
|
|
989
|
+
entity: option.modiParentEntity,
|
|
990
|
+
entityId: option.modiParentId,
|
|
986
991
|
iState: 'active',
|
|
987
992
|
filter: ids_1.length > 0 ? {
|
|
988
993
|
id: {
|
package/lib/store/checker.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Checker, EntityDict,
|
|
1
|
+
import { Checker, EntityDict, OperateOption, SelectOption, StorageSchema, Trigger } from "../types";
|
|
2
2
|
import { EntityDict as BaseEntityDict } from '../base-app-domain';
|
|
3
3
|
import { AsyncContext } from "./AsyncRowStore";
|
|
4
4
|
import { SyncContext } from './SyncRowStore';
|
|
5
5
|
export declare function translateCheckerInAsyncContext<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>>(checker: Checker<ED, keyof ED, Cxt>): Trigger<ED, keyof ED, Cxt>['fn'];
|
|
6
6
|
export declare function translateCheckerInSyncContext<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends SyncContext<ED>>(checker: Checker<ED, T, Cxt>): (operation: ED[T]['Operation'], context: Cxt, option: OperateOption | SelectOption) => void;
|
|
7
|
-
export declare function createRelationHierarchyCheckers<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED> | SyncContext<ED>>(schema: StorageSchema<ED>):
|
|
7
|
+
export declare function createRelationHierarchyCheckers<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED> | SyncContext<ED>>(schema: StorageSchema<ED>): Checker<ED, keyof ED, Cxt>[];
|
package/lib/store/checker.js
CHANGED
|
@@ -304,6 +304,9 @@ function createRelationHierarchyCheckers(schema) {
|
|
|
304
304
|
entity: userEntityName_1,
|
|
305
305
|
action: 'remove',
|
|
306
306
|
type: 'expressionRelation',
|
|
307
|
+
conditionalFilter: {
|
|
308
|
+
relation: r,
|
|
309
|
+
},
|
|
307
310
|
expression: function (operation, context) {
|
|
308
311
|
var _a, _b;
|
|
309
312
|
var userId = context.getCurrentUserId();
|
|
@@ -343,6 +346,41 @@ function createRelationHierarchyCheckers(schema) {
|
|
|
343
346
|
for (var r in reverseHierarchy_1) {
|
|
344
347
|
_loop_2(r);
|
|
345
348
|
}
|
|
349
|
+
/* // 一个人不能授权给自己,也不能删除自己的授权
|
|
350
|
+
checkers.push({
|
|
351
|
+
entity: userEntityName as keyof ED,
|
|
352
|
+
action: 'create' as ED[keyof ED]['Action'],
|
|
353
|
+
type: 'data',
|
|
354
|
+
checker: (data, context) => {
|
|
355
|
+
assert(!(data instanceof Array));
|
|
356
|
+
const { userId } = data as ED[keyof ED]['CreateSingle']['data'];
|
|
357
|
+
const userId2 = context.getCurrentUserId(true);
|
|
358
|
+
if (userId === userId2) {
|
|
359
|
+
throw new OakDataException('不允许授权给自己');
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
checkers.push({
|
|
365
|
+
entity: userEntityName as keyof ED,
|
|
366
|
+
action: 'remove' as ED[keyof ED]['Action'],
|
|
367
|
+
type: 'row',
|
|
368
|
+
filter: (operation, context) => {
|
|
369
|
+
const userId = context.getCurrentUserId(true);
|
|
370
|
+
if (userId) {
|
|
371
|
+
return {
|
|
372
|
+
userId: {
|
|
373
|
+
$ne: userId,
|
|
374
|
+
},
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
console.warn(`没有当前用户但在删除权限,请检查。对象是${entity}`);
|
|
378
|
+
return {};
|
|
379
|
+
},
|
|
380
|
+
errMsg: '不允许回收自己的授权',
|
|
381
|
+
}); */
|
|
382
|
+
// 转让权限现在用update动作,只允许update userId给其它人
|
|
383
|
+
// todo 等实现的时候再写
|
|
346
384
|
}
|
|
347
385
|
};
|
|
348
386
|
for (var entity in schema) {
|
package/lib/store/filter.js
CHANGED
|
@@ -871,8 +871,8 @@ function checkFilterRepel(entity, context, filter1, filter2) {
|
|
|
871
871
|
blockTrigger: true,
|
|
872
872
|
});
|
|
873
873
|
if (count instanceof Promise) {
|
|
874
|
-
return count.then(function (count2) { return count2
|
|
874
|
+
return count.then(function (count2) { return count2 === 0; });
|
|
875
875
|
}
|
|
876
|
-
return count
|
|
876
|
+
return count === 0;
|
|
877
877
|
}
|
|
878
878
|
exports.checkFilterRepel = checkFilterRepel;
|
package/lib/store/modi.js
CHANGED
|
@@ -5,6 +5,7 @@ var tslib_1 = require("tslib");
|
|
|
5
5
|
var action_1 = require("../actions/action");
|
|
6
6
|
var lodash_1 = require("../utils/lodash");
|
|
7
7
|
var uuid_1 = require("../utils/uuid");
|
|
8
|
+
var assert_1 = tslib_1.__importDefault(require("assert"));
|
|
8
9
|
function createOperationsFromModies(modies) {
|
|
9
10
|
return modies.map(function (modi) {
|
|
10
11
|
return {
|
|
@@ -86,12 +87,45 @@ function createModiRelatedCheckers(schema) {
|
|
|
86
87
|
action: restActions,
|
|
87
88
|
type: 'row',
|
|
88
89
|
filter: function (operation, context, option) {
|
|
89
|
-
|
|
90
|
-
|
|
90
|
+
/**
|
|
91
|
+
* 只有一种情况可以通过,即当前是在更新和active的modi所指向同一个父更新对象。
|
|
92
|
+
* 比如:先申请了一个公司(company),再申请修改公司(companyApplyment),这时所有的active modi都指向此条companyApplyment
|
|
93
|
+
* 这时:
|
|
94
|
+
* 1)再申请一条新的修改公司(create companyApplyment),应被拒绝
|
|
95
|
+
* 2)申请修改原来的companyApplyment(update companyApplyment),可以通过
|
|
96
|
+
* 3)在其它路径上对此company对象进行直接的更新,应被拒绝
|
|
97
|
+
*/
|
|
98
|
+
if (option.modiParentEntity) {
|
|
99
|
+
var _a = option, modiParentEntity = _a.modiParentEntity, modiParentId = _a.modiParentId;
|
|
100
|
+
(0, assert_1.default)(modiParentEntity);
|
|
101
|
+
(0, assert_1.default)(modiParentId);
|
|
91
102
|
return {
|
|
92
103
|
id: {
|
|
93
|
-
$
|
|
94
|
-
|
|
104
|
+
$nin: {
|
|
105
|
+
entity: 'modiEntity',
|
|
106
|
+
data: {
|
|
107
|
+
entityId: 1,
|
|
108
|
+
},
|
|
109
|
+
filter: {
|
|
110
|
+
entity: entity,
|
|
111
|
+
modi: {
|
|
112
|
+
iState: 'active',
|
|
113
|
+
$or: [
|
|
114
|
+
{
|
|
115
|
+
entity: {
|
|
116
|
+
$ne: modiParentEntity,
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
entityId: {
|
|
121
|
+
$ne: modiParentId,
|
|
122
|
+
},
|
|
123
|
+
}
|
|
124
|
+
],
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
}
|
|
95
129
|
};
|
|
96
130
|
}
|
|
97
131
|
return {
|
|
@@ -111,7 +145,7 @@ function createModiRelatedCheckers(schema) {
|
|
|
111
145
|
}
|
|
112
146
|
};
|
|
113
147
|
},
|
|
114
|
-
errMsg:
|
|
148
|
+
errMsg: '您请求的更新对象上还有正在申请的更新,请等该更新结束后再试',
|
|
115
149
|
});
|
|
116
150
|
};
|
|
117
151
|
for (var entity in schema) {
|