Skip to content

Commit

Permalink
Fix/Adjust use cases to deletionInfo (#155)
Browse files Browse the repository at this point in the history
* feat: add todos

* fix: adjust ShareRepositoryAttributeUseCase

* test: NotifyPeerAboutRepositoryAttributeSuccession with attribute deleted by peer

* test: SucceedRelationshipAttributeAndNotifyPeer with attribute deleted by peer

* chore: version bump

* chore: remove todo comment

* feat: decouple tests and rename variables

* feat: allow to re-share Attributes that are ToBeDeletedByPeer

* fix: adjust for mongodb and ferretdb

* chore: version bump

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
Milena-Czierlinski and mergify[bot] authored Jul 1, 2024
1 parent d3bc2ff commit ddbec99
Show file tree
Hide file tree
Showing 6 changed files with 256 additions and 129 deletions.
2 changes: 1 addition & 1 deletion 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 packages/runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nmshd/runtime",
"version": "4.13.1",
"version": "4.13.2",
"description": "The enmeshed client runtime.",
"homepage": "https://enmeshed.eu",
"repository": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Result } from "@js-soft/ts-utils";
import { AttributesController, CreateOutgoingRequestParameters, LocalAttribute, OutgoingRequestsController } from "@nmshd/consumption";
import { AttributesController, CreateOutgoingRequestParameters, DeletionStatus, LocalAttribute, OutgoingRequestsController } from "@nmshd/consumption";
import { Request, ShareAttributeRequestItem } from "@nmshd/content";
import { AccountController, CoreAddress, CoreId, MessageController } from "@nmshd/transport";
import { Inject } from "typescript-ioc";
Expand Down Expand Up @@ -54,7 +54,8 @@ export class ShareRepositoryAttributeUseCase extends UseCase<ShareRepositoryAttr
"content.owner": this.accountController.identity.address.toString(),
"content.@type": "IdentityAttribute",
"shareInfo.sourceAttribute": request.attributeId,
"shareInfo.peer": request.peer
"shareInfo.peer": request.peer,
"deletionInfo.deletionStatus": { $nin: [DeletionStatus.DeletedByPeer, DeletionStatus.ToBeDeletedByPeer] }
};
const ownSharedIdentityAttributesOfRepositoryAttribute = await this.attributeController.getLocalAttributes(query);
if (ownSharedIdentityAttributesOfRepositoryAttribute.length > 0) {
Expand All @@ -64,13 +65,12 @@ export class ShareRepositoryAttributeUseCase extends UseCase<ShareRepositoryAttr
}

const sharedVersionsOfRepositoryAttribute = await this.attributeController.getSharedVersionsOfAttribute(repositoryAttributeId, [CoreAddress.from(request.peer)], false);
if (sharedVersionsOfRepositoryAttribute.length > 0) {
const activeSharedVersions = sharedVersionsOfRepositoryAttribute.filter(
(attr) => attr.deletionInfo?.deletionStatus !== DeletionStatus.DeletedByPeer && attr.deletionInfo?.deletionStatus !== DeletionStatus.ToBeDeletedByPeer
);
if (activeSharedVersions.length > 0) {
return Result.fail(
RuntimeErrors.attributes.anotherVersionOfRepositoryAttributeHasAlreadyBeenSharedWithPeer(
request.attributeId,
request.peer,
sharedVersionsOfRepositoryAttribute[0].id
)
RuntimeErrors.attributes.anotherVersionOfRepositoryAttributeHasAlreadyBeenSharedWithPeer(request.attributeId, request.peer, activeSharedVersions[0].id)
);
}

Expand Down
Loading

0 comments on commit ddbec99

Please sign in to comment.