@steedos/service-ui 2.4.6 → 2.4.8-beta.1
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.
|
@@ -59,7 +59,7 @@ router.get('/service/api/:objectServiceName/uiSchema', core.requireAuthenticatio
|
|
|
59
59
|
const { objectServiceName } = req.params;
|
|
60
60
|
const objectName = objectServiceName.substring(1);
|
|
61
61
|
const [result, hasImportTemplates] = yield Promise.all([
|
|
62
|
-
callObjectServiceAction(
|
|
62
|
+
callObjectServiceAction(`objectql.getRecordView`, userSession, { objectName }),
|
|
63
63
|
callObjectServiceAction(`~packages-@steedos/data-import.hasImportTemplates`, userSession, {
|
|
64
64
|
objectName: objectName
|
|
65
65
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steedos/service-ui",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.8-beta.1",
|
|
4
4
|
"main": "package.service.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"steedos"
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
"description": "steedos package",
|
|
12
12
|
"repository": {},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@steedos/core": "2.4.
|
|
15
|
-
"@steedos/i18n": "2.4.
|
|
16
|
-
"@steedos/objectql": "2.4.
|
|
14
|
+
"@steedos/core": "2.4.8-beta.1",
|
|
15
|
+
"@steedos/i18n": "2.4.8-beta.1",
|
|
16
|
+
"@steedos/objectql": "2.4.8-beta.1",
|
|
17
17
|
"express": "4.18.1"
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
@@ -21,5 +21,5 @@
|
|
|
21
21
|
"publishConfig": {
|
|
22
22
|
"access": "public"
|
|
23
23
|
},
|
|
24
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "f35130770cfb86468309f8f9a8ce21a3bbb5b2f6"
|
|
25
25
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* @Author: baozhoutao@steedos.com
|
|
3
3
|
* @Date: 2022-06-09 10:19:47
|
|
4
|
-
* @LastEditors:
|
|
5
|
-
* @LastEditTime:
|
|
4
|
+
* @LastEditors: sunhaolin@hotoa.com
|
|
5
|
+
* @LastEditTime: 2023-03-27 17:19:57
|
|
6
6
|
* @Description:
|
|
7
7
|
*/
|
|
8
8
|
import { getSteedosSchema } from "@steedos/objectql";
|
|
@@ -58,7 +58,7 @@ router.get('/service/api/:objectServiceName/uiSchema', core.requireAuthenticatio
|
|
|
58
58
|
const { objectServiceName } = req.params;
|
|
59
59
|
const objectName = objectServiceName.substring(1);
|
|
60
60
|
const [ result, hasImportTemplates ] = await Promise.all([
|
|
61
|
-
callObjectServiceAction(
|
|
61
|
+
callObjectServiceAction(`objectql.getRecordView`, userSession, { objectName }),
|
|
62
62
|
callObjectServiceAction(`~packages-@steedos/data-import.hasImportTemplates`, userSession, {
|
|
63
63
|
objectName: objectName
|
|
64
64
|
})
|
|
@@ -1,423 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSpaceObjectBootStrap = exports.getSpaceBootStrap = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const steedosI18n = require("@steedos/i18n");
|
|
6
|
-
const core_1 = require("@steedos/core");
|
|
7
|
-
const objectql_1 = require("@steedos/objectql");
|
|
8
|
-
require("@steedos/license");
|
|
9
|
-
const Fiber = require('fibers');
|
|
10
|
-
const clone = require("clone");
|
|
11
|
-
const _ = require('underscore');
|
|
12
|
-
const express = require('express');
|
|
13
|
-
const router = express.Router();
|
|
14
|
-
function getUserProfileObjectsLayout(userId, spaceId, objectName) {
|
|
15
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
let spaceUser;
|
|
17
|
-
let spaceUsers = yield (0, objectql_1.getObject)("space_users").directFind({ filters: [['space', '=', spaceId], ['user', '=', userId]] });
|
|
18
|
-
if (spaceUsers.length > 0) {
|
|
19
|
-
spaceUser = spaceUsers[0];
|
|
20
|
-
}
|
|
21
|
-
if (spaceUser && spaceUser.profile) {
|
|
22
|
-
return yield (0, objectql_1.getObjectLayouts)(spaceUser.profile, spaceId, objectName);
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
;
|
|
27
|
-
function getUserObjects(userId, spaceId, objects) {
|
|
28
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
const objectsLayout = yield getUserProfileObjectsLayout(userId, spaceId);
|
|
30
|
-
for (const objectName in objects) {
|
|
31
|
-
let userObjectLayout = null;
|
|
32
|
-
if (objectsLayout) {
|
|
33
|
-
userObjectLayout = _.find(objectsLayout, function (objectLayout) {
|
|
34
|
-
return objectLayout.object_name === objectName;
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
if (!userObjectLayout && false) {
|
|
38
|
-
userObjectLayout = (0, objectql_1.getLayout)(objectName, 'default');
|
|
39
|
-
}
|
|
40
|
-
if (userObjectLayout) {
|
|
41
|
-
objects[userObjectLayout.object_name] = yield getUserObject(userId, spaceId, objects[userObjectLayout.object_name], userObjectLayout);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
function getUserObject(userId, spaceId, object, layout) {
|
|
47
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
48
|
-
if (!layout) {
|
|
49
|
-
const layouts = yield getUserProfileObjectsLayout(userId, spaceId, object.name);
|
|
50
|
-
if (layouts && layouts.length > 0) {
|
|
51
|
-
layout = layouts[0];
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
let _object = clone(object);
|
|
55
|
-
if (_object && layout) {
|
|
56
|
-
_.each(_object.actions, (action, key) => {
|
|
57
|
-
if (!_.has(action, 'name')) {
|
|
58
|
-
action.name = key;
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
let _fields = {};
|
|
62
|
-
let sort_no = 1;
|
|
63
|
-
_.each(layout.fields, function (_item) {
|
|
64
|
-
_fields[_item.field_name] = _object.fields[_item.field_name];
|
|
65
|
-
if (_fields[_item.field_name]) {
|
|
66
|
-
if (_.has(_item, 'group')) {
|
|
67
|
-
_fields[_item.field_name].group = _item.group;
|
|
68
|
-
}
|
|
69
|
-
if (_item.is_required) {
|
|
70
|
-
_fields[_item.field_name].readonly = false;
|
|
71
|
-
_fields[_item.field_name].disabled = false;
|
|
72
|
-
_fields[_item.field_name].required = true;
|
|
73
|
-
}
|
|
74
|
-
else if (_item.is_readonly) {
|
|
75
|
-
_fields[_item.field_name].readonly = true;
|
|
76
|
-
_fields[_item.field_name].disabled = true;
|
|
77
|
-
_fields[_item.field_name].required = false;
|
|
78
|
-
}
|
|
79
|
-
if (_item.visible_on) {
|
|
80
|
-
_fields[_item.field_name].visible_on = _item.visible_on;
|
|
81
|
-
}
|
|
82
|
-
if (['created', 'created_by', 'modified', 'modified_by'].indexOf(_item.field_name) < 0) {
|
|
83
|
-
_fields[_item.field_name].omit = false;
|
|
84
|
-
_fields[_item.field_name].hidden = false;
|
|
85
|
-
}
|
|
86
|
-
_fields[_item.field_name].sort_no = sort_no;
|
|
87
|
-
sort_no++;
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
const layoutFieldKeys = _.keys(_fields);
|
|
91
|
-
const objectFieldKeys = _.keys(_object.fields);
|
|
92
|
-
const difference = _.difference(objectFieldKeys, layoutFieldKeys);
|
|
93
|
-
_.each(layoutFieldKeys, function (fieldApiName) {
|
|
94
|
-
_object.fields[fieldApiName] = _fields[fieldApiName];
|
|
95
|
-
});
|
|
96
|
-
_.each(difference, function (fieldApiName) {
|
|
97
|
-
_object.fields[fieldApiName].hidden = true;
|
|
98
|
-
_object.fields[fieldApiName].sort_no = 99999;
|
|
99
|
-
});
|
|
100
|
-
_.each(layout.buttons, function (button) {
|
|
101
|
-
const action = _object.actions[button.button_name];
|
|
102
|
-
if (action) {
|
|
103
|
-
if (button.visible_on) {
|
|
104
|
-
action._visible = button.visible_on;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
const layoutButtonsName = _.pluck(layout.buttons, 'button_name');
|
|
109
|
-
_.each(_object.actions, function (action) {
|
|
110
|
-
if (!_.include(layoutButtonsName, action.name)) {
|
|
111
|
-
action.visible = false;
|
|
112
|
-
action._visible = function () { return false; }.toString();
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
_object.related_lists = layout.related_lists || [];
|
|
116
|
-
_.each(_object.related_lists, (related_list) => {
|
|
117
|
-
if (related_list.sort_field_name && _.isArray(related_list.sort_field_name) && related_list.sort_field_name.length > 0) {
|
|
118
|
-
related_list.sort = [];
|
|
119
|
-
_.each(related_list.sort_field_name, (fName) => {
|
|
120
|
-
related_list.sort.push({ field_name: fName, order: related_list.sort_order || 'asc' });
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
return _object;
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
function getSpaceBootStrap(req, res) {
|
|
129
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
130
|
-
return Fiber(function () {
|
|
131
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
132
|
-
let userSession = req.user;
|
|
133
|
-
if (!userSession) {
|
|
134
|
-
return res.status(500).send();
|
|
135
|
-
}
|
|
136
|
-
let urlParams = req.params;
|
|
137
|
-
const { userId, language: lng } = userSession;
|
|
138
|
-
let spaceId = req.headers['x-space-id'] || urlParams.spaceId;
|
|
139
|
-
let [space, object_listviews, apps, assigned_apps, spaceProcessDefinition, dbListViews, layouts, objectsFieldsPermissionGroupRole, allRelationsInfo, _dbApps, _dbDashboards, assigned_menus, allImportTemplates] = yield Promise.all([
|
|
140
|
-
(0, objectql_1.getObject)("spaces").findOne(spaceId, { fields: ['name'] }),
|
|
141
|
-
getUserObjectsListViews(userId, spaceId),
|
|
142
|
-
(0, objectql_1.getAppConfigs)(spaceId),
|
|
143
|
-
(0, objectql_1.getAssignedApps)(userSession),
|
|
144
|
-
(0, objectql_1.getObject)("process_definition").find({ filters: [['space', '=', spaceId], ['active', '=', true]] }),
|
|
145
|
-
(0, objectql_1.getObject)("object_listviews").directFind({ filters: [['space', '=', userSession.spaceId], [['owner', '=', userSession.userId], 'or', ['shared', '=', true]]] }),
|
|
146
|
-
(0, objectql_1.getObjectLayouts)(userSession.profile, spaceId),
|
|
147
|
-
objectql_1.FieldPermission.getObjectsFieldsPermissionGroupRole(),
|
|
148
|
-
(0, objectql_1.getAllRelationsInfo)(),
|
|
149
|
-
(0, objectql_1.getObject)("apps").directFind({ filters: [['space', '=', spaceId], ['is_creator', '=', true]] }),
|
|
150
|
-
(0, objectql_1.getObject)("dashboard").directFind({ filters: [['space', '=', spaceId]] }),
|
|
151
|
-
(0, objectql_1.getAssignedMenus)(userSession),
|
|
152
|
-
(0, objectql_1.getSteedosSchema)().broker.call(`~packages-@steedos/data-import.getAllImportTemplates`, {}, { meta: { user: userSession } })
|
|
153
|
-
]);
|
|
154
|
-
let result = Creator.getAllPermissions(spaceId, userId);
|
|
155
|
-
steedosI18n.translationObjects(lng, result.objects);
|
|
156
|
-
result.user = userSession;
|
|
157
|
-
result.space = space;
|
|
158
|
-
result.dashboards = clone(Creator.Dashboards);
|
|
159
|
-
result.object_workflows = Meteor.call('object_workflows.get', spaceId, userId);
|
|
160
|
-
result.object_listviews = object_listviews;
|
|
161
|
-
result.apps = apps;
|
|
162
|
-
result.assigned_apps = assigned_apps;
|
|
163
|
-
let datasources = Creator.steedosSchema.getDataSources();
|
|
164
|
-
const spaceObjectsProcessDefinition = _.groupBy(spaceProcessDefinition, 'object_name');
|
|
165
|
-
const dbObjectsListViews = _.groupBy(dbListViews, 'object_name');
|
|
166
|
-
const objectsLayouts = _.groupBy(layouts, 'object_name');
|
|
167
|
-
for (const datasourceName in datasources) {
|
|
168
|
-
let datasource = datasources[datasourceName];
|
|
169
|
-
const datasourceObjects = yield datasource.getObjects();
|
|
170
|
-
for (const object of datasourceObjects) {
|
|
171
|
-
const objectConfig = object.metadata;
|
|
172
|
-
if (!result.objects[objectConfig.name] || objectConfig.name.endsWith("__c")) {
|
|
173
|
-
try {
|
|
174
|
-
const userObjectConfig = yield (0, objectql_1.getObject)(objectConfig.name).getRecordView(userSession, {
|
|
175
|
-
objectConfig: objectConfig,
|
|
176
|
-
layouts: objectsLayouts[objectConfig.name] || [],
|
|
177
|
-
spaceProcessDefinition: spaceObjectsProcessDefinition[objectConfig.name] || [],
|
|
178
|
-
dbListViews: dbObjectsListViews[objectConfig.name] || [],
|
|
179
|
-
rolesFieldsPermission: objectsFieldsPermissionGroupRole[objectConfig.name] || [],
|
|
180
|
-
relationsInfo: {
|
|
181
|
-
details: _.map(_.filter(allRelationsInfo.details, { objectName: objectConfig.name }), 'key'),
|
|
182
|
-
masters: _.map(_.filter(allRelationsInfo.masters, { objectName: objectConfig.name }), 'key'),
|
|
183
|
-
lookup_details: _.map(_.filter(allRelationsInfo.lookup_details, { objectName: objectConfig.name }))
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
let _objectConfig = null;
|
|
187
|
-
if (userObjectConfig) {
|
|
188
|
-
_objectConfig = userObjectConfig;
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
_objectConfig = clone(objectConfig);
|
|
192
|
-
}
|
|
193
|
-
const _obj = Creator.convertObject(_objectConfig, spaceId);
|
|
194
|
-
_obj.name = objectConfig.name;
|
|
195
|
-
_obj.database_name = datasourceName;
|
|
196
|
-
if (userObjectConfig) {
|
|
197
|
-
_obj.permission = userObjectConfig.permissions;
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
_obj.permissions = yield (0, objectql_1.getObject)(objectConfig.name).getUserObjectPermission(userSession);
|
|
201
|
-
steedosI18n.translationObject(lng, _obj.name, _obj);
|
|
202
|
-
}
|
|
203
|
-
result.objects[_obj.name] = _obj;
|
|
204
|
-
}
|
|
205
|
-
catch (error) {
|
|
206
|
-
console.error(error.message);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
let dbApps = {};
|
|
212
|
-
_.each(_dbApps, function (dbApp) {
|
|
213
|
-
if (dbApp.visible) {
|
|
214
|
-
return dbApps[dbApp._id] = dbApp;
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
result.apps = _.extend(result.apps || {}, dbApps);
|
|
218
|
-
let dbDashboards = {};
|
|
219
|
-
_.each(_dbDashboards, function (dashboard) {
|
|
220
|
-
dbDashboards[dashboard._id] = dashboard;
|
|
221
|
-
});
|
|
222
|
-
result.dashboards = _.extend(result.dashboards || {}, dbDashboards);
|
|
223
|
-
let _Apps = {};
|
|
224
|
-
_.each(result.apps, function (app, key) {
|
|
225
|
-
if (!app._id) {
|
|
226
|
-
app._id = key;
|
|
227
|
-
}
|
|
228
|
-
if (app.code) {
|
|
229
|
-
app._dbid = app._id;
|
|
230
|
-
app._id = app.code;
|
|
231
|
-
}
|
|
232
|
-
_Apps[app._id] = app;
|
|
233
|
-
});
|
|
234
|
-
_.each(_dbApps, function (dbApp) {
|
|
235
|
-
if (dbApp.visible === false) {
|
|
236
|
-
delete _Apps[dbApp.code];
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
steedosI18n.translationApps(lng, _Apps);
|
|
240
|
-
result.apps = _Apps;
|
|
241
|
-
steedosI18n.translationMenus(lng, assigned_menus);
|
|
242
|
-
result.assigned_menus = assigned_menus;
|
|
243
|
-
let _Dashboards = {};
|
|
244
|
-
_.each(result.dashboards, function (dashboard, key) {
|
|
245
|
-
if (!dashboard._id) {
|
|
246
|
-
dashboard._id = key;
|
|
247
|
-
}
|
|
248
|
-
_Dashboards[dashboard._id] = dashboard;
|
|
249
|
-
});
|
|
250
|
-
result.dashboards = _Dashboards;
|
|
251
|
-
result.plugins = core_1.getPlugins ? (0, core_1.getPlugins)() : null;
|
|
252
|
-
yield getUserObjects(userId, spaceId, result.objects);
|
|
253
|
-
_.each(spaceProcessDefinition, function (item) {
|
|
254
|
-
if (result.objects[item.object_name]) {
|
|
255
|
-
result.objects[item.object_name].enable_process = true;
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
for (const key in result.objects) {
|
|
259
|
-
if (Object.prototype.hasOwnProperty.call(result.objects, key)) {
|
|
260
|
-
const objectConfig = result.objects[key];
|
|
261
|
-
objectConfig.hasImportTemplates = !_.isEmpty(_.find(allImportTemplates, (item) => { return item.object_name === key; }));
|
|
262
|
-
try {
|
|
263
|
-
objectConfig.details = _.map(_.filter(allRelationsInfo.details, { objectName: key }), 'key');
|
|
264
|
-
objectConfig.masters = _.map(_.filter(allRelationsInfo.masters, { objectName: key }), 'key');
|
|
265
|
-
objectConfig.lookup_details = _.map(_.filter(allRelationsInfo.lookup_details, { objectName: key }));
|
|
266
|
-
_.each(objectConfig.triggers, function (trigger, key) {
|
|
267
|
-
if ((trigger === null || trigger === void 0 ? void 0 : trigger.on) != 'client') {
|
|
268
|
-
delete objectConfig.triggers[key];
|
|
269
|
-
}
|
|
270
|
-
});
|
|
271
|
-
delete objectConfig.listeners;
|
|
272
|
-
delete objectConfig.__filename;
|
|
273
|
-
delete objectConfig.extend;
|
|
274
|
-
}
|
|
275
|
-
catch (error) {
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
return res.status(200).send(result);
|
|
280
|
-
});
|
|
281
|
-
}).run();
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
exports.getSpaceBootStrap = getSpaceBootStrap;
|
|
285
|
-
function getObjectConfig(objectName, spaceId, userSession) {
|
|
286
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
287
|
-
let objectConfig = {};
|
|
288
|
-
try {
|
|
289
|
-
let object = (0, objectql_1.getObject)(objectName);
|
|
290
|
-
let _objectConfig = null;
|
|
291
|
-
const userObjectConfig = yield object.getRecordView(userSession);
|
|
292
|
-
if (userObjectConfig) {
|
|
293
|
-
_objectConfig = userObjectConfig;
|
|
294
|
-
}
|
|
295
|
-
else {
|
|
296
|
-
_objectConfig = clone(object.toConfig());
|
|
297
|
-
}
|
|
298
|
-
objectConfig = Creator.convertObject(_objectConfig, spaceId);
|
|
299
|
-
objectConfig.name = objectName;
|
|
300
|
-
objectConfig.datasource = object.datasource.name;
|
|
301
|
-
objectConfig.permissions = yield object.getUserObjectPermission(userSession);
|
|
302
|
-
const relationsInfo = yield object.getRelationsInfo();
|
|
303
|
-
objectConfig.details = relationsInfo.details;
|
|
304
|
-
objectConfig.masters = relationsInfo.masters;
|
|
305
|
-
objectConfig.lookup_details = relationsInfo.lookup_details;
|
|
306
|
-
return objectConfig;
|
|
307
|
-
}
|
|
308
|
-
catch (error) {
|
|
309
|
-
console.warn('not load object', objectName);
|
|
310
|
-
}
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
|
-
function getUserObjectsListViews(userId, spaceId) {
|
|
314
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
315
|
-
const listViews = {};
|
|
316
|
-
const objectsViews = yield (0, objectql_1.getObject)("object_listviews").find({ filters: [['space', '=', spaceId], [["owner", "=", userId], "or", ["shared", "=", true]]] });
|
|
317
|
-
let objectNames = _.pluck(objectsViews, 'object_name');
|
|
318
|
-
objectNames = _.uniq(objectNames);
|
|
319
|
-
const _getUserObjectListViews = function (object_name) {
|
|
320
|
-
var _user_object_list_views, olistViews;
|
|
321
|
-
_user_object_list_views = {};
|
|
322
|
-
olistViews = _.filter(objectsViews, function (ov) {
|
|
323
|
-
return ov.object_name === object_name;
|
|
324
|
-
});
|
|
325
|
-
_.each(olistViews, function (listview) {
|
|
326
|
-
return _user_object_list_views[listview._id] = listview;
|
|
327
|
-
});
|
|
328
|
-
return _user_object_list_views;
|
|
329
|
-
};
|
|
330
|
-
_.forEach(objectNames, function (key) {
|
|
331
|
-
var list_view;
|
|
332
|
-
list_view = _getUserObjectListViews(key);
|
|
333
|
-
if (!_.isEmpty(list_view)) {
|
|
334
|
-
return listViews[key] = list_view;
|
|
335
|
-
}
|
|
336
|
-
});
|
|
337
|
-
return listViews;
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
;
|
|
341
|
-
function getSpaceObjectBootStrap(req, res) {
|
|
342
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
343
|
-
return Fiber(function () {
|
|
344
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
345
|
-
let userSession = req.user;
|
|
346
|
-
let userId = userSession.userId;
|
|
347
|
-
let urlParams = req.params;
|
|
348
|
-
let spaceId = req.headers['x-space-id'] || urlParams.spaceId;
|
|
349
|
-
if (!userSession) {
|
|
350
|
-
return res.status(500).send();
|
|
351
|
-
}
|
|
352
|
-
const objectNames = urlParams.objectNames;
|
|
353
|
-
const objects = {};
|
|
354
|
-
if (objectNames) {
|
|
355
|
-
const objectNamesArray = objectNames.split(',');
|
|
356
|
-
let dbObjects = Creator.getCollection('objects').find({ name: { $in: objectNamesArray } }).fetch() || [];
|
|
357
|
-
let creatorObjects = Creator.getAllPermissions(spaceId, userId).objects;
|
|
358
|
-
let lng = userSession.language;
|
|
359
|
-
for (const objectName of objectNamesArray) {
|
|
360
|
-
let _object = _.find(dbObjects, function (item) { return item.name === objectName; }) || {};
|
|
361
|
-
let objectConfig = {};
|
|
362
|
-
if (_.isEmpty(_object)) {
|
|
363
|
-
objectConfig = creatorObjects[objectName];
|
|
364
|
-
if (_.isEmpty(objectConfig)) {
|
|
365
|
-
objectConfig = yield getObjectConfig(objectName, spaceId, userSession);
|
|
366
|
-
}
|
|
367
|
-
else {
|
|
368
|
-
const object = (0, objectql_1.getObject)(objectName);
|
|
369
|
-
const relationsInfo = yield object.getRelationsInfo();
|
|
370
|
-
objectConfig.details = relationsInfo.details;
|
|
371
|
-
objectConfig.masters = relationsInfo.masters;
|
|
372
|
-
objectConfig.lookup_details = relationsInfo.lookup_details;
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
else {
|
|
376
|
-
if (userSession.is_space_admin || _object.in_development == '0' && _object.is_enable) {
|
|
377
|
-
if (_object.datasource == 'meteor') {
|
|
378
|
-
objectConfig = creatorObjects[objectName];
|
|
379
|
-
const object = (0, objectql_1.getObject)(objectName);
|
|
380
|
-
const relationsInfo = yield object.getRelationsInfo();
|
|
381
|
-
objectConfig.details = relationsInfo.details;
|
|
382
|
-
objectConfig.masters = relationsInfo.masters;
|
|
383
|
-
objectConfig.lookup_details = relationsInfo.lookup_details;
|
|
384
|
-
}
|
|
385
|
-
else {
|
|
386
|
-
objectConfig = yield getObjectConfig(objectName, spaceId, userSession);
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
if (objectConfig) {
|
|
391
|
-
delete objectConfig.db;
|
|
392
|
-
steedosI18n.translationObject(lng, objectConfig.name, objectConfig);
|
|
393
|
-
objectConfig = yield getUserObject(userId, spaceId, objectConfig);
|
|
394
|
-
let spaceProcessDefinition = yield (0, objectql_1.getObject)("process_definition").directFind({ filters: [['space', '=', spaceId], ['object_name', '=', objectName], ['active', '=', true]] });
|
|
395
|
-
if (spaceProcessDefinition.length > 0) {
|
|
396
|
-
objectConfig.enable_process = true;
|
|
397
|
-
}
|
|
398
|
-
_.each(objectConfig.triggers, function (trigger, key) {
|
|
399
|
-
if ((trigger === null || trigger === void 0 ? void 0 : trigger.on) != 'client') {
|
|
400
|
-
delete objectConfig.triggers[key];
|
|
401
|
-
}
|
|
402
|
-
});
|
|
403
|
-
objectConfig.hasImportTemplates = yield (0, objectql_1.getSteedosSchema)().broker.call(`~packages-@steedos/data-import.hasImportTemplates`, {
|
|
404
|
-
objectName: objectConfig.name
|
|
405
|
-
}, { meta: { user: userSession } });
|
|
406
|
-
delete objectConfig.listeners;
|
|
407
|
-
delete objectConfig.__filename;
|
|
408
|
-
delete objectConfig.extend;
|
|
409
|
-
objects[objectConfig.name] = objectConfig;
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
return res.status(200).send({
|
|
414
|
-
objects: objects
|
|
415
|
-
});
|
|
416
|
-
});
|
|
417
|
-
}).run();
|
|
418
|
-
});
|
|
419
|
-
}
|
|
420
|
-
exports.getSpaceObjectBootStrap = getSpaceObjectBootStrap;
|
|
421
|
-
router.use('/api/bootstrap/:spaceId/:objectNames', core_1.requireAuthentication, getSpaceObjectBootStrap);
|
|
422
|
-
router.use('/api/bootstrap/:spaceId/', core_1.requireAuthentication, getSpaceBootStrap);
|
|
423
|
-
exports.default = router;
|
|
@@ -1,481 +0,0 @@
|
|
|
1
|
-
import steedosI18n = require("@steedos/i18n");
|
|
2
|
-
import { getPlugins, requireAuthentication } from '@steedos/core';
|
|
3
|
-
import { getObject, getObjectLayouts, getLayout, getAppConfigs, getAssignedMenus, getAssignedApps, getAllRelationsInfo, FieldPermission, getSteedosSchema } from '@steedos/objectql'
|
|
4
|
-
//
|
|
5
|
-
require("@steedos/license");
|
|
6
|
-
const Fiber = require('fibers')
|
|
7
|
-
const clone = require("clone");
|
|
8
|
-
const _ = require('underscore');
|
|
9
|
-
|
|
10
|
-
const express = require('express');
|
|
11
|
-
const router =express.Router();
|
|
12
|
-
|
|
13
|
-
async function getUserProfileObjectsLayout(userId, spaceId, objectName?) {
|
|
14
|
-
let spaceUser;
|
|
15
|
-
let spaceUsers = await getObject("space_users").directFind({filters: [['space', '=', spaceId], ['user', '=', userId]]});
|
|
16
|
-
if(spaceUsers.length > 0){
|
|
17
|
-
spaceUser = spaceUsers[0];
|
|
18
|
-
}
|
|
19
|
-
if (spaceUser && spaceUser.profile) {
|
|
20
|
-
// let filters = [['space', '=', spaceId],['profiles', '=', spaceUser.profile]];
|
|
21
|
-
// if(objectName){
|
|
22
|
-
// filters.push(['object_name', '=', objectName])
|
|
23
|
-
// }
|
|
24
|
-
// return await getObject("object_layouts").directFind({filters: filters})
|
|
25
|
-
return await getObjectLayouts(spaceUser.profile, spaceId, objectName)
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
async function getUserObjects(userId, spaceId, objects){
|
|
30
|
-
const objectsLayout = await getUserProfileObjectsLayout(userId, spaceId);
|
|
31
|
-
for (const objectName in objects) {
|
|
32
|
-
// objects[objectName].list_views = await getUserObjectListViews(userId, spaceId, objectName)
|
|
33
|
-
let userObjectLayout = null;
|
|
34
|
-
if(objectsLayout){
|
|
35
|
-
userObjectLayout = _.find(objectsLayout, function(objectLayout){
|
|
36
|
-
return objectLayout.object_name === objectName
|
|
37
|
-
})
|
|
38
|
-
}
|
|
39
|
-
if(!userObjectLayout && false){
|
|
40
|
-
userObjectLayout = getLayout(objectName, 'default');
|
|
41
|
-
}
|
|
42
|
-
if(userObjectLayout){
|
|
43
|
-
objects[userObjectLayout.object_name] = await getUserObject(userId, spaceId, objects[userObjectLayout.object_name], userObjectLayout)
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async function getUserObject(userId, spaceId, object, layout?){
|
|
49
|
-
if(!layout){
|
|
50
|
-
const layouts = await getUserProfileObjectsLayout(userId, spaceId, object.name);
|
|
51
|
-
if(layouts && layouts.length > 0){
|
|
52
|
-
layout = layouts[0];
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
let _object = clone(object);
|
|
56
|
-
if(_object && layout){
|
|
57
|
-
_.each(_object.actions, (action, key) => {
|
|
58
|
-
if (!_.has(action, 'name')) {
|
|
59
|
-
action.name = key;
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
let _fields = {};
|
|
63
|
-
let sort_no = 1;
|
|
64
|
-
_.each(layout.fields, function(_item){
|
|
65
|
-
_fields[_item.field_name] = _object.fields[_item.field_name]
|
|
66
|
-
if(_fields[_item.field_name]){
|
|
67
|
-
if(_.has(_item, 'group')){
|
|
68
|
-
_fields[_item.field_name].group = _item.group
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if(_item.is_required){
|
|
72
|
-
_fields[_item.field_name].readonly = false
|
|
73
|
-
_fields[_item.field_name].disabled = false
|
|
74
|
-
_fields[_item.field_name].required = true
|
|
75
|
-
}else if(_item.is_readonly){
|
|
76
|
-
_fields[_item.field_name].readonly = true
|
|
77
|
-
_fields[_item.field_name].disabled = true
|
|
78
|
-
_fields[_item.field_name].required = false
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if(_item.visible_on){
|
|
82
|
-
_fields[_item.field_name].visible_on = _item.visible_on
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if(['created','created_by','modified','modified_by'].indexOf(_item.field_name) < 0){
|
|
86
|
-
_fields[_item.field_name].omit = false;
|
|
87
|
-
_fields[_item.field_name].hidden = false;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
_fields[_item.field_name].sort_no = sort_no;
|
|
91
|
-
sort_no++;
|
|
92
|
-
}
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
const layoutFieldKeys = _.keys(_fields);
|
|
96
|
-
const objectFieldKeys = _.keys(_object.fields);
|
|
97
|
-
|
|
98
|
-
const difference = _.difference(objectFieldKeys, layoutFieldKeys);
|
|
99
|
-
|
|
100
|
-
_.each(layoutFieldKeys, function(fieldApiName){
|
|
101
|
-
_object.fields[fieldApiName] = _fields[fieldApiName];
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
_.each(difference, function(fieldApiName){
|
|
105
|
-
_object.fields[fieldApiName].hidden = true;
|
|
106
|
-
_object.fields[fieldApiName].sort_no = 99999;
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
// let _buttons = {};
|
|
110
|
-
_.each(layout.buttons, function(button){
|
|
111
|
-
const action = _object.actions[button.button_name];
|
|
112
|
-
if(action){
|
|
113
|
-
if(button.visible_on){
|
|
114
|
-
action._visible = button.visible_on;
|
|
115
|
-
}
|
|
116
|
-
// _buttons[button.button_name] = action
|
|
117
|
-
}
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
const layoutButtonsName = _.pluck(layout.buttons,'button_name');
|
|
121
|
-
_.each(_object.actions, function(action){
|
|
122
|
-
if(!_.include(layoutButtonsName, action.name)){
|
|
123
|
-
action.visible = false
|
|
124
|
-
action._visible = function(){return false}.toString()
|
|
125
|
-
}
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
// _object.actions = _buttons;
|
|
129
|
-
// _object.allow_customActions = userObjectLayout.custom_actions || []
|
|
130
|
-
// _object.exclude_actions = userObjectLayout.exclude_actions || []
|
|
131
|
-
_object.related_lists = layout.related_lists || []
|
|
132
|
-
_.each(_object.related_lists, (related_list)=>{
|
|
133
|
-
if(related_list.sort_field_name && _.isArray(related_list.sort_field_name) && related_list.sort_field_name.length > 0){
|
|
134
|
-
related_list.sort = [];
|
|
135
|
-
_.each(related_list.sort_field_name, (fName)=>{
|
|
136
|
-
related_list.sort.push({field_name: fName, order: related_list.sort_order || 'asc'})
|
|
137
|
-
})
|
|
138
|
-
}
|
|
139
|
-
})
|
|
140
|
-
}
|
|
141
|
-
return _object;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
export async function getSpaceBootStrap(req, res) {
|
|
146
|
-
return Fiber(async function () {
|
|
147
|
-
let userSession = req.user;
|
|
148
|
-
|
|
149
|
-
if (!userSession) {
|
|
150
|
-
return res.status(500).send();
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
let urlParams = req.params;
|
|
154
|
-
const { userId, language: lng} = userSession;
|
|
155
|
-
|
|
156
|
-
let spaceId = req.headers['x-space-id'] || urlParams.spaceId
|
|
157
|
-
|
|
158
|
-
let [ space , object_listviews, apps, assigned_apps, spaceProcessDefinition, dbListViews, layouts, objectsFieldsPermissionGroupRole, allRelationsInfo, _dbApps, _dbDashboards, assigned_menus, allImportTemplates] = await Promise.all([
|
|
159
|
-
getObject("spaces").findOne(spaceId, { fields: ['name'] }),
|
|
160
|
-
getUserObjectsListViews(userId, spaceId),
|
|
161
|
-
getAppConfigs(spaceId),
|
|
162
|
-
getAssignedApps(userSession),
|
|
163
|
-
getObject("process_definition").find({ filters: [['space', '=', spaceId], ['active', '=', true]] }),
|
|
164
|
-
getObject("object_listviews").directFind({ filters: [['space', '=', userSession.spaceId], [['owner', '=', userSession.userId], 'or', ['shared', '=', true]]] }),
|
|
165
|
-
getObjectLayouts(userSession.profile, spaceId),
|
|
166
|
-
FieldPermission.getObjectsFieldsPermissionGroupRole(),
|
|
167
|
-
getAllRelationsInfo(),
|
|
168
|
-
getObject("apps").directFind({filters: [['space', '=', spaceId],['is_creator', '=', true]]}),
|
|
169
|
-
getObject("dashboard").directFind({filters: [['space', '=', spaceId]]}),
|
|
170
|
-
getAssignedMenus(userSession),
|
|
171
|
-
getSteedosSchema().broker.call(`~packages-@steedos/data-import.getAllImportTemplates`, {}, { meta: { user: userSession}})
|
|
172
|
-
])
|
|
173
|
-
|
|
174
|
-
//TODO 无需再从getAllPermissions中获取用户的对象权限
|
|
175
|
-
let result = Creator.getAllPermissions(spaceId, userId);
|
|
176
|
-
steedosI18n.translationObjects(lng, result.objects);
|
|
177
|
-
result.user = userSession
|
|
178
|
-
|
|
179
|
-
result.space = space
|
|
180
|
-
|
|
181
|
-
result.dashboards = clone(Creator.Dashboards)
|
|
182
|
-
// TODO 删除此代码, 逻辑重新调整, 提供单独的接口处理此问题: 对象可创建流程的清单接口
|
|
183
|
-
result.object_workflows = Meteor.call('object_workflows.get', spaceId, userId)
|
|
184
|
-
result.object_listviews = object_listviews
|
|
185
|
-
// result.apps = clone(Creator.Apps)
|
|
186
|
-
result.apps = apps
|
|
187
|
-
result.assigned_apps = assigned_apps;
|
|
188
|
-
let datasources = Creator.steedosSchema.getDataSources();
|
|
189
|
-
// for (const datasourceName in datasources) {
|
|
190
|
-
// if(datasourceName != 'default'){
|
|
191
|
-
// let datasource = datasources[datasourceName];
|
|
192
|
-
// const datasourceObjects = datasource.getObjects();
|
|
193
|
-
// for (const objectName in datasourceObjects) {
|
|
194
|
-
// const object = datasourceObjects[objectName];
|
|
195
|
-
// const _obj = Creator.convertObject(clone(object.toConfig()), spaceId)
|
|
196
|
-
// _obj.name = objectName
|
|
197
|
-
// _obj.database_name = datasourceName
|
|
198
|
-
// _obj.permissions = await object.getUserObjectPermission(userSession)
|
|
199
|
-
// result.objects[_obj.name] = _obj
|
|
200
|
-
// }
|
|
201
|
-
// }
|
|
202
|
-
// }
|
|
203
|
-
const spaceObjectsProcessDefinition = _.groupBy(spaceProcessDefinition, 'object_name');
|
|
204
|
-
|
|
205
|
-
const dbObjectsListViews = _.groupBy(dbListViews, 'object_name');
|
|
206
|
-
|
|
207
|
-
const objectsLayouts = _.groupBy(layouts, 'object_name');
|
|
208
|
-
|
|
209
|
-
for (const datasourceName in datasources) {
|
|
210
|
-
let datasource = datasources[datasourceName];
|
|
211
|
-
const datasourceObjects = await datasource.getObjects();
|
|
212
|
-
for (const object of datasourceObjects) {
|
|
213
|
-
const objectConfig = object.metadata;
|
|
214
|
-
if (!result.objects[objectConfig.name] || objectConfig.name.endsWith("__c")) {
|
|
215
|
-
try {
|
|
216
|
-
const userObjectConfig = await getObject(objectConfig.name).getRecordView(userSession, {
|
|
217
|
-
objectConfig: objectConfig,
|
|
218
|
-
layouts: objectsLayouts[objectConfig.name] || [],
|
|
219
|
-
spaceProcessDefinition: spaceObjectsProcessDefinition[objectConfig.name] || [],
|
|
220
|
-
dbListViews: dbObjectsListViews[objectConfig.name] || [],
|
|
221
|
-
rolesFieldsPermission: objectsFieldsPermissionGroupRole[objectConfig.name] || [],
|
|
222
|
-
relationsInfo: {
|
|
223
|
-
details: _.map(_.filter(allRelationsInfo.details, {objectName: objectConfig.name}), 'key'),
|
|
224
|
-
masters: _.map(_.filter(allRelationsInfo.masters, {objectName: objectConfig.name}), 'key'),
|
|
225
|
-
lookup_details: _.map(_.filter(allRelationsInfo.lookup_details, {objectName: objectConfig.name}))
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
let _objectConfig = null;
|
|
229
|
-
if (userObjectConfig) {
|
|
230
|
-
_objectConfig = userObjectConfig
|
|
231
|
-
} else {
|
|
232
|
-
_objectConfig = clone(objectConfig)
|
|
233
|
-
}
|
|
234
|
-
const _obj = Creator.convertObject(_objectConfig, spaceId)
|
|
235
|
-
_obj.name = objectConfig.name
|
|
236
|
-
_obj.database_name = datasourceName
|
|
237
|
-
if (userObjectConfig) {
|
|
238
|
-
_obj.permission = userObjectConfig.permissions
|
|
239
|
-
} else {
|
|
240
|
-
_obj.permissions = await getObject(objectConfig.name).getUserObjectPermission(userSession)
|
|
241
|
-
steedosI18n.translationObject(lng, _obj.name, _obj);
|
|
242
|
-
}
|
|
243
|
-
result.objects[_obj.name] = _obj
|
|
244
|
-
} catch (error) {
|
|
245
|
-
console.error(error.message)
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
let dbApps = {};
|
|
252
|
-
_.each(_dbApps, function(dbApp){
|
|
253
|
-
if(dbApp.visible){
|
|
254
|
-
return dbApps[dbApp._id] = dbApp;
|
|
255
|
-
}
|
|
256
|
-
})
|
|
257
|
-
|
|
258
|
-
result.apps = _.extend( result.apps || {}, dbApps);
|
|
259
|
-
|
|
260
|
-
let dbDashboards = {};
|
|
261
|
-
_.each(_dbDashboards, function(dashboard){
|
|
262
|
-
dbDashboards[dashboard._id] = dashboard;
|
|
263
|
-
})
|
|
264
|
-
result.dashboards = _.extend( result.dashboards || {}, dbDashboards)
|
|
265
|
-
|
|
266
|
-
let _Apps = {}
|
|
267
|
-
_.each(result.apps, function(app, key){
|
|
268
|
-
if(!app._id){
|
|
269
|
-
app._id = key
|
|
270
|
-
}
|
|
271
|
-
if(app.code){
|
|
272
|
-
app._dbid = app._id
|
|
273
|
-
app._id = app.code
|
|
274
|
-
}
|
|
275
|
-
_Apps[app._id] = app
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
_.each(_dbApps, function(dbApp){
|
|
279
|
-
if(dbApp.visible === false){
|
|
280
|
-
delete _Apps[dbApp.code];
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
steedosI18n.translationApps(lng, _Apps);
|
|
285
|
-
result.apps = _Apps;
|
|
286
|
-
steedosI18n.translationMenus(lng, assigned_menus);
|
|
287
|
-
result.assigned_menus = assigned_menus;
|
|
288
|
-
|
|
289
|
-
let _Dashboards = {}
|
|
290
|
-
_.each( result.dashboards, function(dashboard, key){
|
|
291
|
-
if(!dashboard._id){
|
|
292
|
-
dashboard._id = key
|
|
293
|
-
}
|
|
294
|
-
_Dashboards[dashboard._id] = dashboard
|
|
295
|
-
})
|
|
296
|
-
result.dashboards = _Dashboards
|
|
297
|
-
|
|
298
|
-
result.plugins = getPlugins ? getPlugins() : null
|
|
299
|
-
await getUserObjects(userId, spaceId, result.objects);
|
|
300
|
-
// TODO object layout 是否需要控制审批记录显示?
|
|
301
|
-
_.each(spaceProcessDefinition, function(item){
|
|
302
|
-
if(result.objects[item.object_name]){
|
|
303
|
-
result.objects[item.object_name].enable_process = true
|
|
304
|
-
}
|
|
305
|
-
})
|
|
306
|
-
|
|
307
|
-
for (const key in result.objects) {
|
|
308
|
-
if (Object.prototype.hasOwnProperty.call(result.objects, key)) {
|
|
309
|
-
const objectConfig = result.objects[key];
|
|
310
|
-
objectConfig.hasImportTemplates = !_.isEmpty(_.find(allImportTemplates, (item)=>{return item.object_name === key}))
|
|
311
|
-
try {
|
|
312
|
-
// const object = getObject(key);
|
|
313
|
-
// const relationsInfo = await object.getRelationsInfo();
|
|
314
|
-
// objectConfig.details = relationsInfo.details;
|
|
315
|
-
// objectConfig.masters = relationsInfo.masters;
|
|
316
|
-
// objectConfig.lookup_details = relationsInfo.lookup_details;
|
|
317
|
-
objectConfig.details = _.map(_.filter(allRelationsInfo.details, {objectName: key}), 'key');
|
|
318
|
-
objectConfig.masters = _.map(_.filter(allRelationsInfo.masters, {objectName: key}), 'key');
|
|
319
|
-
objectConfig.lookup_details = _.map(_.filter(allRelationsInfo.lookup_details, {objectName: key}));
|
|
320
|
-
_.each(objectConfig.triggers, function(trigger, key){
|
|
321
|
-
if(trigger?.on != 'client'){
|
|
322
|
-
delete objectConfig.triggers[key];
|
|
323
|
-
}
|
|
324
|
-
})
|
|
325
|
-
delete objectConfig.listeners
|
|
326
|
-
delete objectConfig.__filename
|
|
327
|
-
delete objectConfig.extend
|
|
328
|
-
} catch (error) {
|
|
329
|
-
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
return res.status(200).send(result);
|
|
334
|
-
}).run();
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
async function getObjectConfig(objectName, spaceId, userSession) {
|
|
338
|
-
let objectConfig: any = {}
|
|
339
|
-
try {
|
|
340
|
-
let object = getObject(objectName)
|
|
341
|
-
let _objectConfig = null;
|
|
342
|
-
const userObjectConfig = await object.getRecordView(userSession);
|
|
343
|
-
if (userObjectConfig) {
|
|
344
|
-
_objectConfig = userObjectConfig
|
|
345
|
-
} else {
|
|
346
|
-
_objectConfig = clone(object.toConfig())
|
|
347
|
-
}
|
|
348
|
-
objectConfig = Creator.convertObject(_objectConfig, spaceId);
|
|
349
|
-
objectConfig.name = objectName
|
|
350
|
-
objectConfig.datasource = object.datasource.name;
|
|
351
|
-
objectConfig.permissions = await object.getUserObjectPermission(userSession);
|
|
352
|
-
const relationsInfo = await object.getRelationsInfo();
|
|
353
|
-
objectConfig.details = relationsInfo.details;
|
|
354
|
-
objectConfig.masters = relationsInfo.masters;
|
|
355
|
-
objectConfig.lookup_details = relationsInfo.lookup_details;
|
|
356
|
-
return objectConfig;
|
|
357
|
-
} catch (error) {
|
|
358
|
-
console.warn('not load object', objectName)
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
async function getUserObjectsListViews(userId, spaceId) {
|
|
363
|
-
const listViews = {};
|
|
364
|
-
const objectsViews = await getObject("object_listviews").find({filters: [['space', '=', spaceId],[ [ "owner", "=", userId ], "or", [ "shared", "=", true ] ]]});
|
|
365
|
-
let objectNames = _.pluck(objectsViews, 'object_name');
|
|
366
|
-
objectNames = _.uniq(objectNames);
|
|
367
|
-
const _getUserObjectListViews = function(object_name) {
|
|
368
|
-
var _user_object_list_views, olistViews;
|
|
369
|
-
_user_object_list_views = {};
|
|
370
|
-
olistViews = _.filter(objectsViews, function(ov) {
|
|
371
|
-
return ov.object_name === object_name;
|
|
372
|
-
});
|
|
373
|
-
_.each(olistViews, function(listview) {
|
|
374
|
-
return _user_object_list_views[listview._id] = listview;
|
|
375
|
-
});
|
|
376
|
-
return _user_object_list_views;
|
|
377
|
-
};
|
|
378
|
-
_.forEach(objectNames, function(key) {
|
|
379
|
-
var list_view;
|
|
380
|
-
list_view = _getUserObjectListViews(key);
|
|
381
|
-
if (!_.isEmpty(list_view)) {
|
|
382
|
-
return listViews[key] = list_view;
|
|
383
|
-
}
|
|
384
|
-
});
|
|
385
|
-
return listViews;
|
|
386
|
-
};
|
|
387
|
-
|
|
388
|
-
// async function getUserObjectListViews(userId, spaceId, object_name){
|
|
389
|
-
// const _user_object_list_views = {};
|
|
390
|
-
// const object_listview = await getObject("object_listviews").find({filters: [['object_name', '=', object_name],['space', '=', spaceId],[ [ "owner", "=", userId ], "or", [ "shared", "=", true ] ]]});
|
|
391
|
-
// object_listview.forEach(function(listview) {
|
|
392
|
-
// return _user_object_list_views[listview._id] = listview;
|
|
393
|
-
// });
|
|
394
|
-
// return _user_object_list_views;
|
|
395
|
-
// }
|
|
396
|
-
|
|
397
|
-
export async function getSpaceObjectBootStrap(req, res) {
|
|
398
|
-
return Fiber(async function () {
|
|
399
|
-
let userSession = req.user;
|
|
400
|
-
let userId = userSession.userId;
|
|
401
|
-
let urlParams = req.params;
|
|
402
|
-
let spaceId = req.headers['x-space-id'] || urlParams.spaceId
|
|
403
|
-
if (!userSession) {
|
|
404
|
-
return res.status(500).send();
|
|
405
|
-
}
|
|
406
|
-
const objectNames = urlParams.objectNames
|
|
407
|
-
const objects = {};
|
|
408
|
-
if (objectNames) {
|
|
409
|
-
const objectNamesArray = objectNames.split(',');
|
|
410
|
-
let dbObjects = Creator.getCollection('objects').find({ name: { $in: objectNamesArray } }).fetch() || []
|
|
411
|
-
let creatorObjects = Creator.getAllPermissions(spaceId, userId).objects;
|
|
412
|
-
let lng = userSession.language;
|
|
413
|
-
for (const objectName of objectNamesArray) {
|
|
414
|
-
let _object = _.find(dbObjects, function (item) { return item.name === objectName }) || {}
|
|
415
|
-
let objectConfig: any = {}
|
|
416
|
-
if (_.isEmpty(_object)) {
|
|
417
|
-
objectConfig = creatorObjects[objectName];
|
|
418
|
-
if (_.isEmpty(objectConfig)) {
|
|
419
|
-
objectConfig = await getObjectConfig(objectName, spaceId, userSession);
|
|
420
|
-
} else {
|
|
421
|
-
const object = getObject(objectName);
|
|
422
|
-
const relationsInfo = await object.getRelationsInfo();
|
|
423
|
-
objectConfig.details = relationsInfo.details;
|
|
424
|
-
objectConfig.masters = relationsInfo.masters;
|
|
425
|
-
objectConfig.lookup_details = relationsInfo.lookup_details;
|
|
426
|
-
}
|
|
427
|
-
} else {
|
|
428
|
-
if (userSession.is_space_admin || _object.in_development == '0' && _object.is_enable) {
|
|
429
|
-
if (_object.datasource == 'meteor') {
|
|
430
|
-
objectConfig = creatorObjects[objectName]
|
|
431
|
-
const object = getObject(objectName);
|
|
432
|
-
const relationsInfo = await object.getRelationsInfo();
|
|
433
|
-
objectConfig.details = relationsInfo.details;
|
|
434
|
-
objectConfig.masters = relationsInfo.masters;
|
|
435
|
-
objectConfig.lookup_details = relationsInfo.lookup_details;
|
|
436
|
-
} else {
|
|
437
|
-
objectConfig = await getObjectConfig(objectName, spaceId, userSession);
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
if (objectConfig) {
|
|
442
|
-
delete objectConfig.db
|
|
443
|
-
// objectConfig.list_views = await getUserObjectListViews(userId, spaceId, objectName)
|
|
444
|
-
steedosI18n.translationObject(lng, objectConfig.name, objectConfig)
|
|
445
|
-
|
|
446
|
-
objectConfig = await getUserObject(userId, spaceId, objectConfig)
|
|
447
|
-
|
|
448
|
-
// TODO object layout 是否需要控制审批记录显示?
|
|
449
|
-
let spaceProcessDefinition = await getObject("process_definition").directFind({ filters: [['space', '=', spaceId], ['object_name', '=', objectName], ['active', '=', true]] })
|
|
450
|
-
if (spaceProcessDefinition.length > 0) {
|
|
451
|
-
objectConfig.enable_process = true
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
_.each(objectConfig.triggers, function (trigger, key) {
|
|
455
|
-
if (trigger?.on != 'client') {
|
|
456
|
-
delete objectConfig.triggers[key];
|
|
457
|
-
}
|
|
458
|
-
})
|
|
459
|
-
|
|
460
|
-
objectConfig.hasImportTemplates = await getSteedosSchema().broker.call(`~packages-@steedos/data-import.hasImportTemplates`, {
|
|
461
|
-
objectName: objectConfig.name
|
|
462
|
-
}, { meta: { user: userSession}})
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
delete objectConfig.listeners
|
|
466
|
-
delete objectConfig.__filename
|
|
467
|
-
delete objectConfig.extend
|
|
468
|
-
objects[objectConfig.name] = objectConfig;
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
return res.status(200).send({
|
|
473
|
-
objects: objects
|
|
474
|
-
});
|
|
475
|
-
}).run();
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
router.use('/api/bootstrap/:spaceId/:objectNames', requireAuthentication, getSpaceObjectBootStrap)
|
|
479
|
-
router.use('/api/bootstrap/:spaceId/', requireAuthentication, getSpaceBootStrap)
|
|
480
|
-
|
|
481
|
-
exports.default = router;
|