Merge pull request #16247 from mozilla/fxa-8842

feat(delete): Delete user firestore record on delete event
This commit is contained in:
Vijay Budhram 2024-01-16 16:20:22 -05:00 коммит произвёл GitHub
Родитель 7d13382b22 5e02484f51
Коммит a54cbea5a7
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
4 изменённых файлов: 41 добавлений и 1 удалений

Просмотреть файл

@ -185,4 +185,18 @@ describe('#integration - FirestoreService', () => {
}, },
TEST_TIMEOUT TEST_TIMEOUT
); );
it(
'deletes a user record',
async () => {
await service.storeLogin(uid1, 'fx_send');
let result = await service.fetchClientIds(uid1);
expect(result).toStrictEqual(['fx_send']);
await service.deleteUser(uid1);
result = await service.fetchClientIds(uid1);
expect(result).toStrictEqual([]);
},
TEST_TIMEOUT
);
}); });

Просмотреть файл

@ -87,6 +87,19 @@ export class FirestoreService {
return true; return true;
} }
/**
* Deletes a user record in firebase.
*
* @param uid
*/
public async deleteUser(uid: string): Promise<void> {
const document = this.db.doc(
`${this.prefix}users/${uid}`
) as TypedDocumentReference<UserDocument>;
await document.delete();
}
/** /**
* Fetches the OAuth Client Ids that a user has directly logged in to * Fetches the OAuth Client Ids that a user has directly logged in to
* via a Relying Party flow. * via a Relying Party flow.

Просмотреть файл

@ -105,6 +105,7 @@ describe('QueueworkerService', () => {
beforeEach(async () => { beforeEach(async () => {
firestore = { firestore = {
storeLogin: jest.fn().mockResolvedValue({}), storeLogin: jest.fn().mockResolvedValue({}),
deleteUser: jest.fn().mockResolvedValue({}),
fetchClientIds: jest fetchClientIds: jest
.fn() .fn()
.mockResolvedValue(['444c5d137fc34d82ae65441d7f26a504']), .mockResolvedValue(['444c5d137fc34d82ae65441d7f26a504']),

Просмотреть файл

@ -191,6 +191,18 @@ export class QueueworkerService
} }
} }
/**
* Send delete event to RPs and delete user record from datastore.
*
* @param message
* @private
*/
private async handleDeleteEvent(message: dto.deleteSchema) {
await this.handleMessageFanout(message, 'delete');
await this.firestore.deleteUser(message.uid);
}
/** /**
* Save login to RP to datastore. * Save login to RP to datastore.
* *
@ -320,7 +332,7 @@ export class QueueworkerService
break; break;
} }
case dto.DELETE_EVENT: { case dto.DELETE_EVENT: {
await this.handleMessageFanout(message, 'delete'); await this.handleDeleteEvent(message);
break; break;
} }
case dto.PRIMARY_EMAIL_EVENT: case dto.PRIMARY_EMAIL_EVENT: