Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

fix(api): stop treating accounts pending deletion as already deleted (#1816)

Hampus32afbf12d642
diff --git a/fluxer_api/src/api/user/services/UserRelationshipService.ts b/fluxer_api/src/api/user/services/UserRelationshipService.ts
index f127a0793..3b2931487 100644
--- a/fluxer_api/src/api/user/services/UserRelationshipService.ts
+++ b/fluxer_api/src/api/user/services/UserRelationshipService.ts
@@ -808,6 +808,9 @@ export class UserRelationshipService {
if (!user) {
return false;
}
+ if (user.pendingDeletionAt !== null) {
+ return false;
+ }
return (user.flags & UserFlags.DELETED) === UserFlags.DELETED;
}
}
diff --git a/fluxer_api/src/api/user/tests/UserRelationshipStateTransitions.test.ts b/fluxer_api/src/api/user/tests/UserRelationshipStateTransitions.test.ts
index 163da00b7..e15bbce1f 100644
--- a/fluxer_api/src/api/user/tests/UserRelationshipStateTransitions.test.ts
+++ b/fluxer_api/src/api/user/tests/UserRelationshipStateTransitions.test.ts
@@ -19,6 +19,16 @@ import {
} from './RelationshipTestUtils';
import {fetchUserMe} from './UserTestUtils';
+async function markUserScheduledForDeletion(harness: ApiTestHarness, userId: string): Promise<void> {
+ const pendingDeletionAt = new Date(Date.now() + 14 * 24 * 60 * 60 * 1000).toISOString();
+ await createBuilder(harness, '')
+ .post(`/test/users/${userId}/set-pending-deletion`)
+ .body({pending_deletion_at: pendingDeletionAt, set_self_deleted_flag: false})
+ .expect(HTTP_STATUS.OK)
+ .execute();
+ await markUserDeleted(harness, userId);
+}
+
async function markUserDeleted(harness: ApiTestHarness, userId: string): Promise<void> {
await createBuilder(harness, '')
.patch(`/test/users/${userId}/flags`)
@@ -221,6 +231,16 @@ describe('UserRelationshipStateTransitions', () => {
.expect(HTTP_STATUS.BAD_REQUEST, 'FRIEND_REQUEST_BLOCKED')
.execute();
});
+ test('can accept a friend request from a user scheduled for deletion', async () => {
+ const alice = await createTestAccount(harness);
+ const bob = await createTestAccount(harness);
+ await sendFriendRequest(harness, bob.token, alice.userId);
+ await markUserScheduledForDeletion(harness, bob.userId);
+ const {json: friendship} = await acceptFriendRequest(harness, alice.token, bob.userId);
+ assertRelationshipType(friendship, RelationshipTypes.FRIEND);
+ const {json: aliceAfter} = await listRelationships(harness, alice.token);
+ assertRelationshipType(findRelationship(aliceAfter, bob.userId)!, RelationshipTypes.FRIEND);
+ });
test('cannot send friend request to user who blocked you', async () => {
const alice = await createTestAccount(harness);
const bob = await createTestAccount(harness);