passbolt-browser-extension 5.2.0 → 5.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/CHANGELOG.md +79 -1
  2. package/Gruntfile.js +1 -1
  3. package/RELEASE_NOTES.md +27 -71
  4. package/doc/browser-extension-class-diagram.md +9 -0
  5. package/package.json +5 -5
  6. package/src/all/_locales/sl/messages.json +2 -2
  7. package/src/all/background_page/controller/clipboard/cancelClipboardContentFlushController.js +51 -0
  8. package/src/all/background_page/controller/clipboard/cancelClipboardContentFlushController.test.js +46 -0
  9. package/src/all/background_page/controller/clipboard/copyTemporarilyToClipboardController.js +53 -0
  10. package/src/all/background_page/controller/clipboard/copyTemporarilyToClipboardController.test.js +47 -0
  11. package/src/all/background_page/controller/clipboard/{clipboardController.js → copyToClipboardController.js} +8 -8
  12. package/src/all/background_page/controller/clipboard/copyToClipboardController.test.js +47 -0
  13. package/src/all/background_page/controller/extension/getExtensionVersionController.test.js +1 -1
  14. package/src/all/background_page/controller/metadata/getOrFindMetadataKeysSettingsController.js +53 -0
  15. package/src/all/background_page/controller/metadata/getOrFindMetadataKeysSettingsController.test.js +106 -0
  16. package/src/all/background_page/controller/resource/updateResourceLocalStorageByFolderParentIdController.js +70 -0
  17. package/src/all/background_page/controller/resource/updateResourceLocalStorageByFolderParentIdController.test.js +78 -0
  18. package/src/all/background_page/controller/share/shareOneFolderController.test.js +2 -1
  19. package/src/all/background_page/controller/share/shareResourcesController.test.js +1 -1
  20. package/src/all/background_page/controller/user/deleteDryRunUserController.js +73 -0
  21. package/src/all/background_page/controller/user/deleteDryRunUserController.test.js +129 -0
  22. package/src/all/background_page/controller/user/deleteUserController.js +76 -0
  23. package/src/all/background_page/controller/user/deleteUserController.test.js +141 -0
  24. package/src/all/background_page/event/actionLogEvents.js +5 -12
  25. package/src/all/background_page/event/appEvents.js +33 -0
  26. package/src/all/background_page/event/findAllForActionLogController.js +58 -0
  27. package/src/all/background_page/event/findAllForActionLogController.test.js +43 -0
  28. package/src/all/background_page/event/quickAccessEvents.js +32 -0
  29. package/src/all/background_page/event/resourceEvents.js +11 -0
  30. package/src/all/background_page/event/userEvents.js +7 -20
  31. package/src/all/background_page/event/webIntegrationEvents.js +11 -0
  32. package/src/all/background_page/model/actionLog/{actionLogModel.js → findActionLogService.js} +25 -5
  33. package/src/all/background_page/model/actionLog/findActionLogService.test.js +61 -0
  34. package/src/all/background_page/model/comment/commentModel.js +5 -5
  35. package/src/all/background_page/model/entity/actionLog/actionLogsCollection.test.data.js +18 -0
  36. package/src/all/background_page/model/entity/actionLog/defaultActionLogEntity.test.data.js +34 -0
  37. package/src/all/background_page/model/entity/resource/resourcesCollection.js +25 -0
  38. package/src/all/background_page/model/entity/resource/resourcesCollection.test.js +34 -0
  39. package/src/all/background_page/model/import/resources/resourcesKdbxImportParser.test.js +0 -1
  40. package/src/all/background_page/model/user/userModel.js +0 -60
  41. package/src/all/background_page/pagemod/appPagemod.js +0 -2
  42. package/src/all/background_page/pagemod/appPagemod.test.js +2 -6
  43. package/src/all/background_page/service/alarm/globalAlarmService.js +2 -0
  44. package/src/all/background_page/service/api/actionLog/{actionLogService.js → actionLogApiService.js} +5 -4
  45. package/src/all/background_page/service/api/actionLog/actionLogApiService.test.js +55 -0
  46. package/src/all/background_page/service/api/comment/{commentService.js → commentApiService.js} +6 -7
  47. package/src/all/background_page/service/api/comment/commentApiService.test.js +122 -0
  48. package/src/all/background_page/service/api/resource/resourceService.js +1 -0
  49. package/src/all/background_page/service/auth/postLogoutService.js +2 -0
  50. package/src/all/background_page/service/auth/postLogoutService.test.js +4 -1
  51. package/src/all/background_page/service/browser/browserService.js +22 -0
  52. package/src/all/background_page/service/clipboard/clipboardProviderService.js +40 -0
  53. package/src/all/background_page/service/clipboard/clipboardProviderService.test.js +61 -0
  54. package/src/all/background_page/service/clipboard/copyToClipboardService.js +123 -0
  55. package/src/all/background_page/service/clipboard/copyToClipboardService.test.js +174 -0
  56. package/src/all/background_page/service/resource/findAndUpdateResourcesLocalStorageService.js +52 -1
  57. package/src/all/background_page/service/resource/findAndUpdateResourcesLocalStorageService.test.js +100 -0
  58. package/src/all/background_page/service/resource/findResourcesService.js +53 -19
  59. package/src/all/background_page/service/resource/findResourcesService.test.js +191 -0
  60. package/src/all/background_page/service/resourceType/updateResourceTypesService.test.js +1 -1
  61. package/src/all/background_page/service/share/shareResourceService.test.js +1 -1
  62. package/src/all/background_page/service/user/deleteUserService.js +97 -0
  63. package/src/all/background_page/service/user/deleteUserService.test.js +178 -0
  64. package/src/all/locales/de-DE/common.json +2 -2
  65. package/src/all/locales/es-ES/common.json +2 -2
  66. package/src/all/locales/fr-FR/common.json +5 -5
  67. package/src/all/locales/it-IT/common.json +2 -2
  68. package/src/all/locales/ja-JP/common.json +2 -2
  69. package/src/all/locales/ko-KR/common.json +2 -2
  70. package/src/all/locales/lt-LT/common.json +2 -2
  71. package/src/all/locales/nl-NL/common.json +2 -2
  72. package/src/all/locales/pl-PL/common.json +5 -5
  73. package/src/all/locales/pt-BR/common.json +2 -2
  74. package/src/all/locales/ro-RO/common.json +2 -2
  75. package/src/all/locales/ru-RU/common.json +2 -2
  76. package/src/all/locales/sl-SI/common.json +33 -33
  77. package/src/all/locales/sv-SE/common.json +2 -2
  78. package/src/all/locales/uk-UA/common.json +3 -3
  79. package/src/chrome/manifest.json +1 -1
  80. package/src/chrome/polyfill/clipboard/edgeBackgroundPageClipboardService.js +31 -0
  81. package/src/chrome/polyfill/clipboard/edgeBackgroundPageClipboardService.test.js +51 -0
  82. package/src/chrome-mv3/index.js +3 -3
  83. package/src/chrome-mv3/manifest.json +1 -1
  84. package/src/chrome-mv3/offscreens/{fetch.html → offscreen.html} +1 -1
  85. package/src/chrome-mv3/offscreens/{fetch.js → offscreen.js} +2 -2
  86. package/src/chrome-mv3/offscreens/service/clipboard/writeClipobardOffscreenService.js +54 -0
  87. package/src/chrome-mv3/offscreens/service/clipboard/writeClipobardOffscreenService.test.js +56 -0
  88. package/src/chrome-mv3/offscreens/service/network/fetchOffscreenService.js +36 -44
  89. package/src/chrome-mv3/offscreens/service/network/fetchOffscreenService.test.data.js +0 -1
  90. package/src/chrome-mv3/offscreens/service/network/fetchOffscreenService.test.js +90 -120
  91. package/src/chrome-mv3/offscreens/service/offscreen/handleOffscreenRequestService.js +85 -0
  92. package/src/chrome-mv3/offscreens/service/offscreen/handleOffscreenRequestService.test.js +99 -0
  93. package/src/chrome-mv3/polyfill/clipboardOffscreenPolyfill.js +19 -0
  94. package/src/chrome-mv3/serviceWorker/service/clipboard/requestClipboardOffscreenService.js +51 -0
  95. package/src/chrome-mv3/serviceWorker/service/clipboard/requestClipboardOffscreenService.test.js +70 -0
  96. package/src/chrome-mv3/serviceWorker/service/clipboard/responseClipboardOffscreenService.js +25 -0
  97. package/src/chrome-mv3/serviceWorker/service/clipboard/responseClipboardOffscreenService.test.data.js +21 -0
  98. package/src/chrome-mv3/serviceWorker/service/clipboard/responseClipboardOffscreenService.test.js +33 -0
  99. package/src/chrome-mv3/serviceWorker/service/network/requestFetchOffscreenService.js +25 -50
  100. package/src/chrome-mv3/serviceWorker/service/network/requestFetchOffscreenService.test.js +16 -39
  101. package/src/chrome-mv3/serviceWorker/service/network/responseFetchOffscreenService.js +14 -45
  102. package/src/chrome-mv3/serviceWorker/service/network/responseFetchOffscreenService.test.js +5 -37
  103. package/src/chrome-mv3/serviceWorker/service/offscreen/createOffscreenDocumentService.js +43 -0
  104. package/src/chrome-mv3/serviceWorker/service/offscreen/createOffscreenDocumentService.test.js +48 -0
  105. package/src/chrome-mv3/serviceWorker/service/offscreen/handleOffscreenResponseService.js +119 -0
  106. package/src/chrome-mv3/serviceWorker/service/offscreen/handleOffscreenResponseService.test.js +159 -0
  107. package/src/firefox/manifest.json +1 -1
  108. package/src/safari/manifest.json +1 -1
  109. package/test/jest.setup.js +4 -0
  110. package/test/mocks/mockNavigatorClipboard.js +40 -0
  111. package/test/mocks/mockWebExtensionPolyfill.js +2 -1
  112. package/{webpack-offscreens.fetch.config.js → webpack-offscreens.config.js} +1 -1
  113. package/webpack.service-worker.config.js +1 -0
  114. package/src/all/background_page/controller/clipboard/clipboardController.test.js +0 -68
  115. package/src/all/background_page/event/clipboardEvents.js +0 -28
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Passbolt ~ Open source password manager for teams
3
+ * Copyright (c) Passbolt SA (https://www.passbolt.com)
4
+ *
5
+ * Licensed under GNU Affero General Public License version 3 of the or any later version.
6
+ * For full copyright and license information, please see the LICENSE.txt
7
+ * Redistributions of files must retain the above copyright notice.
8
+ *
9
+ * @copyright Copyright (c) Passbolt SA (https://www.passbolt.com)
10
+ * @license https://opensource.org/licenses/AGPL-3.0 AGPL License
11
+ * @link https://www.passbolt.com Passbolt(tm)
12
+ * @since 5.4.0
13
+ */
14
+
15
+ import {enableFetchMocks} from "jest-fetch-mock";
16
+ import {mockApiResponse, mockApiResponseError} from "../../../../../test/mocks/mockApiResponse";
17
+ import {defaultApiClientOptions} from "passbolt-styleguide/src/shared/lib/apiClient/apiClientOptions.test.data";
18
+ import RoleEntity from "passbolt-styleguide/src/shared/models/entity/role/roleEntity";
19
+ import AccountEntity from "../../model/entity/account/accountEntity";
20
+ import {defaultAccountDto} from "../../model/entity/account/accountEntity.test.data";
21
+ import {defaultSharedResourcesWithEncryptedMetadataDtos, defaultResourcesDtos} from "passbolt-styleguide/src/shared/models/entity/resource/resourcesCollection.test.data";
22
+ import {defaultDecryptedSharedMetadataKeysDtos} from "passbolt-styleguide/src/shared/models/entity/metadata/metadataKeysCollection.test.data";
23
+ import PassboltApiFetchError from "passbolt-styleguide/src/shared/lib/Error/PassboltApiFetchError";
24
+ import {v4 as uuidv4} from "uuid";
25
+ import DeleteDryRunError from "../../error/deleteDryRunError";
26
+ import {pgpKeys} from 'passbolt-styleguide/test/fixture/pgpKeys/keys';
27
+ import MetadataKeysCollection from "passbolt-styleguide/src/shared/models/entity/metadata/metadataKeysCollection";
28
+ import {defaultUserDto} from "passbolt-styleguide/src/shared/models/entity/user/userEntity.test.data";
29
+ import DeleteUserController from "./deleteUserController";
30
+ import UserLocalStorage from "../../service/local_storage/userLocalStorage";
31
+ import UsersCollection from "../../model/entity/user/usersCollection";
32
+
33
+ beforeEach(() => {
34
+ enableFetchMocks();
35
+ });
36
+
37
+ describe("DeleteUserController", () => {
38
+ describe("::exec", () => {
39
+ const accountDto = defaultAccountDto();
40
+ accountDto.role_name = RoleEntity.ROLE_ADMIN;
41
+ const account = new AccountEntity(accountDto);
42
+
43
+ it("Should delete the user without transfer", async() => {
44
+ expect.assertions(2);
45
+
46
+ const userDto = defaultUserDto();
47
+ await UserLocalStorage.set(new UsersCollection([userDto]));
48
+
49
+ fetch.doMockOnceIf(new RegExp(`/users/${userDto.id}.json`), () => mockApiResponse({}));
50
+
51
+ const controller = new DeleteUserController(null, null, defaultApiClientOptions(), account);
52
+ jest.spyOn(controller.deleteUserService, "delete");
53
+ jest.spyOn(UserLocalStorage, "delete");
54
+
55
+ await controller.exec(userDto.id);
56
+
57
+ expect(controller.deleteUserService.delete).toHaveBeenCalledWith(userDto.id, null);
58
+ expect(UserLocalStorage.delete).toHaveBeenCalledWith(userDto.id);
59
+ });
60
+
61
+ it("Should throw an error if the user has transfer and decrypt", async() => {
62
+ expect.assertions(3);
63
+
64
+ const userDto = defaultUserDto();
65
+ await UserLocalStorage.set(new UsersCollection([userDto]));
66
+ const metadataKeysDtos = defaultDecryptedSharedMetadataKeysDtos();
67
+ const metadataKeys = new MetadataKeysCollection(metadataKeysDtos);
68
+ const collectionDto = defaultSharedResourcesWithEncryptedMetadataDtos(10, {
69
+ metadata_key_id: metadataKeysDtos[0].id
70
+ });
71
+ const body = {
72
+ errors: {
73
+ resources: {
74
+ sole_owner: collectionDto
75
+ }
76
+ }
77
+ };
78
+
79
+ fetch.doMockOnceIf(new RegExp(`/users/${userDto.id}.json`), () => mockApiResponseError(400, "Need transfer", body));
80
+
81
+ const controller = new DeleteUserController(null, null, defaultApiClientOptions(), account);
82
+ jest.spyOn(controller.decryptMetadataService.getOrFindMetadataKeysService, "getOrFindAll").mockImplementation(() => metadataKeys);
83
+ jest.spyOn(controller.getPassphraseService, "getPassphrase").mockImplementationOnce(() => pgpKeys.ada.passphrase);
84
+ jest.spyOn(UserLocalStorage, "delete");
85
+
86
+ try {
87
+ await controller.exec(userDto.id);
88
+ } catch (error) {
89
+ expect(error).toBeInstanceOf(DeleteDryRunError);
90
+ expect(error.errors.resources.sole_owner.items.every(resourceEntity => resourceEntity.isMetadataDecrypted())).toBeTruthy();
91
+ expect(UserLocalStorage.delete).not.toHaveBeenCalledWith(userDto.id);
92
+ }
93
+ });
94
+
95
+ it("Should throw an error if the user has transfer without decryption", async() => {
96
+ expect.assertions(5);
97
+
98
+ const userDto = defaultUserDto();
99
+ await UserLocalStorage.set(new UsersCollection([userDto]));
100
+ const collectionDto = defaultResourcesDtos();
101
+ const body = {
102
+ errors: {
103
+ resources: {
104
+ sole_owner: collectionDto
105
+ }
106
+ }
107
+ };
108
+
109
+ fetch.doMockOnceIf(new RegExp(`/users/${userDto.id}.json`), () => mockApiResponseError(400, "Need transfer", body));
110
+
111
+ const controller = new DeleteUserController(null, null, defaultApiClientOptions(), account);
112
+ jest.spyOn(controller.decryptMetadataService.getOrFindMetadataKeysService, "getOrFindAll");
113
+ jest.spyOn(controller.getPassphraseService, "getPassphrase");
114
+ jest.spyOn(UserLocalStorage, "delete");
115
+
116
+ try {
117
+ await controller.exec(userDto.id);
118
+ } catch (error) {
119
+ expect(error).toBeInstanceOf(DeleteDryRunError);
120
+ expect(error.errors.resources.sole_owner.items.every(resourceEntity => resourceEntity.isMetadataDecrypted())).toBeTruthy();
121
+ expect(controller.decryptMetadataService.getOrFindMetadataKeysService.getOrFindAll).not.toHaveBeenCalled();
122
+ expect(controller.getPassphraseService.getPassphrase).not.toHaveBeenCalled();
123
+ expect(UserLocalStorage.delete).not.toHaveBeenCalledWith(userDto.id);
124
+ }
125
+ });
126
+
127
+ it("Should throw an error if something wrong happens on the API", async() => {
128
+ expect.assertions(1);
129
+
130
+ const userId = uuidv4();
131
+ fetch.doMockOnceIf(new RegExp(`/users/${userId}.json`), async() => mockApiResponseError(500, "Something went wrong"));
132
+
133
+ const controller = new DeleteUserController(null, null, defaultApiClientOptions(), account);
134
+ try {
135
+ await controller.exec(userId);
136
+ } catch (e) {
137
+ expect(e).toBeInstanceOf(PassboltApiFetchError);
138
+ }
139
+ });
140
+ });
141
+ });
@@ -10,14 +10,14 @@
10
10
  * @license https://opensource.org/licenses/AGPL-3.0 AGPL License
11
11
  * @link https://www.passbolt.com Passbolt(tm)
12
12
  */
13
- import ActionLogModel from "../model/actionLog/actionLogModel";
13
+ import FindAllForActionLogController from "./findAllForActionLogController";
14
14
 
15
15
  /**
16
16
  * Listens to the action logs events
17
17
  * @param {Worker} worker The worker
18
18
  * @param {ApiClientOptions} apiClientOptions The api client options
19
19
  */
20
- const listen = function(worker, apiClientOptions) {
20
+ const listen = function(worker, apiClientOptions, account) {
21
21
  /*
22
22
  * Find all action logs for a given instance
23
23
  *
@@ -25,16 +25,9 @@ const listen = function(worker, apiClientOptions) {
25
25
  * @param requestId {uuid} The request identifier
26
26
  * @param options {object} The options to apply to the find
27
27
  */
28
- worker.port.on('passbolt.actionlogs.find-all-for', async(requestId, foreignModel, foreignId, options) => {
29
- try {
30
- const actionLogModel = new ActionLogModel(apiClientOptions);
31
- const {limit, page} = options;
32
- const actionLogs = await actionLogModel.findAllFor(foreignModel, foreignId, page, limit);
33
- worker.port.emit(requestId, 'SUCCESS', actionLogs);
34
- } catch (error) {
35
- console.error(error);
36
- worker.port.emit(requestId, 'ERROR', error);
37
- }
28
+ worker.port.on('passbolt.actionlogs.find-all-for', async(requestId, foreignModel, foreignId, {page, limit}) => {
29
+ const controller = new FindAllForActionLogController(worker, requestId, apiClientOptions, account);
30
+ await controller._exec(foreignModel, foreignId, {page, limit});
38
31
  });
39
32
  };
40
33
 
@@ -67,6 +67,8 @@ import FindMetadataMigrateResourcesController from "../controller/migrateMetadat
67
67
  import MigrateMetadataResourcesController from "../controller/migrateMetadata/migrateMetadataResourcesController";
68
68
  import DownloadOrganizationGeneratedKey from "../controller/accountRecovery/downloadOrganizationGenerateKeyController";
69
69
  import ShareMetadataKeyPrivateController from "../controller/metadata/shareMetadataKeyPrivateController";
70
+ import CopyToClipboardController from "../controller/clipboard/copyToClipboardController";
71
+ import CopyTemporarilyToClipboardController from "../controller/clipboard/copyTemporarilyToClipboardController";
70
72
 
71
73
  const listen = function(worker, apiClientOptions, account) {
72
74
  /*
@@ -433,5 +435,36 @@ const listen = function(worker, apiClientOptions, account) {
433
435
  const controller = new ShareMetadataKeyPrivateController(worker, requestId, apiClientOptions, account);
434
436
  await controller._exec(userId);
435
437
  });
438
+
439
+
440
+ /*
441
+ * ==================================================================================
442
+ * Clipboard events.
443
+ * ==================================================================================
444
+ */
445
+
446
+ /**
447
+ * Copies the given content into the clipboard and clear any clipboard flush alarms.
448
+ *
449
+ * @listens assbolt.clipboard.copy
450
+ * @param {string} requestId The request identifier
451
+ * @param {string} text the content to copy
452
+ */
453
+ worker.port.on('passbolt.clipboard.copy', async(requestId, text) => {
454
+ const clipboardController = new CopyToClipboardController(worker, requestId);
455
+ await clipboardController._exec(text);
456
+ });
457
+
458
+ /**
459
+ * Copies temporarily the given content into the clipboard and set a clipboard flush alarm.
460
+ *
461
+ * @listens assbolt.clipboard.copy-temporarily
462
+ * @param {string} requestId The request identifier
463
+ * @param {string} text the content to copy
464
+ */
465
+ worker.port.on('passbolt.clipboard.copy-temporarily', async(requestId, text) => {
466
+ const clipboardController = new CopyTemporarilyToClipboardController(worker, requestId);
467
+ await clipboardController._exec(text);
468
+ });
436
469
  };
437
470
  export const AppEvents = {listen};
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Passbolt ~ Open source password manager for teams
3
+ * Copyright (c) Passbolt SA (https://www.passbolt.com)
4
+ *
5
+ * Licensed under GNU Affero General Public License version 3 of the or any later version.
6
+ * For full copyright and license information, please see the LICENSE.txt
7
+ * Redistributions of files must retain the above copyright notice.
8
+ *
9
+ * @copyright Copyright (c) Passbolt SA (https://www.passbolt.com)
10
+ * @license https://opensource.org/licenses/AGPL-3.0 AGPL License
11
+ * @link https://www.passbolt.com Passbolt(tm)
12
+ * @since 5.4.0
13
+ */
14
+ import FindActionLogService from "../model/actionLog/findActionLogService";
15
+
16
+ class FindAllForActionLogController {
17
+ /**
18
+ * @constructor
19
+ * @param {Worker} worker The worker
20
+ * @param {string} requestId uuid
21
+ * @param {ApiClientOptions} apiClientOptions The api client options
22
+ * @param {AccountEntity} account the user account
23
+ */
24
+ constructor(worker, requestId, apiClientOptions, account) {
25
+ this.worker = worker;
26
+ this.requestId = requestId;
27
+ this.findAllForActionLogService = new FindActionLogService(apiClientOptions, account);
28
+ }
29
+
30
+ /**
31
+ * Controller executor.
32
+ * @param {string} foreignModel The foreign model
33
+ * @param {string} foreignId The foreign ID
34
+ * @param {object} options Options
35
+ * @param {number} options.page The page number
36
+ * @param {number} options.limit The limit of activities per page
37
+ * @returns {Promise<void>}
38
+ */
39
+ async _exec(foreignModel, foreignId, {page, limit}) {
40
+ try {
41
+ const result = await this.exec(foreignModel, foreignId, {page, limit});
42
+ this.worker.port.emit(this.requestId, 'SUCCESS', result);
43
+ } catch (error) {
44
+ console.error(error);
45
+ this.worker.port.emit(this.requestId, 'ERROR', error);
46
+ }
47
+ }
48
+
49
+ /**
50
+ * Find all action logs
51
+ * @returns {Promise<*>}
52
+ */
53
+ async exec(foreignModel, foreignId, {page, limit}) {
54
+ return this.findAllForActionLogService.findAllFor(foreignModel, foreignId, page, limit);
55
+ }
56
+ }
57
+
58
+ export default FindAllForActionLogController;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Passbolt ~ Open source password manager for teams
3
+ * Copyright (c) Passbolt SA (https://www.passbolt.com)
4
+ *
5
+ * Licensed under GNU Affero General Public License version 3 of the or any later version.
6
+ * For full copyright and license information, please see the LICENSE.txt
7
+ * Redistributions of files must retain the above copyright notice.
8
+ *
9
+ * @copyright Copyright (c) Passbolt SA (https://www.passbolt.com)
10
+ * @license https://opensource.org/licenses/AGPL-3.0 AGPL License
11
+ * @link https://www.passbolt.com Passbolt(tm)
12
+ * @since 5.4.0
13
+ */
14
+ import AccountEntity from "../model/entity/account/accountEntity";
15
+ import {defaultAccountDto} from "../model/entity/account/accountEntity.test.data";
16
+ import {defaultApiClientOptions} from "passbolt-styleguide/src/shared/lib/apiClient/apiClientOptions.test.data";
17
+ import FindAllForActionLogController from "./findAllForActionLogController";
18
+ import {defaultActionLogsCollection} from "../model/entity/actionLog/actionLogsCollection.test.data";
19
+ import ActionLogsCollection from "../model/entity/actionLog/actionLogsCollection";
20
+ import {v4 as uuid} from "uuid";
21
+
22
+ describe("FindAllForActionLogController", () => {
23
+ let controller, account, apiClientOptions;
24
+
25
+ beforeEach(async() => {
26
+ account = new AccountEntity(defaultAccountDto());
27
+ apiClientOptions = defaultApiClientOptions();
28
+ controller = new FindAllForActionLogController(null, null, apiClientOptions, account);
29
+ });
30
+
31
+ describe("FindAllForActionLogController::exec", () => {
32
+ it("Find all action logs for the resource", async() => {
33
+ expect.assertions(2);
34
+
35
+ const actionLogsDto = defaultActionLogsCollection;
36
+ jest.spyOn(controller.findAllForActionLogService, "findAllFor").mockImplementationOnce(() => new ActionLogsCollection(actionLogsDto));
37
+
38
+ const actionLogsCollection = await controller.exec("Resource", uuid(), {page: 1, limit: 5});
39
+ expect(actionLogsCollection).toBeInstanceOf(ActionLogsCollection);
40
+ expect(actionLogsCollection.toDto()).toEqual(actionLogsDto);
41
+ });
42
+ });
43
+ });
@@ -13,6 +13,8 @@ import GetOrFindPasswordPoliciesController from "../controller/passwordPolicies/
13
13
  import AutofillController from "../controller/autofill/AutofillController";
14
14
  import GetOrFindPasswordExpirySettingsController from "../controller/passwordExpiry/getOrFindPasswordExpirySettingsController";
15
15
  import GetOrFindMetadataTypesController from "../controller/metadata/getMetadataTypesSettingsController";
16
+ import CopyToClipboardController from "../controller/clipboard/copyToClipboardController";
17
+ import CopyTemporarilyToClipboardController from "../controller/clipboard/copyTemporarilyToClipboardController";
16
18
 
17
19
  /**
18
20
  * Listens to the quickaccess application events
@@ -158,6 +160,36 @@ const listen = function(worker, apiClientOptions, account) {
158
160
  const controller = new GetOrFindMetadataTypesController(worker, requestId, apiClientOptions, account);
159
161
  await controller._exec();
160
162
  });
163
+
164
+ /*
165
+ * ==================================================================================
166
+ * Clipboard events.
167
+ * ==================================================================================
168
+ */
169
+
170
+ /**
171
+ * Copies the given content into the clipboard and clear any clipboard flush alarms.
172
+ *
173
+ * @listens assbolt.clipboard.copy
174
+ * @param {string} requestId The request identifier
175
+ * @param {string} text the content to copy
176
+ */
177
+ worker.port.on('passbolt.clipboard.copy', async(requestId, text) => {
178
+ const clipboardController = new CopyToClipboardController(worker, requestId);
179
+ await clipboardController._exec(text);
180
+ });
181
+
182
+ /**
183
+ * Copies temporarily the given content into the clipboard and set a clipboard flush alarm.
184
+ *
185
+ * @listens assbolt.clipboard.copy-temporarily
186
+ * @param {string} requestId The request identifier
187
+ * @param {string} text the content to copy
188
+ */
189
+ worker.port.on('passbolt.clipboard.copy-temporarily', async(requestId, text) => {
190
+ const clipboardController = new CopyTemporarilyToClipboardController(worker, requestId);
191
+ await clipboardController._exec(text);
192
+ });
161
193
  };
162
194
 
163
195
  export const QuickAccessEvents = {listen};
@@ -22,6 +22,7 @@ import FindAllByIdsForDisplayPermissionsController
22
22
  import MoveResourcesController from "../controller/move/moveResourcesController";
23
23
  import ResetResourceGridUserSettingController
24
24
  from "../controller/resourceGridSetting/resetResourceGridUserSettingController";
25
+ import UpdateResourceLocalStorageByFolderParentIdController from "../controller/resource/updateResourceLocalStorageByFolderParentIdController";
25
26
 
26
27
  const listen = function(worker, apiClientOptions, account) {
27
28
  /*
@@ -173,6 +174,16 @@ const listen = function(worker, apiClientOptions, account) {
173
174
  const controller = new MoveResourcesController(worker, requestId, apiClientOptions, account);
174
175
  await controller._exec(resourcesIds, destinationFolderId);
175
176
  });
177
+
178
+ /*
179
+ * Update the local storage for resources in the specified parent folder.
180
+ * @listens passbolt.resources.update-local-storage-by-folder-parent-id
181
+ * @param {string} parentFolderId The id of the parent folder.
182
+ */
183
+ worker.port.on('passbolt.resources.update-local-storage-by-folder-parent-id', async(requestId, parentFolderId) => {
184
+ const controller = new UpdateResourceLocalStorageByFolderParentIdController(worker, requestId, apiClientOptions, account);
185
+ await controller._exec(parentFolderId);
186
+ });
176
187
  };
177
188
 
178
189
  export const ResourceEvents = {listen};
@@ -9,13 +9,14 @@
9
9
  import UserModel from "../model/user/userModel";
10
10
  import AccountModel from "../model/account/accountModel";
11
11
  import UpdatePrivateKeyController from "../controller/account/updatePrivateKeyController";
12
- import UserDeleteTransferEntity from "../model/entity/user/transfer/userDeleteTransferEntity";
13
12
  import UserEntity from "../model/entity/user/userEntity";
14
13
  import SecurityTokenEntity from "../model/entity/securityToken/securityTokenEntity";
15
14
  import AvatarUpdateEntity from "../model/entity/avatar/update/avatarUpdateEntity";
16
15
  import UpdateUserLocalStorageController from "../controller/user/updateUserLocalStorageController";
17
16
  import GetOrFindLoggedInUserController from "../controller/user/getOrFindLoggedInUserController";
18
17
  import UpdateUserController from "../controller/user/updateUserController";
18
+ import DeleteDryRunUserController from "../controller/user/deleteDryRunUserController";
19
+ import DeleteUserController from "../controller/user/deleteUserController";
19
20
 
20
21
  /**
21
22
  * Listens the user events
@@ -154,16 +155,9 @@ const listen = function(worker, apiClientOptions, account) {
154
155
  * @param {string} requestId The request identifier uuid
155
156
  * @param {string} userId The user uuid
156
157
  */
157
- worker.port.on('passbolt.users.delete-dry-run', async(requestId, userId, transferDto) => {
158
- try {
159
- const userModel = new UserModel(apiClientOptions, account);
160
- const transferEntity = transferDto ? new UserDeleteTransferEntity(transferDto) : null;
161
- await userModel.deleteDryRun(userId, transferEntity);
162
- worker.port.emit(requestId, 'SUCCESS');
163
- } catch (error) {
164
- console.error(error);
165
- worker.port.emit(requestId, 'ERROR', error);
166
- }
158
+ worker.port.on('passbolt.users.delete-dry-run', async(requestId, userId) => {
159
+ const controller = new DeleteDryRunUserController(worker, requestId, apiClientOptions, account);
160
+ await controller._exec(userId);
167
161
  });
168
162
 
169
163
  /*
@@ -174,15 +168,8 @@ const listen = function(worker, apiClientOptions, account) {
174
168
  * @param {object} [transferDto] optional data ownership transfer
175
169
  */
176
170
  worker.port.on('passbolt.users.delete', async(requestId, userId, transferDto) => {
177
- try {
178
- const userModel = new UserModel(apiClientOptions, account);
179
- const transferEntity = transferDto ? new UserDeleteTransferEntity(transferDto) : null;
180
- await userModel.delete(userId, transferEntity);
181
- worker.port.emit(requestId, 'SUCCESS');
182
- } catch (error) {
183
- console.error(error);
184
- worker.port.emit(requestId, 'ERROR', error);
185
- }
171
+ const controller = new DeleteUserController(worker, requestId, apiClientOptions, account);
172
+ await controller._exec(userId, transferDto);
186
173
  });
187
174
 
188
175
  /*
@@ -12,6 +12,7 @@
12
12
  */
13
13
  import WebIntegrationController from "../controller/webIntegration/webIntegrationController";
14
14
  import RemovePortController from "../controller/port/removePortController";
15
+ import CancelClipboardContentFlushController from "../controller/clipboard/cancelClipboardContentFlushController";
15
16
 
16
17
  /**
17
18
  * Listens the web integration events
@@ -33,6 +34,16 @@ const listen = function(worker) {
33
34
  const removePortController = new RemovePortController(worker);
34
35
  await removePortController._exec(applicationName);
35
36
  });
37
+
38
+ /*
39
+ * Whenever a cut or a copy event happens on a web page to ensure the clipboard flush alarm is not triggered
40
+ * @listens passbolt.clipboard.cancel-content-flush
41
+ * @param requestId {uuid} The request identifier
42
+ */
43
+ worker.port.on('passbolt.clipboard.cancel-content-flush', async requestId => {
44
+ const clipboardController = new CancelClipboardContentFlushController(worker, requestId);
45
+ await clipboardController._exec();
46
+ });
36
47
  };
37
48
 
38
49
  export const WebIntegrationEvents = {listen};
@@ -11,9 +11,11 @@
11
11
  * @link https://www.passbolt.com Passbolt(tm)
12
12
  */
13
13
  import ActionLogsCollection from "../entity/actionLog/actionLogsCollection";
14
- import ActionLogService from "../../service/api/actionLog/actionLogService";
14
+ import {assertUuid, assertNonEmptyString, assertNumber} from "../../utils/assertions";
15
+ import AbstractActionLogEntity from "../entity/actionLog/abstractActionLogEntity";
16
+ import ActionLogApiService from "../../service/api/actionLog/actionLogApiService";
15
17
 
16
- class ActionLogModel {
18
+ class FindActionLogService {
17
19
  /**
18
20
  * Constructor
19
21
  *
@@ -21,7 +23,7 @@ class ActionLogModel {
21
23
  * @public
22
24
  */
23
25
  constructor(apiClientOptions) {
24
- this.actionLogService = new ActionLogService(apiClientOptions);
26
+ this.actionLogApiService = new ActionLogApiService(apiClientOptions);
25
27
  }
26
28
 
27
29
  /*
@@ -42,9 +44,27 @@ class ActionLogModel {
42
44
  * @public
43
45
  */
44
46
  async findAllFor(foreignModel, foreignId, page, limit) {
45
- const actionLogsDto = await this.actionLogService.findAllFor(foreignModel, foreignId, page, limit);
47
+ this.assertValidForeignModel(foreignModel);
48
+ assertUuid(foreignId);
49
+ assertNumber(page);
50
+ assertNumber(limit);
51
+ const actionLogsDto = await this.actionLogApiService.findAllFor(foreignModel, foreignId, page, limit);
46
52
  return new ActionLogsCollection(actionLogsDto);
47
53
  }
54
+
55
+ /**
56
+ * Assert a foreign model name is supported by the API
57
+ *
58
+ * @param {string} foreignModel for example 'Resource'
59
+ * @throw {TypeError} if the name is not a valid string or is not supported
60
+ * @public
61
+ */
62
+ assertValidForeignModel(foreignModel) {
63
+ assertNonEmptyString(foreignModel, 'ActionLog foreign model should be a valid string.');
64
+ if (!AbstractActionLogEntity.ALLOWED_FOREIGN_MODELS.includes(foreignModel)) {
65
+ throw new TypeError(`ActionLog foreign model ${foreignModel} is not in the list of supported models.`);
66
+ }
67
+ }
48
68
  }
49
69
 
50
- export default ActionLogModel;
70
+ export default FindActionLogService;
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Passbolt ~ Open source password manager for teams
3
+ * Copyright (c) Passbolt SA (https://www.passbolt.com)
4
+ *
5
+ * Licensed under GNU Affero General Public License version 3 of the or any later version.
6
+ * For full copyright and license information, please see the LICENSE.txt
7
+ * Redistributions of files must retain the above copyright notice.
8
+ *
9
+ * @copyright Copyright (c) Passbolt SA (https://www.passbolt.com)
10
+ * @license https://opensource.org/licenses/AGPL-3.0 AGPL License
11
+ * @link https://www.passbolt.com Passbolt(tm)
12
+ * @since 5.4.0
13
+ */
14
+ import BuildApiClientOptionsService from "../../service/account/buildApiClientOptionsService";
15
+ import AccountEntity from "../../model/entity/account/accountEntity";
16
+ import {defaultAccountDto} from "../../model/entity/account/accountEntity.test.data";
17
+ import {v4 as uuidv4} from "uuid";
18
+ import {enableFetchMocks} from "jest-fetch-mock";
19
+ import ActionLogApiService from "../../service/api/actionLog/actionLogApiService";
20
+ import FindActionLogService from "./findActionLogService";
21
+ import {defaultActionLogsCollection} from "../../model/entity/actionLog/actionLogsCollection.test.data";
22
+
23
+ describe("FindActionLogService", () => {
24
+ let apiClientOptions, account,
25
+ service;
26
+
27
+ beforeEach(async() => {
28
+ enableFetchMocks();
29
+ jest.clearAllMocks();
30
+ fetch.resetMocks();
31
+ account = new AccountEntity(defaultAccountDto());
32
+ apiClientOptions = BuildApiClientOptionsService.buildFromAccount(account);
33
+ service = new FindActionLogService(apiClientOptions, account);
34
+ });
35
+
36
+ describe('::findAllFor', () => {
37
+ it("Should call the actionLog service API to get the acitonlog collection", async() => {
38
+ expect.assertions(1);
39
+ const foreignId = uuidv4();
40
+ const actionLogsDto = defaultActionLogsCollection;
41
+
42
+ jest.spyOn(ActionLogApiService.prototype, "findAllFor").mockImplementation(() => actionLogsDto);
43
+
44
+ const actionLogs = await service.findAllFor("Resource", foreignId, 1, 5);
45
+ expect(actionLogs).toHaveLength(actionLogsDto.length);
46
+ });
47
+
48
+ it("should throw an error if id is not defined", async() => {
49
+ expect.assertions(1);
50
+ const promise = service.findAllFor({unknown: true});
51
+ await expect(promise).rejects.toThrowError("ActionLog foreign model should be a valid string.");
52
+ });
53
+
54
+ it("should throw an error if foreign model is unsupported", async() => {
55
+ expect.assertions(1);
56
+ const foreignId = uuidv4();
57
+ const promise = service.findAllFor("ChangeTheme", foreignId, 1, 5);
58
+ await expect(promise).rejects.toThrowError("ActionLog foreign model ChangeTheme is not in the list of supported models.");
59
+ });
60
+ });
61
+ });
@@ -13,7 +13,7 @@
13
13
  */
14
14
  import CommentEntity from "../entity/comment/commentEntity";
15
15
  import CommentsCollection from "../entity/comment/commentsCollection";
16
- import CommentService from "../../service/api/comment/commentService";
16
+ import CommentApiService from "../../service/api/comment/commentApiService";
17
17
 
18
18
  class CommentModel {
19
19
  /**
@@ -23,7 +23,7 @@ class CommentModel {
23
23
  * @public
24
24
  */
25
25
  constructor(apiClientOptions) {
26
- this.commentService = new CommentService(apiClientOptions);
26
+ this.commentApiService = new CommentApiService(apiClientOptions);
27
27
  }
28
28
 
29
29
  /**
@@ -35,7 +35,7 @@ class CommentModel {
35
35
  */
36
36
  async findAllByResourceId(resourceId) {
37
37
  const foreignKey = 'Resource';
38
- const commentsDtos = await this.commentService.findAll(foreignKey, resourceId, {creator: true, modifier: false});
38
+ const commentsDtos = await this.commentApiService.findAll(foreignKey, resourceId, {creator: true, modifier: false});
39
39
  return new CommentsCollection(commentsDtos);
40
40
  }
41
41
 
@@ -46,7 +46,7 @@ class CommentModel {
46
46
  * @returns {Promise<CommentEntity>}
47
47
  */
48
48
  async create(commentEntity) {
49
- const commentDto = await this.commentService.create(commentEntity.toDto({creator: false, modifier: false}));
49
+ const commentDto = await this.commentApiService.create(commentEntity.toDto({creator: false, modifier: false}));
50
50
  return new CommentEntity(commentDto);
51
51
  }
52
52
 
@@ -57,7 +57,7 @@ class CommentModel {
57
57
  * @returns {Promise<void>}
58
58
  */
59
59
  async delete(commentId) {
60
- await this.commentService.delete(commentId);
60
+ await this.commentApiService.delete(commentId);
61
61
  }
62
62
  }
63
63
 
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Passbolt ~ Open source password manager for teams
3
+ * Copyright (c) Passbolt SA (https://www.passbolt.com)
4
+ *
5
+ * Licensed under GNU Affero General Public License version 3 of the or any later version.
6
+ * For full copyright and license information, please see the LICENSE.txt
7
+ * Redistributions of files must retain the above copyright notice.
8
+ *
9
+ * @copyright Copyright (c) Passbolt SA (https://www.passbolt.com)
10
+ * @license https://opensource.org/licenses/AGPL-3.0 AGPL License
11
+ * @link https://www.passbolt.com Passbolt(tm)
12
+ * @since 5.4.0
13
+ */
14
+ import {defaultData} from "./defaultActionLogEntity.test.data";
15
+
16
+ export const defaultActionLogsCollection = [
17
+ defaultData
18
+ ];