@crowdin/app-project-module 0.79.1 → 0.79.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.
@@ -433,6 +433,9 @@ class MySQLStorage {
433
433
  }
434
434
  deleteWebhooks(fileIds, integrationId, crowdinId, provider) {
435
435
  return __awaiter(this, void 0, void 0, function* () {
436
+ if (!fileIds.length) {
437
+ return;
438
+ }
436
439
  yield this.dbPromise;
437
440
  const placeholders = fileIds.map(() => '?').join(',');
438
441
  yield this.executeQuery((connection) => connection.execute(`DELETE FROM webhooks WHERE file_id IN (${placeholders}) AND integration_id = ? AND crowdin_id = ? AND provider = ?`, [...fileIds, integrationId, crowdinId, provider]));
@@ -516,6 +516,9 @@ class PostgreStorage {
516
516
  }
517
517
  deleteWebhooks(fileIds, integrationId, crowdinId, provider) {
518
518
  return __awaiter(this, void 0, void 0, function* () {
519
+ if (!fileIds.length) {
520
+ return;
521
+ }
519
522
  let index = 0;
520
523
  const placeholders = fileIds.map(() => `$${++index}`).join(',');
521
524
  yield this.dbPromise;
@@ -489,6 +489,9 @@ class SQLiteStorage {
489
489
  }
490
490
  deleteWebhooks(fileIds, integrationId, crowdinId, provider) {
491
491
  return __awaiter(this, void 0, void 0, function* () {
492
+ if (!fileIds.length) {
493
+ return;
494
+ }
492
495
  const placeholders = fileIds.map(() => '?').join(',');
493
496
  return this.run(`DELETE FROM webhooks WHERE file_id IN (${placeholders}) AND integration_id = ? AND crowdin_id = ? AND provider = ?`, [...fileIds, integrationId, crowdinId, provider]);
494
497
  });
@@ -919,6 +919,186 @@
919
919
  }
920
920
  }
921
921
 
922
+ function hideConfirmUsersBlock() {
923
+ const confirmUsersBlock = document.querySelector('.confirm-users-block');
924
+ confirmUsersBlock.classList.add('hidden');
925
+
926
+ const permissionsModal = document.getElementById('permissions-modal');
927
+ permissionsModal.setAttribute('body-overflow-unset', true)
928
+ }
929
+
930
+ function showPermissionsDialog() {
931
+ hideConfirmUsersBlock();
932
+ openModal(permissions)
933
+ setLoader('#permissions-modal');
934
+ const select = document.getElementById('users');
935
+
936
+ select.value = '[]';
937
+
938
+ checkOrigin()
939
+ .then(restParams => fetch('api/users' + restParams))
940
+ .then(checkResponse)
941
+ .then((res) => {
942
+ let userOptions = res.data.users.map(user => `<option value="${user.id}">${sanitizeHTML(user.name)}</option>`).join('');
943
+ select.innerHTML = userOptions;
944
+ select.value = JSON.stringify(res.data.managers);
945
+ })
946
+ .catch(e => catchRejection(e, 'Can\'t fetch users'))
947
+ .finally(() => unsetLoader('#permissions-modal'));
948
+ }
949
+
950
+ function showConfirmUsersBlock() {
951
+ const confirmUsersBlock = document.querySelector('.confirm-users-block');
952
+ confirmUsersBlock.classList.remove('hidden');
953
+
954
+ const permissionsModal = document.getElementById('permissions-modal');
955
+ permissionsModal.removeAttribute('body-overflow-unset')
956
+ }
957
+
958
+ async function inviteUsers(onlyCheck = true) {
959
+ setLoader('#permissions-modal');
960
+
961
+ const select = document.getElementById('users');
962
+
963
+ if (onlyCheck && select.value === '[]') {
964
+ hideConfirmUsersBlock();
965
+ unsetLoader('#permissions-modal');
966
+ return;
967
+ }
968
+
969
+ const params = {
970
+ users: JSON.parse(select.value),
971
+ onlyCheck,
972
+ };
973
+
974
+ checkOrigin()
975
+ .then(restParams => fetch('api/invite-users' + restParams, {
976
+ method: 'POST',
977
+ headers: { 'Content-Type': 'application/json' },
978
+ body: JSON.stringify(params)
979
+ }))
980
+ .then(checkResponse)
981
+ .then((response) => {
982
+ if (!onlyCheck) {
983
+ showToast('Users successfully updated');
984
+ hideConfirmUsersBlock();
985
+ closeModal(permissions);
986
+ return;
987
+ }
988
+
989
+ prepareUsersConfirmBlock(response.data);
990
+ })
991
+ .catch(e => {
992
+ catchRejection(e, e?.error || 'Can\'t invite users')
993
+ })
994
+ .finally(() => unsetLoader('#permissions-modal'));
995
+ }
996
+
997
+ function prepareUsersConfirmBlock(usersData) {
998
+ showConfirmUsersBlock();
999
+
1000
+ const organizationInvite = document.querySelector('.organization-invite');
1001
+ const projectInvite = document.querySelector('.project-invite');
1002
+ const applicationCredentialsInvite = document.querySelector('.application-credentials-invite');
1003
+
1004
+ const grantedElement = '<crowdin-p>&horbar;</crowdin-p>';
1005
+ const willGrantedElement = '<span class="badge badge-will-be-granted">Will Be Granted</span>';
1006
+ const notAvailableElement = '<span class="badge badge-not-available">Action Required</span>';
1007
+
1008
+ // only in enterprise
1009
+ if (organizationInvite) {
1010
+ const organizationWillGrantElement = `<span class="badge badge-will-be-granted">Will Be Registered</span>`;
1011
+
1012
+ processUsersWhoWillBeInvited(organizationInvite, usersData.usersWhoWillBeInvitedToOrganization, organizationWillGrantElement, grantedElement);
1013
+ }
1014
+
1015
+ processUsersWhoWillBeInvited(projectInvite, usersData.usersWhoWillBeInvitedToProject, willGrantedElement, grantedElement);
1016
+ processUsersWhoWillBeInvited(applicationCredentialsInvite, usersData.usersWhoNotIssetInIntegration, willGrantedElement, grantedElement);
1017
+
1018
+ processUsersWhoWillBeInvitedApplicationSettings(usersData, willGrantedElement, grantedElement, notAvailableElement);
1019
+ }
1020
+
1021
+ function processUsersWhoWillBeInvited(element, users, grantMessage, alreadyGrantedMessage) {
1022
+ const tooltip = element.querySelector('.status');
1023
+ const userList = element.querySelector('.affected-users');
1024
+
1025
+ if (users.length) {
1026
+ tooltip.innerHTML = grantMessage;
1027
+
1028
+ let affectedUsers = '<ul>';
1029
+ for (const user of users) {
1030
+ affectedUsers += `<li><crowdin-p>${sanitizeHTML(user.name)}</crowdin-p></li>`;
1031
+ }
1032
+ affectedUsers += '</ul>';
1033
+ userList.innerHTML = affectedUsers;
1034
+ } else {
1035
+ tooltip.innerHTML = alreadyGrantedMessage;
1036
+ userList.innerHTML = alreadyGrantedMessage;
1037
+ }
1038
+ }
1039
+
1040
+ function processUsersWhoWillBeInvitedApplicationSettings(usersData, willGrantedElement, grantedElement, notAvailableElement) {
1041
+ const applicationSettingsInvite = document.querySelector('.application-settings-invite');
1042
+
1043
+ const tooltip = applicationSettingsInvite.querySelector('.status');
1044
+ const description = applicationSettingsInvite.querySelector('.permission-description');
1045
+ const userList = applicationSettingsInvite.querySelector('.affected-users');
1046
+
1047
+ let descriptionMessage = 'This can be configured in organization settings (Apps section).';
1048
+ description.classList.remove('text-warning');
1049
+ description.innerText = descriptionMessage;
1050
+
1051
+ let affectedUsers = '<ul>';
1052
+
1053
+ if (!usersData.editApplicationAvailable) {
1054
+ descriptionMessage += ' The application doesn\'t have permission to update this setting.';
1055
+ descriptionMessage += usersData.isAdmin ? ' Please reinstall the app.' : ' Please ask the organization admin to reinstall the app.';
1056
+
1057
+ description.classList.add('text-warning');
1058
+ description.innerText = descriptionMessage;
1059
+
1060
+ tooltip.innerHTML = notAvailableElement;
1061
+ for (const user of usersData.usersWhoNotIssetInApplicationInstallation) {
1062
+ affectedUsers += `<li><crowdin-p>${sanitizeHTML(user.name)}</crowdin-p></li>`;
1063
+ }
1064
+ userList.innerHTML = affectedUsers + '</ul>';
1065
+ } else if (!usersData.usersWhoNotIssetInApplicationInstallation.length) {
1066
+ tooltip.innerHTML = grantedElement;
1067
+ userList.innerHTML = grantedElement;
1068
+ } else {
1069
+ if (usersData.isAdmin) {
1070
+ tooltip.innerHTML = willGrantedElement;
1071
+ for (const user of usersData.usersWhoNotIssetInApplicationInstallation) {
1072
+ affectedUsers += `<li><crowdin-p>${sanitizeHTML(user.name)}</crowdin-p></li>`;
1073
+ }
1074
+ userList.innerHTML = affectedUsers + '</ul>';
1075
+ } else {
1076
+ descriptionMessage += ' Only organization admins have permission to update this setting.';
1077
+
1078
+ description.classList.add('text-warning');
1079
+ description.innerText = descriptionMessage;
1080
+
1081
+ tooltip.innerHTML = notAvailableElement;
1082
+ for (const user of usersData.usersWhoNotIssetInApplicationInstallation) {
1083
+ affectedUsers += `<li><crowdin-p>${sanitizeHTML(user.name)}</crowdin-p></li>`;
1084
+ }
1085
+ userList.innerHTML = affectedUsers + '</ul>';
1086
+ }
1087
+ }
1088
+ }
1089
+
1090
+ function setLoader(id) {
1091
+ const loader = document.querySelector(`${id} .loader`);
1092
+ loader.classList.remove('hidden');
1093
+ }
1094
+
1095
+ function unsetLoader(id) {
1096
+ const loader = document.querySelector(`${id} .loader`);
1097
+ setTimeout(function() {
1098
+ loader.classList.add('hidden');
1099
+ }, 500)
1100
+ }
1101
+
922
1102
  {{#if configurationFields}}
923
1103
  const settingsModal = document.getElementById('settings-modal');
924
1104
  const settingsSaveBtn = document.getElementById('settings-save-btn');
@@ -998,186 +1178,6 @@
998
1178
  {{/if}}
999
1179
  });
1000
1180
  }
1001
-
1002
- function showConfirmUsersBlock() {
1003
- const confirmUsersBlock = document.querySelector('.confirm-users-block');
1004
- confirmUsersBlock.classList.remove('hidden');
1005
-
1006
- const permissionsModal = document.getElementById('permissions-modal');
1007
- permissionsModal.removeAttribute('body-overflow-unset')
1008
- }
1009
-
1010
- function hideConfirmUsersBlock() {
1011
- const confirmUsersBlock = document.querySelector('.confirm-users-block');
1012
- confirmUsersBlock.classList.add('hidden');
1013
-
1014
- const permissionsModal = document.getElementById('permissions-modal');
1015
- permissionsModal.setAttribute('body-overflow-unset', true)
1016
- }
1017
-
1018
- function showPermissionsDialog() {
1019
- hideConfirmUsersBlock();
1020
- openModal(permissions)
1021
- setLoader('#permissions-modal');
1022
- const select = document.getElementById('users');
1023
-
1024
- select.value = '[]';
1025
-
1026
- checkOrigin()
1027
- .then(restParams => fetch('api/users' + restParams))
1028
- .then(checkResponse)
1029
- .then((res) => {
1030
- let userOptions = res.data.users.map(user => `<option value="${user.id}">${sanitizeHTML(user.name)}</option>`).join('');
1031
- select.innerHTML = userOptions;
1032
- select.value = JSON.stringify(res.data.managers);
1033
- })
1034
- .catch(e => catchRejection(e, 'Can\'t fetch users'))
1035
- .finally(() => unsetLoader('#permissions-modal'));
1036
- }
1037
-
1038
- async function inviteUsers(onlyCheck = true) {
1039
- setLoader('#permissions-modal');
1040
-
1041
- const select = document.getElementById('users');
1042
-
1043
- if (onlyCheck && select.value === '[]') {
1044
- hideConfirmUsersBlock();
1045
- unsetLoader('#permissions-modal');
1046
- return;
1047
- }
1048
-
1049
- const params = {
1050
- users: JSON.parse(select.value),
1051
- onlyCheck,
1052
- };
1053
-
1054
- checkOrigin()
1055
- .then(restParams => fetch('api/invite-users' + restParams, {
1056
- method: 'POST',
1057
- headers: { 'Content-Type': 'application/json' },
1058
- body: JSON.stringify(params)
1059
- }))
1060
- .then(checkResponse)
1061
- .then((response) => {
1062
- if (!onlyCheck) {
1063
- showToast('Users successfully updated');
1064
- hideConfirmUsersBlock();
1065
- closeModal(permissions);
1066
- return;
1067
- }
1068
-
1069
- prepareUsersConfirmBlock(response.data);
1070
- })
1071
- .catch(e => {
1072
- catchRejection(e, e?.error || 'Can\'t invite users')
1073
- })
1074
- .finally(() => unsetLoader('#permissions-modal'));
1075
- }
1076
-
1077
- function prepareUsersConfirmBlock(usersData) {
1078
- showConfirmUsersBlock();
1079
-
1080
- const organizationInvite = document.querySelector('.organization-invite');
1081
- const projectInvite = document.querySelector('.project-invite');
1082
- const applicationCredentialsInvite = document.querySelector('.application-credentials-invite');
1083
-
1084
- const grantedElement = '<crowdin-p>&horbar;</crowdin-p>';
1085
- const willGrantedElement = '<span class="badge badge-will-be-granted">Will Be Granted</span>';
1086
- const notAvailableElement = '<span class="badge badge-not-available">Action Required</span>';
1087
-
1088
- // only in enterprise
1089
- if (organizationInvite) {
1090
- const organizationWillGrantElement = `<span class="badge badge-will-be-granted">Will Be Registered</span>`;
1091
-
1092
- processUsersWhoWillBeInvited(organizationInvite, usersData.usersWhoWillBeInvitedToOrganization, organizationWillGrantElement, grantedElement);
1093
- }
1094
-
1095
- processUsersWhoWillBeInvited(projectInvite, usersData.usersWhoWillBeInvitedToProject, willGrantedElement, grantedElement);
1096
- processUsersWhoWillBeInvited(applicationCredentialsInvite, usersData.usersWhoNotIssetInIntegration, willGrantedElement, grantedElement);
1097
-
1098
- processUsersWhoWillBeInvitedApplicationSettings(usersData, willGrantedElement, grantedElement, notAvailableElement);
1099
- }
1100
-
1101
- function processUsersWhoWillBeInvited(element, users, grantMessage, alreadyGrantedMessage) {
1102
- const tooltip = element.querySelector('.status');
1103
- const userList = element.querySelector('.affected-users');
1104
-
1105
- if (users.length) {
1106
- tooltip.innerHTML = grantMessage;
1107
-
1108
- let affectedUsers = '<ul>';
1109
- for (const user of users) {
1110
- affectedUsers += `<li><crowdin-p>${sanitizeHTML(user.name)}</crowdin-p></li>`;
1111
- }
1112
- affectedUsers += '</ul>';
1113
- userList.innerHTML = affectedUsers;
1114
- } else {
1115
- tooltip.innerHTML = alreadyGrantedMessage;
1116
- userList.innerHTML = alreadyGrantedMessage;
1117
- }
1118
- }
1119
-
1120
- function processUsersWhoWillBeInvitedApplicationSettings(usersData, willGrantedElement, grantedElement, notAvailableElement) {
1121
- const applicationSettingsInvite = document.querySelector('.application-settings-invite');
1122
-
1123
- const tooltip = applicationSettingsInvite.querySelector('.status');
1124
- const description = applicationSettingsInvite.querySelector('.permission-description');
1125
- const userList = applicationSettingsInvite.querySelector('.affected-users');
1126
-
1127
- let descriptionMessage = 'This can be configured in organization settings (Apps section).';
1128
- description.classList.remove('text-warning');
1129
- description.innerText = descriptionMessage;
1130
-
1131
- let affectedUsers = '<ul>';
1132
-
1133
- if (!usersData.editApplicationAvailable) {
1134
- descriptionMessage += ' The application doesn\'t have permission to update this setting.';
1135
- descriptionMessage += usersData.isAdmin ? ' Please reinstall the app.' : ' Please ask the organization admin to reinstall the app.';
1136
-
1137
- description.classList.add('text-warning');
1138
- description.innerText = descriptionMessage;
1139
-
1140
- tooltip.innerHTML = notAvailableElement;
1141
- for (const user of usersData.usersWhoNotIssetInApplicationInstallation) {
1142
- affectedUsers += `<li><crowdin-p>${sanitizeHTML(user.name)}</crowdin-p></li>`;
1143
- }
1144
- userList.innerHTML = affectedUsers + '</ul>';
1145
- } else if (!usersData.usersWhoNotIssetInApplicationInstallation.length) {
1146
- tooltip.innerHTML = grantedElement;
1147
- userList.innerHTML = grantedElement;
1148
- } else {
1149
- if (usersData.isAdmin) {
1150
- tooltip.innerHTML = willGrantedElement;
1151
- for (const user of usersData.usersWhoNotIssetInApplicationInstallation) {
1152
- affectedUsers += `<li><crowdin-p>${sanitizeHTML(user.name)}</crowdin-p></li>`;
1153
- }
1154
- userList.innerHTML = affectedUsers + '</ul>';
1155
- } else {
1156
- descriptionMessage += ' Only organization admins have permission to update this setting.';
1157
-
1158
- description.classList.add('text-warning');
1159
- description.innerText = descriptionMessage;
1160
-
1161
- tooltip.innerHTML = notAvailableElement;
1162
- for (const user of usersData.usersWhoNotIssetInApplicationInstallation) {
1163
- affectedUsers += `<li><crowdin-p>${sanitizeHTML(user.name)}</crowdin-p></li>`;
1164
- }
1165
- userList.innerHTML = affectedUsers + '</ul>';
1166
- }
1167
- }
1168
- }
1169
-
1170
- function setLoader(id) {
1171
- const loader = document.querySelector(`${id} .loader`);
1172
- loader.classList.remove('hidden');
1173
- }
1174
-
1175
- function unsetLoader(id) {
1176
- const loader = document.querySelector(`${id} .loader`);
1177
- setTimeout(function() {
1178
- loader.classList.add('hidden');
1179
- }, 500)
1180
- }
1181
1181
  {{else}}
1182
1182
  const settingsModal = undefined;
1183
1183
  {{/if}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowdin/app-project-module",
3
- "version": "0.79.1",
3
+ "version": "0.79.2",
4
4
  "description": "Module that generates for you all common endpoints for serving standalone Crowdin App",
5
5
  "main": "out/index.js",
6
6
  "types": "out/index.d.ts",