@crowdin/app-project-module 0.71.0 → 0.71.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -63,7 +63,8 @@ function handle(config, integration, optional = false) {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
if (!integrationCredentials) {
|
|
66
|
-
|
|
66
|
+
const owners = yield getIntegrationManagedBy(ownerIds, req);
|
|
67
|
+
if (optional && !owners.length) {
|
|
67
68
|
return next();
|
|
68
69
|
}
|
|
69
70
|
const errorOptions = {
|
|
@@ -72,10 +73,10 @@ function handle(config, integration, optional = false) {
|
|
|
72
73
|
owners: null,
|
|
73
74
|
hideActions: false,
|
|
74
75
|
};
|
|
75
|
-
if (
|
|
76
|
+
if (owners) {
|
|
76
77
|
errorOptions.message = 'Looks like you don’t have access';
|
|
77
78
|
errorOptions.hideActions = true;
|
|
78
|
-
errorOptions.owners =
|
|
79
|
+
errorOptions.owners = owners;
|
|
79
80
|
}
|
|
80
81
|
else {
|
|
81
82
|
(0, logger_1.temporaryErrorDebug)('Access denied: integration-credentials', req);
|
|
@@ -109,10 +110,21 @@ function checkUserAccessToIntegration(integrationCredentials, userId) {
|
|
|
109
110
|
}
|
|
110
111
|
function getIntegrationManagedBy(ownerIds, req) {
|
|
111
112
|
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
if (!ownerIds.length) {
|
|
114
|
+
return [];
|
|
115
|
+
}
|
|
112
116
|
const projectId = crowdinAppFunctions.getProjectId(req.crowdinContext.clientId);
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
117
|
+
let owners = [];
|
|
118
|
+
try {
|
|
119
|
+
owners =
|
|
120
|
+
ownerIds.length > 1
|
|
121
|
+
? (yield req.crowdinApiClient.usersApi.listProjectMembers(projectId)).data.filter((member) => ownerIds.includes(member.data.id))
|
|
122
|
+
: [yield req.crowdinApiClient.usersApi.getProjectMemberPermissions(projectId, ownerIds[0])];
|
|
123
|
+
}
|
|
124
|
+
catch (e) {
|
|
125
|
+
console.warn('Failed to get project members', e);
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
116
128
|
return owners.map((owner) => {
|
|
117
129
|
const ownerFullName = 'fullName' in owner.data
|
|
118
130
|
? owner.data.fullName
|
|
@@ -147,7 +147,7 @@ function applyIntegrationModuleDefaults(config, integration) {
|
|
|
147
147
|
fields = yield getUserSettings(projectId, crowdinClient, integrationCredentials);
|
|
148
148
|
}
|
|
149
149
|
const defaultSettings = [];
|
|
150
|
-
const mangers = yield getManagers(
|
|
150
|
+
const mangers = yield getManagers(crowdinClient, projectId, integrationCredentials.ownerId);
|
|
151
151
|
if (mangers.length) {
|
|
152
152
|
defaultSettings.push({
|
|
153
153
|
key: 'managers',
|
|
@@ -320,17 +320,30 @@ function getOAuthLoginFormId(clientId) {
|
|
|
320
320
|
return `oauth_form_${clientId}`;
|
|
321
321
|
}
|
|
322
322
|
exports.getOAuthLoginFormId = getOAuthLoginFormId;
|
|
323
|
-
function getManagers(
|
|
323
|
+
function getManagers(client, projectId, ownerId) {
|
|
324
324
|
return __awaiter(this, void 0, void 0, function* () {
|
|
325
325
|
const managers = [];
|
|
326
326
|
if (client.organization) {
|
|
327
|
-
|
|
328
|
-
|
|
327
|
+
try {
|
|
328
|
+
const admins = (yield client.usersApi.withFetchAll().listUsers()).data.filter((user) => user.data.isAdmin);
|
|
329
|
+
managers.push(...admins.map((admin) => admin.data));
|
|
330
|
+
}
|
|
331
|
+
catch (e) {
|
|
332
|
+
console.error('Failed to get organization users', e);
|
|
333
|
+
}
|
|
329
334
|
}
|
|
330
|
-
const projectMembers = (yield client.usersApi.listProjectMembers(projectId)).data.filter((user) => 'role' in user.data ? ['owner', 'manager'].includes(user.data.role) : user.data.isManager);
|
|
335
|
+
const projectMembers = (yield client.usersApi.withFetchAll().listProjectMembers(projectId)).data.filter((user) => 'role' in user.data ? ['owner', 'manager'].includes(user.data.role) : user.data.isManager);
|
|
331
336
|
managers.push(...projectMembers.map((members) => members.data));
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
337
|
+
const uniqueManagers = new Map();
|
|
338
|
+
managers.forEach((manager) => {
|
|
339
|
+
if (manager.id !== ownerId && !uniqueManagers.has(manager.id)) {
|
|
340
|
+
uniqueManagers.set(manager.id, manager);
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
return Array.from(uniqueManagers.values()).sort((a, b) => {
|
|
344
|
+
const aValue = a.firstName || a.username || '';
|
|
345
|
+
const bValue = b.firstName || b.username || '';
|
|
346
|
+
return aValue.localeCompare(bValue);
|
|
347
|
+
});
|
|
335
348
|
});
|
|
336
349
|
}
|