@steedos/service-metadata-apps 3.0.13-beta.8 → 3.0.13
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/actionsHandler.js +527 -540
- package/lib/actionsHandler.js.map +1 -1
- package/lib/apps.service.js +19 -40
- package/lib/apps.service.js.map +1 -1
- package/lib/getNotLicensedTabNames.js +25 -28
- package/lib/getNotLicensedTabNames.js.map +1 -1
- package/lib/index.js +25 -32
- package/lib/index.js.map +1 -1
- package/package.json +5 -5
- package/tsconfig.json +3 -7
package/lib/actionsHandler.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ActionHandlers = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const _1 = require(".");
|
|
6
5
|
const _ = require("lodash");
|
|
7
6
|
const utils_1 = require("@steedos/utils");
|
|
@@ -11,118 +10,104 @@ const getNotLicensedTabNames_1 = require("./getNotLicensedTabNames");
|
|
|
11
10
|
function cacherKey(appApiName) {
|
|
12
11
|
return `$steedos.#${_1.METADATA_TYPE}.${appApiName}`;
|
|
13
12
|
}
|
|
14
|
-
function registerApp(ctx, appApiName, data, meta) {
|
|
15
|
-
return
|
|
16
|
-
return yield ctx.broker.call("metadata.add", { key: cacherKey(appApiName), data: data }, { meta: meta });
|
|
17
|
-
});
|
|
13
|
+
async function registerApp(ctx, appApiName, data, meta) {
|
|
14
|
+
return await ctx.broker.call("metadata.add", { key: cacherKey(appApiName), data: data }, { meta: meta });
|
|
18
15
|
}
|
|
19
|
-
function getSpaceApp(ctx, appApiName) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
!_.isEmpty(config.mobile_objects)) {
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
16
|
+
async function getSpaceApp(ctx, appApiName) {
|
|
17
|
+
const allApps = await getAllApps(ctx);
|
|
18
|
+
const userSession = ctx.meta.user;
|
|
19
|
+
const spaceId = userSession.spaceId;
|
|
20
|
+
const userApps = _.filter(allApps, function (metadataConfig) {
|
|
21
|
+
const config = metadataConfig.metadata;
|
|
22
|
+
if (!config.visible) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
if (_.has(config, "space") && config.space) {
|
|
26
|
+
return config.space === spaceId;
|
|
27
|
+
}
|
|
28
|
+
if (!_.isEmpty(config.tabs) ||
|
|
29
|
+
!_.isEmpty(config.objects) ||
|
|
30
|
+
!_.isEmpty(config.mobile_objects)) {
|
|
37
31
|
return true;
|
|
38
|
-
}
|
|
39
|
-
return
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
});
|
|
35
|
+
return _.find(userApps, function (metadataConfig) {
|
|
36
|
+
const config = metadataConfig.metadata;
|
|
37
|
+
return config.space && config.code === appApiName;
|
|
43
38
|
});
|
|
44
39
|
}
|
|
45
|
-
function get(ctx) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
40
|
+
async function get(ctx) {
|
|
41
|
+
const spaceAppMetadataConfig = await getSpaceApp(ctx, ctx.params.appApiName);
|
|
42
|
+
if (spaceAppMetadataConfig) {
|
|
43
|
+
return spaceAppMetadataConfig;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
const metadataConfig = await ctx.broker.call("metadata.get", { key: cacherKey(ctx.params.appApiName) }, { meta: ctx.meta });
|
|
47
|
+
if (metadataConfig) {
|
|
48
|
+
return metadataConfig;
|
|
50
49
|
}
|
|
51
50
|
else {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return config.space === spaceId;
|
|
67
|
-
}
|
|
68
|
-
if (!_.isEmpty(config.tabs) ||
|
|
69
|
-
!_.isEmpty(config.objects) ||
|
|
70
|
-
!_.isEmpty(config.mobile_objects)) {
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
51
|
+
const allApps = await getAllApps(ctx);
|
|
52
|
+
const userSession = ctx.meta.user;
|
|
53
|
+
const spaceId = userSession.spaceId;
|
|
54
|
+
const userApps = _.filter(allApps, function (metadataConfig) {
|
|
55
|
+
const config = metadataConfig.metadata;
|
|
56
|
+
if (!config.visible) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
if (_.has(config, "space") && config.space) {
|
|
60
|
+
return config.space === spaceId;
|
|
61
|
+
}
|
|
62
|
+
if (!_.isEmpty(config.tabs) ||
|
|
63
|
+
!_.isEmpty(config.objects) ||
|
|
64
|
+
!_.isEmpty(config.mobile_objects)) {
|
|
73
65
|
return true;
|
|
74
|
-
});
|
|
75
|
-
if (ctx.params.appApiName === "-") {
|
|
76
|
-
return _.first(_.sortBy(userApps, ["metadata.sort"]));
|
|
77
66
|
}
|
|
78
|
-
return
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
67
|
+
return true;
|
|
68
|
+
});
|
|
69
|
+
if (ctx.params.appApiName === "-") {
|
|
70
|
+
return _.first(_.sortBy(userApps, ["metadata.sort"]));
|
|
82
71
|
}
|
|
72
|
+
return _.find(userApps, function (metadataConfig) {
|
|
73
|
+
const app = metadataConfig.metadata;
|
|
74
|
+
return app.code === ctx.params.appApiName;
|
|
75
|
+
});
|
|
83
76
|
}
|
|
84
|
-
}
|
|
77
|
+
}
|
|
85
78
|
}
|
|
86
|
-
function getAllApps(ctx) {
|
|
87
|
-
return
|
|
88
|
-
return yield ctx.broker.call("metadata.filter", { key: cacherKey("*") }, { meta: ctx.meta });
|
|
89
|
-
});
|
|
79
|
+
async function getAllApps(ctx) {
|
|
80
|
+
return await ctx.broker.call("metadata.filter", { key: cacherKey("*") }, { meta: ctx.meta });
|
|
90
81
|
}
|
|
91
|
-
function getAllTabs(ctx) {
|
|
92
|
-
return
|
|
93
|
-
return yield ctx.broker.call("tabs.getAll");
|
|
94
|
-
});
|
|
82
|
+
async function getAllTabs(ctx) {
|
|
83
|
+
return await ctx.broker.call("tabs.getAll");
|
|
95
84
|
}
|
|
96
|
-
function getContext(ctx) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (userSession.is_space_admin) {
|
|
101
|
-
return {
|
|
102
|
-
tabs: allTabs,
|
|
103
|
-
hiddenTabNames: [],
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
let hiddenTabNames = yield getHiddenTabNames(ctx, allTabs);
|
|
107
|
-
const notLicensedTabNames = yield (0, getNotLicensedTabNames_1.getNotLicensedTabNames)(ctx, allTabs);
|
|
108
|
-
hiddenTabNames = hiddenTabNames.concat(notLicensedTabNames);
|
|
85
|
+
async function getContext(ctx) {
|
|
86
|
+
const userSession = ctx.meta.user;
|
|
87
|
+
const allTabs = await getAllTabs(ctx);
|
|
88
|
+
if (userSession.is_space_admin) {
|
|
109
89
|
return {
|
|
110
90
|
tabs: allTabs,
|
|
111
|
-
hiddenTabNames:
|
|
91
|
+
hiddenTabNames: [],
|
|
112
92
|
};
|
|
113
|
-
}
|
|
93
|
+
}
|
|
94
|
+
let hiddenTabNames = await getHiddenTabNames(ctx, allTabs);
|
|
95
|
+
const notLicensedTabNames = await (0, getNotLicensedTabNames_1.getNotLicensedTabNames)(ctx, allTabs);
|
|
96
|
+
hiddenTabNames = hiddenTabNames.concat(notLicensedTabNames);
|
|
97
|
+
return {
|
|
98
|
+
tabs: allTabs,
|
|
99
|
+
hiddenTabNames: hiddenTabNames,
|
|
100
|
+
};
|
|
114
101
|
}
|
|
115
|
-
function getTab(ctx, tabApiName) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
return metadataConfig === null || metadataConfig === void 0 ? void 0 : metadataConfig.metadata;
|
|
119
|
-
});
|
|
102
|
+
async function getTab(ctx, tabApiName) {
|
|
103
|
+
const metadataConfig = await ctx.broker.call("tabs.get", { tabApiName });
|
|
104
|
+
return metadataConfig?.metadata;
|
|
120
105
|
}
|
|
121
106
|
function getTabChildren(context, tabApiName) {
|
|
122
107
|
if (context) {
|
|
123
108
|
const { tabs } = context;
|
|
124
109
|
return _.filter(tabs, function (tab) {
|
|
125
|
-
return
|
|
110
|
+
return tab?.metadata.parent === tabApiName;
|
|
126
111
|
});
|
|
127
112
|
}
|
|
128
113
|
}
|
|
@@ -146,530 +131,532 @@ function checkAppMobile(app, mobile) {
|
|
|
146
131
|
}
|
|
147
132
|
return isChecked;
|
|
148
133
|
}
|
|
149
|
-
function getHiddenTabNames(ctx, allTabs) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
showTabNames.push(permissionTab.tab);
|
|
161
|
-
}
|
|
134
|
+
async function getHiddenTabNames(ctx, allTabs) {
|
|
135
|
+
const userSession = ctx.meta.user;
|
|
136
|
+
if (!userSession) {
|
|
137
|
+
throw new Error("no permission.");
|
|
138
|
+
}
|
|
139
|
+
const hiddenTabNames = [];
|
|
140
|
+
const permissionTabs = await getPermissionTabs(ctx, userSession);
|
|
141
|
+
const showTabNames = [];
|
|
142
|
+
for (const permissionTab of permissionTabs) {
|
|
143
|
+
if (permissionTab.permission === "on") {
|
|
144
|
+
showTabNames.push(permissionTab.tab);
|
|
162
145
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
146
|
+
}
|
|
147
|
+
for (const permissionTab of permissionTabs) {
|
|
148
|
+
if ((permissionTab.permission === "off" ||
|
|
149
|
+
permissionTab.permission === "hidden") &&
|
|
150
|
+
!showTabNames.includes(permissionTab.tab)) {
|
|
151
|
+
hiddenTabNames.push(permissionTab.tab);
|
|
169
152
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
153
|
+
}
|
|
154
|
+
for (const config of allTabs) {
|
|
155
|
+
if (config.metadata && config.metadata.hidden) {
|
|
156
|
+
hiddenTabNames.push(config.metadata.name);
|
|
174
157
|
}
|
|
175
|
-
|
|
176
|
-
|
|
158
|
+
}
|
|
159
|
+
return hiddenTabNames;
|
|
177
160
|
}
|
|
178
|
-
function getPermissionTabs(ctx, userSession) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
},
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
permissionTabs.push(ptConfig.metadata);
|
|
194
|
-
}
|
|
161
|
+
async function getPermissionTabs(ctx, userSession) {
|
|
162
|
+
const { roles, spaceId } = userSession;
|
|
163
|
+
const permissionTabs = [];
|
|
164
|
+
for (const role of roles) {
|
|
165
|
+
const pattern = `${role}_*`;
|
|
166
|
+
const filterResult = await ctx.broker.call("permission_tabs.filter", {
|
|
167
|
+
pattern: pattern,
|
|
168
|
+
}, {
|
|
169
|
+
user: { spaceId: spaceId },
|
|
170
|
+
});
|
|
171
|
+
for (const ptConfig of filterResult) {
|
|
172
|
+
if (ptConfig.metadata.permission_set === role &&
|
|
173
|
+
(!_.has(ptConfig.metadata, "space") ||
|
|
174
|
+
ptConfig.metadata.space === spaceId)) {
|
|
175
|
+
permissionTabs.push(ptConfig.metadata);
|
|
195
176
|
}
|
|
196
177
|
}
|
|
197
|
-
|
|
198
|
-
|
|
178
|
+
}
|
|
179
|
+
return permissionTabs;
|
|
199
180
|
}
|
|
200
|
-
function tabMenus(
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
181
|
+
async function tabMenus(ctx, appPath, tabApiName, menu, mobile, userSession, context, props = {}) {
|
|
182
|
+
try {
|
|
183
|
+
const tab = await getTab(ctx, tabApiName);
|
|
184
|
+
if (props.group) {
|
|
185
|
+
props.group =
|
|
186
|
+
_.find(menu.tab_groups, { id: props.group })?.group_name || props.group;
|
|
187
|
+
}
|
|
188
|
+
if (tabApiName) {
|
|
189
|
+
props.tabApiName = tabApiName;
|
|
190
|
+
}
|
|
191
|
+
if (tab) {
|
|
192
|
+
const isMobileChecked = checkTabMobile(tab, mobile);
|
|
193
|
+
if (!isMobileChecked) {
|
|
194
|
+
return;
|
|
211
195
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
196
|
+
const tabChildren = getTabChildren(context, tabApiName);
|
|
197
|
+
if (tabChildren && tabChildren.length > 0) {
|
|
198
|
+
const tabMenu = {
|
|
199
|
+
id: tab.name,
|
|
200
|
+
icon: tab.icon,
|
|
201
|
+
name: `${tab.label}`,
|
|
202
|
+
children: [],
|
|
203
|
+
...props,
|
|
204
|
+
};
|
|
205
|
+
for (const { metadata: tabChild } of tabChildren) {
|
|
206
|
+
if (tabChild && tabChild.apiName) {
|
|
207
|
+
await tabMenus(ctx, appPath, tabChild.apiName, tabMenu, mobile, userSession, context);
|
|
208
|
+
}
|
|
216
209
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
210
|
+
menu.children.push(tabMenu);
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
if (tab.type === "object") {
|
|
214
|
+
const allowRead = await objectAllowRead(tab.object, userSession);
|
|
215
|
+
if (!allowRead) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const objectConfig = await (0, objectql_1.getObject)(tab.object).getConfig();
|
|
219
|
+
if (objectConfig) {
|
|
220
|
+
const objectLabel = (0, i18n_1.translationObjectLabel)(userSession.language, objectConfig.name, objectConfig.label || objectConfig.name);
|
|
221
|
+
menu.children.push({
|
|
222
|
+
id: objectConfig.name,
|
|
223
|
+
type: tab.type,
|
|
224
|
+
icon: objectConfig.icon,
|
|
225
|
+
path: `${appPath}/${objectConfig.name}`,
|
|
226
|
+
name: `${objectLabel}`,
|
|
227
|
+
...props,
|
|
228
|
+
});
|
|
224
229
|
}
|
|
225
|
-
menu.children.push(tabMenu);
|
|
226
230
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
231
|
+
if (tab.type === "url") {
|
|
232
|
+
tab.label = (0, i18n_1.translationTabLabel)(userSession.language, tab.name, tab.label || tab.name);
|
|
233
|
+
let urlMenu = {
|
|
234
|
+
id: `${tab.name}`,
|
|
235
|
+
type: tab.type,
|
|
236
|
+
icon: tab.icon,
|
|
237
|
+
path: `${tab.url}`,
|
|
238
|
+
name: `${tab.label}`,
|
|
239
|
+
...props,
|
|
240
|
+
};
|
|
241
|
+
if (tab.is_new_window) {
|
|
242
|
+
urlMenu.target = "_blank";
|
|
238
243
|
}
|
|
239
|
-
if (tab.
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
if (tab.is_new_window) {
|
|
243
|
-
urlMenu.target = "_blank";
|
|
244
|
-
}
|
|
245
|
-
else if (tab.is_use_iframe) {
|
|
246
|
-
urlMenu.is_use_iframe = true;
|
|
247
|
-
urlMenu.path = `${appPath}/tab_iframe/${tab.name}/?url=${encodeURIComponent(tab.url)}`;
|
|
248
|
-
}
|
|
249
|
-
menu.children.push(urlMenu);
|
|
244
|
+
else if (tab.is_use_iframe) {
|
|
245
|
+
urlMenu.is_use_iframe = true;
|
|
246
|
+
urlMenu.path = `${appPath}/tab_iframe/${tab.name}/?url=${encodeURIComponent(tab.url)}`;
|
|
250
247
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
248
|
+
menu.children.push(urlMenu);
|
|
249
|
+
}
|
|
250
|
+
if (tab.type === "page") {
|
|
251
|
+
tab.label = (0, i18n_1.translationTabLabel)(userSession.language, tab.name, tab.label || tab.name);
|
|
252
|
+
menu.children.push({
|
|
253
|
+
id: `${tab.name}`,
|
|
254
|
+
icon: tab.icon,
|
|
255
|
+
type: tab.type,
|
|
256
|
+
page: tab.page,
|
|
257
|
+
path: `${appPath}/${tab.type}/${tab.page}`,
|
|
258
|
+
name: `${tab.label}`,
|
|
259
|
+
...props,
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
if (tab.type === "analytics_dashboard") {
|
|
263
|
+
const url = `/analytics/embed/dashboard/${tab.analytics_dashboard}?titled=false&bordered=false`;
|
|
264
|
+
tab.label = (0, i18n_1.translationTabLabel)(userSession.language, tab.name, tab.label || tab.name);
|
|
265
|
+
let urlMenu = {
|
|
266
|
+
id: `${tab.name}`,
|
|
267
|
+
type: tab.type,
|
|
268
|
+
icon: tab.icon,
|
|
269
|
+
path: `${url}`,
|
|
270
|
+
name: `${tab.label}`,
|
|
271
|
+
...props,
|
|
272
|
+
};
|
|
273
|
+
if (tab.is_new_window) {
|
|
274
|
+
urlMenu.target = "_blank";
|
|
254
275
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
let urlMenu = Object.assign({ id: `${tab.name}`, type: tab.type, icon: tab.icon, path: `${url}`, name: `${tab.label}` }, props);
|
|
259
|
-
if (tab.is_new_window) {
|
|
260
|
-
urlMenu.target = "_blank";
|
|
261
|
-
}
|
|
262
|
-
else {
|
|
263
|
-
urlMenu.is_use_iframe = true;
|
|
264
|
-
urlMenu.path = `${appPath}/tab_iframe/${tab.name}/?url=${url}`;
|
|
265
|
-
}
|
|
266
|
-
menu.children.push(urlMenu);
|
|
276
|
+
else {
|
|
277
|
+
urlMenu.is_use_iframe = true;
|
|
278
|
+
urlMenu.path = `${appPath}/tab_iframe/${tab.name}/?url=${url}`;
|
|
267
279
|
}
|
|
280
|
+
menu.children.push(urlMenu);
|
|
268
281
|
}
|
|
269
282
|
}
|
|
270
283
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
}
|
|
284
|
+
}
|
|
285
|
+
catch (error) {
|
|
286
|
+
ctx.broker.logger.info(error.message);
|
|
287
|
+
}
|
|
275
288
|
}
|
|
276
|
-
function objectAllowRead(objectApiName, userSession) {
|
|
277
|
-
return
|
|
278
|
-
return yield (0, objectql_1.getObject)(objectApiName).allowRead(userSession);
|
|
279
|
-
});
|
|
289
|
+
async function objectAllowRead(objectApiName, userSession) {
|
|
290
|
+
return await (0, objectql_1.getObject)(objectApiName).allowRead(userSession);
|
|
280
291
|
}
|
|
281
|
-
function transformAppToMenus(ctx, app, mobile, userSession, context) {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
if (app.url) {
|
|
296
|
-
if (
|
|
297
|
-
|
|
298
|
-
appPath = (0, objectql_1.absoluteUrl)("/api/external/app/" + (app._id || app.code));
|
|
299
|
-
}
|
|
300
|
-
else {
|
|
301
|
-
appPath = app.url;
|
|
302
|
-
}
|
|
292
|
+
async function transformAppToMenus(ctx, app, mobile, userSession, context) {
|
|
293
|
+
if (!app.code && !app._id) {
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
const isAppShow = checkAppMobile(app, mobile);
|
|
297
|
+
if (!isAppShow) {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
if (!app.code) {
|
|
301
|
+
app.code = app._id;
|
|
302
|
+
}
|
|
303
|
+
(0, i18n_1.translationApp)(userSession.language, app.code, app);
|
|
304
|
+
var appPath = `/app/${app.code}`;
|
|
305
|
+
if (app.url) {
|
|
306
|
+
if (/^http(s?):\/\//.test(app.url)) {
|
|
307
|
+
if (app.secret) {
|
|
308
|
+
appPath = (0, objectql_1.absoluteUrl)("/api/external/app/" + (app._id || app.code));
|
|
303
309
|
}
|
|
304
310
|
else {
|
|
305
311
|
appPath = app.url;
|
|
306
312
|
}
|
|
307
313
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
314
|
+
else {
|
|
315
|
+
appPath = app.url;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
const menu = {
|
|
319
|
+
id: app.code,
|
|
320
|
+
path: appPath,
|
|
321
|
+
name: `${app.label || app.name}`,
|
|
322
|
+
icon: app.icon_slds,
|
|
323
|
+
color: app.color,
|
|
324
|
+
dark: app.dark,
|
|
325
|
+
showSidebar: app.showSidebar,
|
|
326
|
+
description: app.description,
|
|
327
|
+
children: [],
|
|
328
|
+
blank: app.is_new_window,
|
|
329
|
+
on_click: app.on_click,
|
|
330
|
+
isExternalUrl: !!app.url,
|
|
331
|
+
tab_groups: app.tab_groups,
|
|
332
|
+
is_hide_mobile_menu: app.is_hide_mobile_menu,
|
|
333
|
+
visible_on: app.visible_on || "${true}",
|
|
334
|
+
default_tab: app.default_tab,
|
|
335
|
+
};
|
|
336
|
+
if (app.enable_nav_schema &&
|
|
337
|
+
app.nav_schema &&
|
|
338
|
+
(!mobile || mobile === "false")) {
|
|
339
|
+
menu.nav_schema = _.isString(app.nav_schema)
|
|
340
|
+
? JSON.parse(app.nav_schema)
|
|
341
|
+
: app.nav_schema;
|
|
342
|
+
}
|
|
343
|
+
const hiddenTabNames = context.hiddenTabNames || [];
|
|
344
|
+
if (app.tab_items) {
|
|
345
|
+
if (_.isArray(app.tab_items)) {
|
|
346
|
+
for (const item of app.tab_items) {
|
|
347
|
+
try {
|
|
348
|
+
if (hiddenTabNames.includes(item.tab_name))
|
|
349
|
+
continue;
|
|
350
|
+
await tabMenus(ctx, appPath, item.tab_name, menu, mobile, userSession, context, item);
|
|
345
351
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
for (const tabApiName in app.tab_items) {
|
|
349
|
-
try {
|
|
350
|
-
if (hiddenTabNames.includes(tabApiName))
|
|
351
|
-
continue;
|
|
352
|
-
const props = app.tab_items[tabApiName];
|
|
353
|
-
yield tabMenus(ctx, appPath, tabApiName, menu, mobile, userSession, context, props);
|
|
354
|
-
}
|
|
355
|
-
catch (error) {
|
|
356
|
-
ctx.broker.logger.info(error.message);
|
|
357
|
-
}
|
|
352
|
+
catch (error) {
|
|
353
|
+
ctx.broker.logger.info(error.message);
|
|
358
354
|
}
|
|
359
355
|
}
|
|
360
356
|
}
|
|
361
|
-
else
|
|
362
|
-
for (const tabApiName
|
|
357
|
+
else {
|
|
358
|
+
for (const tabApiName in app.tab_items) {
|
|
363
359
|
try {
|
|
364
360
|
if (hiddenTabNames.includes(tabApiName))
|
|
365
361
|
continue;
|
|
366
|
-
|
|
362
|
+
const props = app.tab_items[tabApiName];
|
|
363
|
+
await tabMenus(ctx, appPath, tabApiName, menu, mobile, userSession, context, props);
|
|
367
364
|
}
|
|
368
365
|
catch (error) {
|
|
369
366
|
ctx.broker.logger.info(error.message);
|
|
370
367
|
}
|
|
371
368
|
}
|
|
372
369
|
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
ctx,
|
|
381
|
-
appPath,
|
|
382
|
-
app,
|
|
383
|
-
}));
|
|
370
|
+
}
|
|
371
|
+
else if (_.isArray(app.tabs)) {
|
|
372
|
+
for (const tabApiName of app.tabs) {
|
|
373
|
+
try {
|
|
374
|
+
if (hiddenTabNames.includes(tabApiName))
|
|
375
|
+
continue;
|
|
376
|
+
await tabMenus(ctx, appPath, tabApiName, menu, mobile, userSession, context);
|
|
384
377
|
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
if (child) {
|
|
388
|
-
menu.children.push(child);
|
|
389
|
-
}
|
|
378
|
+
catch (error) {
|
|
379
|
+
ctx.broker.logger.info(error.message);
|
|
390
380
|
}
|
|
391
381
|
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
382
|
+
}
|
|
383
|
+
const objects = mobile ? app.mobile_objects : app.objects;
|
|
384
|
+
if (_.isArray(objects)) {
|
|
385
|
+
const getChildrenPromises = [];
|
|
386
|
+
for (const objectApiName of objects) {
|
|
387
|
+
getChildrenPromises.push(getMenuChildren({
|
|
388
|
+
objectApiName,
|
|
389
|
+
userSession,
|
|
390
|
+
ctx,
|
|
391
|
+
appPath,
|
|
392
|
+
app,
|
|
393
|
+
}));
|
|
394
|
+
}
|
|
395
|
+
const children = await Promise.all(getChildrenPromises);
|
|
396
|
+
for (const child of children) {
|
|
397
|
+
if (child) {
|
|
398
|
+
menu.children.push(child);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
if (menu.default_tab && _.isString(menu.default_tab)) {
|
|
403
|
+
const defaultTabStr = menu.default_tab;
|
|
404
|
+
let defaultTab = _.find(menu.children, (item) => {
|
|
405
|
+
return item.id === defaultTabStr || item.tabApiName === defaultTabStr;
|
|
406
|
+
});
|
|
407
|
+
if (!defaultTab && context && context.tabs) {
|
|
408
|
+
const tabConfig = _.find(context.tabs, (t) => t.metadata && t.metadata.name === defaultTabStr);
|
|
409
|
+
if (tabConfig && tabConfig.metadata) {
|
|
410
|
+
const tab = tabConfig.metadata;
|
|
411
|
+
if (tab.type === "object" && tab.object) {
|
|
412
|
+
defaultTab = _.find(menu.children, (item) => item.id === tab.object);
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
defaultTab = _.find(menu.children, (item) => item.id === tab.name);
|
|
416
|
+
}
|
|
417
|
+
if (!defaultTab) {
|
|
418
|
+
try {
|
|
419
|
+
if (tab.type === "object") {
|
|
420
|
+
defaultTab = {
|
|
421
|
+
id: tab.object,
|
|
422
|
+
type: tab.type,
|
|
423
|
+
icon: tab.icon,
|
|
424
|
+
path: `${appPath}/${tab.object}`,
|
|
425
|
+
name: tab.label || tab.name,
|
|
426
|
+
tabApiName: tab.name,
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
else if (tab.type === "url") {
|
|
430
|
+
defaultTab = {
|
|
431
|
+
id: tab.name,
|
|
432
|
+
type: tab.type,
|
|
433
|
+
icon: tab.icon,
|
|
434
|
+
path: tab.url,
|
|
435
|
+
name: tab.label || tab.name,
|
|
436
|
+
tabApiName: tab.name,
|
|
437
|
+
};
|
|
438
|
+
if (tab.is_new_window) {
|
|
439
|
+
defaultTab.target = "_blank";
|
|
418
440
|
}
|
|
419
|
-
else if (tab.
|
|
420
|
-
defaultTab =
|
|
421
|
-
|
|
422
|
-
type: tab.type,
|
|
423
|
-
icon: tab.icon,
|
|
424
|
-
path: tab.url,
|
|
425
|
-
name: tab.label || tab.name,
|
|
426
|
-
tabApiName: tab.name,
|
|
427
|
-
};
|
|
428
|
-
if (tab.is_new_window) {
|
|
429
|
-
defaultTab.target = "_blank";
|
|
430
|
-
}
|
|
431
|
-
else if (tab.is_use_iframe) {
|
|
432
|
-
defaultTab.is_use_iframe = true;
|
|
433
|
-
defaultTab.path = `${appPath}/tab_iframe/${tab.name}/?url=${encodeURIComponent(tab.url)}`;
|
|
434
|
-
}
|
|
441
|
+
else if (tab.is_use_iframe) {
|
|
442
|
+
defaultTab.is_use_iframe = true;
|
|
443
|
+
defaultTab.path = `${appPath}/tab_iframe/${tab.name}/?url=${encodeURIComponent(tab.url)}`;
|
|
435
444
|
}
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
445
|
+
}
|
|
446
|
+
else if (tab.type === "page") {
|
|
447
|
+
defaultTab = {
|
|
448
|
+
id: tab.name,
|
|
449
|
+
icon: tab.icon,
|
|
450
|
+
type: tab.type,
|
|
451
|
+
page: tab.page,
|
|
452
|
+
path: `${appPath}/${tab.type}/${tab.page}`,
|
|
453
|
+
name: tab.label || tab.name,
|
|
454
|
+
tabApiName: tab.name,
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
else if (tab.type === "analytics_dashboard") {
|
|
458
|
+
const url = `/analytics/embed/dashboard/${tab.analytics_dashboard}?titled=false&bordered=false`;
|
|
459
|
+
defaultTab = {
|
|
460
|
+
id: tab.name,
|
|
461
|
+
type: tab.type,
|
|
462
|
+
icon: tab.icon,
|
|
463
|
+
path: url,
|
|
464
|
+
name: tab.label || tab.name,
|
|
465
|
+
tabApiName: tab.name,
|
|
466
|
+
};
|
|
467
|
+
if (tab.is_new_window) {
|
|
468
|
+
defaultTab.target = "_blank";
|
|
446
469
|
}
|
|
447
|
-
else
|
|
448
|
-
|
|
449
|
-
defaultTab = {
|
|
450
|
-
id: tab.name,
|
|
451
|
-
type: tab.type,
|
|
452
|
-
icon: tab.icon,
|
|
453
|
-
path: url,
|
|
454
|
-
name: tab.label || tab.name,
|
|
455
|
-
tabApiName: tab.name,
|
|
456
|
-
};
|
|
457
|
-
if (tab.is_new_window) {
|
|
458
|
-
defaultTab.target = "_blank";
|
|
459
|
-
}
|
|
460
|
-
else {
|
|
461
|
-
defaultTab.is_use_iframe = true;
|
|
462
|
-
defaultTab.path = `${appPath}/tab_iframe/${tab.name}/?url=${url}`;
|
|
463
|
-
}
|
|
470
|
+
else {
|
|
471
|
+
defaultTab.is_use_iframe = true;
|
|
472
|
+
defaultTab.path = `${appPath}/tab_iframe/${tab.name}/?url=${url}`;
|
|
464
473
|
}
|
|
465
474
|
}
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
475
|
+
}
|
|
476
|
+
catch (e) {
|
|
477
|
+
console.error(e);
|
|
469
478
|
}
|
|
470
479
|
}
|
|
471
480
|
}
|
|
472
|
-
if (defaultTab) {
|
|
473
|
-
menu.default_tab = defaultTab;
|
|
474
|
-
}
|
|
475
481
|
}
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
}
|
|
479
|
-
function getMenuChildren(_a) {
|
|
480
|
-
return tslib_1.__awaiter(this, arguments, void 0, function* ({ objectApiName, userSession, ctx, appPath, app, }) {
|
|
481
|
-
try {
|
|
482
|
-
const objectConfig = yield (0, objectql_1.getObject)(objectApiName).getConfig();
|
|
483
|
-
if (!objectConfig) {
|
|
484
|
-
ctx.broker.logger.error(`${objectApiName} is not found in the objects of app ${app.code} `);
|
|
485
|
-
return;
|
|
486
|
-
}
|
|
487
|
-
const allowRead = yield objectAllowRead(objectApiName, userSession);
|
|
488
|
-
if (!allowRead) {
|
|
489
|
-
return;
|
|
490
|
-
}
|
|
491
|
-
if (objectConfig) {
|
|
492
|
-
const objectLabel = (0, i18n_1.translationObjectLabel)(userSession.language, objectConfig.name, objectConfig.label || objectConfig.name);
|
|
493
|
-
return {
|
|
494
|
-
id: objectConfig.name,
|
|
495
|
-
icon: objectConfig.icon,
|
|
496
|
-
path: `${appPath}/${objectConfig.name}`,
|
|
497
|
-
name: `${objectLabel}`,
|
|
498
|
-
};
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
catch (error) {
|
|
502
|
-
ctx.broker.logger.error(error);
|
|
482
|
+
if (defaultTab) {
|
|
483
|
+
menu.default_tab = defaultTab;
|
|
503
484
|
}
|
|
504
|
-
}
|
|
485
|
+
}
|
|
486
|
+
return menu;
|
|
505
487
|
}
|
|
506
|
-
function
|
|
507
|
-
|
|
508
|
-
const
|
|
509
|
-
if (!
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
let assigned_apps = yield (0, objectql_1.getAssignedApps)(userSession);
|
|
513
|
-
let mobile = ctx.params.mobile;
|
|
514
|
-
if (typeof mobile !== "boolean") {
|
|
515
|
-
mobile = mobile === "true" ? true : false;
|
|
516
|
-
}
|
|
517
|
-
const spaceId = userSession.spaceId;
|
|
518
|
-
const metadataApps = yield getAllApps(ctx);
|
|
519
|
-
const context = yield getContext(ctx);
|
|
520
|
-
const allApps = _.map(metadataApps, "metadata");
|
|
521
|
-
if (assigned_apps && assigned_apps.length) {
|
|
522
|
-
assigned_apps = _.filter(allApps, (item) => {
|
|
523
|
-
return assigned_apps.includes(item.code);
|
|
524
|
-
});
|
|
488
|
+
async function getMenuChildren({ objectApiName, userSession, ctx, appPath, app, }) {
|
|
489
|
+
try {
|
|
490
|
+
const objectConfig = await (0, objectql_1.getObject)(objectApiName).getConfig();
|
|
491
|
+
if (!objectConfig) {
|
|
492
|
+
ctx.broker.logger.error(`${objectApiName} is not found in the objects of app ${app.code} `);
|
|
493
|
+
return;
|
|
525
494
|
}
|
|
526
|
-
|
|
527
|
-
|
|
495
|
+
const allowRead = await objectAllowRead(objectApiName, userSession);
|
|
496
|
+
if (!allowRead) {
|
|
497
|
+
return;
|
|
528
498
|
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
499
|
+
if (objectConfig) {
|
|
500
|
+
const objectLabel = (0, i18n_1.translationObjectLabel)(userSession.language, objectConfig.name, objectConfig.label || objectConfig.name);
|
|
501
|
+
return {
|
|
502
|
+
id: objectConfig.name,
|
|
503
|
+
icon: objectConfig.icon,
|
|
504
|
+
path: `${appPath}/${objectConfig.name}`,
|
|
505
|
+
name: `${objectLabel}`,
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
catch (error) {
|
|
510
|
+
ctx.broker.logger.error(error);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
async function getAppsMenus(ctx) {
|
|
514
|
+
const userSession = ctx.meta.user;
|
|
515
|
+
if (!userSession) {
|
|
516
|
+
throw new Error("no permission.");
|
|
517
|
+
}
|
|
518
|
+
let assigned_apps = await (0, objectql_1.getAssignedApps)(userSession);
|
|
519
|
+
let mobile = ctx.params.mobile;
|
|
520
|
+
if (typeof mobile !== "boolean") {
|
|
521
|
+
mobile = mobile === "true" ? true : false;
|
|
522
|
+
}
|
|
523
|
+
const spaceId = userSession.spaceId;
|
|
524
|
+
const metadataApps = await getAllApps(ctx);
|
|
525
|
+
const context = await getContext(ctx);
|
|
526
|
+
const allApps = _.map(metadataApps, "metadata");
|
|
527
|
+
if (assigned_apps && assigned_apps.length) {
|
|
528
|
+
assigned_apps = _.filter(allApps, (item) => {
|
|
529
|
+
return assigned_apps.includes(item.code);
|
|
547
530
|
});
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
531
|
+
}
|
|
532
|
+
else {
|
|
533
|
+
assigned_apps = allApps;
|
|
534
|
+
}
|
|
535
|
+
const _userApps = _.filter(assigned_apps, function (config) {
|
|
536
|
+
if (!config.visible) {
|
|
537
|
+
return false;
|
|
538
|
+
}
|
|
539
|
+
if (config._id === config.code) {
|
|
540
|
+
let dbApp = _.find(assigned_apps, (item) => {
|
|
541
|
+
return (item.code === config.code &&
|
|
542
|
+
item._id != item.code &&
|
|
543
|
+
item.space === spaceId);
|
|
556
544
|
});
|
|
557
|
-
if (
|
|
558
|
-
|
|
559
|
-
}
|
|
560
|
-
else {
|
|
561
|
-
const _app = userApps[_appIndex];
|
|
562
|
-
if (!_app.space && app.space) {
|
|
563
|
-
userApps[_appIndex] = app;
|
|
564
|
-
}
|
|
545
|
+
if (dbApp) {
|
|
546
|
+
return dbApp.visible;
|
|
565
547
|
}
|
|
548
|
+
}
|
|
549
|
+
if (_.has(config, "space") && config.space) {
|
|
550
|
+
return config.space === spaceId;
|
|
551
|
+
}
|
|
552
|
+
return true;
|
|
553
|
+
});
|
|
554
|
+
const menus = [];
|
|
555
|
+
let userApps = [];
|
|
556
|
+
_.each(_.sortBy(_userApps, ["sort"]), function (app) {
|
|
557
|
+
if (!app.code) {
|
|
558
|
+
app.code = app._id;
|
|
559
|
+
}
|
|
560
|
+
const _appIndex = _.findIndex(userApps, function (item) {
|
|
561
|
+
return item.code === app.code;
|
|
566
562
|
});
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
563
|
+
if (_appIndex < 0) {
|
|
564
|
+
userApps.push(app);
|
|
565
|
+
}
|
|
566
|
+
else {
|
|
567
|
+
const _app = userApps[_appIndex];
|
|
568
|
+
if (!_app.space && app.space) {
|
|
569
|
+
userApps[_appIndex] = app;
|
|
571
570
|
}
|
|
572
571
|
}
|
|
573
|
-
return menus;
|
|
574
572
|
});
|
|
573
|
+
for (const app of _.sortBy(userApps, ["sort"])) {
|
|
574
|
+
const menu = await transformAppToMenus(ctx, app, mobile, userSession, context);
|
|
575
|
+
if (menu) {
|
|
576
|
+
menus.push(menu);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
return menus;
|
|
575
580
|
}
|
|
576
|
-
function getAppMenus(ctx) {
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
return;
|
|
591
|
-
}
|
|
592
|
-
const context = yield getContext(ctx);
|
|
593
|
-
const appMenus = yield transformAppToMenus(ctx, appConfig, mobile, userSession, context);
|
|
594
|
-
if (userSession.is_space_admin &&
|
|
595
|
-
appConfig._id &&
|
|
596
|
-
appConfig.code &&
|
|
597
|
-
appConfig._id != appConfig.code) {
|
|
598
|
-
appMenus.allowEditApp = true;
|
|
599
|
-
}
|
|
600
|
-
return appMenus;
|
|
581
|
+
async function getAppMenus(ctx) {
|
|
582
|
+
const userSession = ctx.meta.user;
|
|
583
|
+
const { mobile } = ctx.params;
|
|
584
|
+
if (!userSession) {
|
|
585
|
+
throw new Error("no permission.");
|
|
586
|
+
}
|
|
587
|
+
const spaceId = userSession.spaceId;
|
|
588
|
+
const metadataConf = await get(ctx);
|
|
589
|
+
if (metadataConf) {
|
|
590
|
+
const appConfig = metadataConf.metadata;
|
|
591
|
+
if (_.has(appConfig, "space") &&
|
|
592
|
+
appConfig.space &&
|
|
593
|
+
appConfig.space != spaceId) {
|
|
594
|
+
return;
|
|
601
595
|
}
|
|
602
|
-
|
|
596
|
+
const context = await getContext(ctx);
|
|
597
|
+
const appMenus = await transformAppToMenus(ctx, appConfig, mobile, userSession, context);
|
|
598
|
+
if (userSession.is_space_admin &&
|
|
599
|
+
appConfig._id &&
|
|
600
|
+
appConfig.code &&
|
|
601
|
+
appConfig._id != appConfig.code) {
|
|
602
|
+
appMenus.allowEditApp = true;
|
|
603
|
+
}
|
|
604
|
+
return appMenus;
|
|
605
|
+
}
|
|
603
606
|
}
|
|
604
607
|
exports.ActionHandlers = {
|
|
605
|
-
get(ctx) {
|
|
606
|
-
return
|
|
607
|
-
return yield ctx.broker.call("metadata.get", { key: cacherKey(ctx.params.appApiName) }, { meta: ctx.meta });
|
|
608
|
-
});
|
|
608
|
+
async get(ctx) {
|
|
609
|
+
return await ctx.broker.call("metadata.get", { key: cacherKey(ctx.params.appApiName) }, { meta: ctx.meta });
|
|
609
610
|
},
|
|
610
|
-
getAll(ctx) {
|
|
611
|
-
return
|
|
612
|
-
return yield getAllApps(ctx);
|
|
613
|
-
});
|
|
611
|
+
async getAll(ctx) {
|
|
612
|
+
return await getAllApps(ctx);
|
|
614
613
|
},
|
|
615
|
-
getMenus(ctx) {
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
return menus;
|
|
619
|
-
});
|
|
614
|
+
async getMenus(ctx) {
|
|
615
|
+
const menus = await getAppsMenus(ctx);
|
|
616
|
+
return menus;
|
|
620
617
|
},
|
|
621
|
-
getAppMenus(ctx) {
|
|
622
|
-
return
|
|
623
|
-
return yield getAppMenus(ctx);
|
|
624
|
-
});
|
|
618
|
+
async getAppMenus(ctx) {
|
|
619
|
+
return await getAppMenus(ctx);
|
|
625
620
|
},
|
|
626
|
-
add(ctx) {
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
}),
|
|
640
|
-
});
|
|
641
|
-
const appConfig = yield (0, _1.refreshApp)(ctx, metadataApiName);
|
|
642
|
-
return yield registerApp(ctx, metadataApiName, appConfig, ctx.meta);
|
|
621
|
+
async add(ctx) {
|
|
622
|
+
let config = ctx.params.data;
|
|
623
|
+
const serviceName = ctx.meta.metadataServiceName;
|
|
624
|
+
const metadataApiName = ctx.params.appApiName;
|
|
625
|
+
const metadataConfig = await (0, _1.getServiceAppConfig)(ctx, serviceName, metadataApiName);
|
|
626
|
+
if (metadataConfig && metadataConfig.metadata) {
|
|
627
|
+
config = (0, utils_1.defaultsDeep)(config, metadataConfig.metadata);
|
|
628
|
+
}
|
|
629
|
+
await ctx.broker.call("metadata.addServiceMetadata", { key: cacherKey(metadataApiName), data: config }, {
|
|
630
|
+
meta: Object.assign({}, ctx.meta, {
|
|
631
|
+
metadataType: _1.METADATA_TYPE,
|
|
632
|
+
metadataApiName: metadataApiName,
|
|
633
|
+
}),
|
|
643
634
|
});
|
|
635
|
+
const appConfig = await (0, _1.refreshApp)(ctx, metadataApiName);
|
|
636
|
+
return await registerApp(ctx, metadataApiName, appConfig, ctx.meta);
|
|
644
637
|
},
|
|
645
|
-
delete(ctx) {
|
|
646
|
-
return
|
|
647
|
-
return yield ctx.broker.call("metadata.delete", { key: cacherKey(ctx.params.appApiName) }, { meta: ctx.meta });
|
|
648
|
-
});
|
|
638
|
+
async delete(ctx) {
|
|
639
|
+
return await ctx.broker.call("metadata.delete", { key: cacherKey(ctx.params.appApiName) }, { meta: ctx.meta });
|
|
649
640
|
},
|
|
650
|
-
verify(ctx) {
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
return true;
|
|
654
|
-
});
|
|
641
|
+
async verify(ctx) {
|
|
642
|
+
console.log("verify");
|
|
643
|
+
return true;
|
|
655
644
|
},
|
|
656
|
-
refresh(ctx) {
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
yield registerApp(ctx, metadataApiName, appConfig, {});
|
|
669
|
-
}
|
|
645
|
+
async refresh(ctx) {
|
|
646
|
+
const { isClear, metadataApiNames } = ctx.params;
|
|
647
|
+
if (isClear) {
|
|
648
|
+
for (const metadataApiName of metadataApiNames) {
|
|
649
|
+
const appConfig = await (0, _1.refreshApp)(ctx, metadataApiName);
|
|
650
|
+
if (!appConfig) {
|
|
651
|
+
await ctx.broker.call("metadata.delete", {
|
|
652
|
+
key: cacherKey(metadataApiName),
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
else {
|
|
656
|
+
await registerApp(ctx, metadataApiName, appConfig, {});
|
|
670
657
|
}
|
|
671
658
|
}
|
|
672
|
-
}
|
|
659
|
+
}
|
|
673
660
|
},
|
|
674
661
|
};
|
|
675
662
|
//# sourceMappingURL=actionsHandler.js.map
|