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

Merged
merged 30 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4473bf6
feat: revoke relationship in status pending when the neded attribute …
sebbi08 Jan 27, 2025
4f8d26e
chore: remove focused test
sebbi08 Jan 27, 2025
ef7653b
Merge branch 'main' into feature/ABL-354
sebbi08 Jan 27, 2025
5e2237a
feat: add error message when deleting an attribute while a relationsh…
sebbi08 Jan 31, 2025
d76fbce
Merge branch 'main' into feature/ABL-354
mergify[bot] Jan 31, 2025
77cb61f
revert: unwanted change
sebbi08 Jan 31, 2025
4e6814f
chore: pr comments
sebbi08 Jan 31, 2025
c5994b1
Merge branch 'main' into feature/ABL-354
mergify[bot] Feb 3, 2025
c9f4062
Merge branch 'main' into feature/ABL-354
mergify[bot] Feb 3, 2025
f670e7e
chore: pr comments
sebbi08 Feb 4, 2025
cd7fcdc
Update packages/runtime/test/consumption/attributes.test.ts
sebbi08 Feb 4, 2025
af5fc20
Update packages/runtime/test/lib/testUtils.ts
sebbi08 Feb 4, 2025
11f0270
Update packages/runtime/test/consumption/attributes.test.ts
sebbi08 Feb 4, 2025
3724471
chore: fix renaming
sebbi08 Feb 4, 2025
e76a5f1
chore: fix renaming
sebbi08 Feb 4, 2025
e470075
chore: fix sending messsage when relationsip is not activatable anymore
sebbi08 Feb 4, 2025
356abea
Merge branch 'main' into feature/ABL-354
mergify[bot] Feb 4, 2025
96d653a
chore: improve return type and variable naming
sebbi08 Feb 4, 2025
054e1d2
chore: pr comments
sebbi08 Feb 5, 2025
02f5178
Merge branch 'main' into feature/ABL-354
mergify[bot] Feb 5, 2025
d9a8294
Merge branch 'main' into feature/ABL-354
mergify[bot] Feb 5, 2025
d8dce26
Update packages/transport/src/modules/messages/MessageController.ts
sebbi08 Feb 6, 2025
4eb668e
chore: make notificationId optional
sebbi08 Feb 7, 2025
a26e5fd
chore: make notificationId optional
sebbi08 Feb 7, 2025
03aaebd
chore: fix tests
sebbi08 Feb 7, 2025
d966278
chore: beauty changes
sebbi08 Feb 10, 2025
3cbc4aa
chore: beauty changes
sebbi08 Feb 10, 2025
2f1e767
Merge branch 'main' into feature/ABL-354
mergify[bot] Feb 10, 2025
e38baa0
chore: beauty changes
sebbi08 Feb 10, 2025
bb78c35
Merge branch 'main' into feature/ABL-354
jkoenig134 Feb 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/runtime/src/useCases/common/RuntimeErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,13 @@ class Attributes {
public setDefaultRepositoryAttributesIsDisabled(): ApplicationError {
return new ApplicationError("error.runtime.attributes.setDefaultRepositoryAttributesIsDisabled", "Setting default RepositoryAttributes is disabled for this Account.");
}

public cannotDeleteSharedAttributeWhileRelationshipIsPending(): ApplicationError {
return new ApplicationError(
"error.runtime.attributes.cannotDeleteSharedAttributeWhileRelationshipIsPending",
"The shared Attribute cannot be deleted while the Relationship to the peer is in status 'Pending'."
);
}
}

class IdentityDeletionProcess {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Result } from "@js-soft/ts-utils";
import { AttributesController, ConsumptionIds, LocalAttribute } from "@nmshd/consumption";
import { Notification, OwnSharedAttributeDeletedByOwnerNotificationItem } from "@nmshd/content";
import { CoreId } from "@nmshd/core-types";
import { AccountController, MessageController } from "@nmshd/transport";
import { AccountController, MessageController, RelationshipsController, RelationshipStatus } from "@nmshd/transport";
import { Inject } from "@nmshd/typescript-ioc";
import { AttributeIdString, NotificationIdString, RuntimeErrors, SchemaRepository, SchemaValidator, UseCase } from "../../common";

Expand All @@ -11,7 +11,7 @@ export interface DeleteOwnSharedAttributeAndNotifyPeerRequest {
}

export interface DeleteOwnSharedAttributeAndNotifyPeerResponse {
notificationId: NotificationIdString;
notificationId?: NotificationIdString;
}

class Validator extends SchemaValidator<DeleteOwnSharedAttributeAndNotifyPeerRequest> {
Expand All @@ -25,6 +25,7 @@ export class DeleteOwnSharedAttributeAndNotifyPeerUseCase extends UseCase<Delete
@Inject private readonly attributesController: AttributesController,
@Inject private readonly accountController: AccountController,
@Inject private readonly messageController: MessageController,
@Inject private readonly relationshipsController: RelationshipsController,
@Inject validator: Validator
) {
super(validator);
Expand All @@ -39,13 +40,23 @@ export class DeleteOwnSharedAttributeAndNotifyPeerUseCase extends UseCase<Delete
return Result.fail(RuntimeErrors.attributes.isNotOwnSharedAttribute(ownSharedAttributeId));
}

