Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deleting a SharedAttribute does not validate if it's possible to send the Notification #398

Open
wants to merge 25 commits into
base: main
Choose a base branch
from

Conversation

sebbi08
Copy link
Contributor

@sebbi08 sebbi08 commented Jan 27, 2025

Readiness checklist

  • I added/updated tests.
  • I ensured that the PR title is good enough for the changelog.
  • I labeled the PR.
  • I self-reviewed the PR.

@sebbi08 sebbi08 added the wip Work in Progress (blocks mergify from auto update the branch) label Jan 27, 2025
@jkoenig134
Copy link
Member

with #404 this can be defenitely closed as we can just send these messages right away now

@sebbi08 sebbi08 changed the title Revoke relationship in status pending when the neded Attribute is deleted Return an error when deleting a SharedAttribute where the Relationship is still pending Jan 31, 2025
@sebbi08 sebbi08 marked this pull request as ready for review January 31, 2025 10:42
@sebbi08 sebbi08 added bug Something isn't working and removed wip Work in Progress (blocks mergify from auto update the branch) labels Jan 31, 2025
@sebbi08
Copy link
Contributor Author

sebbi08 commented Jan 31, 2025

with #404 this can be defenitely closed as we can just send these messages right away now

Sadly, the messages cannot be encrypted until the relationship got accepted by both Peers

@jkoenig134
Copy link
Member

image
?

@jkoenig134 jkoenig134 added enhancement New feature or request bug Something isn't working and removed bug Something isn't working enhancement New feature or request labels Jan 31, 2025
@jkoenig134 jkoenig134 changed the title Return an error when deleting a SharedAttribute where the Relationship is still pending Deleting a SharedAttribute does not validate if it's possible to send the Notification Jan 31, 2025
Co-authored-by: Britta Stallknecht <146106656+britsta@users.noreply.github.com>
sebbi08 and others added 5 commits February 4, 2025 10:52
Co-authored-by: Milena Czierlinski <146972016+Milena-Czierlinski@users.noreply.github.com>
Co-authored-by: Milena Czierlinski <146972016+Milena-Czierlinski@users.noreply.github.com>
Comment on lines 43 to 60
const relationshipToPeer = await this.relationshipsController.getRelationshipToIdentity(ownSharedAttribute.shareInfo.peer, RelationshipStatus.Pending);

if (relationshipToPeer) {
return Result.fail(RuntimeErrors.attributes.cannotDeleteSharedAttributeBecausePeerCannotBeNotified());
}

const validationResult = await this.attributesController.validateFullAttributeDeletionProcess(ownSharedAttribute);
if (validationResult.isError()) {
return Result.fail(validationResult.error);
}

await this.attributesController.executeFullAttributeDeletionProcess(ownSharedAttribute);

const canSendMessageResult = await this.messageController.validateMessageRecipients([ownSharedAttribute.shareInfo.peer]);

if (canSendMessageResult) {
return Result.ok({ notificationId: "" });
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm so confused.

  1. why do you return Result.ok({ notificationId: "" })? This doesn't make any sense.
  2. if (canSendMessageResult) should always return true. I think you wanted to run if (canSendMessageResult.isError) here
  3. Why do you run two checks, one for Pending and the other validateMessageRecipients check. IMO these checks should do exactly the same.

Copy link
Contributor

@britsta britsta Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please say if I am wrong @sebbi08, but regarding point 2 I think the variable canSendMessageResult should be renamed to messageRecipientsValidationError. Then the implementation should be more clear.

Regarding point 3, the differentiation is necessary in order to allow to delete Attributes even though no Notification can be sent (this is necessary, for example, for "DeletionProposed" Relationships). So we call validateMessageRecipients in order to avoid that an attempt is made to send a Notification which can't be sent, and we check for a pending Relationship before to avoid deleting the Attribute in the first place. (#398 (comment))

@sebbi08 sebbi08 requested a review from jkoenig134 February 6, 2025 09:07
Copy link
Contributor

@Milena-Czierlinski Milena-Czierlinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some beauty comments :)

const validationResult = await this.attributesController.validateFullAttributeDeletionProcess(peerSharedAttribute);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Comment on lines +58 to +62
const messageRecipientsValidationResult = await this.messageController.validateMessageRecipients([peerSharedAttribute.shareInfo.peer]);

