passbolt-styleguide 5.14.4 → 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 (57) hide show
  1. package/RELEASE_NOTES.md +6 -6
  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 +2 -2
  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 +2 -2
  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 +2 -2
  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 +2 -2
  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/package.json +1 -1
  41. package/src/react-extension/components/Resource/HandlePermissionWorkflow/flows/FolderShareFlow.test.js +4 -7
  42. package/src/react-extension/components/Resource/HandlePermissionWorkflow/flows/ResourceCreationFlow.js +12 -18
  43. package/src/react-extension/components/Resource/HandlePermissionWorkflow/flows/ResourceCreationFlow.test.js +15 -17
  44. package/src/react-extension/components/Resource/HandlePermissionWorkflow/flows/ResourceEditFlow.js +10 -14
  45. package/src/react-extension/components/Resource/HandlePermissionWorkflow/flows/ResourceEditFlow.test.js +18 -31
  46. package/src/react-extension/components/Resource/HandlePermissionWorkflow/flows/ResourceShareFlow.test.js +14 -22
  47. package/src/react-extension/components/Share/ShareDialog.js +15 -12
  48. package/src/react-extension/components/Share/ShareDialog.test.data.js +56 -8
  49. package/src/react-extension/components/Share/ShareDialog.test.js +14 -4
  50. package/src/react-extension/contexts/WorkflowContext.js +4 -0
  51. package/src/shared/models/entity/groupUser/groupUserEntity.js +52 -6
  52. package/src/shared/models/entity/groupUser/groupUserEntity.test.data.js +5 -0
  53. package/src/shared/models/entity/groupUser/groupUserEntity.test.js +54 -0
  54. package/src/shared/services/permission/permissionSnapshotService.js +20 -20
  55. package/src/shared/services/permission/permissionSnapshotService.test.js +77 -53
  56. package/src/shared/services/serviceWorker/group/groupServiceWorkerService.js +6 -18
  57. package/src/shared/services/serviceWorker/group/groupServiceWorkerService.test.js +13 -27
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "passbolt-styleguide",
3
- "version": "5.14.4",
3
+ "version": "5.14.5",
4
4
  "license": "AGPL-3.0",
5
5
  "copyright": "Copyright 2023 Passbolt SA",
6
6
  "description": "Passbolt styleguide contains common styling assets used by the different sites, plugin, etc.",
@@ -26,8 +26,7 @@ import {
26
26
  PERMISSIONS_FIND_ACO_PERMISSIONS_FOR_DISPLAY,
27
27
  SHARE_FOLDERS_SAVE,
28
28
  } from "../../../../../shared/services/serviceWorker/permission/permissionServiceWorkerService";
29
- import { GROUPS_GET_BY_IDS } from "../../../../../shared/services/serviceWorker/group/groupServiceWorkerService";
30
- import { USERS_GET_BY_IDS } from "../../../../../shared/services/serviceWorker/user/userServiceWorkerService";
29
+ import { GROUPS_FIND_BY_IDS_FOR_SHARE } from "../../../../../shared/services/serviceWorker/group/groupServiceWorkerService";
31
30
 
