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.
- package/RELEASE_NOTES.md +6 -2
- package/build/css/help.min.css +2 -2
- package/build/css/public.min.css +2 -2
- package/build/css/themes/default/api_authentication.min.css +2 -2
- package/build/css/themes/default/api_cloud.min.css +2 -2
- package/build/css/themes/default/api_main.min.css +2 -2
- package/build/css/themes/default/api_reports.min.css +2 -2
- package/build/css/themes/default/api_webinstaller.min.css +2 -2
- package/build/css/themes/default/ext_app.min.css +3 -3
- package/build/css/themes/default/ext_authentication.min.css +2 -2
- package/build/css/themes/default/ext_external.min.css +2 -2
- package/build/css/themes/default/ext_in_form_cta.min.css +2 -2
- package/build/css/themes/default/ext_in_form_menu.min.css +2 -2
- package/build/css/themes/default/ext_quickaccess.min.css +2 -2
- package/build/css/themes/midgar/api_authentication.min.css +2 -2
- package/build/css/themes/midgar/api_main.min.css +2 -2
- package/build/css/themes/midgar/api_reports.min.css +2 -2
- package/build/css/themes/midgar/ext_app.min.css +3 -3
- package/build/css/themes/midgar/ext_authentication.min.css +2 -2
- package/build/css/themes/midgar/ext_in_form_cta.min.css +2 -2
- package/build/css/themes/midgar/ext_in_form_menu.min.css +2 -2
- package/build/css/themes/midgar/ext_quickaccess.min.css +2 -2
- package/build/css/themes/solarized_dark/api_authentication.min.css +2 -2
- package/build/css/themes/solarized_dark/api_main.min.css +2 -2
- package/build/css/themes/solarized_dark/api_reports.min.css +2 -2
- package/build/css/themes/solarized_dark/ext_app.min.css +3 -3
- package/build/css/themes/solarized_dark/ext_authentication.min.css +2 -2
- package/build/css/themes/solarized_dark/ext_in_form_cta.min.css +2 -2
- package/build/css/themes/solarized_dark/ext_in_form_menu.min.css +2 -2
- package/build/css/themes/solarized_dark/ext_quickaccess.min.css +2 -2
- package/build/css/themes/solarized_light/api_authentication.min.css +2 -2
- package/build/css/themes/solarized_light/api_main.min.css +2 -2
- package/build/css/themes/solarized_light/api_reports.min.css +2 -2
- package/build/css/themes/solarized_light/ext_app.min.css +3 -3
- package/build/css/themes/solarized_light/ext_authentication.min.css +2 -2
- package/build/css/themes/solarized_light/ext_in_form_cta.min.css +2 -2
- package/build/css/themes/solarized_light/ext_in_form_menu.min.css +2 -2
- package/build/css/themes/solarized_light/ext_quickaccess.min.css +2 -2
- package/build/js/dist/api-app.js +1 -1
- package/build/locales/cs-CZ/common.json +1 -1
- package/build/locales/de-DE/common.json +1 -1
- package/build/locales/en-UK/common.json +1 -1
- package/build/locales/es-ES/common.json +1 -1
- package/build/locales/fr-FR/common.json +1 -1
- package/build/locales/it-IT/common.json +1 -1
- package/build/locales/ja-JP/common.json +1 -1
- package/build/locales/ko-KR/common.json +1 -1
- package/build/locales/lt-LT/common.json +1 -1
- package/build/locales/nl-NL/common.json +1 -1
- package/build/locales/pl-PL/common.json +1 -1
- package/build/locales/pt-BR/common.json +1 -1
- package/build/locales/ro-RO/common.json +1 -1
- package/build/locales/ru-RU/common.json +1 -1
- package/build/locales/sl-SI/common.json +1 -1
- package/build/locales/sv-SE/common.json +1 -1
- package/build/locales/uk-UA/common.json +1 -1
- package/package.json +1 -1
- package/src/locales/cs-CZ/common.json +1 -1
- package/src/locales/de-DE/common.json +1 -1
- package/src/locales/en-UK/common.json +1 -1
- package/src/locales/es-ES/common.json +1 -1
- package/src/locales/fr-FR/common.json +1 -1
- package/src/locales/it-IT/common.json +1 -1
- package/src/locales/ja-JP/common.json +1 -1
- package/src/locales/ko-KR/common.json +1 -1
- package/src/locales/lt-LT/common.json +1 -1
- package/src/locales/nl-NL/common.json +1 -1
- package/src/locales/pl-PL/common.json +1 -1
- package/src/locales/pt-BR/common.json +1 -1
- package/src/locales/ro-RO/common.json +1 -1
- package/src/locales/ru-RU/common.json +1 -1
- package/src/locales/sl-SI/common.json +1 -1
- package/src/locales/sv-SE/common.json +1 -1
- package/src/locales/uk-UA/common.json +1 -1
- package/src/react-extension/components/Administration/DisplaySubscriptionKey/DisplaySubscriptionKey.js +6 -11
- package/src/react-extension/components/Administration/DisplaySubscriptionKey/DisplaySubscriptionKey.test.js +0 -28
- package/src/react-extension/components/Resource/HandlePermissionWorkflow/flows/FolderShareFlow.js +7 -7
- package/src/react-extension/components/Resource/HandlePermissionWorkflow/flows/FolderShareFlow.test.js +6 -9
- package/src/react-extension/components/Resource/HandlePermissionWorkflow/flows/ResourceCreationFlow.js +17 -24
- package/src/react-extension/components/Resource/HandlePermissionWorkflow/flows/ResourceCreationFlow.test.js +15 -17
- package/src/react-extension/components/Resource/HandlePermissionWorkflow/flows/ResourceEditFlow.js +23 -17
- package/src/react-extension/components/Resource/HandlePermissionWorkflow/flows/ResourceEditFlow.test.js +18 -31
- package/src/react-extension/components/Resource/HandlePermissionWorkflow/flows/ResourceShareFlow.js +4 -5
- package/src/react-extension/components/Resource/HandlePermissionWorkflow/flows/ResourceShareFlow.test.js +14 -22
- package/src/react-extension/components/Share/GroupPermissionItem.js +12 -19
- package/src/react-extension/components/Share/GroupPermissionItem.test.data.js +0 -1
- package/src/react-extension/components/Share/GroupPermissionItem.test.js +6 -14
- package/src/react-extension/components/Share/GroupPermissionItem.test.stories.js +0 -4
- package/src/react-extension/components/Share/ShareDialog.js +176 -159
- package/src/react-extension/components/Share/ShareDialog.test.data.js +241 -8
- package/src/react-extension/components/Share/ShareDialog.test.js +108 -505
- package/src/react-extension/components/Share/ShareDialog.test.stories.js +0 -3
- package/src/react-extension/contexts/ExtAppContext.js +0 -6
- package/src/react-extension/contexts/WorkflowContext.js +4 -0
- package/src/shared/models/entity/groupUser/groupUserEntity.js +52 -6
- package/src/shared/models/entity/groupUser/groupUserEntity.test.data.js +5 -0
- package/src/shared/models/entity/groupUser/groupUserEntity.test.js +54 -0
- package/src/shared/services/permission/permissionSnapshotService.js +20 -20
- package/src/shared/services/permission/permissionSnapshotService.test.js +77 -53
- package/src/shared/services/serviceWorker/group/groupServiceWorkerService.js +6 -18
- package/src/shared/services/serviceWorker/group/groupServiceWorkerService.test.js +13 -27
|
@@ -22,9 +22,6 @@ const port = mockPort(storage);
|
|
|
22
22
|
port.addRequestListener("passbolt.resources.find-all-by-ids-for-display-permissions", () => resources);
|
|
23
23
|
|
|
24
24
|
const context = defaultAppContext({
|
|
25
|
-
shareDialogProps: {
|
|
26
|
-
resourcesIds: resources.map((resource) => resource.id),
|
|
27
|
-
},
|
|
28
25
|
port: port,
|
|
29
26
|
});
|
|
30
27
|
|
|
@@ -106,12 +106,6 @@ class ExtAppContextProvider extends React.Component {
|
|
|
106
106
|
resourcesIds: [],
|
|
107
107
|
},
|
|
108
108
|
|
|
109
|
-
// share dialog
|
|
110
|
-
shareDialogProps: {
|
|
111
|
-
foldersIds: null,
|
|
112
|
-
resourcesIds: null,
|
|
113
|
-
},
|
|
114
|
-
|
|
115
109
|
// user dialog
|
|
116
110
|
editUserDialogProps: {
|
|
117
111
|
id: null, // The id of the current user to edit
|
|
@@ -45,6 +45,10 @@ export default class WorkflowContextProvider extends React.Component {
|
|
|
45
45
|
return {
|
|
46
46
|
workflows: [],
|
|
47
47
|
start: (Workflow, workflowProps) => {
|
|
48
|
+
const isWorkflowStarted = this.state.workflows.find((w) => w.Workflow === Workflow);
|
|
49
|
+
if (isWorkflowStarted) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
48
52
|
const workflowKey = uuidv4();
|
|
49
53
|
this.setState({ workflows: [...this.state.workflows, { key: workflowKey, Workflow, workflowProps }] });
|
|
50
54
|
|
|
@@ -13,10 +13,24 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import Validator from "validator";
|
|
15
15
|
import EntityV2 from "../abstract/entityV2";
|
|
16
|
+
import UserEntity from "../user/userEntity";
|
|
16
17
|
|
|
17
18
|
const ENTITY_NAME = "GroupUser";
|
|
18
19
|
|
|
19
20
|
class GroupUserEntity extends EntityV2 {
|
|
21
|
+
/**
|
|
22
|
+
* @inheritDoc
|
|
23
|
+
*/
|
|
24
|
+
constructor(dto, options = {}) {
|
|
25
|
+
super(dto, options);
|
|
26
|
+
|
|
27
|
+
// Association
|
|
28
|
+
if (this._props.user) {
|
|
29
|
+
this._user = new UserEntity(this._props.user, { ...options, clone: false });
|
|
30
|
+
delete this._props.user;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
20
34
|
/**
|
|
21
35
|
* Get groupUser entity schema
|
|
22
36
|
* @returns {Object} schema
|
|
@@ -46,20 +60,44 @@ class GroupUserEntity extends EntityV2 {
|
|
|
46
60
|
format: "date-time",
|
|
47
61
|
},
|
|
48
62
|
/*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
63
|
+
* Associated models
|
|
64
|
+
* The user schema is declared as a generic object to break the infinite schema recursion
|
|
65
|
+
* UserEntity -> GroupsUsersCollection -> GroupUserEntity -> UserEntity. The user is fully
|
|
66
|
+
* validated by the UserEntity constructor when the association is built.
|
|
52
67
|
*/
|
|
68
|
+
user: {
|
|
69
|
+
type: "object",
|
|
70
|
+
},
|
|
53
71
|
},
|
|
54
72
|
};
|
|
55
73
|
}
|
|
56
74
|
|
|
57
75
|
/**
|
|
58
76
|
* Return a DTO ready to be sent to API
|
|
77
|
+
* @param {object} [contain] optional for example {user: {profile: true}}
|
|
59
78
|
* @returns {Object}
|
|
60
79
|
*/
|
|
61
|
-
toDto() {
|
|
62
|
-
|
|
80
|
+
toDto(contain) {
|
|
81
|
+
const result = Object.assign({}, this._props);
|
|
82
|
+
if (!contain) {
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
if (this._user && contain.user) {
|
|
86
|
+
if (contain.user === true) {
|
|
87
|
+
result.user = this._user.toDto();
|
|
88
|
+
} else {
|
|
89
|
+
result.user = this._user.toDto(contain.user);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Customizes JSON stringification behavior
|
|
97
|
+
* @returns {*}
|
|
98
|
+
*/
|
|
99
|
+
toJSON() {
|
|
100
|
+
return this.toDto(GroupUserEntity.ALL_CONTAIN_OPTIONS);
|
|
63
101
|
}
|
|
64
102
|
|
|
65
103
|
/*
|
|
@@ -107,6 +145,14 @@ class GroupUserEntity extends EntityV2 {
|
|
|
107
145
|
return this._props.created || null;
|
|
108
146
|
}
|
|
109
147
|
|
|
148
|
+
/**
|
|
149
|
+
* Get the group user associated user
|
|
150
|
+
* @returns {(UserEntity|null)} user
|
|
151
|
+
*/
|
|
152
|
+
get user() {
|
|
153
|
+
return this._user || null;
|
|
154
|
+
}
|
|
155
|
+
|
|
110
156
|
/*
|
|
111
157
|
* ==================================================
|
|
112
158
|
* Dynamic properties setters
|
|
@@ -144,7 +190,7 @@ class GroupUserEntity extends EntityV2 {
|
|
|
144
190
|
* @returns {object} all contain options that can be used in toDto()
|
|
145
191
|
*/
|
|
146
192
|
static get ALL_CONTAIN_OPTIONS() {
|
|
147
|
-
return {};
|
|
193
|
+
return { user: UserEntity.ALL_CONTAIN_OPTIONS };
|
|
148
194
|
}
|
|
149
195
|
}
|
|
150
196
|
|
|
@@ -45,3 +45,8 @@ export function groupsWithoutOwnership(data = {}) {
|
|
|
45
45
|
|
|
46
46
|
return Object.assign(groupsUsers, data);
|
|
47
47
|
}
|
|
48
|
+
|
|
49
|
+
export const defaultGroupUserWithUserDto = (data = {}) => {
|
|
50
|
+
const user = defaultUserDto({}, { withGpgkey: true });
|
|
51
|
+
return defaultGroupUser({ user_id: user.id, user, ...data });
|
|
52
|
+
};
|
|
@@ -12,10 +12,13 @@
|
|
|
12
12
|
* @since 2.13.0
|
|
13
13
|
*/
|
|
14
14
|
import GroupUserEntity from "./groupUserEntity";
|
|
15
|
+
import UserEntity from "../user/userEntity";
|
|
16
|
+
import EntityValidationError from "../abstract/entityValidationError";
|
|
15
17
|
import EntitySchema from "../abstract/entitySchema";
|
|
16
18
|
import * as assertEntityProperty from "passbolt-styleguide/test/assert/assertEntityProperty";
|
|
17
19
|
import {
|
|
18
20
|
defaultGroupUser,
|
|
21
|
+
defaultGroupUserWithUserDto,
|
|
19
22
|
minimumGroupUserDto,
|
|
20
23
|
} from "passbolt-styleguide/src/shared/models/entity/groupUser/groupUserEntity.test.data.js";
|
|
21
24
|
|
|
@@ -68,4 +71,55 @@ describe("GroupUserEntity", () => {
|
|
|
68
71
|
expect(entity.toDto()).toEqual(dto);
|
|
69
72
|
});
|
|
70
73
|
});
|
|
74
|
+
|
|
75
|
+
describe("GroupUserEntity::user association", () => {
|
|
76
|
+
it("constructor parses an embedded user as a UserEntity", () => {
|
|
77
|
+
const dto = defaultGroupUserWithUserDto();
|
|
78
|
+
const entity = new GroupUserEntity(dto);
|
|
79
|
+
expect(entity.user).toBeInstanceOf(UserEntity);
|
|
80
|
+
expect(entity.user.id).toEqual(dto.user.id);
|
|
81
|
+
expect(entity.user.username).toEqual(dto.user.username);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("user getter returns null when the DTO has no user", () => {
|
|
85
|
+
const dto = defaultGroupUser();
|
|
86
|
+
const entity = new GroupUserEntity(dto);
|
|
87
|
+
expect(entity.user).toBeNull();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("zero-arg toDto() omits user for back-compat", () => {
|
|
91
|
+
const dto = defaultGroupUserWithUserDto();
|
|
92
|
+
const entity = new GroupUserEntity(dto);
|
|
93
|
+
const result = entity.toDto();
|
|
94
|
+
expect(result.user).toBeUndefined();
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("toDto(GroupUserEntity.ALL_CONTAIN_OPTIONS) returns the full DTO including user with profile and gpgkey", () => {
|
|
98
|
+
const dto = defaultGroupUserWithUserDto();
|
|
99
|
+
const entity = new GroupUserEntity(dto);
|
|
100
|
+
const result = entity.toDto(GroupUserEntity.ALL_CONTAIN_OPTIONS);
|
|
101
|
+
expect(result.user).toBeDefined();
|
|
102
|
+
expect(result.user.id).toEqual(dto.user.id);
|
|
103
|
+
expect(result.user.profile).toBeDefined();
|
|
104
|
+
expect(result.user.gpgkey).toBeDefined();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("JSON.parse(JSON.stringify(entity)) retains user id, profile, and gpgkey", () => {
|
|
108
|
+
const dto = defaultGroupUserWithUserDto();
|
|
109
|
+
const entity = new GroupUserEntity(dto);
|
|
110
|
+
const serialized = JSON.stringify(entity);
|
|
111
|
+
const deserialized = JSON.parse(serialized);
|
|
112
|
+
expect(deserialized.user).toBeDefined();
|
|
113
|
+
expect(deserialized.user.id).toEqual(dto.user.id);
|
|
114
|
+
expect(deserialized.user.profile).toBeDefined();
|
|
115
|
+
expect(deserialized.user.gpgkey).toBeDefined();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("constructor throws EntityValidationError for an invalid embedded user", () => {
|
|
119
|
+
const dto = defaultGroupUser({ user: { username: 42 } });
|
|
120
|
+
expect(() => {
|
|
121
|
+
new GroupUserEntity(dto);
|
|
122
|
+
}).toThrow(EntityValidationError);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
71
125
|
});
|
|
@@ -14,12 +14,13 @@
|
|
|
14
14
|
import KeyringServiceWorkerService from "../serviceWorker/keyring/keyringServiceWorkerService";
|
|
15
15
|
import PermissionServiceWorkerService from "../serviceWorker/permission/permissionServiceWorkerService";
|
|
16
16
|
import GroupServiceWorkerService from "../serviceWorker/group/groupServiceWorkerService";
|
|
17
|
-
import UserServiceWorkerService from "../serviceWorker/user/userServiceWorkerService";
|
|
18
17
|
import PermissionEntity from "../../models/entity/permission/permissionEntity";
|
|
18
|
+
import UserEntity from "../../models/entity/user/userEntity";
|
|
19
|
+
import GroupsCollection from "../../models/entity/group/groupsCollection";
|
|
19
20
|
import PermissionSnapshotEntity from "../../models/entity/permission/permissionSnapshotEntity";
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
|
-
* Higher-level orchestrator that composes the keyring, permission,
|
|
23
|
+
* Higher-level orchestrator that composes the keyring, permission, and group service-worker
|
|
23
24
|
* services to build an immutable permission snapshot. The snapshot is used by the permission-review
|
|
24
25
|
* workflow to guarantee that the permission set displayed to the operator is exactly the one applied
|
|
25
26
|
* when secrets are encrypted and shared.
|
|
@@ -32,7 +33,6 @@ export default class PermissionSnapshotService {
|
|
|
32
33
|
this.keyringServiceWorkerService = new KeyringServiceWorkerService(port);
|
|
33
34
|
this.permissionServiceWorkerService = new PermissionServiceWorkerService(port);
|
|
34
35
|
this.groupServiceWorkerService = new GroupServiceWorkerService(port);
|
|
35
|
-
this.userServiceWorkerService = new UserServiceWorkerService(port);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
/**
|
|
@@ -121,7 +121,10 @@ export default class PermissionSnapshotService {
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
/**
|
|
124
|
-
* Resolve the groups
|
|
124
|
+
* Resolve the groups referenced by a permission set and assemble the immutable snapshot.
|
|
125
|
+
* The snapshot user list is derived from the member users embedded in the groups, deduplicated
|
|
126
|
+
* by user id, so the dialog can list a group's members when expanded. Directly-permissioned
|
|
127
|
+
* users are not resolved separately: their display data travels embedded in the permissions.
|
|
125
128
|
* @param {PermissionsCollection} permissions The permission set to capture.
|
|
126
129
|
* @returns {Promise<PermissionSnapshotEntity>}
|
|
127
130
|
* @private
|
|
@@ -130,25 +133,22 @@ export default class PermissionSnapshotService {
|
|
|
130
133
|
const groupIds = permissions.items
|
|
131
134
|
.filter((permission) => permission.aro === PermissionEntity.ARO_GROUP)
|
|
132
135
|
.map((permission) => permission.aroForeignKey);
|
|
133
|
-
//
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
)
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
]),
|
|
146
|
-
];
|
|
147
|
-
const users = await this.userServiceWorkerService.getByIds(userIds);
|
|
136
|
+
// No group permissions: skip the round-trip to the service worker entirely.
|
|
137
|
+
const groups = groupIds.length
|
|
138
|
+
? await this.groupServiceWorkerService.findByIdsForShare(groupIds)
|
|
139
|
+
: new GroupsCollection([]);
|
|
140
|
+
const usersById = new Map();
|
|
141
|
+
for (const group of groups.items) {
|
|
142
|
+
for (const groupUser of group.groupsUsers?.items ?? []) {
|
|
143
|
+
if (groupUser.user && !usersById.has(groupUser.user.id)) {
|
|
144
|
+
usersById.set(groupUser.user.id, groupUser.user.toDto(UserEntity.ALL_CONTAIN_OPTIONS));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
148
|
return new PermissionSnapshotEntity({
|
|
149
149
|
permissions: permissions.toDto(),
|
|
150
150
|
groups: groups.toDto(),
|
|
151
|
-
users:
|
|
151
|
+
users: [...usersById.values()],
|
|
152
152
|
created: new Date().toISOString(),
|
|
153
153
|
});
|
|
154
154
|
}
|
|
@@ -18,13 +18,11 @@ import PermissionSnapshotService from "./permissionSnapshotService";
|
|
|
18
18
|
import PermissionSnapshotEntity from "../../models/entity/permission/permissionSnapshotEntity";
|
|
19
19
|
import { KEYRING_SYNC_EVENT } from "../serviceWorker/keyring/keyringServiceWorkerService";
|
|
20
20
|
import { PERMISSIONS_FIND_ACO_PERMISSIONS_FOR_DISPLAY } from "../serviceWorker/permission/permissionServiceWorkerService";
|
|
21
|
-
import {
|
|
22
|
-
import { USERS_GET_BY_IDS } from "../serviceWorker/user/userServiceWorkerService";
|
|
21
|
+
import { GROUPS_FIND_BY_IDS_FOR_SHARE } from "../serviceWorker/group/groupServiceWorkerService";
|
|
23
22
|
import { defaultPermissionDto } from "../../models/entity/permission/permissionEntity.test.data";
|
|
24
|
-
import { defaultGroupsDtos } from "../../models/entity/group/groupsCollection.test.data";
|
|
25
23
|
import { defaultGroupDto } from "../../models/entity/group/groupEntity.test.data";
|
|
26
24
|
import { defaultGroupUser } from "../../models/entity/groupUser/groupUserEntity.test.data";
|
|
27
|
-
import {
|
|
25
|
+
import { defaultUserDto } from "../../models/entity/user/userEntity.test.data";
|
|
28
26
|
|
|
29
27
|
beforeEach(() => {
|
|
30
28
|
jest.clearAllMocks();
|
|
@@ -40,11 +38,12 @@ describe("PermissionSnapshotService", () => {
|
|
|
40
38
|
|
|
41
39
|
describe("::buildSnapshotForResourceCreation", () => {
|
|
42
40
|
it("synchronises the keyring then fetches the parent folder permissions, groups, and users referenced by them, and returns a PermissionSnapshotEntity", async () => {
|
|
43
|
-
expect.assertions(
|
|
41
|
+
expect.assertions(7);
|
|
44
42
|
|
|
45
43
|
const folderId = uuidv4();
|
|
46
44
|
const groupIds = [uuidv4(), uuidv4()];
|
|
47
|
-
const
|
|
45
|
+
const memberA = defaultUserDto({ username: "member-a@passbolt.com" });
|
|
46
|
+
const memberB = defaultUserDto({ username: "member-b@passbolt.com" });
|
|
48
47
|
const permissionsDto = [
|
|
49
48
|
defaultPermissionDto({
|
|
50
49
|
aco: "Folder",
|
|
@@ -64,57 +63,71 @@ describe("PermissionSnapshotService", () => {
|
|
|
64
63
|
aco: "Folder",
|
|
65
64
|
aco_foreign_key: folderId,
|
|
66
65
|
aro: "User",
|
|
67
|
-
aro_foreign_key:
|
|
66
|
+
aro_foreign_key: uuidv4(),
|
|
68
67
|
type: 1,
|
|
69
68
|
}),
|
|
70
69
|
];
|
|
71
|
-
const groupsDto =
|
|
72
|
-
|
|
70
|
+
const groupsDto = [
|
|
71
|
+
defaultGroupDto({
|
|
72
|
+
id: groupIds[0],
|
|
73
|
+
name: "Group 0",
|
|
74
|
+
groups_users: [defaultGroupUser({ group_id: groupIds[0], user_id: memberA.id, user: memberA })],
|
|
75
|
+
}),
|
|
76
|
+
defaultGroupDto({
|
|
77
|
+
id: groupIds[1],
|
|
78
|
+
name: "Group 1",
|
|
79
|
+
groups_users: [defaultGroupUser({ group_id: groupIds[1], user_id: memberB.id, user: memberB })],
|
|
80
|
+
}),
|
|
81
|
+
];
|
|
73
82
|
port.addRequestListener(KEYRING_SYNC_EVENT, () => {});
|
|
74
83
|
port.addRequestListener(PERMISSIONS_FIND_ACO_PERMISSIONS_FOR_DISPLAY, () => permissionsDto);
|
|
75
|
-
port.addRequestListener(
|
|
76
|
-
port.addRequestListener(USERS_GET_BY_IDS, () => usersDto);
|
|
84
|
+
port.addRequestListener(GROUPS_FIND_BY_IDS_FOR_SHARE, () => groupsDto);
|
|
77
85
|
jest.spyOn(port, "request");
|
|
78
86
|
|
|
79
87
|
const snapshot = await service.buildSnapshotForResourceCreation(folderId);
|
|
80
88
|
|
|
81
89
|
expect(port.request).toHaveBeenCalledWith(KEYRING_SYNC_EVENT);
|
|
82
90
|
expect(port.request).toHaveBeenCalledWith(PERMISSIONS_FIND_ACO_PERMISSIONS_FOR_DISPLAY, folderId, "Folder");
|
|
83
|
-
expect(port.request).toHaveBeenCalledWith(
|
|
84
|
-
expect(port.request).toHaveBeenCalledWith(USERS_GET_BY_IDS, userIds);
|
|
91
|
+
expect(port.request).toHaveBeenCalledWith(GROUPS_FIND_BY_IDS_FOR_SHARE, groupIds);
|
|
85
92
|
expect(snapshot).toBeInstanceOf(PermissionSnapshotEntity);
|
|
86
93
|
expect(snapshot.permissions.toDto()).toStrictEqual(permissionsDto);
|
|
87
94
|
expect(snapshot.groups.toDto()).toStrictEqual(groupsDto);
|
|
88
|
-
expect(snapshot.users.toDto()).toStrictEqual(
|
|
95
|
+
expect(snapshot.users.toDto()).toStrictEqual([memberA, memberB]);
|
|
89
96
|
});
|
|
90
97
|
|
|
91
|
-
it("
|
|
92
|
-
expect.assertions(
|
|
98
|
+
it("skips the group fetch when the parent folder has no group permissions, derives no users, and still returns a PermissionSnapshotEntity", async () => {
|
|
99
|
+
expect.assertions(4);
|
|
93
100
|
|
|
94
101
|
const folderId = uuidv4();
|
|
95
102
|
port.addRequestListener(KEYRING_SYNC_EVENT, () => {});
|
|
96
103
|
port.addRequestListener(PERMISSIONS_FIND_ACO_PERMISSIONS_FOR_DISPLAY, () => []);
|
|
97
|
-
port.addRequestListener(
|
|
98
|
-
port.addRequestListener(USERS_GET_BY_IDS, () => []);
|
|
104
|
+
port.addRequestListener(GROUPS_FIND_BY_IDS_FOR_SHARE, () => []);
|
|
99
105
|
jest.spyOn(port, "request");
|
|
100
106
|
|
|
101
107
|
const snapshot = await service.buildSnapshotForResourceCreation(folderId);
|
|
102
108
|
|
|
103
|
-
expect(port.request).toHaveBeenCalledWith(
|
|
104
|
-
expect(port.request).toHaveBeenCalledWith(USERS_GET_BY_IDS, []);
|
|
109
|
+
expect(port.request).not.toHaveBeenCalledWith(GROUPS_FIND_BY_IDS_FOR_SHARE, []);
|
|
105
110
|
expect(snapshot).toBeInstanceOf(PermissionSnapshotEntity);
|
|
106
111
|
expect(snapshot.groups).toHaveLength(0);
|
|
107
112
|
expect(snapshot.users).toHaveLength(0);
|
|
108
113
|
});
|
|
109
114
|
|
|
110
|
-
it("synchronises the keyring before the permission fetch, and fetches the permissions before the groups
|
|
111
|
-
expect.assertions(
|
|
115
|
+
it("synchronises the keyring before the permission fetch, and fetches the permissions before the groups", async () => {
|
|
116
|
+
expect.assertions(3);
|
|
112
117
|
|
|
113
118
|
const folderId = uuidv4();
|
|
119
|
+
const groupId = uuidv4();
|
|
114
120
|
port.addRequestListener(KEYRING_SYNC_EVENT, () => {});
|
|
115
|
-
port.addRequestListener(PERMISSIONS_FIND_ACO_PERMISSIONS_FOR_DISPLAY, () => [
|
|
116
|
-
|
|
117
|
-
|
|
121
|
+
port.addRequestListener(PERMISSIONS_FIND_ACO_PERMISSIONS_FOR_DISPLAY, () => [
|
|
122
|
+
defaultPermissionDto({
|
|
123
|
+
aco: "Folder",
|
|
124
|
+
aco_foreign_key: folderId,
|
|
125
|
+
aro: "Group",
|
|
126
|
+
aro_foreign_key: groupId,
|
|
127
|
+
type: 1,
|
|
128
|
+
}),
|
|
129
|
+
]);
|
|
130
|
+
port.addRequestListener(GROUPS_FIND_BY_IDS_FOR_SHARE, () => [defaultGroupDto({ id: groupId, name: "Group 0" })]);
|
|
118
131
|
jest.spyOn(port, "request");
|
|
119
132
|
|
|
120
133
|
await service.buildSnapshotForResourceCreation(folderId);
|
|
@@ -122,28 +135,35 @@ describe("PermissionSnapshotService", () => {
|
|
|
122
135
|
// Deterministic prefix: keyring sync first, then the permission fetch.
|
|
123
136
|
expect(port.request).toHaveBeenNthCalledWith(1, KEYRING_SYNC_EVENT);
|
|
124
137
|
expect(port.request).toHaveBeenNthCalledWith(2, PERMISSIONS_FIND_ACO_PERMISSIONS_FOR_DISPLAY, folderId, "Folder");
|
|
125
|
-
// Groups are fetched
|
|
126
|
-
// permission fetch.
|
|
138
|
+
// Groups are fetched after the permission fetch.
|
|
127
139
|
const events = port.request.mock.calls.map(([event]) => event);
|
|
128
|
-
expect(events.indexOf(
|
|
140
|
+
expect(events.indexOf(GROUPS_FIND_BY_IDS_FOR_SHARE)).toBeGreaterThan(
|
|
129
141
|
events.indexOf(PERMISSIONS_FIND_ACO_PERMISSIONS_FOR_DISPLAY),
|
|
130
142
|
);
|
|
131
|
-
expect(events.indexOf(USERS_GET_BY_IDS)).toBeGreaterThan(events.indexOf(GROUPS_GET_BY_IDS));
|
|
132
143
|
});
|
|
133
144
|
|
|
134
|
-
it("
|
|
135
|
-
expect.assertions(
|
|
145
|
+
it("derives the snapshot users from the permissioned groups members, deduplicated across groups, excluding directly-permissioned non-members", async () => {
|
|
146
|
+
expect.assertions(3);
|
|
136
147
|
|
|
137
148
|
const folderId = uuidv4();
|
|
138
|
-
const
|
|
149
|
+
const groupAId = uuidv4();
|
|
150
|
+
const groupBId = uuidv4();
|
|
139
151
|
const directUserId = uuidv4();
|
|
140
|
-
const
|
|
152
|
+
const sharedMember = defaultUserDto({ username: "shared@passbolt.com" });
|
|
153
|
+
const soloMember = defaultUserDto({ username: "solo@passbolt.com" });
|
|
141
154
|
const permissionsDto = [
|
|
142
155
|
defaultPermissionDto({
|
|
143
156
|
aco: "Folder",
|
|
144
157
|
aco_foreign_key: folderId,
|
|
145
158
|
aro: "Group",
|
|
146
|
-
aro_foreign_key:
|
|
159
|
+
aro_foreign_key: groupAId,
|
|
160
|
+
type: 1,
|
|
161
|
+
}),
|
|
162
|
+
defaultPermissionDto({
|
|
163
|
+
aco: "Folder",
|
|
164
|
+
aco_foreign_key: folderId,
|
|
165
|
+
aro: "Group",
|
|
166
|
+
aro_foreign_key: groupBId,
|
|
147
167
|
type: 1,
|
|
148
168
|
}),
|
|
149
169
|
defaultPermissionDto({
|
|
@@ -154,24 +174,31 @@ describe("PermissionSnapshotService", () => {
|
|
|
154
174
|
type: 15,
|
|
155
175
|
}),
|
|
156
176
|
];
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
177
|
+
const groupsDto = [
|
|
178
|
+
defaultGroupDto({
|
|
179
|
+
id: groupAId,
|
|
180
|
+
name: "Group A",
|
|
181
|
+
groups_users: [
|
|
182
|
+
defaultGroupUser({ group_id: groupAId, user_id: sharedMember.id, user: sharedMember, is_admin: true }),
|
|
183
|
+
defaultGroupUser({ group_id: groupAId, user_id: soloMember.id, user: soloMember }),
|
|
184
|
+
],
|
|
185
|
+
}),
|
|
186
|
+
defaultGroupDto({
|
|
187
|
+
id: groupBId,
|
|
188
|
+
name: "Group B",
|
|
189
|
+
groups_users: [defaultGroupUser({ group_id: groupBId, user_id: sharedMember.id, user: sharedMember })],
|
|
190
|
+
}),
|
|
191
|
+
];
|
|
166
192
|
port.addRequestListener(KEYRING_SYNC_EVENT, () => {});
|
|
167
193
|
port.addRequestListener(PERMISSIONS_FIND_ACO_PERMISSIONS_FOR_DISPLAY, () => permissionsDto);
|
|
168
|
-
port.addRequestListener(
|
|
169
|
-
port.addRequestListener(USERS_GET_BY_IDS, () => []);
|
|
194
|
+
port.addRequestListener(GROUPS_FIND_BY_IDS_FOR_SHARE, () => groupsDto);
|
|
170
195
|
jest.spyOn(port, "request");
|
|
171
196
|
|
|
172
|
-
await service.buildSnapshotForResourceCreation(folderId);
|
|
197
|
+
const snapshot = await service.buildSnapshotForResourceCreation(folderId);
|
|
173
198
|
|
|
174
|
-
expect(
|
|
199
|
+
expect(snapshot.users.toDto()).toStrictEqual([sharedMember, soloMember]);
|
|
200
|
+
expect(snapshot.users.items.find((u) => u.id === directUserId)).toBeUndefined();
|
|
201
|
+
expect(port.request).not.toHaveBeenCalledWith("passbolt.users.get-by-ids", expect.anything());
|
|
175
202
|
});
|
|
176
203
|
|
|
177
204
|
it("propagates the error when the keyring synchronisation fails", async () => {
|
|
@@ -202,8 +229,7 @@ describe("PermissionSnapshotService", () => {
|
|
|
202
229
|
type: 15,
|
|
203
230
|
}),
|
|
204
231
|
]);
|
|
205
|
-
port.addRequestListener(
|
|
206
|
-
port.addRequestListener(USERS_GET_BY_IDS, () => []);
|
|
232
|
+
port.addRequestListener(GROUPS_FIND_BY_IDS_FOR_SHARE, () => []);
|
|
207
233
|
jest.spyOn(port, "request");
|
|
208
234
|
|
|
209
235
|
const snapshots = await service.buildSnapshotForResourcesShare(resourcesIds);
|
|
@@ -229,8 +255,7 @@ describe("PermissionSnapshotService", () => {
|
|
|
229
255
|
const resourcesIds = [uuidv4(), uuidv4(), uuidv4()];
|
|
230
256
|
port.addRequestListener(KEYRING_SYNC_EVENT, () => {});
|
|
231
257
|
port.addRequestListener(PERMISSIONS_FIND_ACO_PERMISSIONS_FOR_DISPLAY, () => []);
|
|
232
|
-
port.addRequestListener(
|
|
233
|
-
port.addRequestListener(USERS_GET_BY_IDS, () => []);
|
|
258
|
+
port.addRequestListener(GROUPS_FIND_BY_IDS_FOR_SHARE, () => []);
|
|
234
259
|
jest.spyOn(port, "request");
|
|
235
260
|
|
|
236
261
|
await service.buildSnapshotForResourcesShare(resourcesIds);
|
|
@@ -275,8 +300,7 @@ describe("PermissionSnapshotService", () => {
|
|
|
275
300
|
];
|
|
276
301
|
port.addRequestListener(KEYRING_SYNC_EVENT, () => {});
|
|
277
302
|
port.addRequestListener(PERMISSIONS_FIND_ACO_PERMISSIONS_FOR_DISPLAY, () => permissionsDto);
|
|
278
|
-
port.addRequestListener(
|
|
279
|
-
port.addRequestListener(USERS_GET_BY_IDS, () => defaultUsersDtos(1));
|
|
303
|
+
port.addRequestListener(GROUPS_FIND_BY_IDS_FOR_SHARE, () => []);
|
|
280
304
|
jest.spyOn(port, "request");
|
|
281
305
|
|
|
282
306
|
const snapshot = await service.buildSnapshotForFolderShare(folderId);
|
|
@@ -12,11 +12,9 @@
|
|
|
12
12
|
* @since 5.7.0
|
|
13
13
|
*/
|
|
14
14
|
import GroupsCollection from "../../../models/entity/group/groupsCollection";
|
|
15
|
-
import GroupsUsersCollection from "../../../models/entity/groupUser/groupsUsersCollection";
|
|
16
15
|
|
|
17
16
|
export const GROUPS_FIND_MY_GROUPS = "passbolt.groups.find-my-groups";
|
|
18
|
-
export const
|
|
19
|
-
export const GROUPS_USERS_GET_BY_GROUP_ID = "passbolt.groups_users.get-by-group-id";
|
|
17
|
+
export const GROUPS_FIND_BY_IDS_FOR_SHARE = "passbolt.groups.find-by-ids-for-share";
|
|
20
18
|
|
|
21
19
|
export default class GroupServiceWorkerService {
|
|
22
20
|
/**
|
|
@@ -37,24 +35,14 @@ export default class GroupServiceWorkerService {
|
|
|
37
35
|
}
|
|
38
36
|
|
|
39
37
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
38
|
+
* Find the groups matching the given ids, with their member users embedded (user with profile and
|
|
39
|
+
* gpgkey). The list is always fetched fresh from the API so the share/permission-review workflow
|
|
40
|
+
* validates against current group data, never a cache.
|
|
42
41
|
* @param {Array<string>} groupIds The ids of the groups to retrieve.
|
|
43
42
|
* @returns {Promise<GroupsCollection>}
|
|
44
43
|
*/
|
|
45
|
-
async
|
|
46
|
-
const groupsDto = await this.port.request(
|
|
44
|
+
async findByIdsForShare(groupIds) {
|
|
45
|
+
const groupsDto = await this.port.request(GROUPS_FIND_BY_IDS_FOR_SHARE, groupIds);
|
|
47
46
|
return new GroupsCollection(groupsDto);
|
|
48
47
|
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Get the members of the group matching the given id. The list comes from the service-worker
|
|
52
|
-
* local-storage cache when initialised, otherwise it is fetched from the API.
|
|
53
|
-
* @param {string} groupId The id of the group whose members are requested.
|
|
54
|
-
* @returns {Promise<GroupsUsersCollection>}
|
|
55
|
-
*/
|
|
56
|
-
async getGroupsUsersByGroupId(groupId) {
|
|
57
|
-
const groupsUsersDto = await this.port.request(GROUPS_USERS_GET_BY_GROUP_ID, groupId);
|
|
58
|
-
return new GroupsUsersCollection(groupsUsersDto);
|
|
59
|
-
}
|
|
60
48
|
}
|
|
@@ -14,13 +14,13 @@
|
|
|
14
14
|
|
|
15
15
|
import MockPort from "../../../../react-extension/test/mock/MockPort";
|
|
16
16
|
import GroupsCollection from "../../../models/entity/group/groupsCollection";
|
|
17
|
-
import GroupsUsersCollection from "../../../models/entity/groupUser/groupsUsersCollection";
|
|
18
17
|
import { defaultGroupDto } from "../../../models/entity/group/groupEntity.test.data";
|
|
19
18
|
import { defaultGroupsDtos } from "../../../models/entity/group/groupsCollection.test.data";
|
|
19
|
+
import { defaultUserDto } from "../../../models/entity/user/userEntity.test.data";
|
|
20
|
+
import { defaultGroupUser } from "../../../models/entity/groupUser/groupUserEntity.test.data";
|
|
20
21
|
import GroupServiceWorkerService, {
|
|
21
22
|
GROUPS_FIND_MY_GROUPS,
|
|
22
|
-
|
|
23
|
-
GROUPS_USERS_GET_BY_GROUP_ID,
|
|
23
|
+
GROUPS_FIND_BY_IDS_FOR_SHARE,
|
|
24
24
|
} from "./groupServiceWorkerService";
|
|
25
25
|
|
|
26
26
|
beforeEach(() => {
|
|
@@ -52,39 +52,25 @@ describe("GroupServiceWorkerService", () => {
|
|
|
52
52
|
});
|
|
53
53
|
});
|
|
54
54
|
|
|
55
|
-
describe("::
|
|
56
|
-
it("requests the service worker with the expected event and returns a GroupsCollection.", async () => {
|
|
55
|
+
describe("::findByIdsForShare", () => {
|
|
56
|
+
it("requests the service worker with the expected event, preserves member users, and returns a GroupsCollection.", async () => {
|
|
57
57
|
expect.assertions(4);
|
|
58
58
|
|
|
59
|
-
const
|
|
59
|
+
const member = defaultUserDto({ username: "member@passbolt.com" }, { withGpgkey: true });
|
|
60
|
+
const groupsDto = [
|
|
61
|
+
defaultGroupDto({ groups_users: [defaultGroupUser({ user_id: member.id, user: member })] }),
|
|
62
|
+
...defaultGroupsDtos(2),
|
|
63
|
+
];
|
|
60
64
|
const requestedIds = groupsDto.map((group) => group.id);
|
|
61
|
-
port.addRequestListener(
|
|
65
|
+
port.addRequestListener(GROUPS_FIND_BY_IDS_FOR_SHARE, () => groupsDto);
|
|
62
66
|
jest.spyOn(port, "request");
|
|
63
67
|
|
|
64
|
-
const result = await service.
|
|
68
|
+
const result = await service.findByIdsForShare(requestedIds);
|
|
65
69
|
|
|
66
70
|
expect(port.request).toHaveBeenCalledTimes(1);
|
|
67
|
-
expect(port.request).toHaveBeenCalledWith(
|
|
71
|
+
expect(port.request).toHaveBeenCalledWith(GROUPS_FIND_BY_IDS_FOR_SHARE, requestedIds);
|
|
68
72
|
expect(result).toBeInstanceOf(GroupsCollection);
|
|
69
73
|
expect(result.toDto()).toStrictEqual(groupsDto);
|
|
70
74
|
});
|
|
71
75
|
});
|
|
72
|
-
|
|
73
|
-
describe("::getGroupsUsersByGroupId", () => {
|
|
74
|
-
it("requests the service worker with the expected event and returns a GroupsUsersCollection.", async () => {
|
|
75
|
-
expect.assertions(4);
|
|
76
|
-
|
|
77
|
-
const groupDto = defaultGroupDto({}, { withGroupsUsers: 3 });
|
|
78
|
-
const groupsUsersDto = groupDto.groups_users;
|
|
79
|
-
port.addRequestListener(GROUPS_USERS_GET_BY_GROUP_ID, () => groupsUsersDto);
|
|
80
|
-
jest.spyOn(port, "request");
|
|
81
|
-
|
|
82
|
-
const result = await service.getGroupsUsersByGroupId(groupDto.id);
|
|
83
|
-
|
|
84
|
-
expect(port.request).toHaveBeenCalledTimes(1);
|
|
85
|
-
expect(port.request).toHaveBeenCalledWith(GROUPS_USERS_GET_BY_GROUP_ID, groupDto.id);
|
|
86
|
-
expect(result).toBeInstanceOf(GroupsUsersCollection);
|
|
87
|
-
expect(result.toDto()).toStrictEqual(groupsUsersDto);
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
76
|
});
|