diff --git a/src/react-extension/components/Resource/EditResource/EditResource.js b/src/react-extension/components/Resource/EditResource/EditResource.js index e8464ebce..8cb1f9c48 100644 --- a/src/react-extension/components/Resource/EditResource/EditResource.js +++ b/src/react-extension/components/Resource/EditResource/EditResource.js @@ -59,21 +59,21 @@ class EditResource extends Component { const resource = this.props.context.resources.find(item => item.id === this.props.resourceId) || {}; return { - nameOriginal: resource.name || "", - name: resource.name || "", + nameOriginal: resource.metadata.name || "", + name: resource.metadata.name || "", nameError: "", nameWarning: "", - username: resource.username || "", + username: resource.metadata.username || "", usernameError: "", usernameWarning: "", - uri: resource.uri || "", + uri: resource.metadata.uris?.[0] || "", uriError: "", uriWarning: "", passwordOriginal: null, password: "", passwordError: "", passwordWarning: "", - description: resource.description || "", + description: resource.metadata.description || "", descriptionError: "", descriptionWarning: "", totp: null, // The totp @@ -468,9 +468,11 @@ class EditResource extends Component { async updateResource() { const resourceDto = { id: this.props.resourceId, - name: this.state.name, - username: this.state.username, - uri: this.state.uri, + metadata: { + name: this.state.name, + username: this.state.username, + uris: [this.state.uri], + } }; const isPasswordExpiryEnabled = this.props.passwordExpiryContext.isFeatureEnabled(); @@ -529,7 +531,7 @@ class EditResource extends Component { * @deprecated will be removed when v2 support is dropped */ async updateResourceLegacy(resourceDto) { - resourceDto.description = this.state.description; + resourceDto.metadata.description = this.state.description; const plaintextDto = this.hasSecretChanged() ? this.state.password : null; return this.props.context.port.request("passbolt.resources.update", resourceDto, plaintextDto); @@ -540,7 +542,9 @@ class EditResource extends Component { * @param resourceDto */ async updateWithoutEncryptedDescription(resourceDto) { - resourceDto.description = this.state.description; + resourceDto.metadata.description = this.state.description; + resourceDto.metadata.resource_type_id = this.state.resourceTypeId; + // @TODO E2EE resource_type_id duplicate for resource resourceDto.resource_type_id = this.state.resourceTypeId; const plaintextDto = this.hasSecretChanged() ? this.state.password : null; @@ -552,8 +556,10 @@ class EditResource extends Component { * @param resourceDto */ async updateWithEncryptedDescription(resourceDto) { + resourceDto.metadata.resource_type_id = this.state.resourceTypeId; + // @TODO E2EE resource_type_id duplicate for resource resourceDto.resource_type_id = this.state.resourceTypeId; - resourceDto.description = ''; + resourceDto.metadata.description = ''; let plaintextDto = null; if (this.hasSecretChanged()) { plaintextDto = { @@ -570,8 +576,10 @@ class EditResource extends Component { * @param resourceDto */ async updateWithEncryptedDescriptionAndTotp(resourceDto) { + resourceDto.metadata.resource_type_id = this.state.resourceTypeId; + // @TODO E2EE resource_type_id duplicate for resource resourceDto.resource_type_id = this.state.resourceTypeId; - resourceDto.description = ''; + resourceDto.metadata.description = ''; let plaintextDto = null; if (this.hasSecretChanged()) { diff --git a/src/react-extension/components/Resource/EditResource/EditResource.test.js b/src/react-extension/components/Resource/EditResource/EditResource.test.js index 366da0e89..208b8cd34 100644 --- a/src/react-extension/components/Resource/EditResource/EditResource.test.js +++ b/src/react-extension/components/Resource/EditResource/EditResource.test.js @@ -158,8 +158,7 @@ describe("See the Edit Resource", () => { it('Add totp when clicking on the add totp button.', async() => { expect.assertions(4); - const context = defaultUserAppContext(); - const props = defaultProps({context}); // The props to pass + const props = defaultProps(); // The props to pass const secretDto = {password: "secret-decrypted", description: "description"}; mockContextRequest(props.context, () => secretDto); const page = new EditResourcePage(props); @@ -180,8 +179,9 @@ describe("See the Edit Resource", () => { it('Edit totp when clicking on the edit totp button.', async() => { expect.assertions(2); - const context = defaultUserAppContext({resources: [resourceWithTotpDto()]}); - const props = defaultProps({context}); // The props to pass + const resource = resourceWithTotpDto(); + const context = defaultUserAppContext({resources: [resource]}); + const props = defaultProps({context, resourceId: resource.id}); // The props to pass const secretDto = { password: "secret-decrypted", description: "description", @@ -196,8 +196,9 @@ describe("See the Edit Resource", () => { }); it('Delete totp when clicking on the delete totp button.', async() => { - const context = defaultUserAppContext({resources: [resourceWithTotpDto()]}); - const props = defaultProps({context}); // The props to pass + const resource = resourceWithTotpDto(); + const context = defaultUserAppContext({resources: [resource]}); + const props = defaultProps({context, resourceId: resource.id}); // The props to pass const secretDto = { password: "secret-decrypted", description: "description", @@ -252,10 +253,13 @@ describe("See the Edit Resource", () => { const onApiUpdateResourceMeta = { id: resource.id, - name: resourceMeta.name, - uri: resourceMeta.uri, - username: resourceMeta.username, - description: "", + metadata: { + resource_type_id: TEST_RESOURCE_TYPE_PASSWORD_AND_DESCRIPTION, + name: resourceMeta.name, + uris: [resourceMeta.uri], + username: resourceMeta.username, + description: "", + }, resource_type_id: TEST_RESOURCE_TYPE_PASSWORD_AND_DESCRIPTION, expired: date.toISO(), }; @@ -291,10 +295,13 @@ describe("See the Edit Resource", () => { const onApiUpdateResourceMeta = { id: resource.id, - name: resourceMeta.name, - uri: resource.uri, - username: resource.username, - description: "", + metadata: { + resource_type_id: TEST_RESOURCE_TYPE_PASSWORD_AND_DESCRIPTION, + name: resourceMeta.name, + uris: [resource.uri], + username: resource.username, + description: "", + }, resource_type_id: TEST_RESOURCE_TYPE_PASSWORD_AND_DESCRIPTION }; @@ -325,10 +332,13 @@ describe("See the Edit Resource", () => { const onApiUpdateResourceMeta = { id: resource.id, - name: resourceMeta.name, - uri: resource.uri, - username: resource.username, - description: resourceMeta.description, + metadata: { + name: resourceMeta.name, + uris: [resource.uri], + username: resource.username, + description: resourceMeta.description, + resource_type_id: TEST_RESOURCE_TYPE_PASSWORD_STRING + }, resource_type_id: TEST_RESOURCE_TYPE_PASSWORD_STRING }; @@ -368,10 +378,13 @@ describe("See the Edit Resource", () => { const onApiUpdateResourceMeta = { id: resource.id, - name: resourceMeta.name, - uri: resource.uri, - username: resource.username, - description: "", + metadata: { + name: resourceMeta.name, + uris: [resource.uri], + username: resource.username, + description: "", + resource_type_id: TEST_RESOURCE_TYPE_PASSWORD_DESCRIPTION_TOTP + }, resource_type_id: TEST_RESOURCE_TYPE_PASSWORD_DESCRIPTION_TOTP }; @@ -415,10 +428,13 @@ describe("See the Edit Resource", () => { const onApiUpdateResourceDto = { id: resource.id, - name: resourceMeta.name, - uri: resourceMeta.uri, - username: resourceMeta.username, - description: '', + metadata: { + name: resourceMeta.name, + uris: [resourceMeta.uri], + username: resourceMeta.username, + description: '', + resource_type_id: TEST_RESOURCE_TYPE_PASSWORD_AND_DESCRIPTION + }, resource_type_id: TEST_RESOURCE_TYPE_PASSWORD_AND_DESCRIPTION }; const onApiUpdateSecretDto = {