@steedos/objectql 2.2.40 → 2.2.43
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/services/datasourceServiceFactory.js +1 -1
- package/lib/services/datasourceServiceFactory.js.map +1 -1
- package/lib/services/objectService.d.ts +14 -2
- package/lib/services/objectService.js +154 -52
- package/lib/services/objectService.js.map +1 -1
- package/lib/services/objectServiceDispatcher.js +4 -4
- package/lib/services/objectServiceDispatcher.js.map +1 -1
- package/lib/types/datasource.d.ts +1 -1
- package/lib/types/datasource.js +11 -6
- package/lib/types/datasource.js.map +1 -1
- package/lib/types/object.d.ts +13 -7
- package/lib/types/object.js +194 -220
- package/lib/types/object.js.map +1 -1
- package/lib/types/schema.d.ts +2 -0
- package/lib/types/schema.js +15 -1
- package/lib/types/schema.js.map +1 -1
- package/package.json +9 -10
- package/src/services/datasourceServiceFactory.ts +1 -1
- package/src/services/objectService.ts +91 -53
- package/src/services/objectServiceDispatcher.ts +4 -4
- package/src/types/datasource.ts +4 -1
- package/src/types/object.ts +119 -179
- package/src/types/schema.ts +8 -0
package/src/types/object.ts
CHANGED
|
@@ -19,6 +19,7 @@ import { ShareRules } from './shareRule';
|
|
|
19
19
|
import { RestrictionRule } from './restrictionRule';
|
|
20
20
|
import { FieldPermission } from './field_permission';
|
|
21
21
|
import { getPatternListeners } from '../dynamic-load';
|
|
22
|
+
import { getCacher } from '@steedos/cachers';
|
|
22
23
|
|
|
23
24
|
const clone = require('clone')
|
|
24
25
|
|
|
@@ -393,12 +394,55 @@ export class SteedosObjectType extends SteedosObjectProperties {
|
|
|
393
394
|
|
|
394
395
|
}
|
|
395
396
|
|
|
397
|
+
getTriggerActions(when: string){
|
|
398
|
+
|
|
399
|
+
const triggers = [];
|
|
400
|
+
|
|
401
|
+
const cache = getCacher('action-triggers');
|
|
402
|
+
const triggerActions = cache.get('triggerActions');
|
|
403
|
+
|
|
404
|
+
if(!_.isEmpty(triggerActions)){
|
|
405
|
+
_.map(triggerActions, (item)=>{
|
|
406
|
+
if(item && item.metadata){
|
|
407
|
+
const { metadata } = item
|
|
408
|
+
if(metadata.isPattern){
|
|
409
|
+
try {
|
|
410
|
+
if(metadata.listenTo === '*'){
|
|
411
|
+
triggers.push(item);
|
|
412
|
+
}else if(_.isArray(metadata.listenTo) && _.include(metadata.listenTo, this.name)){
|
|
413
|
+
triggers.push(item);
|
|
414
|
+
}else if(_.isRegExp(metadata.listenTo) && metadata.listenTo.test(this.name)){
|
|
415
|
+
triggers.push(item);
|
|
416
|
+
}else if(_.isString(metadata.listenTo) && metadata.listenTo.startsWith("/")){
|
|
417
|
+
try {
|
|
418
|
+
if(_.isRegExp(eval(metadata.listenTo)) && eval(metadata.listenTo).test(this.name)){
|
|
419
|
+
triggers.push(item);
|
|
420
|
+
}
|
|
421
|
+
} catch (error) {
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
} catch (error) {
|
|
425
|
+
console.log(`error`, error);
|
|
426
|
+
}
|
|
427
|
+
}else{
|
|
428
|
+
if(metadata.when === when && metadata.listenTo === this.name){
|
|
429
|
+
triggers.push(item);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
}
|
|
434
|
+
})
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
return triggers;
|
|
438
|
+
}
|
|
439
|
+
|
|
396
440
|
async runTriggerActions(when: string, context: SteedosTriggerContextConfig) {
|
|
397
|
-
let triggers =
|
|
441
|
+
let triggers = this.getTriggerActions(when);
|
|
398
442
|
if (_.isEmpty(triggers)) {
|
|
399
443
|
return;
|
|
400
444
|
}
|
|
401
|
-
|
|
445
|
+
|
|
402
446
|
for (const trigger of triggers) {
|
|
403
447
|
let params = generateActionParams(when, context); //参考sf
|
|
404
448
|
await this._schema.metadataBroker.call(`${trigger.service.name}.${trigger.metadata.action}`, params).catch((error)=>{
|
|
@@ -646,6 +690,13 @@ export class SteedosObjectType extends SteedosObjectProperties {
|
|
|
646
690
|
return globalPermission
|
|
647
691
|
}
|
|
648
692
|
|
|
693
|
+
|
|
694
|
+
/**
|
|
695
|
+
* @description:
|
|
696
|
+
* @param {SteedosUserSession} userSession
|
|
697
|
+
* @param {any} rolesFieldsPermission: 如果为false, 则不计算字段集权限,提交计算效率.
|
|
698
|
+
* @return {*}
|
|
699
|
+
*/
|
|
649
700
|
async getUserObjectPermission(userSession: SteedosUserSession, rolesFieldsPermission?: any) {
|
|
650
701
|
|
|
651
702
|
if (!userSession) {
|
|
@@ -686,8 +737,12 @@ export class SteedosObjectType extends SteedosObjectProperties {
|
|
|
686
737
|
throw new Error('not find user permission');
|
|
687
738
|
}
|
|
688
739
|
|
|
689
|
-
if
|
|
690
|
-
rolesFieldsPermission =
|
|
740
|
+
if(rolesFieldsPermission === false){
|
|
741
|
+
rolesFieldsPermission = {};
|
|
742
|
+
}else{
|
|
743
|
+
if (!rolesFieldsPermission) {
|
|
744
|
+
rolesFieldsPermission = await FieldPermission.getObjectFieldsPermissionGroupRole(this.name);
|
|
745
|
+
}
|
|
691
746
|
}
|
|
692
747
|
|
|
693
748
|
roles.forEach((role) => {
|
|
@@ -781,10 +836,10 @@ export class SteedosObjectType extends SteedosObjectProperties {
|
|
|
781
836
|
return userObjectPermission;
|
|
782
837
|
}
|
|
783
838
|
|
|
784
|
-
|
|
839
|
+
async allowRead(userSession: SteedosUserSession) {
|
|
785
840
|
if (!userSession)
|
|
786
841
|
return true
|
|
787
|
-
let userObjectPermission = await this.getUserObjectPermission(userSession)
|
|
842
|
+
let userObjectPermission = await this.getUserObjectPermission(userSession, false)
|
|
788
843
|
if (userObjectPermission.allowRead) {
|
|
789
844
|
return true
|
|
790
845
|
} else {
|
|
@@ -792,10 +847,10 @@ export class SteedosObjectType extends SteedosObjectProperties {
|
|
|
792
847
|
}
|
|
793
848
|
}
|
|
794
849
|
|
|
795
|
-
|
|
850
|
+
async allowInsert(userSession: SteedosUserSession) {
|
|
796
851
|
if (!userSession)
|
|
797
852
|
return true
|
|
798
|
-
let userObjectPermission = await this.getUserObjectPermission(userSession)
|
|
853
|
+
let userObjectPermission = await this.getUserObjectPermission(userSession, false)
|
|
799
854
|
if (userObjectPermission.allowCreate) {
|
|
800
855
|
return true
|
|
801
856
|
} else {
|
|
@@ -803,10 +858,10 @@ export class SteedosObjectType extends SteedosObjectProperties {
|
|
|
803
858
|
}
|
|
804
859
|
}
|
|
805
860
|
|
|
806
|
-
|
|
861
|
+
async allowUpdate(userSession: SteedosUserSession) {
|
|
807
862
|
if (!userSession)
|
|
808
863
|
return true
|
|
809
|
-
let userObjectPermission = await this.getUserObjectPermission(userSession)
|
|
864
|
+
let userObjectPermission = await this.getUserObjectPermission(userSession, false)
|
|
810
865
|
if (userObjectPermission.allowEdit) {
|
|
811
866
|
return true
|
|
812
867
|
} else {
|
|
@@ -814,10 +869,10 @@ export class SteedosObjectType extends SteedosObjectProperties {
|
|
|
814
869
|
}
|
|
815
870
|
}
|
|
816
871
|
|
|
817
|
-
|
|
872
|
+
async allowDelete(userSession: SteedosUserSession) {
|
|
818
873
|
if (!userSession)
|
|
819
874
|
return true
|
|
820
|
-
let userObjectPermission = await this.getUserObjectPermission(userSession)
|
|
875
|
+
let userObjectPermission = await this.getUserObjectPermission(userSession, false)
|
|
821
876
|
if (userObjectPermission.allowDelete) {
|
|
822
877
|
return true
|
|
823
878
|
} else {
|
|
@@ -827,35 +882,41 @@ export class SteedosObjectType extends SteedosObjectProperties {
|
|
|
827
882
|
|
|
828
883
|
async find(query: SteedosQueryOptions, userSession?: SteedosUserSession) {
|
|
829
884
|
let clonedQuery = Object.assign({}, query);
|
|
830
|
-
|
|
885
|
+
if(userSession)
|
|
886
|
+
await this.processUnreadableField(userSession, clonedQuery);
|
|
831
887
|
return await this.callAdapter('find', this.table_name, clonedQuery, userSession)
|
|
832
888
|
}
|
|
833
889
|
|
|
834
890
|
// 此函数支持driver: MeteorMongo
|
|
835
891
|
async aggregate(query: SteedosQueryOptions, externalPipeline, userSession?: SteedosUserSession) {
|
|
836
892
|
let clonedQuery = Object.assign({}, query);
|
|
837
|
-
|
|
893
|
+
if(userSession)
|
|
894
|
+
await this.processUnreadableField(userSession, clonedQuery);
|
|
838
895
|
return await this.callAdapter('aggregate', this.table_name, clonedQuery, externalPipeline, userSession)
|
|
839
896
|
}
|
|
840
897
|
|
|
841
898
|
// 此函数支持driver: MeteorMongo
|
|
842
899
|
async directAggregate(query: SteedosQueryOptions, externalPipeline: any[], userSession?: SteedosUserSession) {
|
|
843
900
|
let clonedQuery = Object.assign({}, query);
|
|
844
|
-
|
|
901
|
+
if(userSession)
|
|
902
|
+
await this.processUnreadableField(userSession, clonedQuery);
|
|
845
903
|
return await this.callAdapter('directAggregate', this.table_name, clonedQuery, externalPipeline, userSession)
|
|
846
904
|
}
|
|
847
905
|
|
|
848
906
|
// 此函数支持driver: MeteorMongo,类似于aggregate,其参数externalPipeline放在最前面而已
|
|
849
907
|
async directAggregatePrefixalPipeline(query: SteedosQueryOptions, prefixalPipeline: any[], userSession?: SteedosUserSession) {
|
|
850
908
|
let clonedQuery = Object.assign({}, query);
|
|
851
|
-
|
|
909
|
+
if(userSession)
|
|
910
|
+
await this.processUnreadableField(userSession, clonedQuery);
|
|
852
911
|
return await this.callAdapter('directAggregatePrefixalPipeline', this.table_name, clonedQuery, prefixalPipeline, userSession)
|
|
853
912
|
}
|
|
854
913
|
|
|
855
914
|
async findOne(id: SteedosIDType, query: SteedosQueryOptions, userSession?: SteedosUserSession) {
|
|
856
915
|
let clonedQuery = Object.assign({}, query);
|
|
857
|
-
|
|
858
|
-
|
|
916
|
+
if(userSession)
|
|
917
|
+
await this.processUnreadableField(userSession, clonedQuery);
|
|
918
|
+
const result = await this.callAdapter('findOne', this.table_name, id, clonedQuery, userSession);
|
|
919
|
+
return result
|
|
859
920
|
}
|
|
860
921
|
|
|
861
922
|
async insert(doc: Dictionary<any>, userSession?: SteedosUserSession) {
|
|
@@ -865,21 +926,21 @@ export class SteedosObjectType extends SteedosObjectProperties {
|
|
|
865
926
|
|
|
866
927
|
async update(id: SteedosIDType, doc: Dictionary<any>, userSession?: SteedosUserSession) {
|
|
867
928
|
doc = this.formatRecord(doc);
|
|
868
|
-
await this.processUneditableFields(userSession, doc)
|
|
929
|
+
// await this.processUneditableFields(userSession, doc)
|
|
869
930
|
let clonedId = id;
|
|
870
931
|
return await this.callAdapter('update', this.table_name, clonedId, doc, userSession)
|
|
871
932
|
}
|
|
872
933
|
|
|
873
934
|
async updateOne(id: SteedosIDType, doc: Dictionary<any>, userSession?: SteedosUserSession) {
|
|
874
935
|
doc = this.formatRecord(doc);
|
|
875
|
-
await this.processUneditableFields(userSession, doc)
|
|
936
|
+
// await this.processUneditableFields(userSession, doc)
|
|
876
937
|
let clonedId = id;
|
|
877
938
|
return await this.callAdapter('updateOne', this.table_name, clonedId, doc, userSession)
|
|
878
939
|
}
|
|
879
940
|
// 此函数支持driver: MeteorMongo、Mongo
|
|
880
941
|
async updateMany(queryFilters: SteedosQueryFilters, doc: Dictionary<any>, userSession?: SteedosUserSession) {
|
|
881
942
|
doc = this.formatRecord(doc);
|
|
882
|
-
await this.processUneditableFields(userSession, doc)
|
|
943
|
+
// await this.processUneditableFields(userSession, doc)
|
|
883
944
|
let clonedQueryFilters = queryFilters;
|
|
884
945
|
return await this.callAdapter('updateMany', this.table_name, clonedQueryFilters, doc, userSession)
|
|
885
946
|
}
|
|
@@ -902,7 +963,7 @@ export class SteedosObjectType extends SteedosObjectProperties {
|
|
|
902
963
|
|
|
903
964
|
async directUpdate(id: SteedosIDType, doc: Dictionary<any>, userSession?: SteedosUserSession) {
|
|
904
965
|
doc = this.formatRecord(doc);
|
|
905
|
-
await this.processUneditableFields(userSession, doc)
|
|
966
|
+
// await this.processUneditableFields(userSession, doc)
|
|
906
967
|
let clonedId = id;
|
|
907
968
|
return await this.callAdapter('directUpdate', this.table_name, clonedId, doc, userSession)
|
|
908
969
|
}
|
|
@@ -1150,21 +1211,8 @@ export class SteedosObjectType extends SteedosObjectProperties {
|
|
|
1150
1211
|
return accessFields;
|
|
1151
1212
|
}
|
|
1152
1213
|
|
|
1153
|
-
async getRecordView(userSession, context
|
|
1154
|
-
let objectConfig;
|
|
1155
|
-
let layouts;
|
|
1156
|
-
let spaceProcessDefinition;
|
|
1157
|
-
let dbListViews;
|
|
1158
|
-
let rolesFieldsPermission;
|
|
1159
|
-
|
|
1160
|
-
if (context) {
|
|
1161
|
-
objectConfig = context.objectConfig;
|
|
1162
|
-
layouts = context.layouts;
|
|
1163
|
-
spaceProcessDefinition = context.spaceProcessDefinition;
|
|
1164
|
-
dbListViews = context.dbListViews;
|
|
1165
|
-
rolesFieldsPermission = context.rolesFieldsPermission;
|
|
1166
|
-
}
|
|
1167
|
-
|
|
1214
|
+
async getRecordView(userSession, context: any = {}) {
|
|
1215
|
+
let { objectConfig, layouts, spaceProcessDefinition, dbListViews, rolesFieldsPermission, relationsInfo} = context;
|
|
1168
1216
|
const lng = userSession.language;
|
|
1169
1217
|
if (!objectConfig) {
|
|
1170
1218
|
const objectMetadataConfig: any = await this.callMetadataObjectServiceAction('get', { objectApiName: this.name });
|
|
@@ -1173,69 +1221,21 @@ export class SteedosObjectType extends SteedosObjectProperties {
|
|
|
1173
1221
|
objectConfig.name = this.name
|
|
1174
1222
|
objectConfig.datasource = this.datasource.name;
|
|
1175
1223
|
objectConfig.permissions = await this.getUserObjectPermission(userSession, rolesFieldsPermission);
|
|
1176
|
-
|
|
1224
|
+
if(!relationsInfo){
|
|
1225
|
+
relationsInfo = await this.getRelationsInfo();
|
|
1226
|
+
}
|
|
1177
1227
|
objectConfig.details = relationsInfo.details;
|
|
1178
1228
|
objectConfig.masters = relationsInfo.masters;
|
|
1179
1229
|
objectConfig.lookup_details = relationsInfo.lookup_details;
|
|
1180
1230
|
delete objectConfig.db
|
|
1181
|
-
|
|
1182
1231
|
translationObject(lng, objectConfig.name, objectConfig, true);
|
|
1183
1232
|
if (!layouts) {
|
|
1184
1233
|
layouts = await getObjectLayouts(userSession.profile, userSession.spaceId, this.name);
|
|
1185
1234
|
}
|
|
1186
1235
|
|
|
1187
|
-
// let layoutHiddenFields = [];
|
|
1188
1236
|
let objectLayout = null
|
|
1189
1237
|
if(layouts && layouts.length > 0){
|
|
1190
1238
|
objectLayout = layouts[0];
|
|
1191
|
-
// let _fields = {};
|
|
1192
|
-
// let sort_no = 1;
|
|
1193
|
-
// _.each(layout.fields, function(_item){
|
|
1194
|
-
// _fields[_item.field_name] = objectConfig.fields[_item.field_name]
|
|
1195
|
-
// if(_fields[_item.field_name]){
|
|
1196
|
-
// if(_.has(_item, 'group')){
|
|
1197
|
-
// _fields[_item.field_name].group = _item.group
|
|
1198
|
-
// }
|
|
1199
|
-
|
|
1200
|
-
// if(_item.is_required){
|
|
1201
|
-
// _fields[_item.field_name].readonly = false
|
|
1202
|
-
// _fields[_item.field_name].disabled = false
|
|
1203
|
-
// _fields[_item.field_name].required = true
|
|
1204
|
-
// }else if(_item.is_readonly){
|
|
1205
|
-
// _fields[_item.field_name].readonly = true
|
|
1206
|
-
// _fields[_item.field_name].disabled = true
|
|
1207
|
-
// _fields[_item.field_name].required = false
|
|
1208
|
-
// }
|
|
1209
|
-
|
|
1210
|
-
// if(_item.visible_on){
|
|
1211
|
-
// _fields[_item.field_name].visible_on = _item.visible_on
|
|
1212
|
-
// }
|
|
1213
|
-
|
|
1214
|
-
// // TODO 按新字段权限规则, 调整此部分代码
|
|
1215
|
-
// if(['created','created_by','modified','modified_by'].indexOf(_item.field_name) < 0){
|
|
1216
|
-
// _fields[_item.field_name].omit = false;
|
|
1217
|
-
// _fields[_item.field_name].hidden = false;
|
|
1218
|
-
// }
|
|
1219
|
-
|
|
1220
|
-
// _fields[_item.field_name].sort_no = sort_no;
|
|
1221
|
-
// sort_no++;
|
|
1222
|
-
// }
|
|
1223
|
-
// })
|
|
1224
|
-
|
|
1225
|
-
// const layoutFieldKeys = _.keys(_fields);
|
|
1226
|
-
// const objectFieldKeys = _.keys(objectConfig.fields);
|
|
1227
|
-
|
|
1228
|
-
// layoutHiddenFields = _.difference(objectFieldKeys, layoutFieldKeys);
|
|
1229
|
-
|
|
1230
|
-
// _.each(layoutFieldKeys, function(fieldApiName){
|
|
1231
|
-
// objectConfig.fields[fieldApiName] = _fields[fieldApiName];
|
|
1232
|
-
// })
|
|
1233
|
-
|
|
1234
|
-
// _.each(layoutHiddenFields, function(fieldApiName){
|
|
1235
|
-
// objectConfig.fields[fieldApiName].hidden = true;
|
|
1236
|
-
// objectConfig.fields[fieldApiName].sort_no = 99999;
|
|
1237
|
-
// })
|
|
1238
|
-
|
|
1239
1239
|
_.each(objectLayout.buttons, function(button){
|
|
1240
1240
|
const action = objectConfig.actions[button.button_name];
|
|
1241
1241
|
if(action){
|
|
@@ -1252,8 +1252,6 @@ export class SteedosObjectType extends SteedosObjectProperties {
|
|
|
1252
1252
|
action._visible = function(){return false}.toString()
|
|
1253
1253
|
}
|
|
1254
1254
|
})
|
|
1255
|
-
// _object.allow_customActions = userObjectLayout.custom_actions || []
|
|
1256
|
-
// _object.exclude_actions = userObjectLayout.exclude_actions || []
|
|
1257
1255
|
objectConfig.related_lists = objectLayout.related_lists || []
|
|
1258
1256
|
_.each(objectConfig.related_lists, (related_list)=>{
|
|
1259
1257
|
if(related_list.sort_field_name && _.isArray(related_list.sort_field_name) && related_list.sort_field_name.length > 0){
|
|
@@ -1264,62 +1262,7 @@ export class SteedosObjectType extends SteedosObjectProperties {
|
|
|
1264
1262
|
}
|
|
1265
1263
|
})
|
|
1266
1264
|
}
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
// _.each(objectConfig.fields, (field)=>{
|
|
1270
|
-
// if(field){
|
|
1271
|
-
// const fieldPermission = objectConfig.permissions.field_permissions[field.name];
|
|
1272
|
-
// const {read, edit} = fieldPermission || {read: !field.hidden, edit: !field.hidden && !field.readonly}
|
|
1273
|
-
// //不可查看: 配置了字段权限且不可查看; 没有配置字段权限,字段的hidden为true
|
|
1274
|
-
// if(read === false){
|
|
1275
|
-
// delete objectConfig.fields[field.name];
|
|
1276
|
-
// return;
|
|
1277
|
-
// }
|
|
1278
|
-
|
|
1279
|
-
// //可查看不可编辑: 配置了字段权限可查看不可编辑; 没有配置字段权限 字段的hidden 为false 且字段的readonly为true
|
|
1280
|
-
// if(read === true && edit === false){
|
|
1281
|
-
// objectConfig.fields[field.name].hidden = false;
|
|
1282
|
-
// objectConfig.fields[field.name].readonly = true;
|
|
1283
|
-
// objectConfig.fields[field.name].disabled = true;
|
|
1284
|
-
// return;
|
|
1285
|
-
// }
|
|
1286
|
-
|
|
1287
|
-
// //可查看可编辑: 配置了字段权限可查看可编辑; 没有配置字段权限 字段的hidden 为false 且字段的readonly为false
|
|
1288
|
-
// if(read === true && edit === true){
|
|
1289
|
-
// objectConfig.fields[field.name].hidden = false;
|
|
1290
|
-
// objectConfig.fields[field.name].readonly = false;
|
|
1291
|
-
// objectConfig.fields[field.name].disabled = false;
|
|
1292
|
-
// return;
|
|
1293
|
-
// }
|
|
1294
|
-
// console.error('字段权限处理异常', field, read, edit);
|
|
1295
|
-
// }
|
|
1296
|
-
// })
|
|
1297
|
-
|
|
1298
|
-
// _.each(objectConfig.permissions.field_permissions, (field_permission, field) => {
|
|
1299
|
-
// const { read, edit } = field_permission;
|
|
1300
|
-
// if (userObjectFields[field] && !_.include(layoutHiddenFields, field)) {
|
|
1301
|
-
// if (read) {
|
|
1302
|
-
// userObjectFields[field].hidden = false;
|
|
1303
|
-
// userObjectFields[field].omit = true;
|
|
1304
|
-
// userObjectFields[field].readonly = true;
|
|
1305
|
-
// userObjectFields[field].disabled = true;
|
|
1306
|
-
// }
|
|
1307
|
-
// if (edit) {
|
|
1308
|
-
// userObjectFields[field].omit = false;
|
|
1309
|
-
// userObjectFields[field].hidden = false;
|
|
1310
|
-
// userObjectFields[field].readonly = false;
|
|
1311
|
-
// userObjectFields[field].disabled = false;
|
|
1312
|
-
// }
|
|
1313
|
-
// if (!read && !edit) {
|
|
1314
|
-
// delete userObjectFields[field]
|
|
1315
|
-
// }
|
|
1316
|
-
// }
|
|
1317
|
-
// })
|
|
1318
|
-
|
|
1319
|
-
// objectConfig.fields = userObjectFields
|
|
1320
|
-
|
|
1321
1265
|
objectConfig.fields = this.getAccessFields(objectConfig.fields, objectLayout, objectConfig.permissions)
|
|
1322
|
-
|
|
1323
1266
|
// TODO object layout 是否需要控制审批记录显示?
|
|
1324
1267
|
if (!spaceProcessDefinition) {
|
|
1325
1268
|
spaceProcessDefinition = await getObject("process_definition").directFind({ filters: [['space', '=', userSession.spaceId], ['object_name', '=', this.name], ['active', '=', true]] })
|
|
@@ -1327,9 +1270,7 @@ export class SteedosObjectType extends SteedosObjectProperties {
|
|
|
1327
1270
|
if (spaceProcessDefinition.length > 0) {
|
|
1328
1271
|
objectConfig.enable_process = true
|
|
1329
1272
|
}
|
|
1330
|
-
|
|
1331
1273
|
//清理数据
|
|
1332
|
-
|
|
1333
1274
|
_.each(objectConfig.triggers, function(trigger, key){
|
|
1334
1275
|
if(trigger?.on != 'client'){
|
|
1335
1276
|
delete objectConfig.triggers[key];
|
|
@@ -1352,7 +1293,7 @@ export class SteedosObjectType extends SteedosObjectProperties {
|
|
|
1352
1293
|
return objectConfig;
|
|
1353
1294
|
}
|
|
1354
1295
|
|
|
1355
|
-
async
|
|
1296
|
+
async getDefaultRecordView(userSession){
|
|
1356
1297
|
const object_name = this.name;
|
|
1357
1298
|
const type = 'record';
|
|
1358
1299
|
const buttons = [];
|
|
@@ -1456,12 +1397,12 @@ export class SteedosObjectType extends SteedosObjectProperties {
|
|
|
1456
1397
|
}
|
|
1457
1398
|
}
|
|
1458
1399
|
|
|
1459
|
-
async
|
|
1400
|
+
async createDefaultRecordView(userSession){
|
|
1460
1401
|
const name = 'default';
|
|
1461
1402
|
const label = 'Default';
|
|
1462
1403
|
const profiles = ['user'];
|
|
1463
1404
|
try {
|
|
1464
|
-
let defaultRecordView = await this.
|
|
1405
|
+
let defaultRecordView = await this.getDefaultRecordView(userSession);
|
|
1465
1406
|
return await getObject('object_layouts').insert(Object.assign({},defaultRecordView, {name, label, profiles}), userSession)
|
|
1466
1407
|
} catch (error) {
|
|
1467
1408
|
return {error: error.message}
|
|
@@ -1531,7 +1472,7 @@ export class SteedosObjectType extends SteedosObjectProperties {
|
|
|
1531
1472
|
return true
|
|
1532
1473
|
}
|
|
1533
1474
|
if (method === 'find' || method === 'findOne' || method === 'count' || method === 'aggregate' || method === 'aggregatePrefixalPipeline') {
|
|
1534
|
-
return await this.
|
|
1475
|
+
return await this.allowRead(userSession)
|
|
1535
1476
|
} else if (method === 'insert') {
|
|
1536
1477
|
return await this.allowInsert(userSession)
|
|
1537
1478
|
} else if (method === 'update' || method === 'updateOne' || method === 'updateMany') {
|
|
@@ -1560,7 +1501,7 @@ export class SteedosObjectType extends SteedosObjectProperties {
|
|
|
1560
1501
|
|
|
1561
1502
|
private async appendRecordPermission(records, userSession) {
|
|
1562
1503
|
const _ids = _.pluck(records, '_id');
|
|
1563
|
-
const objPm = await this.getUserObjectPermission(userSession);
|
|
1504
|
+
const objPm = await this.getUserObjectPermission(userSession, false);
|
|
1564
1505
|
const permissionFilters = this.getObjectEditPermissionFilters(objPm, userSession);
|
|
1565
1506
|
if (_.isEmpty(permissionFilters)) {
|
|
1566
1507
|
return;
|
|
@@ -1617,7 +1558,7 @@ export class SteedosObjectType extends SteedosObjectProperties {
|
|
|
1617
1558
|
if (!userSession) {
|
|
1618
1559
|
return
|
|
1619
1560
|
}
|
|
1620
|
-
let userObjectPermission = await this.getUserObjectPermission(userSession)
|
|
1561
|
+
let userObjectPermission = await this.getUserObjectPermission(userSession, false)
|
|
1621
1562
|
let userObjectUnreadableFields = userObjectPermission.unreadable_fields
|
|
1622
1563
|
if (userObjectUnreadableFields.length > 0) {
|
|
1623
1564
|
let queryFields = [];
|
|
@@ -1652,25 +1593,25 @@ export class SteedosObjectType extends SteedosObjectProperties {
|
|
|
1652
1593
|
}
|
|
1653
1594
|
}
|
|
1654
1595
|
|
|
1655
|
-
private async processUneditableFields(userSession: SteedosUserSession, doc: JsonMap) {
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1596
|
+
// private async processUneditableFields(userSession: SteedosUserSession, doc: JsonMap) {
|
|
1597
|
+
// 后台直接去掉uneditable_fields相关判断逻辑
|
|
1598
|
+
// [签约对象同时配置了company_ids必填及uneditable_fields造成部分用户新建签约对象时报错 #192](https://github.com/steedos/steedos-project-dzug/issues/192)
|
|
1599
|
+
// if (!userSession) {
|
|
1600
|
+
// return
|
|
1601
|
+
// }
|
|
1661
1602
|
|
|
1662
|
-
|
|
1663
|
-
|
|
1603
|
+
// let userObjectPermission = await this.getUserObjectPermission(userSession)
|
|
1604
|
+
// let userObjectUneditableFields = userObjectPermission.uneditable_fields
|
|
1664
1605
|
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1606
|
+
// let intersection = _.intersection(userObjectUneditableFields, _.keys(doc))
|
|
1607
|
+
// if (intersection.length > 0) {
|
|
1608
|
+
// throw new Error(`no permissions to edit fields ${intersection.join(', ')}`)
|
|
1609
|
+
// }
|
|
1669
1610
|
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
}
|
|
1611
|
+
// // _.each(userObjectUneditableFields, (name: string)=>{
|
|
1612
|
+
// // delete doc[name]
|
|
1613
|
+
// // })
|
|
1614
|
+
// }
|
|
1674
1615
|
|
|
1675
1616
|
private formatRecord(doc: JsonMap) {
|
|
1676
1617
|
let adapterFormat = this._datasource["formatRecord"];
|
|
@@ -1686,9 +1627,12 @@ export class SteedosObjectType extends SteedosObjectProperties {
|
|
|
1686
1627
|
if (typeof adapterMethod !== 'function') {
|
|
1687
1628
|
throw new Error('Adapted does not support "' + method + '" method');
|
|
1688
1629
|
}
|
|
1689
|
-
|
|
1690
|
-
if
|
|
1691
|
-
|
|
1630
|
+
const userSession: SteedosUserSession = args[args.length - 1];
|
|
1631
|
+
if(!_.isEmpty(userSession)){
|
|
1632
|
+
let allow = await this.allow(method, userSession)
|
|
1633
|
+
if (!allow) {
|
|
1634
|
+
throw new Error('not find permission')
|
|
1635
|
+
}
|
|
1692
1636
|
}
|
|
1693
1637
|
|
|
1694
1638
|
let objectName = args[0], recordId: string, doc: JsonMap;
|
|
@@ -1711,32 +1655,28 @@ export class SteedosObjectType extends SteedosObjectProperties {
|
|
|
1711
1655
|
}
|
|
1712
1656
|
|
|
1713
1657
|
// 判断处理工作区权限,公司级权限,owner权限
|
|
1714
|
-
if (this._datasource.enable_space) {
|
|
1658
|
+
if (!_.isEmpty(userSession) && this._datasource.enable_space) {
|
|
1715
1659
|
this.dealWithFilters(method, args);
|
|
1716
1660
|
await this.dealWithMethodPermission(method, args);
|
|
1717
1661
|
}
|
|
1718
|
-
|
|
1719
1662
|
let returnValue: any;
|
|
1720
|
-
let userSession: SteedosUserSession;
|
|
1721
1663
|
if (this.isDirectCRUD(method)) {
|
|
1722
|
-
userSession = args[args.length - 1]
|
|
1723
1664
|
args.splice(args.length - 1, 1, userSession ? userSession.userId : undefined)
|
|
1724
1665
|
returnValue = await adapterMethod.apply(this._datasource, args);
|
|
1725
1666
|
} else {
|
|
1726
|
-
userSession = args[args.length - 1]
|
|
1727
1667
|
let beforeTriggerContext = await this.getTriggerContext('before', method, args)
|
|
1728
1668
|
if (paramRecordId) {
|
|
1729
1669
|
beforeTriggerContext = Object.assign({} , beforeTriggerContext, { id: paramRecordId });
|
|
1730
1670
|
}
|
|
1731
1671
|
await this.runBeforeTriggers(method, beforeTriggerContext)
|
|
1732
1672
|
await runValidationRules(method, beforeTriggerContext, args[0], userSession)
|
|
1733
|
-
|
|
1734
1673
|
let afterTriggerContext = await this.getTriggerContext('after', method, args, paramRecordId)
|
|
1735
1674
|
if (paramRecordId) {
|
|
1736
1675
|
afterTriggerContext = Object.assign({}, afterTriggerContext, { id: paramRecordId });
|
|
1737
1676
|
}
|
|
1738
1677
|
let previousDoc = clone(afterTriggerContext.previousDoc);
|
|
1739
1678
|
args.splice(args.length - 1, 1, userSession ? userSession.userId : undefined)
|
|
1679
|
+
|
|
1740
1680
|
returnValue = await adapterMethod.apply(this._datasource, args);
|
|
1741
1681
|
if (method === 'find' || method == 'findOne' || method == 'count' || method == 'aggregate' || method == 'aggregatePrefixalPipeline') {
|
|
1742
1682
|
let values = returnValue || {}
|
|
@@ -1863,7 +1803,7 @@ export class SteedosObjectType extends SteedosObjectProperties {
|
|
|
1863
1803
|
if (userSession) {
|
|
1864
1804
|
let spaceId = userSession.spaceId;
|
|
1865
1805
|
let userId = userSession.userId;
|
|
1866
|
-
let objPm = await this.getUserObjectPermission(userSession);
|
|
1806
|
+
let objPm = await this.getUserObjectPermission(userSession, false);
|
|
1867
1807
|
if (method === 'find' || method === 'count' || method === 'findOne' || method === 'aggregate' || method === 'aggregatePrefixalPipeline') {
|
|
1868
1808
|
let query = args[args.length - 2];
|
|
1869
1809
|
if (method === 'aggregate' || method === 'aggregatePrefixalPipeline') {
|
package/src/types/schema.ts
CHANGED
|
@@ -241,6 +241,10 @@ export class SteedosSchema {
|
|
|
241
241
|
return schemaObjects;
|
|
242
242
|
// return await this.metadataBroker.call("objects.getAll");
|
|
243
243
|
}
|
|
244
|
+
|
|
245
|
+
async getAllRelationsInfo(){
|
|
246
|
+
return await this.broker.call('objects.getAllRelationsInfo');
|
|
247
|
+
}
|
|
244
248
|
}
|
|
245
249
|
|
|
246
250
|
export function getSteedosSchema(broker?: any, metadataBroker?: any): SteedosSchema {
|
|
@@ -261,5 +265,9 @@ export function getSteedosSchema(broker?: any, metadataBroker?: any): SteedosSch
|
|
|
261
265
|
return schema;
|
|
262
266
|
}
|
|
263
267
|
|
|
268
|
+
export function getAllRelationsInfo(schema?: SteedosSchema) {
|
|
269
|
+
return (schema ? schema : getSteedosSchema()).getAllRelationsInfo();
|
|
270
|
+
}
|
|
271
|
+
|
|
264
272
|
(function loadRun() {
|
|
265
273
|
})();
|