passbolt-styleguide 5.14.2 → 5.14.5

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.
Files changed (101) hide show
  1. package/RELEASE_NOTES.md +6 -2
  2. package/build/css/help.min.css +2 -2
  3. package/build/css/public.min.css +2 -2
  4. package/build/css/themes/default/api_authentication.min.css +2 -2
  5. package/build/css/themes/default/api_cloud.min.css +2 -2
  6. package/build/css/themes/default/api_main.min.css +2 -2
  7. package/build/css/themes/default/api_reports.min.css +2 -2
  8. package/build/css/themes/default/api_webinstaller.min.css +2 -2
  9. package/build/css/themes/default/ext_app.min.css +3 -3
  10. package/build/css/themes/default/ext_authentication.min.css +2 -2
  11. package/build/css/themes/default/ext_external.min.css +2 -2
  12. package/build/css/themes/default/ext_in_form_cta.min.css +2 -2
  13. package/build/css/themes/default/ext_in_form_menu.min.css +2 -2
  14. package/build/css/themes/default/ext_quickaccess.min.css +2 -2
  15. package/build/css/themes/midgar/api_authentication.min.css +2 -2
  16. package/build/css/themes/midgar/api_main.min.css +2 -2
  17. package/build/css/themes/midgar/api_reports.min.css +2 -2
  18. package/build/css/themes/midgar/ext_app.min.css +3 -3
  19. package/build/css/themes/midgar/ext_authentication.min.css +2 -2
  20. package/build/css/themes/midgar/ext_in_form_cta.min.css +2 -2
  21. package/build/css/themes/midgar/ext_in_form_menu.min.css +2 -2
  22. package/build/css/themes/midgar/ext_quickaccess.min.css +2 -2
  23. package/build/css/themes/solarized_dark/api_authentication.min.css +2 -2
  24. package/build/css/themes/solarized_dark/api_main.min.css +2 -2
  25. package/build/css/themes/solarized_dark/api_reports.min.css +2 -2
  26. package/build/css/themes/solarized_dark/ext_app.min.css +3 -3
  27. package/build/css/themes/solarized_dark/ext_authentication.min.css +2 -2
  28. package/build/css/themes/solarized_dark/ext_in_form_cta.min.css +2 -2
  29. package/build/css/themes/solarized_dark/ext_in_form_menu.min.css +2 -2
  30. package/build/css/themes/solarized_dark/ext_quickaccess.min.css +2 -2
  31. package/build/css/themes/solarized_light/api_authentication.min.css +2 -2
  32. package/build/css/themes/solarized_light/api_main.min.css +2 -2
  33. package/build/css/themes/solarized_light/api_reports.min.css +2 -2
  34. package/build/css/themes/solarized_light/ext_app.min.css +3 -3
  35. package/build/css/themes/solarized_light/ext_authentication.min.css +2 -2
  36. package/build/css/themes/solarized_light/ext_in_form_cta.min.css +2 -2
  37. package/build/css/themes/solarized_light/ext_in_form_menu.min.css +2 -2
  38. package/build/css/themes/solarized_light/ext_quickaccess.min.css +2 -2
  39. package/build/js/dist/api-app.js +1 -1
  40. package/build/locales/cs-CZ/common.json +1 -1
  41. package/build/locales/de-DE/common.json +1 -1
  42. package/build/locales/en-UK/common.json +1 -1
  43. package/build/locales/es-ES/common.json +1 -1
  44. package/build/locales/fr-FR/common.json +1 -1
  45. package/build/locales/it-IT/common.json +1 -1
  46. package/build/locales/ja-JP/common.json +1 -1
  47. package/build/locales/ko-KR/common.json +1 -1
  48. package/build/locales/lt-LT/common.json +1 -1
  49. package/build/locales/nl-NL/common.json +1 -1
  50. package/build/locales/pl-PL/common.json +1 -1
  51. package/build/locales/pt-BR/common.json +1 -1
  52. package/build/locales/ro-RO/common.json +1 -1
  53. package/build/locales/ru-RU/common.json +1 -1
  54. package/build/locales/sl-SI/common.json +1 -1
  55. package/build/locales/sv-SE/common.json +1 -1
  56. package/build/locales/uk-UA/common.json +1 -1
  57. package/package.json +1 -1
  58. package/src/locales/cs-CZ/common.json +1 -1
  59. package/src/locales/de-DE/common.json +1 -1
  60. package/src/locales/en-UK/common.json +1 -1
  61. package/src/locales/es-ES/common.json +1 -1
  62. package/src/locales/fr-FR/common.json +1 -1
  63. package/src/locales/it-IT/common.json +1 -1
  64. package/src/locales/ja-JP/common.json +1 -1
  65. package/src/locales/ko-KR/common.json +1 -1
  66. package/src/locales/lt-LT/common.json +1 -1
  67. package/src/locales/nl-NL/common.json +1 -1
  68. package/src/locales/pl-PL/common.json +1 -1
  69. package/src/locales/pt-BR/common.json +1 -1
  70. package/src/locales/ro-RO/common.json +1 -1
  71. package/src/locales/ru-RU/common.json +1 -1
  72. package/src/locales/sl-SI/common.json +1 -1
  73. package/src/locales/sv-SE/common.json +1 -1
  74. package/src/locales/uk-UA/common.json +1 -1
  75. package/src/react-extension/components/Administration/DisplaySubscriptionKey/DisplaySubscriptionKey.js +6 -11
  76. package/src/react-extension/components/Administration/DisplaySubscriptionKey/DisplaySubscriptionKey.test.js +0 -28
  77. package/src/react-extension/components/Resource/HandlePermissionWorkflow/flows/FolderShareFlow.js +7 -7
  78. package/src/react-extension/components/Resource/HandlePermissionWorkflow/flows/FolderShareFlow.test.js +6 -9
  79. package/src/react-extension/components/Resource/HandlePermissionWorkflow/flows/ResourceCreationFlow.js +17 -24
  80. package/src/react-extension/components/Resource/HandlePermissionWorkflow/flows/ResourceCreationFlow.test.js +15 -17
  81. package/src/react-extension/components/Resource/HandlePermissionWorkflow/flows/ResourceEditFlow.js +23 -17
  82. package/src/react-extension/components/Resource/HandlePermissionWorkflow/flows/ResourceEditFlow.test.js +18 -31
  83. package/src/react-extension/components/Resource/HandlePermissionWorkflow/flows/ResourceShareFlow.js +4 -5
  84. package/src/react-extension/components/Resource/HandlePermissionWorkflow/flows/ResourceShareFlow.test.js +14 -22
  85. package/src/react-extension/components/Share/GroupPermissionItem.js +12 -19
  86. package/src/react-extension/components/Share/GroupPermissionItem.test.data.js +0 -1
  87. package/src/react-extension/components/Share/GroupPermissionItem.test.js +6 -14
  88. package/src/react-extension/components/Share/GroupPermissionItem.test.stories.js +0 -4
  89. package/src/react-extension/components/Share/ShareDialog.js +176 -159
  90. package/src/react-extension/components/Share/ShareDialog.test.data.js +241 -8
  91. package/src/react-extension/components/Share/ShareDialog.test.js +108 -505
  92. package/src/react-extension/components/Share/ShareDialog.test.stories.js +0 -3
  93. package/src/react-extension/contexts/ExtAppContext.js +0 -6
  94. package/src/react-extension/contexts/WorkflowContext.js +4 -0
  95. package/src/shared/models/entity/groupUser/groupUserEntity.js +52 -6
  96. package/src/shared/models/entity/groupUser/groupUserEntity.test.data.js +5 -0
  97. package/src/shared/models/entity/groupUser/groupUserEntity.test.js +54 -0
  98. package/src/shared/services/permission/permissionSnapshotService.js +20 -20
  99. package/src/shared/services/permission/permissionSnapshotService.test.js +77 -53
  100. package/src/shared/services/serviceWorker/group/groupServiceWorkerService.js +6 -18
  101. package/src/shared/services/serviceWorker/group/groupServiceWorkerService.test.js +13 -27