if (messageRecipientsValidationResult.isError) {
return Result.ok({});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const messageRecipientsValidationResult = await this.messageController.validateMessageRecipients([peerSharedAttribute.shareInfo.peer]);
if (messageRecipientsValidationResult.isError) {
return Result.ok({});
}
const messageRecipientsValidationResult = await this.messageController.validateMessageRecipients([peerSharedAttribute.shareInfo.peer]);
if (messageRecipientsValidationResult.isError) {
return Result.ok({});
}

Grouping results and throwing their errors enhances the readability of the code in my opinion. Please adjust it equally in the other files.

@@ -39,13 +41,26 @@ export class DeletePeerSharedAttributeAndNotifyOwnerUseCase extends UseCase<Dele
return Result.fail(RuntimeErrors.attributes.isNotPeerSharedAttribute(peerSharedAttributeId));
}

const relationshipToPeer = await this.relationshipsController.getRelationshipToIdentity(peerSharedAttribute.shareInfo.peer, RelationshipStatus.Pending);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

@@ -39,13 +41,26 @@ export class DeletePeerSharedAttributeAndNotifyOwnerUseCase extends UseCase<Dele
return Result.fail(RuntimeErrors.attributes.isNotPeerSharedAttribute(peerSharedAttributeId));
}

const relationshipToPeer = await this.relationshipsController.getRelationshipToIdentity(peerSharedAttribute.shareInfo.peer, RelationshipStatus.Pending);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const relationshipToPeer = await this.relationshipsController.getRelationshipToIdentity(peerSharedAttribute.shareInfo.peer, RelationshipStatus.Pending);
const relationshipWithStatusPending = await this.relationshipsController.getRelationshipToIdentity(peerSharedAttribute.shareInfo.peer, RelationshipStatus.Pending);

Same in other files.

@@ -915,3 +917,38 @@ export async function cleanupAttributes(...services: TestRuntimeServices[]): Pro
})
);
}

export async function createRelationshipInPendingState(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export async function createRelationshipInPendingState(
export async function createRelationshipWithStatusPending(

}
};

const content: RelationshipTemplateContentJSON = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const content: RelationshipTemplateContentJSON = {
const relationshipTemplateContent: RelationshipTemplateContentJSON = {

Comment on lines +2682 to +2698
const item: ReadAttributeRequestItemJSON = {
"@type": "ReadAttributeRequestItem",
mustBeAccepted: true,
query: {
"@type": "IdentityAttributeQuery",
valueType: "GivenName"
}
};

const content: RelationshipTemplateContentJSON = {
"@type": "RelationshipTemplateContent",
title: "aTitle",
onNewRelationship: {
items: [item],
"@type": "Request"
}
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move this below the declaration of repositoryAttribute, such that is is closer to its usage.

Comment on lines +2722 to +2724
const attributeDeletion = await services2.consumption.attributes.deleteOwnSharedAttributeAndNotifyPeer({ attributeId: ownSharedAttribute.value[0].id });

expect(attributeDeletion).toBeAnError(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const attributeDeletion = await services2.consumption.attributes.deleteOwnSharedAttributeAndNotifyPeer({ attributeId: ownSharedAttribute.value[0].id });
expect(attributeDeletion).toBeAnError(
const result = await services2.consumption.attributes.deleteOwnSharedAttributeAndNotifyPeer({ attributeId: ownSharedAttribute.value[0].id });
expect(result).toBeAnError(

or attributeDeletionResult.

@@ -2665,6 +2671,61 @@ describe("DeleteAttributeUseCases", () => {
expect(updatedPredecessor.deletionInfo?.deletionStatus).toStrictEqual(LocalAttributeDeletionStatus.DeletedByOwner);
expect(CoreDate.from(updatedPredecessor.deletionInfo!.deletionDate).isBetween(timeBeforeUpdate, timeAfterUpdate.add(1))).toBe(true);
});

test("should throw an error trying to delete an own shared Attribute when the Relationship is in status Pending", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check if the comments on this test are also applicable to the other tests you added.

@@ -419,7 +419,7 @@ export class MessageController extends TransportController {
return message;
}

private async validateMessageRecipients(recipients: CoreAddress[]) {
public async validateMessageRecipients(recipients: CoreAddress[]): Promise<Result<void, CoreError>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public async validateMessageRecipients(recipients: CoreAddress[]): Promise<Result<void, CoreError>> {
public async validateMessageRecipients(recipients: CoreAddress[]): Promise<Result<void>> {

I think the Result already implies that it might be an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants