Skip to content

Commit

Permalink
PB-33327 - Switch ResourcesCollection to EntityV2Collection
Browse files Browse the repository at this point in the history
Signed-off-by: Cedric Alfonsi <cedric@passbolt.com>
  • Loading branch information
cedricalfonsi committed May 11, 2024
1 parent a86ac38 commit 32a9f4c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 19 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "passbolt-styleguide",
"version": "4.8.0-alpha.7",
"version": "4.8.0-alpha.8",
"license": "AGPL-3.0",
"copyright": "Copyright 2023 Passbolt SA",
"description": "Passbolt styleguide contains common styling assets used by the different sites, plugin, etc.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ import {defaultPermissionDto} from "./permissionEntity.test.data";
/**
* Build dtos.
* @param {number} [count=10] The number of dtos.
* @param {object} data The data to override the default dto.
* @param {object} options Options to pass to the permission factory.
* @returns {object}
*/
export const defaultPermissionsDtos = (count = 10) => {
export const defaultPermissionsDtos = (count = 10, data = {}, options = {}) => {
const dtos = [];
const acoForeignKey = crypto.randomUUID();
for (let i = 0; i < count; i++) {
const groupDto = defaultPermissionDto({aco_foreign_key: acoForeignKey});
dtos.push(groupDto);
const dto = defaultPermissionDto({aco_foreign_key: acoForeignKey, ...data}, options);
dtos.push(dto);
}
return dtos;
};
Expand Down
53 changes: 40 additions & 13 deletions src/shared/models/entity/resource/resourceEntity.test.data.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,58 @@ import {
TEST_RESOURCE_TYPE_PASSWORD_DESCRIPTION_TOTP,
TEST_RESOURCE_TYPE_TOTP
} from "../resourceType/resourceTypeEntity.test.data";
import {defaultUserDto} from "../user/userEntity.test.data";
import {defaultPermissionsDtos} from "../permission/permissionCollection.test.data";

export const defaultResourceDto = (data = {}) => {
/**
* Build default resource dto.
* @param {object} data The data to override the default dto.
* @param {Object} [options]
* @param {boolean} [options.withModifier=false] Add modifier default dto.
* @param {boolean} [options.withCreator=false] Add creator default dto.
* @param {boolean|integer} [options.withPermissions=0] Add permission default dtos.
* @param {boolean|integer} [options.withFavorite=false] Add favorite default dto.
* @returns {object}
*/
export const defaultResourceDto = (data = {}, options = {}) => {
const id = data?.id || uuidv4();

return {
const defaultData = {
id: id,
resource_type_id: TEST_RESOURCE_TYPE_PASSWORD_AND_DESCRIPTION,
name: "Passbolt",
uri: "https://passbolt.com",
username: "admin@passbolt.com",
folder_parent_id: null,
uri: "https://passbolt.com",
description: "",
expired: null,
deleted: false,
created: "2022-03-04T13:59:11+00:00",
created_by: uuidv4(),
modified: "2022-03-04T13:59:11+00:00",
created_by: uuidv4(),
modified_by: uuidv4(),
expired: null,
deleted: false,
description: "",
folder_parent_id: null,
personal: false,
resource_type_id: TEST_RESOURCE_TYPE_PASSWORD_AND_DESCRIPTION,
permission: ownerPermissionDto({aco_foreign_key: id}),
// permissions: [], // Permission are not retrieved by the process storing the information in the local storage.
favorite: null,
// secrets: [], // Secrets are not retrieved by the process storing the information in the local storage.
permission: ownerPermissionDto({aco_foreign_key: id}),
...data
};

if (!data.permissions && options.withPermissions) {
defaultData.permissions = defaultPermissionsDtos(options.withPermissions, {aco_foreign_key: id});
}

if (!data.creator && options?.withCreator) {
defaultData.creator = defaultUserDto();
}

if (!data.modifier && options?.withModifier) {
defaultData.modifier = defaultUserDto();
}

if (!data.favorite && options?.withFavorite) {
defaultData.favorite = defaultFavoriteDto({foreign_key: id});
}

return defaultData;
};

export const resourceWithUpdatePermissionDto = (data = {}) => {
Expand Down

0 comments on commit 32a9f4c

Please sign in to comment.