const relationshipWithStatusPending = await this.relationshipsController.getRelationshipToIdentity(ownSharedAttribute.shareInfo.peer, RelationshipStatus.Pending);
if (relationshipWithStatusPending) {
return Result.fail(RuntimeErrors.attributes.cannotDeleteSharedAttributeWhileRelationshipIsPending());
sebbi08 marked this conversation as resolved.
Show resolved Hide resolved
}

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

await this.attributesController.executeFullAttributeDeletionProcess(ownSharedAttribute);

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

const notificationId = await ConsumptionIds.notification.generate();
const notificationItem = OwnSharedAttributeDeletedByOwnerNotificationItem.from({ attributeId: ownSharedAttributeId });
const notification = Notification.from({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ import { Result } from "@js-soft/ts-utils";
import { AttributesController, ConsumptionIds, LocalAttribute } from "@nmshd/consumption";
import { Notification, PeerSharedAttributeDeletedByPeerNotificationItem } from "@nmshd/content";
import { CoreId } from "@nmshd/core-types";
import { AccountController, MessageController } from "@nmshd/transport";
import { AccountController, MessageController, RelationshipsController } from "@nmshd/transport";
import { Inject } from "@nmshd/typescript-ioc";
import { RelationshipStatus } from "../../../types";
import { AttributeIdString, NotificationIdString, RuntimeErrors, SchemaRepository, SchemaValidator, UseCase } from "../../common";

export interface DeletePeerSharedAttributeAndNotifyOwnerRequest {
attributeId: AttributeIdString;
}

export interface DeletePeerSharedAttributeAndNotifyOwnerResponse {
notificationId: NotificationIdString;
notificationId?: NotificationIdString;
}

class Validator extends SchemaValidator<DeletePeerSharedAttributeAndNotifyOwnerRequest> {
Expand All @@ -25,6 +26,7 @@ export class DeletePeerSharedAttributeAndNotifyOwnerUseCase extends UseCase<Dele
@Inject private readonly attributesController: AttributesController,
@Inject private readonly accountController: AccountController,
@Inject private readonly messageController: MessageController,
@Inject private readonly relationshipsController: RelationshipsController,
@Inject validator: Validator
) {
super(validator);
Expand All @@ -39,13 +41,23 @@ export class DeletePeerSharedAttributeAndNotifyOwnerUseCase extends UseCase<Dele
return Result.fail(RuntimeErrors.attributes.isNotPeerSharedAttribute(peerSharedAttributeId));
}

const relationshipWithStatusPending = await this.relationshipsController.getRelationshipToIdentity(peerSharedAttribute.shareInfo.peer, RelationshipStatus.Pending);
if (relationshipWithStatusPending) {
return Result.fail(RuntimeErrors.attributes.cannotDeleteSharedAttributeWhileRelationshipIsPending());
}

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

await this.attributesController.executeFullAttributeDeletionProcess(peerSharedAttribute);

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

const notificationId = await ConsumptionIds.notification.generate();
const notificationItem = PeerSharedAttributeDeletedByPeerNotificationItem.from({ attributeId: peerSharedAttributeId });
const notification = Notification.from({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Result } from "@js-soft/ts-utils";
import { AttributesController, ConsumptionIds, LocalAttribute } from "@nmshd/consumption";
import { Notification, ThirdPartyRelationshipAttributeDeletedByPeerNotificationItem } from "@nmshd/content";
import { CoreId } from "@nmshd/core-types";
import { AccountController, MessageController } from "@nmshd/transport";
import { AccountController, MessageController, RelationshipsController, RelationshipStatus } from "@nmshd/transport";
import { Inject } from "@nmshd/typescript-ioc";
import { AttributeIdString, NotificationIdString, RuntimeErrors, SchemaRepository, SchemaValidator, UseCase } from "../../common";

Expand All @@ -11,7 +11,7 @@ export interface DeleteThirdPartyRelationshipAttributeAndNotifyPeerRequest {
}

export interface DeleteThirdPartyRelationshipAttributeAndNotifyPeerResponse {
notificationId: NotificationIdString;
notificationId?: NotificationIdString;
}

class Validator extends SchemaValidator<DeleteThirdPartyRelationshipAttributeAndNotifyPeerRequest> {
Expand All @@ -28,6 +28,7 @@ export class DeleteThirdPartyRelationshipAttributeAndNotifyPeerUseCase extends U
@Inject private readonly attributesController: AttributesController,
@Inject private readonly accountController: AccountController,
@Inject private readonly messageController: MessageController,
@Inject private readonly relationshipsController: RelationshipsController,
@Inject validator: Validator
) {
super(validator);
Expand All @@ -44,11 +45,24 @@ export class DeleteThirdPartyRelationshipAttributeAndNotifyPeerUseCase extends U
return Result.fail(RuntimeErrors.attributes.isNotThirdPartyRelationshipAttribute(thirdPartyRelationshipAttributeId));
}

const relationshipWithStatusPending = await this.relationshipsController.getRelationshipToIdentity(
thirdPartyRelationshipAttribute.shareInfo.peer,
RelationshipStatus.Pending
);
if (relationshipWithStatusPending) {
return Result.fail(RuntimeErrors.attributes.cannotDeleteSharedAttributeWhileRelationshipIsPending());
}

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

await this.attributesController.executeFullAttributeDeletionProcess(thirdPartyRelationshipAttribute);

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

const notificationId = await ConsumptionIds.notification.generate();
const notificationItem = ThirdPartyRelationshipAttributeDeletedByPeerNotificationItem.from({ attributeId: thirdPartyRelationshipAttributeId });
const notification = Notification.from({
Expand Down
Loading