-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
|
with #404 this can be defenitely closed as we can just send these messages right away now |
…ip is still in Pending state
Sadly, the messages cannot be encrypted until the relationship got accepted by both Peers |
packages/runtime/src/useCases/consumption/attributes/DeleteOwnSharedAttributeAndNotifyPeer.ts
Outdated
Show resolved
Hide resolved
packages/runtime/src/useCases/consumption/attributes/DeletePeerSharedAttributeAndNotifyOwner.ts
Outdated
Show resolved
Hide resolved
packages/runtime/src/useCases/consumption/attributes/DeleteOwnSharedAttributeAndNotifyPeer.ts
Outdated
Show resolved
Hide resolved
packages/runtime/src/useCases/consumption/attributes/DeletePeerSharedAttributeAndNotifyOwner.ts
Outdated
Show resolved
Hide resolved
...me/src/useCases/consumption/attributes/DeleteThirdPartyRelationshipAttributeAndNotifyPeer.ts
Outdated
Show resolved
Hide resolved
packages/transport/src/modules/relationships/RelationshipsController.ts
Outdated
Show resolved
Hide resolved
packages/transport/src/modules/relationships/RelationshipsController.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: Britta Stallknecht <146106656+britsta@users.noreply.github.com>
Co-authored-by: Milena Czierlinski <146972016+Milena-Czierlinski@users.noreply.github.com>
Co-authored-by: Milena Czierlinski <146972016+Milena-Czierlinski@users.noreply.github.com>
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: "" }); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm so confused.
- why do you return
Result.ok({ notificationId: "" })
? This doesn't make any sense. if (canSendMessageResult)
should always return true. I think you wanted to runif (canSendMessageResult.isError)
here- Why do you run two checks, one for Pending and the other validateMessageRecipients check. IMO these checks should do exactly the same.
There was a problem hiding this comment.
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))
packages/runtime/src/useCases/consumption/attributes/DeleteOwnSharedAttributeAndNotifyPeer.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: Julian König <33655937+jkoenig134@users.noreply.github.com>
There was a problem hiding this 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); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const messageRecipientsValidationResult = await this.messageController.validateMessageRecipients([peerSharedAttribute.shareInfo.peer]); | ||
|
||
if (messageRecipientsValidationResult.isError) { | ||
return Result.ok({}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export async function createRelationshipInPendingState( | |
export async function createRelationshipWithStatusPending( |
} | ||
}; | ||
|
||
const content: RelationshipTemplateContentJSON = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const content: RelationshipTemplateContentJSON = { | |
const relationshipTemplateContent: RelationshipTemplateContentJSON = { |
const item: ReadAttributeRequestItemJSON = { | ||
"@type": "ReadAttributeRequestItem", | ||
mustBeAccepted: true, | ||
query: { | ||
"@type": "IdentityAttributeQuery", | ||
valueType: "GivenName" | ||
} | ||
}; | ||
|
||
const content: RelationshipTemplateContentJSON = { | ||
"@type": "RelationshipTemplateContent", | ||
title: "aTitle", | ||
onNewRelationship: { | ||
items: [item], | ||
"@type": "Request" | ||
} | ||
}; |
There was a problem hiding this comment.
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.
const attributeDeletion = await services2.consumption.attributes.deleteOwnSharedAttributeAndNotifyPeer({ attributeId: ownSharedAttribute.value[0].id }); | ||
|
||
expect(attributeDeletion).toBeAnError( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 () => { |
There was a problem hiding this comment.
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>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Readiness checklist