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

Simplify identity deletion process handling on second device by republishing events #347

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
b9c11f2
WIP: Enhance LocalAccountDTO with deletion Info
Siolto Nov 18, 2024
4c04d6b
feat: try to untangle changes
Milena-Czierlinski Nov 18, 2024
6c0696d
feat: add getAccounts(Not)InDeletion functions
Milena-Czierlinski Nov 19, 2024
b716807
test: clean up IdentityDeletionProcessStatusChangedModule test
Milena-Czierlinski Nov 19, 2024
d55f26e
Merge remote-tracking branch 'origin/main' into feat/enhance_app_runt…
Milena-Czierlinski Nov 19, 2024
29d1313
refactor: stuff
Milena-Czierlinski Nov 20, 2024
9ee6fd4
refactor: clean up changes
Milena-Czierlinski Nov 20, 2024
7641e3e
test: notes
Milena-Czierlinski Nov 21, 2024
fa2df9a
feat: publish DatawalletSynchronizedEvent in AccountController
Milena-Czierlinski Nov 21, 2024
5f66098
test: receive DatawalletSynchronizedEvent calling syncDatawallet use …
Milena-Czierlinski Nov 22, 2024
7d850e1
feat: use runtime event in app-runtime
Milena-Czierlinski Nov 22, 2024
e581140
feat: add DatawalletSynchronized module
Milena-Czierlinski Nov 22, 2024
7bede00
chore: remove LocalAccountDeletionDateChangedModule
Milena-Czierlinski Nov 22, 2024
a5329a2
Merge branch 'main' into feat/enhance_app_runtime_with_deletion_info
Milena-Czierlinski Nov 25, 2024
af6f321
test: clean up IdentityDeletionProcessStatusChangedModule test
Milena-Czierlinski Nov 25, 2024
273b1ff
fix: DatawalletSynchronizedModule
Milena-Czierlinski Nov 25, 2024
f15acf6
fix: don't publish event updating LocalAccount deletionDate
Milena-Czierlinski Nov 25, 2024
b535752
fix and test: getAccounts(Not)InDeletion
Milena-Czierlinski Nov 25, 2024
e534108
Merge remote-tracking branch 'origin/main' into feat/enhance_app_runt…
Milena-Czierlinski Nov 26, 2024
b518fa9
test: don's skip tests
Milena-Czierlinski Nov 26, 2024
d74bab5
Merge branch 'main' into feat/enhance_app_runtime_with_deletion_info
Milena-Czierlinski Nov 26, 2024
9abeb75
test: remove unrelated test
Milena-Czierlinski Nov 26, 2024
20d5077
chore: remove dangerous getters
jkoenig134 Nov 27, 2024
863f39d
fix: write deletionDate to cached local account from MultiAccountCont…
jkoenig134 Nov 27, 2024
f5b17dc
fix: use correct apis
jkoenig134 Nov 27, 2024
425a640
refactor: massively simplify tests
jkoenig134 Nov 27, 2024
1279d34
chore: naming
jkoenig134 Nov 27, 2024
f927644
chore: more asserts
jkoenig134 Nov 27, 2024
325bed0
refactor: move event publish location
jkoenig134 Nov 27, 2024
e4386a2
fix: change location of publishing
jkoenig134 Nov 27, 2024
de6eb61
refactor: collect IDs for changed objects during datawallet sync
jkoenig134 Nov 28, 2024
63e4261
feat: re-publish event
jkoenig134 Nov 28, 2024
af3932d
refactor: update usage
jkoenig134 Nov 28, 2024
d5aa70e
Merge branch 'main' into simplify-IdentityDeletionProcess-handling-on…
jkoenig134 Nov 28, 2024
c1452ec
chore: simplify method
jkoenig134 Dec 2, 2024
63153cb
refactor: remove all occurences of the DatawalletSynchronizedModule
jkoenig134 Dec 2, 2024
96d2670
fix: publish event
jkoenig134 Dec 2, 2024
273fce5
fix: for..of instead of for..in
jkoenig134 Dec 2, 2024
9768fa5
fix: properly await events
jkoenig134 Dec 2, 2024
9609f51
Merge branch 'main' into simplify-IdentityDeletionProcess-handling-on…
jkoenig134 Dec 2, 2024
7793dbb
Merge branch 'main' into simplify-IdentityDeletionProcess-handling-on…
jkoenig134 Dec 2, 2024
6134537
chore: remove unused testutils
jkoenig134 Dec 2, 2024
5900cfd
chore: use proper eventbus
jkoenig134 Dec 2, 2024
f67bbe7
Merge branch 'main' into simplify-IdentityDeletionProcess-handling-on…
mergify[bot] Dec 3, 2024
3e179d1
chore: use for loop
jkoenig134 Dec 3, 2024
6fa3e6a
refactor: allow to announce that there are changes in IdentityDeletio…
jkoenig134 Dec 3, 2024
5ac5870
chore: simplify publishing
jkoenig134 Dec 3, 2024
a05ef57
chore: test wording
jkoenig134 Dec 3, 2024
5cc8abf
feat: update logic
jkoenig134 Dec 3, 2024
0b43107
fix: tests
jkoenig134 Dec 3, 2024
03ea3c3
Merge branch 'main' into simplify-IdentityDeletionProcess-handling-on…
mergify[bot] Dec 3, 2024
62ffc49
Merge branch 'main' into simplify-IdentityDeletionProcess-handling-on…
mergify[bot] Dec 4, 2024
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
6 changes: 0 additions & 6 deletions packages/app-runtime/src/AppConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ export function createAppConfig(...configs: AppConfigOverwrite[]): AppConfig {
location: "onboardingChangeReceived",
enabled: true
},
datawalletSynchronized: {
name: "datawalletSynchronized",
displayName: "Datawallet Synchronized Module",
location: "datawalletSynchronized",
enabled: true
},
identityDeletionProcessStatusChanged: {
name: "identityDeletionProcessStatusChanged",
displayName: "Identity Deletion Process Status Changed Module",
Expand Down
2 changes: 0 additions & 2 deletions packages/app-runtime/src/AppRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
AppLaunchModule,
AppRuntimeModuleConfiguration,
AppSyncModule,
DatawalletSynchronizedModule,
IAppRuntimeModuleConstructor,
IdentityDeletionProcessStatusChangedModule,
MailReceivedModule,
Expand Down Expand Up @@ -264,7 +263,6 @@ export class AppRuntime extends Runtime<AppConfig> {
pushNotification: PushNotificationModule,
mailReceived: MailReceivedModule,
onboardingChangeReceived: OnboardingChangeReceivedModule,
datawalletSynchronized: DatawalletSynchronizedModule,
identityDeletionProcessStatusChanged: IdentityDeletionProcessStatusChangedModule,
messageReceived: MessageReceivedModule,
relationshipChanged: RelationshipChangedModule,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { CoreDate } from "@nmshd/core-types";
import { IdentityDeletionProcessStatus, IdentityDeletionProcessStatusChangedEvent } from "@nmshd/runtime";
import { AppRuntimeError } from "../../AppRuntimeError";
import { LocalAccountDeletionDateChangedEvent } from "../../events";
import { LocalAccountMapper } from "../../multiAccount/data/LocalAccountMapper";
import { AppRuntimeModule, AppRuntimeModuleConfiguration } from "../AppRuntimeModule";

export interface IdentityDeletionProcessStatusChangedModuleConfig extends AppRuntimeModuleConfiguration {}
Expand All @@ -19,25 +21,44 @@ export class IdentityDeletionProcessStatusChangedModule extends AppRuntimeModule
private async handleIdentityDeletionProcessStatusChanged(event: IdentityDeletionProcessStatusChangedEvent) {
const identityDeletionProcess = event.data;

if (!identityDeletionProcess) {
const services = await this.runtime.getServices(event.eventTargetAddress);
const identityDeletionProcesses = await services.transportServices.identityDeletionProcesses.getIdentityDeletionProcesses();

const approvedIdentityDeletionProcess = identityDeletionProcesses.value.filter((idp) => idp.status === IdentityDeletionProcessStatus.Approved).at(0);
const deletionDate = approvedIdentityDeletionProcess?.gracePeriodEndsAt ? CoreDate.from(approvedIdentityDeletionProcess.gracePeriodEndsAt) : undefined;

await this.updateLocalAccountDeletionDate(event.eventTargetAddress, deletionDate, true);
return;
}

switch (identityDeletionProcess.status) {
case IdentityDeletionProcessStatus.Approved:
await this.runtime.multiAccountController.updateLocalAccountDeletionDate(event.eventTargetAddress, CoreDate.from(identityDeletionProcess.gracePeriodEndsAt!));
await this.updateLocalAccountDeletionDate(event.eventTargetAddress, CoreDate.from(identityDeletionProcess.gracePeriodEndsAt!));
break;

case IdentityDeletionProcessStatus.Cancelled:
const account = await this.runtime.multiAccountController.getAccountByAddress(event.eventTargetAddress);
const previousDeletionDate = account.deletionDate;

if (!previousDeletionDate) break;

await this.runtime.multiAccountController.updateLocalAccountDeletionDate(event.eventTargetAddress, undefined);
await this.updateLocalAccountDeletionDate(event.eventTargetAddress, undefined);
break;

default:
break;
}
}

private async updateLocalAccountDeletionDate(eventTargetAddress: string, deletionDate: CoreDate | undefined, publishEvent = false) {
const account = await this.runtime.multiAccountController.getAccountByAddress(eventTargetAddress);
const previousDeletionDate = account.deletionDate;

if (!deletionDate && !previousDeletionDate) return;
if (deletionDate && previousDeletionDate && deletionDate.equals(previousDeletionDate)) return;

const localAccount = await this.runtime.multiAccountController.updateLocalAccountDeletionDate(eventTargetAddress, deletionDate);

if (!publishEvent) return;
this.runtime.eventBus.publish(new LocalAccountDeletionDateChangedEvent(eventTargetAddress, LocalAccountMapper.toLocalAccountDTO(localAccount)));
}

public override stop(): Promise<void> | void {
this.unsubscribeFromAllEvents();
}
Expand Down
1 change: 0 additions & 1 deletion packages/app-runtime/src/modules/runtimeEvents/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from "./DatawalletSynchronizedModule";
export * from "./IdentityDeletionProcessStatusChangedModule";
export * from "./MessageReceivedModule";
export * from "./RelationshipChangedModule";
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export class MultiAccountController {
await this._localAccounts.update(oldAccount, renamedAccount);
}

public async updateLocalAccountDeletionDate(address: string, deletionDate?: CoreDate): Promise<void> {
public async updateLocalAccountDeletionDate(address: string, deletionDate?: CoreDate): Promise<LocalAccount> {
const oldAccount = await this._localAccounts.findOne({ address });

if (!oldAccount) {
Expand All @@ -265,6 +265,8 @@ export class MultiAccountController {

const cachedAccount = this.sessionStorage.findSession(address)?.account;
if (cachedAccount) cachedAccount.deletionDate = deletionDate?.toString();

return account;
}

public async updateLastAccessedAt(accountId: string): Promise<void> {
Expand Down
44 changes: 2 additions & 42 deletions packages/app-runtime/test/lib/TestUtil.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable jest/no-standalone-expect */
import { ILoggerFactory } from "@js-soft/logging-abstractions";
import { SimpleLoggerFactory } from "@js-soft/simple-logger";
import { EventBus, Result, sleep, SubscriptionTarget } from "@js-soft/ts-utils";
import { EventBus, Result, sleep } from "@js-soft/ts-utils";
import { ArbitraryMessageContent, ArbitraryRelationshipCreationContent, ArbitraryRelationshipTemplateContent } from "@nmshd/content";
import { CoreDate } from "@nmshd/core-types";
import {
Expand Down Expand Up @@ -81,46 +81,6 @@ export class TestUtil {
TransportLoggerFactory.init(this.oldLogger);
}

public static async awaitEvent<TEvent>(
runtime: AppRuntime,
subscriptionTarget: SubscriptionTarget<TEvent>,
timeout?: number,
assertionFunction?: (t: TEvent) => boolean
): Promise<TEvent> {
const eventBus = runtime.eventBus;
let subscriptionId: number;

const eventPromise = new Promise<TEvent>((resolve) => {
subscriptionId = eventBus.subscribe(subscriptionTarget, (event: TEvent) => {
if (assertionFunction && !assertionFunction(event)) return;

resolve(event);
});
});
if (!timeout) {
return await eventPromise.finally(() => eventBus.unsubscribe(subscriptionId));
}

let timeoutId: NodeJS.Timeout;
const timeoutPromise = new Promise<TEvent>((_resolve, reject) => {
timeoutId = setTimeout(
() => reject(new Error(`timeout exceeded for waiting for event ${typeof subscriptionTarget === "string" ? subscriptionTarget : subscriptionTarget.name}`)),
timeout
);
});

return await Promise.race([eventPromise, timeoutPromise]).finally(() => {
eventBus.unsubscribe(subscriptionId);
clearTimeout(timeoutId);
});
}

public static async expectEvent<T>(runtime: AppRuntime, subscriptionTarget: SubscriptionTarget<T>, timeoutInMS = 1000): Promise<T> {
const eventInstance: T = await this.awaitEvent(runtime, subscriptionTarget, timeoutInMS);
expect(eventInstance, "Event received").toBeDefined();
return eventInstance;
}

public static expectThrows(method: Function | Promise<any>, errorMessageRegexp: RegExp | string): void {
let error: Error | undefined;
try {
Expand Down Expand Up @@ -292,7 +252,7 @@ export class TestUtil {
expiresAt: CoreDate.utc().add({ minutes: 5 }).toString(),
filename: "Test.bin",
mimetype: "application/json",
title: "Test",
title: "aFileName",
content: fileContent
});
return file.value;
Expand Down

This file was deleted.

Loading
Loading