Merged PR 512: ADB2Cユーザが一括で削除できないことに対する対応優先度の数値根拠だし
## 概要 [Task2831: ADB2Cユーザが一括で削除できないことに対する対応優先度の数値根拠だし](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/2831) - 元PBI or タスクへのリンク(内容・目的などはそちらにあるはず) - 何をどう変更したか、追加したライブラリなど 削除処理の同期化、エラー出力の追加 - このPull Requestでの対象/対象外 - 影響範囲(他の機能にも影響があるか) ## レビューポイント - 特にレビューしてほしい箇所 - 軽微なものや自明なものは記載不要 - 修正範囲が大きい場合などに記載 - 全体的にや仕様を満たしているか等は本当に必要な時のみ記載 ## UIの変更 - Before/Afterのスクショなど - スクショ置き場 ## 動作確認状況 - ユニットテスト ## 補足 - 相談、参考資料などがあれば
This commit is contained in:
parent
f4347ff5c0
commit
f3dde1874d
@ -6,8 +6,9 @@ import { ConfigService } from '@nestjs/config';
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { Aadb2cUser, B2cMetadata, JwkSignKey } from '../../common/token';
|
import { Aadb2cUser, B2cMetadata, JwkSignKey } from '../../common/token';
|
||||||
import { AdB2cResponse, AdB2cUser } from './types/types';
|
import { AdB2cResponse, AdB2cUser } from './types/types';
|
||||||
|
import { isPromiseRejectedResult } from './utils/utils';
|
||||||
import { Context } from '../../common/log';
|
import { Context } from '../../common/log';
|
||||||
import { ADB2C_SIGN_IN_TYPE } from '../../constants';
|
import { ADB2C_SIGN_IN_TYPE, MANUAL_RECOVERY_REQUIRED } from '../../constants';
|
||||||
|
|
||||||
export type ConflictError = {
|
export type ConflictError = {
|
||||||
reason: 'email';
|
reason: 'email';
|
||||||
@ -267,12 +268,33 @@ export class AdB2cService {
|
|||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 複数ユーザーを一括削除する方法が不明なため、rate limitの懸念があるのを承知のうえ単一削除の繰り返しで実装
|
// 複数ユーザーを一括削除する方法がないため、1人ずつで削除を行う(rate limitに大きな影響がないこと確認済)
|
||||||
// TODO 一括削除する方法が判明したら修正する
|
const results = await Promise.allSettled(
|
||||||
// https://learn.microsoft.com/en-us/graph/api/user-delete?view=graph-rest-1.0&tabs=javascript#example
|
externalIds.map(
|
||||||
externalIds.map(
|
async (x) => await this.graphClient.api(`users/${x}`).delete(),
|
||||||
async (x) => await this.graphClient.api(`users/${x}`).delete(),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 失敗したプロミスを抽出
|
||||||
|
const failedPromises = results.filter(
|
||||||
|
(result) => result.status === 'rejected',
|
||||||
|
);
|
||||||
|
|
||||||
|
// 失敗したプロミスのエラーをログに記録
|
||||||
|
failedPromises.forEach((result, index) => {
|
||||||
|
const failedId = externalIds[index];
|
||||||
|
if (isPromiseRejectedResult(result)) {
|
||||||
|
const error = result.reason.toString();
|
||||||
|
|
||||||
|
this.logger.error(
|
||||||
|
`${MANUAL_RECOVERY_REQUIRED}[${context.trackingId}] Failed to delete user ${failedId}: ${error}`,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
this.logger.error(
|
||||||
|
`${MANUAL_RECOVERY_REQUIRED}[${context.trackingId}] Failed to delete user ${failedId}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error(`error=${e}`);
|
this.logger.error(`error=${e}`);
|
||||||
throw e;
|
throw e;
|
||||||
|
|||||||
10
dictation_server/src/gateways/adb2c/utils/utils.ts
Normal file
10
dictation_server/src/gateways/adb2c/utils/utils.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
export const isPromiseRejectedResult = (
|
||||||
|
data: unknown,
|
||||||
|
): data is PromiseRejectedResult => {
|
||||||
|
return (
|
||||||
|
data !== null &&
|
||||||
|
typeof data === 'object' &&
|
||||||
|
'status' in data &&
|
||||||
|
'reason' in data
|
||||||
|
);
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user