@@ -31,8 +31,8 @@ import { withActionFeedback } from "../../contexts/ActionFeedbackContext";
31
31
  import { withResourceWorkspace } from "../../contexts/ResourceWorkspaceContext";
32
32
  import { Trans, withTranslation } from "react-i18next";
33
33
  import PermissionEntity from "../../../shared/models/entity/permission/permissionEntity";
34
+ import UserEntity from "../../../shared/models/entity/user/userEntity";
34
35
  import GroupServiceWorkerService from "../../../shared/services/serviceWorker/group/groupServiceWorkerService";
35
- import UserServiceWorkerService from "../../../shared/services/serviceWorker/user/userServiceWorkerService";
36
36
 
37
37
  class ShareDialog extends Component {
38
38
  /**
@@ -53,31 +53,16 @@ class ShareDialog extends Component {
53
53
  * ComponentDidMount
54
54
  * Invoked immediately after component is inserted into the tree.
55
55
  *
56
- * Controlled mode: when `initialResources` is provided (alongside `initialGroups`,
57
- * `initialUsers`, and an `onConfirm` callback) the dialog seeds itself from those
58
- * collections instead of fetching via the port. Used by the HandlePermissionWorkflow flows
59
- * to review a permission set before applying it.
56
+ * The dialog seeds itself from those collections instead of fetching via the port.
57
+ * Used by the HandlePermissionWorkflow flows to review a permission set before applying it.
60
58
  *
61
59
  * @return {void}
62
60
  */
63
61
  async componentDidMount() {
64
- if (this.isControlledMode()) {
65
- const controlledAcos = this.buildControlledResources();
66
- if (this.props.acoType === PermissionEntity.ACO_FOLDER) {
67
- this.folders = controlledAcos;
68
- } else {
69
- this.resources = controlledAcos;
70
- }
62
+ if (this.props.acoType === PermissionEntity.ACO_FOLDER) {
63
+ this.folders = this.buildControlledResources(this.props.initialFolders);
71
64
  } else {
72
- if (this.props.context.shareDialogProps.resourcesIds) {
73
- await this.findResourcesDetails();
74
- }
75
- if (this.props.context.shareDialogProps.foldersIds) {
76
- this.folders = await this.props.context.port.request(
77
- "passbolt.share.get-folders",
78
- this.props.context.shareDialogProps.foldersIds,
79
- );
80
- }
65
+ this.resources = this.buildControlledResources(this.props.initialResources);
81
66
  }
82
67
 
83
68
  this.shareChanges = new ShareChanges(this.resources, this.folders);
@@ -97,14 +82,6 @@ class ShareDialog extends Component {
97
82
  });
98
83
  }
99
84
 
100
- /**
101
- * True when the dialog is operated by the workflow handler with controlled-mode props.
102
- * @returns {boolean}
103
- */
104
- isControlledMode() {
105
- return Boolean(this.props.initialResources);
106
- }
107
-
108
85
  /**
109
86
  * True when the dialog is displayed read-only: the operator can review the permission set and
110
87
  * confirm it as-is but cannot change it. Used by the edit workflow when the operator has update
@@ -123,7 +100,7 @@ class ShareDialog extends Component {
123
100
  * real resources. The user/group lookup maps are built once and shared across resources.
124
101
  * @returns {Array<object>}
125
102
  */
126
- buildControlledResources() {
103
+ buildControlledResources(resourcesList) {
127
104
  const groupsById = {};
128
105
  this.props.initialGroups?.items.forEach((group) => {
129
106
  groupsById[group.id] = group.toDto();
@@ -133,14 +110,14 @@ class ShareDialog extends Component {
133
110
  usersById[user.id] = user.toDto(this.props.initialUsers.entityClass?.ALL_CONTAIN_OPTIONS);
134
111
  });
135
112
 
136
- return this.props.initialResources.map((resource) => this.buildControlledResource(resource, groupsById, usersById));
113
+ return resourcesList.map((resource) => this.buildControlledResource(resource, groupsById, usersById));
137
114
  }
138
115
 
139
116
  /**
140
117
  * Build a single controlled-mode resource DTO, embedding the referenced user/group from the
141
- * provided lookup maps so ShareChanges can render and track edits. The resource id (null for a
142
- * not-yet-created resource, the real id when sharing an existing one) is stamped as each
143
- * permission's `aco_foreign_key`.
118
+ * provided lookup maps — falling back to the aro embedded in the permission itself, since
119
+ * directly-permissioned users are not part of `initialUsers` — so ShareChanges can render and
120
+ * track edits.
144
121
  * @param {{id: (string|null), metadata: object, permission: object, permissions: PermissionsCollection}} resource
145
122
  * @param {object} groupsById The referenced groups keyed by id.
146
123
  * @param {object} usersById The referenced users keyed by id.
@@ -148,13 +125,13 @@ class ShareDialog extends Component {
148
125
  */
149
126
  buildControlledResource(resource, groupsById, usersById) {
150
127
  const mappedPermissions = resource.permissions.items.map((permission) => {
151
- const dto = permission.toDto();
128
+ const dto = permission.toDto(PermissionEntity.ALL_CONTAIN_OPTIONS);
152
129
  dto.aco = this.props.acoType ?? PermissionEntity.ACO_RESOURCE;
153
130
  dto.aco_foreign_key = resource.id;
154
131
  if (dto.aro === PermissionEntity.ARO_USER) {
155
- dto.user = usersById[dto.aro_foreign_key];
132
+ dto.user = usersById[dto.aro_foreign_key] ?? dto.user;
156
133
  } else if (dto.aro === PermissionEntity.ARO_GROUP) {
157
- dto.group = groupsById[dto.aro_foreign_key];
134
+ dto.group = groupsById[dto.aro_foreign_key] ?? dto.group;
158
135
  }
159
136
  return dto;
160
137
  });
@@ -189,6 +166,8 @@ class ShareDialog extends Component {
189
166
 
190
167
  // autocomplete
191
168
  autocompleteOpen: false,
169
+
170
+ isFetchingGroupMembers: false,
192
171
  };
193
172
  }
194
173
 
@@ -212,23 +191,6 @@ class ShareDialog extends Component {
212
191
  this.renderContainer = this.renderContainer.bind(this);
213
192
  }
214
193
 
215
- /**
216
- * Find the resources details.
217
- * Close the dialog in case of error.
218
- * @returns {Promise<void>}
219
- */
220
- async findResourcesDetails() {
221
- try {
222
- this.resources = await this.props.context.port.request(
223
- "passbolt.resources.find-all-by-ids-for-display-permissions",
224
- this.props.context.shareDialogProps.resourcesIds,
225
- );
226
- } catch (error) {
227
- this.handleError(error);
228
- this.props.onClose();
229
- }
230
- }
231
-
232
194
  /**
233
195
  * Handle close button click.
234
196
  * @returns {void}
@@ -274,6 +236,10 @@ class ShareDialog extends Component {
274
236
  return;
275
237
  }
276
238
 
239
+ if (this.state.isFetchingGroupMembers) {
240
+ return;
241
+ }
242
+
277
243
  this.setState({ processing: true });
278
244
  try {
279
245
  await this.shareSave();
@@ -292,15 +258,8 @@ class ShareDialog extends Component {
292
258
  * when this dialog closes — so we only close.
293
259
  */
294
260
  async handleSaveSuccess() {
295
- if (this.isControlledMode()) {
296
- this.props.onClose();
297
- return;
298
- }
299
- await this.props.actionFeedbackContext.displaySuccess(
300
- this.translate("The permissions have been changed successfully."),
301
- );
302
- await this.props.resourceWorkspaceContext.onResourceShared();
303
261
  this.props.onClose();
262
+ return;
304
263
  }
305
264
 
306
265
  /**
@@ -333,6 +292,10 @@ class ShareDialog extends Component {
333
292
  return;
334
293
  }
335
294
 
295
+ if (!aro.profile && !this.hasFetchedGroupMembers(aro.id)) {
296
+ this.fetchGroupMembers(aro.id);
297
+ }
298
+
336
299
  // TODO restore to original permission if any
337
300
  const permission = this.shareChanges.addAroPermissions(aro);
338
301
  permission.updated = this.shareChanges.hasChanges(aro.id);
@@ -385,12 +348,6 @@ class ShareDialog extends Component {
385
348
  expandedGroupIds.delete(groupId);
386
349
  } else {
387
350
  expandedGroupIds.add(groupId);
388
- // Groups added during the dialog session are not in initialGroups and carry no members yet;
389
- // fetch them lazily the first time they are expanded. Members render once the fetch resolves.
390
- const isInitialGroup = this.props.initialGroups?.items.some((item) => item.id === groupId);
391
- if (!isInitialGroup && !this.state.fetchedGroupMembers[groupId]) {
392
- this.fetchGroupMembers(groupId);
393
- }
394
351
  }
395
352
  this.setState({ expandedGroupIds: [...expandedGroupIds] });
396
353
  }
@@ -401,22 +358,36 @@ class ShareDialog extends Component {
401
358
  * cache (falling back to the API). A failure leaves the group with no displayed members rather than
402
359
  * interrupting the dialog with an error popup.
403
360
  * @param {string} groupId The group identifier
404
- * @returns {Promise<void>}
405
361
  */
406
- async fetchGroupMembers(groupId) {
407
- try {
408
- const groupServiceWorkerService = new GroupServiceWorkerService(this.props.context.port);
409
- const userServiceWorkerService = new UserServiceWorkerService(this.props.context.port);
410
- const groupsUsers = await groupServiceWorkerService.getGroupsUsersByGroupId(groupId);
411
- const memberUserIds = groupsUsers.items.map((groupUser) => groupUser.userId);
412
- const users = await userServiceWorkerService.getByIds(memberUserIds);
413
- const members = users.items.map((user) => user.toDto(users.entityClass?.ALL_CONTAIN_OPTIONS));
414
- this.setState({
415
- fetchedGroupMembers: { ...this.state.fetchedGroupMembers, [groupId]: members },
416
- });
417
- } catch (error) {
418
- console.error(error);
419
- }
362
+ fetchGroupMembers(groupId) {
363
+ this.setState({ isFetchingGroupMembers: true }, async () => {
364
+ try {
365
+ const groupServiceWorkerService = new GroupServiceWorkerService(this.props.context.port);
366
+ // The share fetch embeds the members (groups_users with their user), so a single call
367
+ // resolves both the membership and the user display data.
368
+ const groups = await groupServiceWorkerService.findByIdsForShare([groupId]);
369
+ const group = groups.items.find((item) => item.id === groupId);
370
+ const members = (group?.groupsUsers?.items ?? [])
371
+ .filter((groupUser) => groupUser.user)
372
+ .map((groupUser) => groupUser.user.toDto(UserEntity.ALL_CONTAIN_OPTIONS));
373
+ this.setState({
374
+ fetchedGroupMembers: { ...this.state.fetchedGroupMembers, [groupId]: members },
375
+ isFetchingGroupMembers: false,
376
+ });
377
+ } catch (error) {
378
+ console.error(error);
379
+ this.setState({ isFetchingGroupMembers: false });
380
+ }
381
+ });
382
+ }
383
+
384
+ /**
385
+ * Returns true if the given group has already its members fetched
386
+ * @param {string} groupId
387
+ * @returns {boolean}
388
+ */
389
+ hasFetchedGroupMembers(groupId) {
390
+ return Boolean(this.state.fetchedGroupMembers[groupId]);
420
391
  }
421
392
 
422
393
  /**
@@ -429,7 +400,7 @@ class ShareDialog extends Component {
429
400
  */
430
401
  getGroupMembers(groupId) {
431
402
  // Groups added during the dialog session have their members fetched on demand and cached.
432
- if (this.state.fetchedGroupMembers[groupId]) {
403
+ if (this.hasFetchedGroupMembers(groupId)) {
433
404
  return this.state.fetchedGroupMembers[groupId];
434
405
  }
435
406
  const group = this.props.initialGroups?.items.find((item) => item.id === groupId);
@@ -455,7 +426,7 @@ class ShareDialog extends Component {
455
426
  return;
456
427
  }
457
428
  displayedPermissions.push({ kind: "group", permission });
458
- if (this.isControlledMode() && this.state.expandedGroupIds.includes(permission.aro.id)) {
429
+ if (this.state.expandedGroupIds.includes(permission.aro.id)) {
459
430
  this.getGroupMembers(permission.aro.id).forEach((user) => {
460
431
  displayedPermissions.push({ kind: "group-user", user, groupId: permission.aro.id });
461
432
  });
@@ -470,32 +441,14 @@ class ShareDialog extends Component {
470
441
  * @returns {Promise<void>}
471
442
  */
472
443
  async shareSave() {
473
- if (this.isControlledMode()) {
474
- const changes =
475
- this.props.acoType === PermissionEntity.ACO_FOLDER
476
- ? this.shareChanges.getFoldersChanges()
477
- : this.shareChanges.getResourcesChanges();
478
- await this.props.onConfirm(changes);
444
+ if (this.props.acoType === PermissionEntity.ACO_FOLDER) {
445
+ await this.props.onConfirm(this.shareChanges.getFoldersChanges(), this.canOperatorRead());
479
446
  return;
480
447
  }
481
- if (this.props.context.shareDialogProps.resourcesIds && this.props.context.shareDialogProps.foldersIds) {
482
- throw new Error(this.translate("Multi resource and folder share is not implemented."));
483
- }
484
- if (this.props.context.shareDialogProps.resourcesIds) {
485
- await this.props.context.port.request(
486
- "passbolt.share.resources.save",
487
- this.props.context.shareDialogProps.resourcesIds,
488
- this.shareChanges.getResourcesChanges(),
489
- );
490
- return;
491
- }
492
- if (this.props.context.shareDialogProps.foldersIds) {
493
- await this.props.context.port.request(
494
- "passbolt.share.folders.save",
495
- this.props.context.shareDialogProps.foldersIds[0],
496
- this.shareChanges.getFoldersChanges(),
497
- );
498
- }
448
+
449
+ const changes = this.shareChanges.getResourcesChanges();
450
+ const isPersonal = this.state.permissions.length === 1 && Boolean(this.state.permissions[0].aro.profile);
451
+ await this.props.onConfirm(changes, this.canOperatorRead(), isPersonal);
499
452
  }
500
453
 
501
454
  /**
@@ -537,12 +490,7 @@ class ShareDialog extends Component {
537
490
  * @returns {boolean}
538
491
  */
539
492
  isAboutItems() {
540
- return (
541
- this.props.context.shareDialogProps?.resourcesIds &&
542
- this.props.context.shareDialogProps?.foldersIds &&
543
- this.props.context.shareDialogProps.resourcesIds.length &&
544
- this.props.context.shareDialogProps.foldersIds.length
545
- );
493
+ return this.props.initialResources?.length && this.props.initialFolders?.length;
546
494
  }
547
495
 
548
496
  /**
@@ -550,9 +498,7 @@ class ShareDialog extends Component {
550
498
  * @returns {boolean}
551
499
  */
552
500
  isAboutResources() {
553
- return (
554
- this.props.context.shareDialogProps?.resourcesIds && this.props.context.shareDialogProps.resourcesIds.length > 1
555
- );
501
+ return this.props.initialResources?.length > 1;
556
502
  }
557
503
 
558
504
  /**
@@ -560,7 +506,7 @@ class ShareDialog extends Component {
560
506
  * @returns {boolean}
561
507
  */
562
508
  isAboutFolders() {
563
- return this.props.context.shareDialogProps?.foldersIds && this.props.context.shareDialogProps.foldersIds.length > 1;
509
+ return this.props.initialFolders?.length > 1;
564
510
  }
565
511
 
566
512
  /**
@@ -568,9 +514,7 @@ class ShareDialog extends Component {
568
514
  * @returns {boolean}
569
515
  */
570
516
  isAboutAFolder() {
571
- return (
572
- this.props.context.shareDialogProps?.foldersIds && this.props.context.shareDialogProps.foldersIds.length === 1
573
- );
517
+ return this.props.initialFolders?.length === 1;
574
518
  }
575
519
 
576
520
  /**
@@ -578,9 +522,7 @@ class ShareDialog extends Component {
578
522
  * @returns {boolean}
579
523
  */
580
524
  isAboutAResource() {
581
- return (
582
- this.props.context.shareDialogProps?.resourcesIds && this.props.context.shareDialogProps.resourcesIds.length === 1
583
- );
525
+ return this.props.initialResources?.length === 1;
584
526
  }
585
527
 
586
528
  /**
@@ -594,14 +536,9 @@ class ShareDialog extends Component {
594
536
  if (this.props.isPermissionConfirmationMode) {
595
537
  return this.translate("Confirm permissions");
596
538
  }
597
- if (this.isControlledMode()) {
598
- return this.translate("Share");
599
- }
600
539
  if (this.isAboutItems()) {
601
540
  return this.translate("Share {{count}} items", {
602
- count:
603
- this.props.context.shareDialogProps.resourcesIds.length +
604
- this.props.context.shareDialogProps.foldersIds.length,
541
+ count: this.props.initialResources.length + this.props.initialFolders.length,
605
542
  });
606
543
  }
607
544
  if (this.isAboutAResource()) {
@@ -609,7 +546,7 @@ class ShareDialog extends Component {
609
546
  }
610
547
  if (this.isAboutResources()) {
611
548
  return this.translate("Share {{count}} resources", {
612
- count: this.props.context.shareDialogProps.resourcesIds.length,
549
+ count: this.props.initialResources.length,
613
550
  });
614
551
  }
615
552
  if (this.isAboutAFolder()) {
@@ -617,7 +554,7 @@ class ShareDialog extends Component {
617
554
  }
618
555
  if (this.isAboutFolders()) {
619
556
  return this.translate("Share {{count}} folders", {
620
- count: this.props.context.shareDialogProps.foldersIds.length,
557
+ count: this.props.initialFolders.length,
621
558
  });
622
559
  }
623
560
  }
@@ -627,14 +564,14 @@ class ShareDialog extends Component {
627
564
  * @returns {string}
628
565
  */
629
566
  getSubtitle() {
630
- if (this.state.loading || this.isControlledMode()) {
567
+ if (this.state.loading) {
631
568
  return;
632
569
  }
633
570
  if (this.isAboutAResource()) {
634
571
  return this.resources[0].metadata.name;
635
572
  }
636
573
  if (this.isAboutAFolder()) {
637
- return this.folders[0].name;
574
+ return this.folders[0].metadata.name;
638
575
  }
639
576
  }
640
577
 
@@ -683,13 +620,7 @@ class ShareDialog extends Component {
683
620
  * @returns {boolean}
684
621
  */
685
622
  hasSubmitDisabled() {
686
- if (this.hasNoOwner() || this.hasAllInputDisabled()) {
687
- return true;
688
- }
689
- if (this.isControlledMode()) {
690
- return false;
691
- }
692
- return !this.hasChanges();
623
+ return this.hasNoOwner() || this.operatorOwnershipIsInvalid() || this.hasAllInputDisabled();
693
624
  }
694
625
 
695
626
  /**
@@ -717,7 +648,7 @@ class ShareDialog extends Component {
717
648
  id={permission.aro.id}
718
649
  key={permission.aro.id}
719
650
  group={permission.aro}
720
- membersCount={this.isControlledMode() ? this.getGroupMembers(permission.aro.id).length : null}
651
+ membersCount={this.getGroupMembers(permission.aro.id).length}
721
652
  permissionType={permissionType}
722
653
  variesDetails={permission.variesDetails}
723
654
  updated={permission.updated}
@@ -726,7 +657,6 @@ class ShareDialog extends Component {
726
657
  onDelete={this.handlePermissionDelete}
727
658
  onToggleGroupMemberVisibility={this.handleToggleGroupMemberVisibility}
728
659
  shouldDisplayGroupMembers={this.state.expandedGroupIds.includes(permission.aro.id)}
729
- canDisplayGroupMembers={this.isControlledMode()}
730
660
  isReadOnly={this.props.readOnly}
731
661
  />
732
662
  );
@@ -762,6 +692,76 @@ class ShareDialog extends Component {
762
692
  );
763
693
  }
764
694
 
695
+ /**
696
+ * Returns true if the operator ownership requirement is not met.
697
+ * If the props asks to ensure that the current operator must have ownership on the resource
698
+ * then a verification is ensured that the operator has ownership through a direct permission
699
+ * or from at least a group permissions.
700
+ * If the requirement is not enforce by the props this method considers the requirement has met
701
+ * and returns false has there is no error.
702
+ * @returns {boolean}
703
+ */
704
+ operatorOwnershipIsInvalid() {
705
+ if (!this.props.ensureOperatorIsOwner) {
706
+ return false;
707
+ }
708
+
709
+ if (!this.state.permissions?.length) {
710
+ return true;
711
+ }
712
+
713
+ const operatorId = this.props.context.loggedInUser?.id;
714
+ const operatorOwnerPermission = this.state.permissions.find((p) => {
715
+ // no need to check non owner permission
716
+ if (p.type !== PermissionEntity.PERMISSION_OWNER) {
717
+ return false;
718
+ }
719
+
720
+ //we are dealing with a direct user permission here
721
+ if (p.aro.profile) {
722
+ if (operatorId === p.aro.id) {
723
+ // the current oeprator has a direct OWNER permission in the list
724
+ return true;
725
+ }
726
+ // we ignore direct user permission that are not the operator user
727
+ return false;
728
+ }
729
+
730
+ const groupMembers = this.getGroupMembers(p.aro.id);
731
+ const operatorGroupMember = groupMembers.find((gm) => gm.id === operatorId);
732
+ return Boolean(operatorGroupMember);
733
+ });
734
+ return !operatorOwnerPermission;
735
+ }
736
+
737
+ /**
738
+ * Returns true if the operator has permission to at least read the resource
739
+ * @returns {boolean}
740
+ */
741
+ canOperatorRead() {
742
+ if (!this.state.permissions?.length) {
743
+ return false;
744
+ }
745
+
746
+ const operatorId = this.props.context.loggedInUser?.id;
747
+ const operatorPermission = this.state.permissions.find((p) => {
748
+ //we are dealing with a direct user permission here
749
+ if (p.aro.profile) {
750
+ if (operatorId === p.aro.id) {
751
+ // the current oeprator has a permission in the list
752
+ return true;
753
+ }
754
+ // we ignore direct user permission that are not the operator user
755
+ return false;
756
+ }
757
+
758
+ const groupMembers = this.getGroupMembers(p.aro.id);
759
+ const operatorGroupMember = groupMembers.find((gm) => gm.id === operatorId);
760
+ return Boolean(operatorGroupMember);
761
+ });
762
+ return Boolean(operatorPermission);
763
+ }
764
+
765
765
  /**
766
766
  * Returns true if the feature flag disableUser is enabled.
767
767
  * @returns {boolean}
@@ -785,6 +785,9 @@ class ShareDialog extends Component {
785
785
  render() {
786
786
  // Computed once per render so ReactList's length and itemRenderer read the same list.
787
787
  const displayedPermissions = this.state.loading ? [] : this.getDisplayedPermissions();
788
+ const isReadOnly = this.isReadOnly();
789
+ const operatorOwnershipIsInvalid = !isReadOnly && this.operatorOwnershipIsInvalid();
790
+ const hasNoOwner = !isReadOnly && this.hasNoOwner();
788
791
  return (
789
792
  <DialogWrapper
790
793
  className="share-dialog"
@@ -834,15 +837,24 @@ class ShareDialog extends Component {
834
837
  />
835
838
  </div>
836
839
  )}
837
- {!this.isReadOnly() && this.hasNoOwner() && (
838
- <div className="message error">
839
- <Trans>Please make sure there is at least one owner.</Trans>
840
- </div>
841
- )}
842
- {!this.isReadOnly() && this.hasChanges() && !this.hasNoOwner() && (
843
- <div className="message warning">
844
- <Trans>Click save to apply your pending changes.</Trans>
845
- </div>
840
+ {!isReadOnly && (
841
+ <>
842
+ {operatorOwnershipIsInvalid && (
843
+ <div className="message error">
844
+ <Trans>Please make sure you are still owner.</Trans>
845
+ </div>
846
+ )}
847
+ {!operatorOwnershipIsInvalid && hasNoOwner && (
848
+ <div className="message error">
849
+ <Trans>Please make sure there is at least one owner.</Trans>
850
+ </div>
851
+ )}
852
+ {this.hasChanges() && !hasNoOwner && !operatorOwnershipIsInvalid && (
853
+ <div className="message warning">
854
+ <Trans>Click save to apply your pending changes.</Trans>
855
+ </div>
856
+ )}
857
+ </>
846
858
  )}
847
859
  </div>
848
860
  <div className="submit-wrapper">
@@ -863,6 +875,9 @@ ShareDialog.defaultProps = {
863
875
  listMinSize: 4,
864
876
  isPermissionConfirmationMode: true,
865
877
  initialChanges: [],
878
+ ensureOperatorIsOwner: false,
879
+ initialResources: [],
880
+ initialFolders: [],
866
881
  };
867
882
 
868
883
  ShareDialog.propTypes = {
@@ -873,13 +888,15 @@ ShareDialog.propTypes = {
873
888
  dialogContext: PropTypes.any, // The dialog context
874
889
  listMinSize: PropTypes.number, // The minimum size to be renderered in the permission list
875
890
  isPermissionConfirmationMode: PropTypes.bool, // Is the dialog used to confirm permissions
876
- initialResources: PropTypes.array, // Controlled mode: the ACOs to seed the dialog with instead of fetching from the API, each as { id, metadata, permission, permissions: PermissionsCollection }
891
+ initialResources: PropTypes.array, // the ACO resources to seed the dialog with instead of fetching from the API, each as { id, metadata, permission, permissions: PermissionsCollection }
892
+ initialFolders: PropTypes.array, // the ACO folders to see the dialog with
877
893
  initialChanges: PropTypes.array, // Set of permission to mark them as "modified" in the initial list
878
- acoType: PropTypes.string, // Controlled mode: the ACO type of the seeded entries (PermissionEntity.ACO_RESOURCE, default, or ACO_FOLDER)
879
- initialGroups: PropTypes.object, // Controlled mode: GroupsCollection providing the groups referenced by the resources' permissions
880
- initialUsers: PropTypes.object, // Controlled mode: UsersCollection providing the users referenced by the resources' permissions
881
- onConfirm: PropTypes.func, // Controlled mode: callback invoked with the operator-confirmed permission changes instead of saving via the port
882
- readOnly: PropTypes.bool, // Controlled mode: display the permission set read-only (review/confirm only, no edits)
894
+ acoType: PropTypes.string, // the ACO type of the seeded entries (PermissionEntity.ACO_RESOURCE, default, or ACO_FOLDER)
895
+ initialGroups: PropTypes.object, // GroupsCollection providing the groups referenced by the resources' permissions
896
+ initialUsers: PropTypes.object, // UsersCollection providing the users referenced by the resources' permissions
897
+ onConfirm: PropTypes.func, // callback invoked with the operator-confirmed permission changes instead of saving via the port
898
+ readOnly: PropTypes.bool, // display the permission set read-only (review/confirm only, no edits)
899
+ ensureOperatorIsOwner: PropTypes.bool, // Ensure the operator remains owner of the edited resource
883
900
  t: PropTypes.func, // The translation function
884
901
  };
885
902