32
31
  beforeEach(() => {
33
32
  jest.clearAllMocks();
@@ -49,13 +48,12 @@ function permissionDto(aco, acoForeignKey, aroForeignKey, type = PermissionEntit
49
48
 
50
49
  /**
51
50
  * Wire the folder-snapshot port events. `folderPermissions` answers the folder permission fetch;
52
- * groups/users resolve to empty by default.
51
+ * groups resolve to empty by default.
53
52
  */
54
53
  function wireSnapshotListeners(port, { folderPermissions = [] } = {}) {
55
54
  port.addRequestListener(KEYRING_SYNC_EVENT, () => {});
56
55
  port.addRequestListener(PERMISSIONS_FIND_ACO_PERMISSIONS_FOR_DISPLAY, () => folderPermissions);
57
- port.addRequestListener(GROUPS_GET_BY_IDS, () => []);
58
- port.addRequestListener(USERS_GET_BY_IDS, () => []);
56
+ port.addRequestListener(GROUPS_FIND_BY_IDS_FOR_SHARE, () => []);
59
57
  }
60
58
 
61
59
  /**
@@ -173,8 +171,7 @@ describe("FolderShareFlow", () => {
173
171
  folderFindCount += 1;
174
172
  return folderFindCount === 1 ? initialFolderPermissions : driftedFolderPermissions;
175
173
  });
176
- props.context.port.addRequestListener(GROUPS_GET_BY_IDS, () => []);
177
- props.context.port.addRequestListener(USERS_GET_BY_IDS, () => []);
174
+ props.context.port.addRequestListener(GROUPS_FIND_BY_IDS_FOR_SHARE, () => []);
178
175
 
179
176
  await mountUntilShareOpen(props);
180
177
 
@@ -82,21 +82,10 @@ export class ResourceCreationFlow extends AbstractPermissionFlow {
82
82
  }
83
83
 
84
84
  /**
85
- * Component did mount: build the snapshot (when applicable) and open the resource-creation form.
86
- * @returns {Promise<void>}
85
+ * Component did mount: open the resource-creation form.
87
86
  */
88
- async componentDidMount() {
89
- try {
90
- if (this.props.folderParentId) {
91
- const snapshot = await this.permissionSnapshotService.buildSnapshotForResourceCreation(
92
- this.props.folderParentId,
93
- );
94
- this.setState({ snapshot });
95
- }
96
- this.openCreateResourceDialog();
97
- } catch (error) {
98
- this.handleError(error);
99
- }
87
+ componentDidMount() {
88
+ this.openCreateResourceDialog();
100
89
  }
101
90
 
102
91
  /**
@@ -140,8 +129,10 @@ export class ResourceCreationFlow extends AbstractPermissionFlow {
140
129
 
141
130
  /**
142
131
  * Handle the operator's submission of the resource-creation form.
143
- * If the parent folder is shared, dispatches ShareDialog so the operator confirms the permission
144
- * set first. Otherwise creates the resource immediately.
132
+ * Captures the parent folder's permission snapshot (when there is one) now that the operator has
133
+ * committed, so the fetch runs while the form dialog's submit button spins. If the parent folder is
134
+ * shared, dispatches ShareDialog so the operator confirms the permission set first. Otherwise
135
+ * creates the resource immediately.
145
136
  * @param {ResourceFormEntity} resourceFormEntity The validated form entity.
146
137
  * @returns {Promise<void>}
147
138
  */
@@ -149,8 +140,11 @@ export class ResourceCreationFlow extends AbstractPermissionFlow {
149
140
  this.formSubmitted = true;
150
141
  this.pendingResourceFormEntity = resourceFormEntity;
151
142
  try {
152
- if (this.isShared(this.state.snapshot)) {
153
- this.openShareDialog();
143
+ const snapshot = this.props.folderParentId
144
+ ? await this.permissionSnapshotService.buildSnapshotForResourceCreation(this.props.folderParentId)
145
+ : null;
146
+ if (this.isShared(snapshot)) {
147
+ this.setState({ snapshot }, () => this.openShareDialog());
154
148
  return;
155
149
  }
156
150
  const created = await this.createResource(resourceFormEntity);
@@ -23,27 +23,24 @@ import ShareDialog from "../../../Share/ShareDialog";
23
23
  import NotifyError from "../../../Common/Error/NotifyError/NotifyError";
24
24
  import { KEYRING_SYNC_EVENT } from "../../../../../shared/services/serviceWorker/keyring/keyringServiceWorkerService";
25
25
  import { PERMISSIONS_FIND_ACO_PERMISSIONS_FOR_DISPLAY } from "../../../../../shared/services/serviceWorker/permission/permissionServiceWorkerService";
26
- import { GROUPS_GET_BY_IDS } from "../../../../../shared/services/serviceWorker/group/groupServiceWorkerService";
27
- import { USERS_GET_BY_IDS } from "../../../../../shared/services/serviceWorker/user/userServiceWorkerService";
26
+ import { GROUPS_FIND_BY_IDS_FOR_SHARE } from "../../../../../shared/services/serviceWorker/group/groupServiceWorkerService";
28
27
 
29
28
  beforeEach(() => {
30
29
  jest.clearAllMocks();
31
30
  });
32
31
 
33
32
  /**
34
- * Wire the four port events the snapshot service relies on. Returns the listener stubs so the
33
+ * Wire the three port events the snapshot service relies on. Returns the listener stubs so the
35
34
  * test can override one (e.g. throw an error) before mounting the workflow.
36
35
  * @param {object} port The MockPort from defaultAppContext.
37
36
  * @param {object} options
38
37
  * @param {Array} [options.permissions] The permissions DTO array returned by findPermissions.
39
38
  * @param {Array} [options.groups]
40
- * @param {Array} [options.users]
41
39
  */
42
- function wireSnapshotListeners(port, { permissions = [], groups = [], users = [] } = {}) {
40
+ function wireSnapshotListeners(port, { permissions = [], groups = [] } = {}) {
43
41
  port.addRequestListener(KEYRING_SYNC_EVENT, () => {});
44
42
  port.addRequestListener(PERMISSIONS_FIND_ACO_PERMISSIONS_FOR_DISPLAY, () => permissions);
45
- port.addRequestListener(GROUPS_GET_BY_IDS, () => groups);
46
- port.addRequestListener(USERS_GET_BY_IDS, () => users);
43
+ port.addRequestListener(GROUPS_FIND_BY_IDS_FOR_SHARE, () => groups);
47
44
  }
48
45
 
49
46
  /**
@@ -87,10 +84,6 @@ describe("ResourceCreationFlow", () => {
87
84
  type: 1,
88
85
  },
89
86
  ],
90
- users: [
91
- { id: operatorId, username: "operator@passbolt.com" },
92
- { id: readerId, username: "reader@passbolt.com" },
93
- ],
94
87
  });
95
88
 
96
89
  let page;
@@ -210,11 +203,7 @@ describe("ResourceCreationFlow", () => {
210
203
  permissionsFindCallCount += 1;
211
204
  return permissionsFindCallCount === 1 ? initialPermissionsDto : driftedPermissionsDto;
212
205
  });
213
- props.context.port.addRequestListener(GROUPS_GET_BY_IDS, () => []);
214
- props.context.port.addRequestListener(USERS_GET_BY_IDS, () => [
215
- { id: operatorId, username: "operator@passbolt.com" },
216
- { id: uuidv4(), username: "reader@passbolt.com" },
217
- ]);
206
+ props.context.port.addRequestListener(GROUPS_FIND_BY_IDS_FOR_SHARE, () => []);
218
207
 
219
208
  let page;
220
209
  await act(() => (page = new ResourceCreationFlowTestPage(props)));
@@ -261,7 +250,6 @@ describe("ResourceCreationFlow", () => {
261
250
  const operatorId = props.context.loggedInUser.id;
262
251
  wireSnapshotListeners(props.context.port, {
263
252
  permissions: [operatorOwnerPermissionDto(operatorId, props.folderParentId)],
264
- users: [{ id: operatorId, username: "operator@passbolt.com" }],
265
253
  });
266
254
 
267
255
  let page;
@@ -401,6 +389,16 @@ describe("ResourceCreationFlow", () => {
401
389
 
402
390
  let page;
403
391
  await act(() => (page = new ResourceCreationFlowTestPage(props)));
392
+ await waitFor(() => {
393
+ if (page._instance.state.status !== RESOURCE_CREATION_FLOW_STATUS.CREATE_RESOURCE_OPEN) {
394
+ throw new Error("CreateResource not yet opened");
395
+ }
396
+ });
397
+
398
+ // The snapshot is built on submit, so the keyring-sync failure surfaces there.
399
+ const createProps = dialogPropsFor(props.dialogContext, CreateResource);
400
+ const fakeResourceFormEntity = { toResourceDto: () => ({}), toSecretDto: () => ({}) };
401
+ await act(() => createProps.onSubmit(fakeResourceFormEntity));
404
402
  await waitFor(() => {
405
403
  if (page._instance.state.status !== RESOURCE_CREATION_FLOW_STATUS.ERROR) {
406
404
  throw new Error("Workflow not yet in error state");
@@ -95,17 +95,10 @@ export class ResourceEditFlow extends AbstractPermissionFlow {
95
95
  }
96
96
 
97
97
  /**
98
- * Component did mount: build the snapshot from the resource and open the edition form.
99
- * @returns {Promise<void>}
98
+ * Component did mount: open the edition form.
100
99
  */
101
- async componentDidMount() {
102
- try {
103
- const snapshot = await this.permissionSnapshotService.buildSnapshotForResourceEdition(this.props.resource.id);
104
- this.setState({ snapshot });
105
- this.openEditResourceDialog();
106
- } catch (error) {
107
- this.handleError(error);
108
- }
100
+ componentDidMount() {
101
+ this.openEditResourceDialog();
109
102
  }
110
103
 
111
104
  /**
@@ -147,8 +140,10 @@ export class ResourceEditFlow extends AbstractPermissionFlow {
147
140
 
148
141
  /**
149
142
  * Handle the operator's submission of the resource-edition form.
150
- * If the resource is shared, dispatches ShareDialog so the operator confirms the recipient set
151
- * first (the secret is re-encrypted for them). Otherwise updates the resource immediately.
143
+ * Captures the resource's permission snapshot now that the operator has committed, so the fetch
144
+ * runs while the form dialog's submit button spins. If the resource is shared, dispatches
145
+ * ShareDialog so the operator confirms the recipient set first (the secret is re-encrypted for
146
+ * them). Otherwise updates the resource immediately.
152
147
  * @param {ResourceFormEntity} resourceFormEntity The validated form entity.
153
148
  * @returns {Promise<void>}
154
149
  */
@@ -157,8 +152,9 @@ export class ResourceEditFlow extends AbstractPermissionFlow {
157
152
  this.pendingResourceFormEntity = resourceFormEntity;
158
153
  this.pendingResourceSecret = secretDto;
159
154
  try {
160
- if (this.isShared(this.state.snapshot)) {
161
- this.openShareDialog();
155
+ const snapshot = await this.permissionSnapshotService.buildSnapshotForResourceEdition(this.props.resource.id);
156
+ if (this.isShared(snapshot)) {
157
+ this.setState({ snapshot }, () => this.openShareDialog());
162
158
  return;
163
159
  }
164
160
  await this.updateResource(resourceFormEntity, secretDto);
@@ -24,21 +24,19 @@ import NotifyError from "../../../Common/Error/NotifyError/NotifyError";
24
24
  import PermissionEntity from "../../../../../shared/models/entity/permission/permissionEntity";
25
25
  import { KEYRING_SYNC_EVENT } from "../../../../../shared/services/serviceWorker/keyring/keyringServiceWorkerService";
26
26
  import { PERMISSIONS_FIND_ACO_PERMISSIONS_FOR_DISPLAY } from "../../../../../shared/services/serviceWorker/permission/permissionServiceWorkerService";
27
- import { GROUPS_GET_BY_IDS } from "../../../../../shared/services/serviceWorker/group/groupServiceWorkerService";
28
- import { USERS_GET_BY_IDS } from "../../../../../shared/services/serviceWorker/user/userServiceWorkerService";
27
+ import { GROUPS_FIND_BY_IDS_FOR_SHARE } from "../../../../../shared/services/serviceWorker/group/groupServiceWorkerService";
29
28
 
30
29
  beforeEach(() => {
31
30
  jest.clearAllMocks();
32
31
  });
33
32
 
34
33
  /**
35
- * Wire the four port events the snapshot service relies on.
34
+ * Wire the three port events the snapshot service relies on.
36
35
  */
37
- function wireSnapshotListeners(port, { permissions = [], groups = [], users = [] } = {}) {
36
+ function wireSnapshotListeners(port, { permissions = [], groups = [] } = {}) {
38
37
  port.addRequestListener(KEYRING_SYNC_EVENT, () => {});
39
38
  port.addRequestListener(PERMISSIONS_FIND_ACO_PERMISSIONS_FOR_DISPLAY, () => permissions);
40
- port.addRequestListener(GROUPS_GET_BY_IDS, () => groups);
41
- port.addRequestListener(USERS_GET_BY_IDS, () => users);
39
+ port.addRequestListener(GROUPS_FIND_BY_IDS_FOR_SHARE, () => groups);
42
40
  }
43
41
 
44
42
  /**
@@ -92,23 +90,12 @@ describe("ResourceEditFlow", () => {
92
90
  resourcePermissionDto(operatorId, props.resource.id),
93
91
  resourcePermissionDto(readerId, props.resource.id, PermissionEntity.PERMISSION_READ),
94
92
  ],
95
- users: [
96
- { id: operatorId, username: "operator@passbolt.com" },
97
- { id: readerId, username: "reader@passbolt.com" },
98
- ],
99
93
  });
100
94
 
101
- // Spy before mounting: the snapshot is built during componentDidMount.
95
+ // Spy before submitting: the snapshot is built when the operator submits the form.
102
96
  jest.spyOn(props.context.port, "request");
103
97
  const page = await mountUntilEditOpen(props);
104
98
 
105
- // The snapshot must be built from the resource itself (ACO_RESOURCE), not a parent folder.
106
- expect(props.context.port.request).toHaveBeenCalledWith(
107
- PERMISSIONS_FIND_ACO_PERMISSIONS_FOR_DISPLAY,
108
- props.resource.id,
109
- PermissionEntity.ACO_RESOURCE,
110
- );
111
-
112
99
  // Submit the form: ShareDialog must follow because the resource is shared.
113
100
  const editProps = dialogPropsFor(props.dialogContext, EditResource);
114
101
  await act(() => editProps.onSubmit(fakeResourceFormEntity, fakeSecretDto));
@@ -118,6 +105,13 @@ describe("ResourceEditFlow", () => {
118
105
  }
119
106
  });
120
107
 
108
+ // The snapshot must be built from the resource itself (ACO_RESOURCE), not a parent folder.
109
+ expect(props.context.port.request).toHaveBeenCalledWith(
110
+ PERMISSIONS_FIND_ACO_PERMISSIONS_FOR_DISPLAY,
111
+ props.resource.id,
112
+ PermissionEntity.ACO_RESOURCE,
113
+ );
114
+
121
115
  // Owner → the dialog is editable (not read-only), seeded from the snapshot.
122
116
  const shareProps = dialogPropsFor(props.dialogContext, ShareDialog);
123
117
  expect(shareProps.readOnly).toBe(false);
@@ -161,11 +155,7 @@ describe("ResourceEditFlow", () => {
161
155
  findCallCount += 1;
162
156
  return findCallCount === 1 ? initialPermissionsDto : driftedPermissionsDto;
163
157
  });
164
- props.context.port.addRequestListener(GROUPS_GET_BY_IDS, () => []);
165
- props.context.port.addRequestListener(USERS_GET_BY_IDS, () => [
166
- { id: operatorId, username: "operator@passbolt.com" },
167
- { id: uuidv4(), username: "reader@passbolt.com" },
168
- ]);
158
+ props.context.port.addRequestListener(GROUPS_FIND_BY_IDS_FOR_SHARE, () => []);
169
159
 
170
160
  const page = await mountUntilEditOpen(props);
171
161
  const editProps = dialogPropsFor(props.dialogContext, EditResource);
@@ -207,10 +197,6 @@ describe("ResourceEditFlow", () => {
207
197
  resourcePermissionDto(ownerId, props.resource.id),
208
198
  resourcePermissionDto(operatorId, props.resource.id, PermissionEntity.PERMISSION_UPDATE),
209
199
  ],
210
- users: [
211
- { id: ownerId, username: "owner@passbolt.com" },
212
- { id: operatorId, username: "operator@passbolt.com" },
213
- ],
214
200
  });
215
201
 
216
202
  const page = await mountUntilEditOpen(props);
@@ -248,7 +234,6 @@ describe("ResourceEditFlow", () => {
248
234
  const operatorId = props.context.loggedInUser.id;
249
235
  wireSnapshotListeners(props.context.port, {
250
236
  permissions: [resourcePermissionDto(operatorId, props.resource.id)],
251
- users: [{ id: operatorId, username: "operator@passbolt.com" }],
252
237
  });
253
238
 
254
239
  await mountUntilEditOpen(props);
@@ -276,7 +261,6 @@ describe("ResourceEditFlow", () => {
276
261
  const operatorId = props.context.loggedInUser.id;
277
262
  wireSnapshotListeners(props.context.port, {
278
263
  permissions: [resourcePermissionDto(operatorId, props.resource.id)],
279
- users: [{ id: operatorId, username: "operator@passbolt.com" }],
280
264
  });
281
265
 
282
266
  await mountUntilEditOpen(props);
@@ -340,8 +324,11 @@ describe("ResourceEditFlow", () => {
340
324
  throw new Error("Keyring sync failed");
341
325
  });
342
326
 
343
- let page;
344
- await act(() => (page = new ResourceEditFlowTestPage(props)));
327
+ const page = await mountUntilEditOpen(props);
328
+
329
+ // The snapshot is built on submit, so the keyring-sync failure surfaces there.
330
+ const editProps = dialogPropsFor(props.dialogContext, EditResource);
331
+ await act(() => editProps.onSubmit(fakeResourceFormEntity, fakeSecretDto));
345
332
  await waitFor(() => {
346
333
  if (page._instance.state.status !== RESOURCE_EDIT_FLOW_STATUS.ERROR) {
347
334
  throw new Error("Workflow not yet in error state");
@@ -26,8 +26,7 @@ import {
26
26
  PERMISSIONS_FIND_ACO_PERMISSIONS_FOR_DISPLAY,
27
27
  SHARE_RESOURCES_SAVE,
28
28
  } from "../../../../../shared/services/serviceWorker/permission/permissionServiceWorkerService";
29
- import { GROUPS_GET_BY_IDS } from "../../../../../shared/services/serviceWorker/group/groupServiceWorkerService";
30
- import { USERS_GET_BY_IDS } from "../../../../../shared/services/serviceWorker/user/userServiceWorkerService";
29
+ import { GROUPS_FIND_BY_IDS_FOR_SHARE } from "../../../../../shared/services/serviceWorker/group/groupServiceWorkerService";
31
30
  import { defaultGroupDto } from "../../../../../shared/models/entity/group/groupEntity.test.data";
32
31
  import { defaultGroupUser } from "../../../../../shared/models/entity/groupUser/groupUserEntity.test.data";
33
32
  import { defaultUserDto } from "../../../../../shared/models/entity/user/userEntity.test.data";
@@ -54,14 +53,13 @@ function resourcePermissionDto(aroForeignKey, resourceId, type = PermissionEntit
54
53
  * Wire the snapshot port events. `permissionsByResourceId` maps a resource id to its permission DTOs;
55
54
  * the find event answers per requested resource id.
56
55
  */
57
- function wireSnapshotListeners(port, { permissionsByResourceId = {}, users = [] } = {}) {
56
+ function wireSnapshotListeners(port, { permissionsByResourceId = {} } = {}) {
58
57
  port.addRequestListener(KEYRING_SYNC_EVENT, () => {});
59
58
  port.addRequestListener(
60
59
  PERMISSIONS_FIND_ACO_PERMISSIONS_FOR_DISPLAY,
61
60
  (acoId) => permissionsByResourceId[acoId] ?? [],
62
61
  );
63
- port.addRequestListener(GROUPS_GET_BY_IDS, () => []);
64
- port.addRequestListener(USERS_GET_BY_IDS, () => users);
62
+ port.addRequestListener(GROUPS_FIND_BY_IDS_FOR_SHARE, () => []);
65
63
  }
66
64
 
67
65
  /**
@@ -95,7 +93,6 @@ describe("ResourceShareFlow", () => {
95
93
  const resourceId = props.resources[0].id;
96
94
  wireSnapshotListeners(props.context.port, {
97
95
  permissionsByResourceId: { [resourceId]: [resourcePermissionDto(operatorId, resourceId)] },
98
- users: [{ id: operatorId, username: "operator@passbolt.com" }],
99
96
  });
100
97
 
101
98
  jest.spyOn(props.context.port, "request");
@@ -122,7 +119,6 @@ describe("ResourceShareFlow", () => {
122
119
  const resourceId = props.resources[0].id;
123
120
  wireSnapshotListeners(props.context.port, {
124
121
  permissionsByResourceId: { [resourceId]: [resourcePermissionDto(operatorId, resourceId)] },
125
- users: [{ id: operatorId, username: "operator@passbolt.com" }],
126
122
  });
127
123
 
128
124
  await mountUntilShareOpen(props);
@@ -147,7 +143,6 @@ describe("ResourceShareFlow", () => {
147
143
  const resourceId = props.resources[0].id;
148
144
  wireSnapshotListeners(props.context.port, {
149
145
  permissionsByResourceId: { [resourceId]: [resourcePermissionDto(operatorId, resourceId)] },
150
- users: [{ id: operatorId, username: "operator@passbolt.com" }],
151
146
  });
152
147
 
153
148
  await mountUntilShareOpen(props);
@@ -181,10 +176,7 @@ describe("ResourceShareFlow", () => {
181
176
  findCallCount += 1;
182
177
  return findCallCount === 1 ? initialPermissionsDto : driftedPermissionsDto;
183
178
  });
184
- props.context.port.addRequestListener(GROUPS_GET_BY_IDS, () => []);
185
- props.context.port.addRequestListener(USERS_GET_BY_IDS, () => [
186
- { id: operatorId, username: "operator@passbolt.com" },
187
- ]);
179
+ props.context.port.addRequestListener(GROUPS_FIND_BY_IDS_FOR_SHARE, () => []);
188
180
 
189
181
  await mountUntilShareOpen(props);
190
182
 
@@ -224,7 +216,6 @@ describe("ResourceShareFlow", () => {
224
216
  const resourceId = props.resources[0].id;
225
217
  wireSnapshotListeners(props.context.port, {
226
218
  permissionsByResourceId: { [resourceId]: [resourcePermissionDto(operatorId, resourceId)] },
227
- users: [{ id: operatorId, username: "operator@passbolt.com" }],
228
219
  });
229
220
 
230
221
  await mountUntilShareOpen(props);
@@ -244,7 +235,7 @@ describe("ResourceShareFlow", () => {
244
235
 
245
236
  describe("As LU sharing a resource shared with a group", () => {
246
237
  it("As LU I should see the group members preserved in the dialog (not 'Group with 0 member')", async () => {
247
- expect.assertions(2);
238
+ expect.assertions(3);
248
239
  const props = defaultProps();
249
240
  const resourceId = props.resources[0].id;
250
241
  const operatorId = props.context.loggedInUser.id;
@@ -253,18 +244,20 @@ describe("ResourceShareFlow", () => {
253
244
  const group = defaultGroupDto({
254
245
  id: groupId,
255
246
  name: "Developer",
256
- groups_users: [defaultGroupUser({ user_id: memberId, group_id: groupId })],
247
+ groups_users: [
248
+ defaultGroupUser({
249
+ user_id: memberId,
250
+ group_id: groupId,
251
+ user: defaultUserDto({ id: memberId, username: "member@passbolt.com" }),
252
+ }),
253
+ ],
257
254
  });
258
255
  props.context.port.addRequestListener(KEYRING_SYNC_EVENT, () => {});
259
256
  props.context.port.addRequestListener(PERMISSIONS_FIND_ACO_PERMISSIONS_FOR_DISPLAY, () => [
260
257
  resourcePermissionDto(operatorId, resourceId),
261
258
  { id: uuidv4(), aco: "Resource", aco_foreign_key: resourceId, aro: "Group", aro_foreign_key: groupId, type: 7 },
262
259
  ]);
263
- props.context.port.addRequestListener(GROUPS_GET_BY_IDS, () => [group]);
264
- props.context.port.addRequestListener(USERS_GET_BY_IDS, () => [
265
- { id: operatorId, username: "operator@passbolt.com" },
266
- defaultUserDto({ id: memberId, username: "member@passbolt.com" }),
267
- ]);
260
+ props.context.port.addRequestListener(GROUPS_FIND_BY_IDS_FOR_SHARE, () => [group]);
268
261
 
269
262
  await mountUntilShareOpen(props);
270
263
 
@@ -273,6 +266,7 @@ describe("ResourceShareFlow", () => {
273
266
  expect(sharedGroup).toBeTruthy();
274
267
  // Regression: the merge used to drop groups_users, so the dialog showed "Group with 0 member".
275
268
  expect(sharedGroup.groupsUsers.items).toHaveLength(1);
269
+ expect(shareProps.initialUsers.items.map((user) => user.id)).toStrictEqual([memberId]);
276
270
  });
277
271
  });
278
272
 
@@ -287,7 +281,6 @@ describe("ResourceShareFlow", () => {
287
281
  [resources[0].id]: [resourcePermissionDto(operatorId, resources[0].id)],
288
282
  [resources[1].id]: [resourcePermissionDto(operatorId, resources[1].id)],
289
283
  },
290
- users: [{ id: operatorId, username: "operator@passbolt.com" }],
291
284
  });
292
285
 
293
286
  jest.spyOn(props.context.port, "request");
@@ -321,7 +314,6 @@ describe("ResourceShareFlow", () => {
321
314
  [resources[0].id]: [resourcePermissionDto(operatorId, resources[0].id)],
322
315
  [resources[1].id]: [resourcePermissionDto(operatorId, resources[1].id)],
323
316
  },
324
- users: [{ id: operatorId, username: "operator@passbolt.com" }],
325
317
  });
326
318
 
327
319
  await mountUntilShareOpen(props);
@@ -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
  /**
@@ -115,9 +115,9 @@ class ShareDialog extends Component {
115
115
 
116
116
  /**
117
117
  * Build a single controlled-mode resource DTO, embedding the referenced user/group from the
118
- * provided lookup maps so ShareChanges can render and track edits. The resource id (null for a
119
- * not-yet-created resource, the real id when sharing an existing one) is stamped as each
120
- * 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.
121
121
  * @param {{id: (string|null), metadata: object, permission: object, permissions: PermissionsCollection}} resource
122
122
  * @param {object} groupsById The referenced groups keyed by id.
123
123
  * @param {object} usersById The referenced users keyed by id.
@@ -125,13 +125,13 @@ class ShareDialog extends Component {
125
125
  */
126
126
  buildControlledResource(resource, groupsById, usersById) {
127
127
  const mappedPermissions = resource.permissions.items.map((permission) => {
128
- const dto = permission.toDto();
128
+ const dto = permission.toDto(PermissionEntity.ALL_CONTAIN_OPTIONS);
129
129
  dto.aco = this.props.acoType ?? PermissionEntity.ACO_RESOURCE;
130
130
  dto.aco_foreign_key = resource.id;
131
131
  if (dto.aro === PermissionEntity.ARO_USER) {
132
- dto.user = usersById[dto.aro_foreign_key];
132
+ dto.user = usersById[dto.aro_foreign_key] ?? dto.user;
133
133
  } else if (dto.aro === PermissionEntity.ARO_GROUP) {
134
- dto.group = groupsById[dto.aro_foreign_key];
134
+ dto.group = groupsById[dto.aro_foreign_key] ?? dto.group;
135
135
  }
136
136
  return dto;
137
137
  });
@@ -363,17 +363,20 @@ class ShareDialog extends Component {
363
363
  this.setState({ isFetchingGroupMembers: true }, async () => {
364
364
  try {
365
365
  const groupServiceWorkerService = new GroupServiceWorkerService(this.props.context.port);
366
- const userServiceWorkerService = new UserServiceWorkerService(this.props.context.port);
367
- const groupsUsers = await groupServiceWorkerService.getGroupsUsersByGroupId(groupId);
368
- const memberUserIds = groupsUsers.items.map((groupUser) => groupUser.userId);
369
- const users = await userServiceWorkerService.getByIds(memberUserIds);
370
- const members = users.items.map((user) => user.toDto(users.entityClass?.ALL_CONTAIN_OPTIONS));
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));
371
373
  this.setState({
372
374
  fetchedGroupMembers: { ...this.state.fetchedGroupMembers, [groupId]: members },
373
375
  isFetchingGroupMembers: false,
374
376
  });
375
377
  } catch (error) {
376
378
  console.error(error);
379
+ this.setState({ isFetchingGroupMembers: false });
377
380
  }
378
381
  });
379
382
  }
@@ -957,10 +957,10 @@ export function controlledModeWithGroupProps(data = {}) {
957
957
  * Build the artifacts simulating a group added through the autocomplete during the dialog session.
958
958
  * Such a group is not part of the controlled-mode initial collections, so its members must be fetched
959
959
  * on demand when it is expanded. Returns the search result the autocomplete receives (no members,
960
- * just a user_count), the group's memberships, and the member user DTOs — to be returned respectively
961
- * by the `passbolt.share.search-aros`, `passbolt.groups_users.get-by-group-id`, and
962
- * `passbolt.users.get-by-ids` port mocks.
963
- * @returns {{searchResult: object, groupsUsers: Array<object>, members: Array<object>}}
960
+ * just a user_count) and the full group — its memberships carrying their embedded user — as fetched
961
+ * for share; to be returned respectively by the `passbolt.share.search-aros` and
962
+ * `passbolt.groups.find-by-ids-for-share` port mocks.
963
+ * @returns {{searchResult: object, group: object, members: Array<object>}}
964
964
  */
965
965
  export function addedGroupWithMembersFixture() {
966
966
  const groupId = uuidv4();
@@ -975,10 +975,14 @@ export function addedGroupWithMembersFixture() {
975
975
 
976
976
  return {
977
977
  searchResult: { id: groupId, name: "Marketing", user_count: 2 },
978
- groupsUsers: [
979
- defaultGroupUser({ user_id: memberUserC.id, group_id: groupId, is_admin: true }),
980
- defaultGroupUser({ user_id: memberUserD.id, group_id: groupId, is_admin: false }),
981
- ],
978
+ group: defaultGroupDto({
979
+ id: groupId,
980
+ name: "Marketing",
981
+ groups_users: [
982
+ defaultGroupUser({ user_id: memberUserC.id, group_id: groupId, user: memberUserC, is_admin: true }),
983
+ defaultGroupUser({ user_id: memberUserD.id, group_id: groupId, user: memberUserD, is_admin: false }),
984
+ ],
985
+ }),
982
986
  members: [memberUserC, memberUserD],
983
987
  };
984
988
  }
@@ -1167,3 +1171,47 @@ export function twoResourcesShareProps(data = {}) {
1167
1171
  ...data,
1168
1172
  };
1169
1173
  }
1174
+
1175
+ /**
1176
+ * Build controlled-mode props where the direct users travel embedded in the permissions only
1177
+ * (initialUsers is empty), as produced by the group-member-derived snapshot.
1178
+ * @param {object} data Props to override
1179
+ * @returns {object}
1180
+ */
1181
+ export function controlledModeEmbeddedUsersProps(data = {}) {
1182
+ const ownerUser = defaultUserDto({ username: "operator@passbolt.com" });
1183
+ const readerUser = defaultUserDto({ username: "reader@passbolt.com" });
1184
+ const acoId = uuidv4();
1185
+ const permissionsDto = [
1186
+ defaultPermissionDto({
1187
+ aco: "Folder",
1188
+ aco_foreign_key: acoId,
1189
+ aro: "User",
1190
+ aro_foreign_key: ownerUser.id,
1191
+ type: 15,
1192
+ user: ownerUser,
1193
+ }),
1194
+ defaultPermissionDto({
1195
+ aco: "Folder",
1196
+ aco_foreign_key: acoId,
1197
+ aro: "User",
1198
+ aro_foreign_key: readerUser.id,
1199
+ type: 1,
1200
+ user: readerUser,
1201
+ }),
1202
+ ];
1203
+ const aco = {
1204
+ id: null,
1205
+ metadata: { name: "" },
1206
+ permission: { type: 15 },
1207
+ permissions: new PermissionsCollection(permissionsDto, { assertAtLeastOneOwner: false }),
1208
+ };
1209
+ return {
1210
+ ...defaultProps(),
1211
+ initialResources: [aco],
1212
+ initialGroups: new GroupsCollection([]),
1213
+ initialUsers: new UsersCollection([]),
1214
+ onConfirm: jest.fn(),
1215
+ ...data,
1216
+ };
1217
+ }
@@ -18,6 +18,7 @@
18
18
  import ShareDialogPage from "./ShareDialog.test.page";
19
19
  import {
20
20
  addedGroupWithMembersFixture,
21
+ controlledModeEmbeddedUsersProps,
21
22
  controlledModeProps,
22
23
  controlledModeWithGroupProps,
23
24
  defaultAppContext,
@@ -256,6 +257,17 @@ describe("As LU running ShareDialog in controlled mode (workflow-driven)", () =>
256
257
  expect(page.aroDetails(2)).toEqual(expect.stringContaining("@passbolt.com"));
257
258
  });
258
259
 
260
+ it("As LU I should see directly-permissioned users rendered from the permission-embedded user when absent from initialUsers", async () => {
261
+ expect.assertions(2);
262
+ const props = controlledModeEmbeddedUsersProps();
263
+ mockContextRequest(jest.fn());
264
+
265
+ await act(() => (page = new ShareDialogPage(context, props)));
266
+
267
+ expect(page.aroDetails(1)).toEqual(expect.stringContaining("@passbolt.com"));
268
+ expect(page.aroDetails(2)).toEqual(expect.stringContaining("@passbolt.com"));
269
+ });
270
+
259
271
  it("As LU I should see the Save button enabled as soon as the dialog opens so I can confirm the snapshot as-is", async () => {
260
272
  expect.assertions(1);
261
273
  const props = controlledModeProps();
@@ -443,10 +455,8 @@ describe("As LU running ShareDialog in controlled mode (workflow-driven)", () =>
443
455
  switch (request) {
444
456
  case "passbolt.share.search-aros":
445
457
  return [addedGroup.searchResult];
446
- case "passbolt.groups_users.get-by-group-id":
447
- return addedGroup.groupsUsers;
448
- case "passbolt.users.get-by-ids":
449
- return addedGroup.members;
458
+ case "passbolt.groups.find-by-ids-for-share":
459
+ return [addedGroup.group];
450
460
  }
451
461
  };
452
462
  mockContextRequest(requestBextMockImpl);