@steedos/service-ui 2.2.41
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/LICENSE.txt +25 -0
- package/main/default/objects/.gitkeep +0 -0
- package/main/default/permissionsets/.gitkeep +0 -0
- package/main/default/profiles/.gitkeep +0 -0
- package/main/default/routes/apps.router.js +27 -0
- package/main/default/routes/bootstrap.router.js +457 -0
- package/main/default/routes/objects.router.js +114 -0
- package/main/default/routes/objects.router.todo.js +22 -0
- package/main/default/tabs/.gitkeep +0 -0
- package/main/default/triggers/.gitkeep +0 -0
- package/package.json +23 -0
- package/package.service.js +69 -0
- package/src/routes/apps.router.ts +23 -0
- package/src/routes/bootstrap.router.ts +466 -0
- package/src/routes/declare.d.ts +7 -0
- package/src/routes/objects.router.ts +99 -0
- package/tsconfig.json +37 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Steedos Licensing
|
|
2
|
+
|
|
3
|
+
SOFTWARE LICENSING
|
|
4
|
+
|
|
5
|
+
To determine under which license you may use a file from the Steedos source code,
|
|
6
|
+
please resort to the header of that file.
|
|
7
|
+
|
|
8
|
+
If the file has no header, the following rules apply
|
|
9
|
+
1. project templates are licensed under MIT, see License.MIT.txt
|
|
10
|
+
2. enterprise features are licensed under Steedos Enterprise Terms, see License.enterprise.txt
|
|
11
|
+
3. source code that is neither (1) nor (2) is licensed under AGPL, see License.AGPL.txt
|
|
12
|
+
|
|
13
|
+
On request, licenses under different terms are available.
|
|
14
|
+
|
|
15
|
+
Project templates can be found in the folders steedos-projects/
|
|
16
|
+
|
|
17
|
+
Source code of enterprise features are files that
|
|
18
|
+
* are in folders named "ee" or start with "ee_", or in subfolders of such folders.
|
|
19
|
+
* contain the strings "ee_" in its filename name.
|
|
20
|
+
The files can be found by running the command `find . -iname ee -or -iname "*_ee*" -or -iname "*ee_*"`
|
|
21
|
+
|
|
22
|
+
STEEDOS TRADEMARK GUIDELINES
|
|
23
|
+
|
|
24
|
+
Your use of the mark Steedos is subject to Steedos, Inc's prior written approval. For trademark approval or any questions
|
|
25
|
+
you have about using these trademarks, please email zhuangjianguo@steedos.com
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
/*
|
|
5
|
+
* @Author: baozhoutao@steedos.com
|
|
6
|
+
* @Date: 2022-06-08 23:28:39
|
|
7
|
+
* @LastEditors: baozhoutao@steedos.com
|
|
8
|
+
* @LastEditTime: 2022-06-09 10:21:45
|
|
9
|
+
* @Description:
|
|
10
|
+
*/
|
|
11
|
+
const express = require("express");
|
|
12
|
+
const core_1 = require("@steedos/core");
|
|
13
|
+
const objectql_1 = require("@steedos/objectql");
|
|
14
|
+
const router = express.Router();
|
|
15
|
+
router.get('/service/api/apps/menus', core_1.requireAuthentication, function (req, res) {
|
|
16
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const userSession = req.user;
|
|
18
|
+
try {
|
|
19
|
+
const result = yield (0, objectql_1.getSteedosSchema)().broker.call('apps.getMenus', {}, { meta: { user: userSession } });
|
|
20
|
+
res.status(200).send(result);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
res.status(500).send(error.message);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
exports.default = router;
|
|
@@ -0,0 +1,457 @@
|
|
|
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
|
+
//
|
|
9
|
+
require("@steedos/license");
|
|
10
|
+
const Fiber = require('fibers');
|
|
11
|
+
const clone = require("clone");
|
|
12
|
+
const _ = require('underscore');
|
|
13
|
+
var express = require('express');
|
|
14
|
+
const bootStrapExpress = express.Router();
|
|
15
|
+
function getUserProfileObjectsLayout(userId, spaceId, objectName) {
|
|
16
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
let spaceUser;
|
|
18
|
+
let spaceUsers = yield (0, objectql_1.getObject)("space_users").directFind({ filters: [['space', '=', spaceId], ['user', '=', userId]] });
|
|
19
|
+
if (spaceUsers.length > 0) {
|
|
20
|
+
spaceUser = spaceUsers[0];
|
|
21
|
+
}
|
|
22
|
+
if (spaceUser && spaceUser.profile) {
|
|
23
|
+
// let filters = [['space', '=', spaceId],['profiles', '=', spaceUser.profile]];
|
|
24
|
+
// if(objectName){
|
|
25
|
+
// filters.push(['object_name', '=', objectName])
|
|
26
|
+
// }
|
|
27
|
+
// return await getObject("object_layouts").directFind({filters: filters})
|
|
28
|
+
return yield (0, objectql_1.getObjectLayouts)(spaceUser.profile, spaceId, objectName);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
;
|
|
33
|
+
function getUserObjects(userId, spaceId, objects) {
|
|
34
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
const objectsLayout = yield getUserProfileObjectsLayout(userId, spaceId);
|
|
36
|
+
for (const objectName in objects) {
|
|
37
|
+
// objects[objectName].list_views = await getUserObjectListViews(userId, spaceId, objectName)
|
|
38
|
+
let userObjectLayout = null;
|
|
39
|
+
if (objectsLayout) {
|
|
40
|
+
userObjectLayout = _.find(objectsLayout, function (objectLayout) {
|
|
41
|
+
return objectLayout.object_name === objectName;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (!userObjectLayout && false) {
|
|
45
|
+
userObjectLayout = (0, objectql_1.getLayout)(objectName, 'default');
|
|
46
|
+
}
|
|
47
|
+
if (userObjectLayout) {
|
|
48
|
+
objects[userObjectLayout.object_name] = yield getUserObject(userId, spaceId, objects[userObjectLayout.object_name], userObjectLayout);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function getUserObject(userId, spaceId, object, layout) {
|
|
54
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
if (!layout) {
|
|
56
|
+
const layouts = yield getUserProfileObjectsLayout(userId, spaceId, object.name);
|
|
57
|
+
if (layouts && layouts.length > 0) {
|
|
58
|
+
layout = layouts[0];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
let _object = clone(object);
|
|
62
|
+
if (_object && layout) {
|
|
63
|
+
_.each(_object.actions, (action, key) => {
|
|
64
|
+
if (!_.has(action, 'name')) {
|
|
65
|
+
action.name = key;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
let _fields = {};
|
|
69
|
+
let sort_no = 1;
|
|
70
|
+
_.each(layout.fields, function (_item) {
|
|
71
|
+
_fields[_item.field_name] = _object.fields[_item.field_name];
|
|
72
|
+
if (_fields[_item.field_name]) {
|
|
73
|
+
if (_.has(_item, 'group')) {
|
|
74
|
+
_fields[_item.field_name].group = _item.group;
|
|
75
|
+
}
|
|
76
|
+
if (_item.is_required) {
|
|
77
|
+
_fields[_item.field_name].readonly = false;
|
|
78
|
+
_fields[_item.field_name].disabled = false;
|
|
79
|
+
_fields[_item.field_name].required = true;
|
|
80
|
+
}
|
|
81
|
+
else if (_item.is_readonly) {
|
|
82
|
+
_fields[_item.field_name].readonly = true;
|
|
83
|
+
_fields[_item.field_name].disabled = true;
|
|
84
|
+
_fields[_item.field_name].required = false;
|
|
85
|
+
}
|
|
86
|
+
if (_item.visible_on) {
|
|
87
|
+
_fields[_item.field_name].visible_on = _item.visible_on;
|
|
88
|
+
}
|
|
89
|
+
if (['created', 'created_by', 'modified', 'modified_by'].indexOf(_item.field_name) < 0) {
|
|
90
|
+
_fields[_item.field_name].omit = false;
|
|
91
|
+
_fields[_item.field_name].hidden = false;
|
|
92
|
+
}
|
|
93
|
+
_fields[_item.field_name].sort_no = sort_no;
|
|
94
|
+
sort_no++;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
const layoutFieldKeys = _.keys(_fields);
|
|
98
|
+
const objectFieldKeys = _.keys(_object.fields);
|
|
99
|
+
const difference = _.difference(objectFieldKeys, layoutFieldKeys);
|
|
100
|
+
_.each(layoutFieldKeys, function (fieldApiName) {
|
|
101
|
+
_object.fields[fieldApiName] = _fields[fieldApiName];
|
|
102
|
+
});
|
|
103
|
+
_.each(difference, function (fieldApiName) {
|
|
104
|
+
_object.fields[fieldApiName].hidden = true;
|
|
105
|
+
_object.fields[fieldApiName].sort_no = 99999;
|
|
106
|
+
});
|
|
107
|
+
// let _buttons = {};
|
|
108
|
+
_.each(layout.buttons, function (button) {
|
|
109
|
+
const action = _object.actions[button.button_name];
|
|
110
|
+
if (action) {
|
|
111
|
+
if (button.visible_on) {
|
|
112
|
+
action._visible = button.visible_on;
|
|
113
|
+
}
|
|
114
|
+
// _buttons[button.button_name] = action
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
const layoutButtonsName = _.pluck(layout.buttons, 'button_name');
|
|
118
|
+
_.each(_object.actions, function (action) {
|
|
119
|
+
if (!_.include(layoutButtonsName, action.name)) {
|
|
120
|
+
action.visible = false;
|
|
121
|
+
action._visible = function () { return false; }.toString();
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
// _object.actions = _buttons;
|
|
125
|
+
// _object.allow_customActions = userObjectLayout.custom_actions || []
|
|
126
|
+
// _object.exclude_actions = userObjectLayout.exclude_actions || []
|
|
127
|
+
_object.related_lists = layout.related_lists || [];
|
|
128
|
+
_.each(_object.related_lists, (related_list) => {
|
|
129
|
+
if (related_list.sort_field_name && _.isArray(related_list.sort_field_name) && related_list.sort_field_name.length > 0) {
|
|
130
|
+
related_list.sort = [];
|
|
131
|
+
_.each(related_list.sort_field_name, (fName) => {
|
|
132
|
+
related_list.sort.push({ field_name: fName, order: related_list.sort_order || 'asc' });
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
return _object;
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
function getSpaceBootStrap(req, res) {
|
|
141
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
142
|
+
return Fiber(function () {
|
|
143
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
144
|
+
let userSession = req.user;
|
|
145
|
+
if (!userSession) {
|
|
146
|
+
return res.status(500).send();
|
|
147
|
+
}
|
|
148
|
+
let urlParams = req.params;
|
|
149
|
+
const { userId, language: lng } = userSession;
|
|
150
|
+
let spaceId = req.headers['x-space-id'] || urlParams.spaceId;
|
|
151
|
+
let space = yield (0, objectql_1.getObject)("spaces").findOne(spaceId, { fields: ['name'] });
|
|
152
|
+
//TODO 无需再从getAllPermissions中获取用户的对象权限
|
|
153
|
+
let result = Creator.getAllPermissions(spaceId, userId);
|
|
154
|
+
steedosI18n.translationObjects(lng, result.objects);
|
|
155
|
+
result.user = userSession;
|
|
156
|
+
result.space = space;
|
|
157
|
+
result.dashboards = clone(Creator.Dashboards);
|
|
158
|
+
result.object_workflows = Meteor.call('object_workflows.get', spaceId, userId);
|
|
159
|
+
result.object_listviews = yield getUserObjectsListViews(userId, spaceId);
|
|
160
|
+
// result.apps = clone(Creator.Apps)
|
|
161
|
+
result.apps = yield (0, objectql_1.getAppConfigs)(spaceId);
|
|
162
|
+
result.assigned_apps = yield (0, objectql_1.getAssignedApps)(userSession);
|
|
163
|
+
let datasources = Creator.steedosSchema.getDataSources();
|
|
164
|
+
// for (const datasourceName in datasources) {
|
|
165
|
+
// if(datasourceName != 'default'){
|
|
166
|
+
// let datasource = datasources[datasourceName];
|
|
167
|
+
// const datasourceObjects = datasource.getObjects();
|
|
168
|
+
// for (const objectName in datasourceObjects) {
|
|
169
|
+
// const object = datasourceObjects[objectName];
|
|
170
|
+
// const _obj = Creator.convertObject(clone(object.toConfig()), spaceId)
|
|
171
|
+
// _obj.name = objectName
|
|
172
|
+
// _obj.database_name = datasourceName
|
|
173
|
+
// _obj.permissions = await object.getUserObjectPermission(userSession)
|
|
174
|
+
// result.objects[_obj.name] = _obj
|
|
175
|
+
// }
|
|
176
|
+
// }
|
|
177
|
+
// }
|
|
178
|
+
const spaceProcessDefinition = yield (0, objectql_1.getObject)("process_definition").find({ filters: [['space', '=', spaceId], ['active', '=', true]] });
|
|
179
|
+
const spaceObjectsProcessDefinition = _.groupBy(spaceProcessDefinition, 'object_name');
|
|
180
|
+
const dbListViews = yield (0, objectql_1.getObject)("object_listviews").directFind({ filters: [['space', '=', userSession.spaceId], [['owner', '=', userSession.userId], 'or', ['shared', '=', true]]] });
|
|
181
|
+
const dbObjectsListViews = _.groupBy(dbListViews, 'object_name');
|
|
182
|
+
const layouts = yield (0, objectql_1.getObjectLayouts)(userSession.profile, spaceId);
|
|
183
|
+
const objectsLayouts = _.groupBy(layouts, 'object_name');
|
|
184
|
+
const objectsFieldsPermissionGroupRole = yield objectql_1.FieldPermission.getObjectsFieldsPermissionGroupRole();
|
|
185
|
+
const allRelationsInfo = yield (0, objectql_1.getAllRelationsInfo)();
|
|
186
|
+
for (const datasourceName in datasources) {
|
|
187
|
+
let datasource = datasources[datasourceName];
|
|
188
|
+
const datasourceObjects = yield datasource.getObjects();
|
|
189
|
+
for (const object of datasourceObjects) {
|
|
190
|
+
const objectConfig = object.metadata;
|
|
191
|
+
if (!result.objects[objectConfig.name] || objectConfig.name.endsWith("__c")) {
|
|
192
|
+
try {
|
|
193
|
+
const userObjectConfig = yield (0, objectql_1.getObject)(objectConfig.name).getRecordView(userSession, {
|
|
194
|
+
objectConfig: objectConfig,
|
|
195
|
+
layouts: objectsLayouts[objectConfig.name] || [],
|
|
196
|
+
spaceProcessDefinition: spaceObjectsProcessDefinition[objectConfig.name] || [],
|
|
197
|
+
dbListViews: dbObjectsListViews[objectConfig.name] || [],
|
|
198
|
+
rolesFieldsPermission: objectsFieldsPermissionGroupRole[objectConfig.name] || [],
|
|
199
|
+
relationsInfo: {
|
|
200
|
+
details: _.map(_.filter(allRelationsInfo.details, { objectName: objectConfig.name }), 'key'),
|
|
201
|
+
masters: _.map(_.filter(allRelationsInfo.masters, { objectName: objectConfig.name }), 'key'),
|
|
202
|
+
lookup_details: _.map(_.filter(allRelationsInfo.lookup_details, { objectName: objectConfig.name }))
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
let _objectConfig = null;
|
|
206
|
+
if (userObjectConfig) {
|
|
207
|
+
_objectConfig = userObjectConfig;
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
_objectConfig = clone(objectConfig);
|
|
211
|
+
}
|
|
212
|
+
const _obj = Creator.convertObject(_objectConfig, spaceId);
|
|
213
|
+
_obj.name = objectConfig.name;
|
|
214
|
+
_obj.database_name = datasourceName;
|
|
215
|
+
if (userObjectConfig) {
|
|
216
|
+
_obj.permission = userObjectConfig.permissions;
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
_obj.permissions = yield (0, objectql_1.getObject)(objectConfig.name).getUserObjectPermission(userSession);
|
|
220
|
+
steedosI18n.translationObject(lng, _obj.name, _obj);
|
|
221
|
+
}
|
|
222
|
+
result.objects[_obj.name] = _obj;
|
|
223
|
+
}
|
|
224
|
+
catch (error) {
|
|
225
|
+
console.error(error.message);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
var _dbApps = yield (0, objectql_1.getObject)("apps").directFind({ filters: [['space', '=', spaceId], ['is_creator', '=', true]] });
|
|
231
|
+
let dbApps = {};
|
|
232
|
+
_.each(_dbApps, function (dbApp) {
|
|
233
|
+
if (dbApp.visible) {
|
|
234
|
+
return dbApps[dbApp._id] = dbApp;
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
result.apps = _.extend(result.apps || {}, dbApps);
|
|
238
|
+
var _dbDashboards = yield (0, objectql_1.getObject)("dashboard").directFind({ filters: [['space', '=', spaceId]] });
|
|
239
|
+
let dbDashboards = {};
|
|
240
|
+
_.each(_dbDashboards, function (dashboard) {
|
|
241
|
+
dbDashboards[dashboard._id] = dashboard;
|
|
242
|
+
});
|
|
243
|
+
result.dashboards = _.extend(result.dashboards || {}, dbDashboards);
|
|
244
|
+
let _Apps = {};
|
|
245
|
+
_.each(result.apps, function (app, key) {
|
|
246
|
+
if (!app._id) {
|
|
247
|
+
app._id = key;
|
|
248
|
+
}
|
|
249
|
+
if (app.code) {
|
|
250
|
+
app._dbid = app._id;
|
|
251
|
+
app._id = app.code;
|
|
252
|
+
}
|
|
253
|
+
_Apps[app._id] = app;
|
|
254
|
+
});
|
|
255
|
+
_.each(_dbApps, function (dbApp) {
|
|
256
|
+
if (dbApp.visible === false) {
|
|
257
|
+
delete _Apps[dbApp.code];
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
steedosI18n.translationApps(lng, _Apps);
|
|
261
|
+
result.apps = _Apps;
|
|
262
|
+
let assigned_menus = yield (0, objectql_1.getAssignedMenus)(userSession);
|
|
263
|
+
steedosI18n.translationMenus(lng, assigned_menus);
|
|
264
|
+
result.assigned_menus = assigned_menus;
|
|
265
|
+
let _Dashboards = {};
|
|
266
|
+
_.each(result.dashboards, function (dashboard, key) {
|
|
267
|
+
if (!dashboard._id) {
|
|
268
|
+
dashboard._id = key;
|
|
269
|
+
}
|
|
270
|
+
_Dashboards[dashboard._id] = dashboard;
|
|
271
|
+
});
|
|
272
|
+
result.dashboards = _Dashboards;
|
|
273
|
+
result.plugins = core_1.getPlugins ? (0, core_1.getPlugins)() : null;
|
|
274
|
+
yield getUserObjects(userId, spaceId, result.objects);
|
|
275
|
+
// TODO object layout 是否需要控制审批记录显示?
|
|
276
|
+
_.each(spaceProcessDefinition, function (item) {
|
|
277
|
+
if (result.objects[item.object_name]) {
|
|
278
|
+
result.objects[item.object_name].enable_process = true;
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
for (const key in result.objects) {
|
|
282
|
+
if (Object.prototype.hasOwnProperty.call(result.objects, key)) {
|
|
283
|
+
const objectConfig = result.objects[key];
|
|
284
|
+
try {
|
|
285
|
+
// const object = getObject(key);
|
|
286
|
+
// const relationsInfo = await object.getRelationsInfo();
|
|
287
|
+
// objectConfig.details = relationsInfo.details;
|
|
288
|
+
// objectConfig.masters = relationsInfo.masters;
|
|
289
|
+
// objectConfig.lookup_details = relationsInfo.lookup_details;
|
|
290
|
+
objectConfig.details = _.map(_.filter(allRelationsInfo.details, { objectName: key }), 'key');
|
|
291
|
+
objectConfig.masters = _.map(_.filter(allRelationsInfo.masters, { objectName: key }), 'key');
|
|
292
|
+
objectConfig.lookup_details = _.map(_.filter(allRelationsInfo.lookup_details, { objectName: key }));
|
|
293
|
+
_.each(objectConfig.triggers, function (trigger, key) {
|
|
294
|
+
if ((trigger === null || trigger === void 0 ? void 0 : trigger.on) != 'client') {
|
|
295
|
+
delete objectConfig.triggers[key];
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
delete objectConfig.listeners;
|
|
299
|
+
delete objectConfig.__filename;
|
|
300
|
+
delete objectConfig.extend;
|
|
301
|
+
}
|
|
302
|
+
catch (error) {
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return res.status(200).send(result);
|
|
307
|
+
});
|
|
308
|
+
}).run();
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
exports.getSpaceBootStrap = getSpaceBootStrap;
|
|
312
|
+
function getObjectConfig(objectName, spaceId, userSession) {
|
|
313
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
314
|
+
let objectConfig = {};
|
|
315
|
+
try {
|
|
316
|
+
let object = (0, objectql_1.getObject)(objectName);
|
|
317
|
+
let _objectConfig = null;
|
|
318
|
+
const userObjectConfig = yield object.getRecordView(userSession);
|
|
319
|
+
if (userObjectConfig) {
|
|
320
|
+
_objectConfig = userObjectConfig;
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
_objectConfig = clone(object.toConfig());
|
|
324
|
+
}
|
|
325
|
+
objectConfig = Creator.convertObject(_objectConfig, spaceId);
|
|
326
|
+
objectConfig.name = objectName;
|
|
327
|
+
objectConfig.datasource = object.datasource.name;
|
|
328
|
+
objectConfig.permissions = yield object.getUserObjectPermission(userSession);
|
|
329
|
+
const relationsInfo = yield object.getRelationsInfo();
|
|
330
|
+
objectConfig.details = relationsInfo.details;
|
|
331
|
+
objectConfig.masters = relationsInfo.masters;
|
|
332
|
+
objectConfig.lookup_details = relationsInfo.lookup_details;
|
|
333
|
+
return objectConfig;
|
|
334
|
+
}
|
|
335
|
+
catch (error) {
|
|
336
|
+
console.warn('not load object', objectName);
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
function getUserObjectsListViews(userId, spaceId) {
|
|
341
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
342
|
+
const listViews = {};
|
|
343
|
+
const objectsViews = yield (0, objectql_1.getObject)("object_listviews").find({ filters: [['space', '=', spaceId], [["owner", "=", userId], "or", ["shared", "=", true]]] });
|
|
344
|
+
let objectNames = _.pluck(objectsViews, 'object_name');
|
|
345
|
+
objectNames = _.uniq(objectNames);
|
|
346
|
+
const _getUserObjectListViews = function (object_name) {
|
|
347
|
+
var _user_object_list_views, olistViews;
|
|
348
|
+
_user_object_list_views = {};
|
|
349
|
+
olistViews = _.filter(objectsViews, function (ov) {
|
|
350
|
+
return ov.object_name === object_name;
|
|
351
|
+
});
|
|
352
|
+
_.each(olistViews, function (listview) {
|
|
353
|
+
return _user_object_list_views[listview._id] = listview;
|
|
354
|
+
});
|
|
355
|
+
return _user_object_list_views;
|
|
356
|
+
};
|
|
357
|
+
_.forEach(objectNames, function (key) {
|
|
358
|
+
var list_view;
|
|
359
|
+
list_view = _getUserObjectListViews(key);
|
|
360
|
+
if (!_.isEmpty(list_view)) {
|
|
361
|
+
return listViews[key] = list_view;
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
return listViews;
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
;
|
|
368
|
+
// async function getUserObjectListViews(userId, spaceId, object_name){
|
|
369
|
+
// const _user_object_list_views = {};
|
|
370
|
+
// const object_listview = await getObject("object_listviews").find({filters: [['object_name', '=', object_name],['space', '=', spaceId],[ [ "owner", "=", userId ], "or", [ "shared", "=", true ] ]]});
|
|
371
|
+
// object_listview.forEach(function(listview) {
|
|
372
|
+
// return _user_object_list_views[listview._id] = listview;
|
|
373
|
+
// });
|
|
374
|
+
// return _user_object_list_views;
|
|
375
|
+
// }
|
|
376
|
+
function getSpaceObjectBootStrap(req, res) {
|
|
377
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
378
|
+
return Fiber(function () {
|
|
379
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
380
|
+
let userSession = req.user;
|
|
381
|
+
let userId = userSession.userId;
|
|
382
|
+
let urlParams = req.params;
|
|
383
|
+
let spaceId = req.headers['x-space-id'] || urlParams.spaceId;
|
|
384
|
+
if (!userSession) {
|
|
385
|
+
return res.status(500).send();
|
|
386
|
+
}
|
|
387
|
+
const objectNames = urlParams.objectNames;
|
|
388
|
+
const objects = {};
|
|
389
|
+
if (objectNames) {
|
|
390
|
+
const objectNamesArray = objectNames.split(',');
|
|
391
|
+
let dbObjects = Creator.getCollection('objects').find({ name: { $in: objectNamesArray } }).fetch() || [];
|
|
392
|
+
let creatorObjects = Creator.getAllPermissions(spaceId, userId).objects;
|
|
393
|
+
let lng = userSession.language;
|
|
394
|
+
for (const objectName of objectNamesArray) {
|
|
395
|
+
let _object = _.find(dbObjects, function (item) { return item.name === objectName; }) || {};
|
|
396
|
+
let objectConfig = {};
|
|
397
|
+
if (_.isEmpty(_object)) {
|
|
398
|
+
objectConfig = creatorObjects[objectName];
|
|
399
|
+
if (_.isEmpty(objectConfig)) {
|
|
400
|
+
objectConfig = yield getObjectConfig(objectName, spaceId, userSession);
|
|
401
|
+
}
|
|
402
|
+
else {
|
|
403
|
+
const object = (0, objectql_1.getObject)(objectName);
|
|
404
|
+
const relationsInfo = yield object.getRelationsInfo();
|
|
405
|
+
objectConfig.details = relationsInfo.details;
|
|
406
|
+
objectConfig.masters = relationsInfo.masters;
|
|
407
|
+
objectConfig.lookup_details = relationsInfo.lookup_details;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
else {
|
|
411
|
+
if (userSession.is_space_admin || _object.in_development == '0' && _object.is_enable) {
|
|
412
|
+
if (_object.datasource == 'meteor') {
|
|
413
|
+
objectConfig = creatorObjects[objectName];
|
|
414
|
+
const object = (0, objectql_1.getObject)(objectName);
|
|
415
|
+
const relationsInfo = yield object.getRelationsInfo();
|
|
416
|
+
objectConfig.details = relationsInfo.details;
|
|
417
|
+
objectConfig.masters = relationsInfo.masters;
|
|
418
|
+
objectConfig.lookup_details = relationsInfo.lookup_details;
|
|
419
|
+
}
|
|
420
|
+
else {
|
|
421
|
+
objectConfig = yield getObjectConfig(objectName, spaceId, userSession);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
if (objectConfig) {
|
|
426
|
+
delete objectConfig.db;
|
|
427
|
+
// objectConfig.list_views = await getUserObjectListViews(userId, spaceId, objectName)
|
|
428
|
+
steedosI18n.translationObject(lng, objectConfig.name, objectConfig);
|
|
429
|
+
objectConfig = yield getUserObject(userId, spaceId, objectConfig);
|
|
430
|
+
// TODO object layout 是否需要控制审批记录显示?
|
|
431
|
+
let spaceProcessDefinition = yield (0, objectql_1.getObject)("process_definition").directFind({ filters: [['space', '=', spaceId], ['object_name', '=', objectName], ['active', '=', true]] });
|
|
432
|
+
if (spaceProcessDefinition.length > 0) {
|
|
433
|
+
objectConfig.enable_process = true;
|
|
434
|
+
}
|
|
435
|
+
_.each(objectConfig.triggers, function (trigger, key) {
|
|
436
|
+
if ((trigger === null || trigger === void 0 ? void 0 : trigger.on) != 'client') {
|
|
437
|
+
delete objectConfig.triggers[key];
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
delete objectConfig.listeners;
|
|
441
|
+
delete objectConfig.__filename;
|
|
442
|
+
delete objectConfig.extend;
|
|
443
|
+
objects[objectConfig.name] = objectConfig;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
return res.status(200).send({
|
|
448
|
+
objects: objects
|
|
449
|
+
});
|
|
450
|
+
});
|
|
451
|
+
}).run();
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
exports.getSpaceObjectBootStrap = getSpaceObjectBootStrap;
|
|
455
|
+
bootStrapExpress.use('/api/bootstrap/:spaceId/:objectNames', core_1.requireAuthentication, getSpaceObjectBootStrap);
|
|
456
|
+
bootStrapExpress.use('/api/bootstrap/:spaceId/', core_1.requireAuthentication, getSpaceBootStrap);
|
|
457
|
+
exports.default = bootStrapExpress;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
/*
|
|
5
|
+
* @Author: baozhoutao@steedos.com
|
|
6
|
+
* @Date: 2022-06-09 10:19:47
|
|
7
|
+
* @LastEditors: baozhoutao@steedos.com
|
|
8
|
+
* @LastEditTime: 2022-06-10 15:52:17
|
|
9
|
+
* @Description:
|
|
10
|
+
*/
|
|
11
|
+
const objectql_1 = require("@steedos/objectql");
|
|
12
|
+
const express = require("express");
|
|
13
|
+
const router = express.Router();
|
|
14
|
+
const core = require('@steedos/core');
|
|
15
|
+
const callObjectServiceAction = function (actionName, userSession, data) {
|
|
16
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const broker = (0, objectql_1.getSteedosSchema)().broker;
|
|
18
|
+
return broker.call(actionName, data, { meta: { user: userSession } });
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
router.get('/service/api/:objectServiceName/fields', core.requireAuthentication, function (req, res) {
|
|
22
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
const userSession = req.user;
|
|
24
|
+
try {
|
|
25
|
+
const { objectServiceName } = req.params;
|
|
26
|
+
const result = yield callObjectServiceAction(`${objectServiceName}.getFields`, userSession);
|
|
27
|
+
res.status(200).send(result);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
res.status(500).send(error.message);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
router.get('/service/api/:objectServiceName/getUserObjectPermission', core.requireAuthentication, function (req, res) {
|
|
35
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
const userSession = req.user;
|
|
37
|
+
try {
|
|
38
|
+
const { objectServiceName } = req.params;
|
|
39
|
+
const result = yield callObjectServiceAction(`${objectServiceName}.getUserObjectPermission`, userSession);
|
|
40
|
+
res.status(200).send(result);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
res.status(500).send(error.message);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
router.get('/service/api/:objectServiceName/recordPermissions/:recordId', core.requireAuthentication, function (req, res) {
|
|
48
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
const userSession = req.user;
|
|
50
|
+
try {
|
|
51
|
+
const { objectServiceName, recordId } = req.params;
|
|
52
|
+
const result = yield callObjectServiceAction(`${objectServiceName}.getRecordPermissionsById`, userSession, {
|
|
53
|
+
recordId: recordId
|
|
54
|
+
});
|
|
55
|
+
res.status(200).send(result);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
res.status(500).send(error.message);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
router.get('/service/api/:objectServiceName/uiSchema', core.requireAuthentication, function (req, res) {
|
|
63
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
const userSession = req.user;
|
|
65
|
+
try {
|
|
66
|
+
const { objectServiceName } = req.params;
|
|
67
|
+
const result = yield callObjectServiceAction(`${objectServiceName}.getRecordView`, userSession);
|
|
68
|
+
res.status(200).send(result);
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
res.status(500).send(error.message);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
router.post('/service/api/:objectServiceName/defUiSchema', core.requireAuthentication, function (req, res) {
|
|
76
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
const userSession = req.user;
|
|
78
|
+
try {
|
|
79
|
+
const { objectServiceName } = req.params;
|
|
80
|
+
const result = yield callObjectServiceAction(`${objectServiceName}.createDefaultRecordView`, userSession);
|
|
81
|
+
res.status(200).send(result);
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
res.status(500).send(error.message);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
router.get('/service/api/:objectServiceName/uiSchemaTemplate', core.requireAuthentication, function (req, res) {
|
|
89
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
90
|
+
const userSession = req.user;
|
|
91
|
+
try {
|
|
92
|
+
const { objectServiceName } = req.params;
|
|
93
|
+
const result = yield callObjectServiceAction(`${objectServiceName}.getDefaultRecordView`, userSession);
|
|
94
|
+
res.status(200).send(result);
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
res.status(500).send(error.message);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
router.get('/service/api/:objectServiceName/relateds', core.requireAuthentication, function (req, res) {
|
|
102
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
const userSession = req.user;
|
|
104
|
+
try {
|
|
105
|
+
const { objectServiceName } = req.params;
|
|
106
|
+
const result = yield callObjectServiceAction(`${objectServiceName}.getRelateds`, userSession);
|
|
107
|
+
res.status(200).send(result);
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
res.status(500).send(error.message);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
exports.default = router;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
const express = require("express");
|
|
11
|
+
const router = express.Router();
|
|
12
|
+
const core = require('@steedos/core');
|
|
13
|
+
router.get('/service/api/:objectServiceName/uiSchema', core.requireAuthentication, function (req, res) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
// const userSession = req.user;
|
|
16
|
+
// const spaceId = userSession.spaceId;
|
|
17
|
+
// const userId = userSession.userId;
|
|
18
|
+
// const isSpaceAdmin = userSession.is_space_admin;
|
|
19
|
+
res.status(200).send({ message: 'router ok' });
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
exports.default = router;
|
|
File without changes
|
|
File without changes
|