@topconsultnpm/sdkui-react 6.20.0-dev2.11 → 6.20.0-dev2.12

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.
@@ -225,9 +225,6 @@ export const useRelatedDocuments = ({ selectedSearchResult, focusedItem, current
225
225
  const filterRelationsWithAssociations = (relations) => {
226
226
  return relations.filter(rel => rel.associations && rel.associations.length > 0);
227
227
  };
228
- const getRelatedDcmt = async (relation, type) => {
229
- return await DcmtTypeListCacheService.GetAsync(type === 'detail' ? relation.detailTID : relation.masterTID);
230
- };
231
228
  const showNoRelationsAlert = (type) => {
232
229
  ShowAlert({
233
230
  message: type === 'detail'
@@ -282,6 +279,26 @@ export const useRelatedDocuments = ({ selectedSearchResult, focusedItem, current
282
279
  TMExceptionBoxManager.show({ exception: error });
283
280
  }
284
281
  }, [mapAssociationsToMids]);
282
+ const filterRelationsByPermission = async (relations, type) => {
283
+ const dataSourcePromises = relations.map(async (rel) => {
284
+ const targetTID = type === 'detail' ? rel.detailTID : rel.masterTID;
285
+ const dtd = await DcmtTypeListCacheService.GetWithNotGrantedAsync(targetTID, undefined);
286
+ const hasPermission = dtd?.perm?.canArchive === AccessLevelsEx.Yes || dtd?.perm?.canArchive === AccessLevelsEx.Mixed;
287
+ return { id: rel?.id, name: dtd?.name, hasPermission, relation: rel };
288
+ });
289
+ const allResults = await Promise.all(dataSourcePromises);
290
+ return allResults.filter(r => r.hasPermission);
291
+ };
292
+ const showNoPermissionAlert = (type) => {
293
+ ShowAlert({
294
+ message: type === 'detail'
295
+ ? SDKUI_Localizator.YouDoNotHavePermissionsToArchiveDetailDocumentsOfThisType
296
+ : SDKUI_Localizator.YouDoNotHavePermissionsToArchiveMasterDocumentsOfThisType,
297
+ mode: 'warning',
298
+ title: type === 'detail' ? SDKUI_Localizator.DcmtsDetail : SDKUI_Localizator.DcmtsMaster,
299
+ duration: 5000
300
+ });
301
+ };
285
302
  const archiveRelatedDocuments = useCallback(async (tid, type) => {
286
303
  try {
287
304
  TMSpinner.show({ description: SDKUI_Localizator.Loading });
@@ -300,14 +317,20 @@ export const useRelatedDocuments = ({ selectedSearchResult, focusedItem, current
300
317
  }
301
318
  setRelatedDcmts(withAssociations);
302
319
  if (withAssociations.length > 1) {
303
- const dataSourcePromises = withAssociations.map(async (rel) => {
304
- const relatedDcmt = await getRelatedDcmt(rel, type);
305
- return { id: rel?.id, name: relatedDcmt?.name };
306
- });
307
- const dataSource = await Promise.all(dataSourcePromises);
308
- setRelatedDcmtsChooserDataSource(dataSource);
309
- setArchiveType(type);
310
- setShowRelatedDcmtsChooser(true);
320
+ const permittedResults = await filterRelationsByPermission(withAssociations, type);
321
+ if (permittedResults.length === 0) {
322
+ showNoPermissionAlert(type);
323
+ return;
324
+ }
325
+ if (permittedResults.length === 1) {
326
+ await archiveRelatedDcmtHandler(permittedResults[0].relation, type);
327
+ }
328
+ else {
329
+ const dataSource = permittedResults.map(r => ({ id: r.id, name: r.name }));
330
+ setRelatedDcmtsChooserDataSource(dataSource);
331
+ setArchiveType(type);
332
+ setShowRelatedDcmtsChooser(true);
333
+ }
311
334
  }
312
335
  else {
313
336
  await archiveRelatedDcmtHandler(withAssociations[0], type);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@topconsultnpm/sdkui-react",
3
- "version": "6.20.0-dev2.11",
3
+ "version": "6.20.0-dev2.12",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",