From f975ecf551b8dadd873bba371f1efee707ad413a Mon Sep 17 00:00:00 2001 From: "saito.k" Date: Tue, 16 Apr 2024 05:08:04 +0000 Subject: [PATCH 1/2] =?UTF-8?q?Merged=20PR=20869:=20Functions=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task4085: Functions修正](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/4085) - メール送信対象のアカウント取得条件を修正 - プライマリー管理者の規約同意用のカラムがNULLであった場合は、そのアカウントにはメール送信しない。 - Entityの`@Column`で設定する型が実際のパラメータの型と異なっていたため修正 - 文字列のところをDateTimeとしていた ## レビューポイント - 修正内容の認識あっているか - テストケースは足りているか ## クエリの変更 - Repositoryを変更し、クエリが変更された場合は変更内容を確認する - Before/Afterのクエリ - https://ndstokyo.sharepoint.com/:f:/r/sites/Piranha/Shared%20Documents/General/OMDS/%E3%82%AF%E3%82%A8%E3%83%AA/4085?csf=1&web=1&e=WRec5O - 35行目に変更あり(規約系のカラムがNULLではないという条件を追加) ## 動作確認状況 - ローカルで確認 - 行った修正がデグレを発生させていないことを確認できるか - 既存のテスト結果に影響なし ## 補足 - 相談、参考資料などがあれば --- .../src/entity/account.entity.ts | 4 +- .../src/entity/license.entity.ts | 8 +-- dictation_function/src/entity/user.entity.ts | 7 ++- .../src/functions/licenseAlert.ts | 7 +++ dictation_function/src/test/common/utility.ts | 14 ++++- .../src/test/licenseAlert.spec.ts | 58 ++++++++++++++++++- 6 files changed, 86 insertions(+), 12 deletions(-) diff --git a/dictation_function/src/entity/account.entity.ts b/dictation_function/src/entity/account.entity.ts index 3a1c9af..15988a6 100644 --- a/dictation_function/src/entity/account.entity.ts +++ b/dictation_function/src/entity/account.entity.ts @@ -49,7 +49,7 @@ export class Account { @Column({ nullable: true, type: "datetime" }) deleted_at: Date | null; - @Column({ nullable: true, type: "datetime" }) + @Column({ nullable: true, type: "varchar" }) created_by: string | null; @CreateDateColumn({ @@ -58,7 +58,7 @@ export class Account { }) // defaultはSQLite用設定値.本番用は別途migrationで設定 created_at: Date; - @Column({ nullable: true, type: "datetime" }) + @Column({ nullable: true, type: "varchar"}) updated_by: string | null; @UpdateDateColumn({ diff --git a/dictation_function/src/entity/license.entity.ts b/dictation_function/src/entity/license.entity.ts index 56f2f00..ca38f5a 100644 --- a/dictation_function/src/entity/license.entity.ts +++ b/dictation_function/src/entity/license.entity.ts @@ -40,7 +40,7 @@ export class License { @Column({ nullable: true, type: "bigint", transformer: bigintTransformer }) delete_order_id: number | null; - @Column({ nullable: true, type: "datetime" }) + @Column({ nullable: true, type: "varchar" }) created_by: string | null; @CreateDateColumn({ @@ -49,7 +49,7 @@ export class License { }) created_at: Date; - @Column({ nullable: true, type: "datetime" }) + @Column({ nullable: true, type: "varchar" }) updated_by: string | null; @UpdateDateColumn({ @@ -89,7 +89,7 @@ export class LicenseAllocationHistory { @Column({ nullable: true, type: "datetime" }) deleted_at: Date | null; - @Column({ nullable: true, type: "datetime" }) + @Column({ nullable: true, type: "varchar" }) created_by: string | null; @CreateDateColumn({ @@ -98,7 +98,7 @@ export class LicenseAllocationHistory { }) created_at: Date; - @Column({ nullable: true, type: "datetime" }) + @Column({ nullable: true, type: "varchar" }) updated_by: string | null; @UpdateDateColumn({ diff --git a/dictation_function/src/entity/user.entity.ts b/dictation_function/src/entity/user.entity.ts index 10032d4..d8c78f9 100644 --- a/dictation_function/src/entity/user.entity.ts +++ b/dictation_function/src/entity/user.entity.ts @@ -31,6 +31,9 @@ export class User { @Column({ nullable: true, type: "varchar" }) accepted_eula_version: string | null; + @Column({ nullable: true, type: "varchar" }) + accepted_privacy_notice_version: string | null; + @Column({ nullable: true, type: "varchar" }) accepted_dpa_version: string | null; @@ -55,7 +58,7 @@ export class User { @Column({ nullable: true, type: "datetime" }) deleted_at: Date | null; - @Column({ nullable: true, type: "datetime" }) + @Column({ nullable: true, type: "varchar" }) created_by: string | null; @CreateDateColumn({ @@ -64,7 +67,7 @@ export class User { }) // defaultはSQLite用設定値.本番用は別途migrationで設定 created_at: Date; - @Column({ nullable: true, type: "datetime" }) + @Column({ nullable: true, type: "varchar" }) updated_by: string | null; @UpdateDateColumn({ diff --git a/dictation_function/src/functions/licenseAlert.ts b/dictation_function/src/functions/licenseAlert.ts index ad4119f..b3735fc 100644 --- a/dictation_function/src/functions/licenseAlert.ts +++ b/dictation_function/src/functions/licenseAlert.ts @@ -167,9 +167,16 @@ async function getAlertMailTargetAccount( // 第五のアカウントを取得 const accountRepository = datasource.getRepository(Account); + // 管理者ユーザーが規約に同意しているアカウントのみを取得 + // プロダクト バックログ項目 4073: [保守]システムに一度もログインしていないユーザーにはライセンスアラートメールを送信しないようにしたい の対応 const accounts = await accountRepository.find({ where: { tier: TIERS.TIER5, + primaryAdminUser: { + accepted_dpa_version: Not(IsNull()), + accepted_eula_version: Not(IsNull()), + accepted_privacy_notice_version: Not(IsNull()), + }, }, relations: { primaryAdminUser: true, diff --git a/dictation_function/src/test/common/utility.ts b/dictation_function/src/test/common/utility.ts index f675ed7..3db9a67 100644 --- a/dictation_function/src/test/common/utility.ts +++ b/dictation_function/src/test/common/utility.ts @@ -96,7 +96,7 @@ export const makeTestAccount = async ( locked: d?.locked ?? false, company_name: d?.company_name ?? "test inc.", verified: d?.verified ?? true, - deleted_at: d?.deleted_at ?? "", + deleted_at: d?.deleted_at ?? null, created_by: d?.created_by ?? "test_runner", created_at: d?.created_at ?? new Date(), updated_by: d?.updated_by ?? "updater", @@ -112,8 +112,16 @@ export const makeTestAccount = async ( account_id: accountId, role: d?.role ?? "admin none", author_id: d?.author_id ?? undefined, - accepted_eula_version: d?.accepted_eula_version ?? "1.0", - accepted_dpa_version: d?.accepted_dpa_version ?? "1.0", + accepted_eula_version: + d?.accepted_eula_version !== undefined + ? d.accepted_eula_version + : "1.0", + accepted_privacy_notice_version: + d?.accepted_privacy_notice_version !== undefined + ? d.accepted_privacy_notice_version + : "1.0", + accepted_dpa_version: + d?.accepted_dpa_version !== undefined ? d.accepted_dpa_version : "1.0", email_verified: d?.email_verified ?? true, auto_renew: d?.auto_renew ?? true, notification: d?.notification ?? true, diff --git a/dictation_function/src/test/licenseAlert.spec.ts b/dictation_function/src/test/licenseAlert.spec.ts index c3891a0..f013f47 100644 --- a/dictation_function/src/test/licenseAlert.spec.ts +++ b/dictation_function/src/test/licenseAlert.spec.ts @@ -80,7 +80,7 @@ describe("licenseAlert", () => { // redisからキャッシュが削除されていることを確認 const getAsync = promisify(redisClient.keys).bind(redisClient); const keys = await getAsync(`*`); - expect(keys).toHaveLength(0); + expect(keys).toHaveLength(0); }); it("ライセンス在庫不足メール、ライセンス失効警告メールが送信されること", async () => { @@ -224,6 +224,51 @@ describe("licenseAlert", () => { const keys = await getAsync(`*`); expect(keys).toHaveLength(0); }); + + it("規約同意していない管理者ユーザーに対して、ライセンス失効警告メール・在庫不足メールが送信されないこと", async () => { + if (!source) fail(); + const context = new InvocationContext(); + const sendgridMock = new SendGridServiceMock() as SendGridService; + const adb2cMock = new AdB2cServiceMock() as AdB2cService; + + // 呼び出し回数でテスト成否を判定 + const spySend = jest.spyOn(sendgridMock, "sendMail"); + + const currentDate = new DateWithZeroTime(); + const expiringSoonDate = new DateWithDayEndTime(currentDate.getTime()); + const { account, admin } = await makeTestAccount( + source, + { tier: 5 }, + { + external_id: "external_id5", + auto_renew: false, + accepted_dpa_version: null, + accepted_eula_version: null, + accepted_privacy_notice_version: null, + } + ); + await createLicense( + source, + 1, + expiringSoonDate, + account.id, + "NORMAL", + "Allocated", + admin.id, + null, + null, + null + ); + await licenseAlertProcessing( + context, + source, + redisClient, + sendgridMock, + adb2cMock + ); + // メール送信がされていないことを確認 + expect(spySend.mock.calls).toHaveLength(0); + }); }); // テスト用sendgrid @@ -305,6 +350,17 @@ export class AdB2cServiceMock { }, ], }, + { + id: "external_id5", + displayName: "test5", + identities: [ + { + signInType: ADB2C_SIGN_IN_TYPE.EMAILADDRESS, + issuer: "issuer", + issuerAssignedId: "test5@mail.com", + }, + ], + }, ]; return AdB2cMockUsers; } From 566da623bf51f28585857507c053da32f45999f1 Mon Sep 17 00:00:00 2001 From: "saito.k" Date: Wed, 17 Apr 2024 01:01:31 +0000 Subject: [PATCH 2/2] =?UTF-8?q?Merged=20PR=20873:=20dev=E5=8B=95=E4=BD=9C?= =?UTF-8?q?=E7=A2=BA=E8=AA=8D=E4=B8=8D=E5=85=B7=E5=90=88=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task4131: dev動作確認不具合修正](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/4131) - メール送信対象のアカウント取得条件を修正 - 第五階層はDPAの規約に同意することがないため、accepted_dpa_versionは常にNULLとなる - 取得条件にaccepted_dpa_versionがNOTNULLを追加するとカラムに値が入る契機がないのでアカウントを取得できなくなってしまっていた。 ## レビューポイント - 特になし ## 動作確認状況 - ローカルで確認 - 行った修正がデグレを発生させていないことを確認できるか - ほかのテストケースで使用しているユーザーデータをaccepted_dpa_versionはNULLの状態で作成するようにし、テストがすべて通ることを確認 ## 補足 - 相談、参考資料などがあれば --- .../src/functions/licenseAlert.ts | 3 ++- .../src/test/licenseAlert.spec.ts | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/dictation_function/src/functions/licenseAlert.ts b/dictation_function/src/functions/licenseAlert.ts index b3735fc..5e7fd6d 100644 --- a/dictation_function/src/functions/licenseAlert.ts +++ b/dictation_function/src/functions/licenseAlert.ts @@ -168,12 +168,13 @@ async function getAlertMailTargetAccount( // 第五のアカウントを取得 const accountRepository = datasource.getRepository(Account); // 管理者ユーザーが規約に同意しているアカウントのみを取得 + // 第五階層が同意する規約はeulaとprivacy_noticeのみであるため、それらがnullでないことを条件に追加 + // 管理者が規約同意していない = 一度もログインしていないアカウントであるため、そのアカウントにはアラートメールを送信しない // プロダクト バックログ項目 4073: [保守]システムに一度もログインしていないユーザーにはライセンスアラートメールを送信しないようにしたい の対応 const accounts = await accountRepository.find({ where: { tier: TIERS.TIER5, primaryAdminUser: { - accepted_dpa_version: Not(IsNull()), accepted_eula_version: Not(IsNull()), accepted_privacy_notice_version: Not(IsNull()), }, diff --git a/dictation_function/src/test/licenseAlert.spec.ts b/dictation_function/src/test/licenseAlert.spec.ts index f013f47..610fe7e 100644 --- a/dictation_function/src/test/licenseAlert.spec.ts +++ b/dictation_function/src/test/licenseAlert.spec.ts @@ -54,7 +54,7 @@ describe("licenseAlert", () => { const { account, admin } = await makeTestAccount( source, { tier: 5 }, - { external_id: "external_id1" } + { external_id: "external_id1", accepted_dpa_version: null } ); await createLicense( source, @@ -97,7 +97,11 @@ describe("licenseAlert", () => { const { account, admin } = await makeTestAccount( source, { tier: 5 }, - { external_id: "external_id2", auto_renew: false } + { + external_id: "external_id2", + auto_renew: false, + accepted_dpa_version: null, + } ); await createLicense( source, @@ -141,7 +145,7 @@ describe("licenseAlert", () => { const { account, admin } = await makeTestAccount( source, { tier: 5 }, - { external_id: "external_id3" } + { external_id: "external_id3", accepted_dpa_version: null } ); await createLicense( source, @@ -196,7 +200,11 @@ describe("licenseAlert", () => { const { account, admin } = await makeTestAccount( source, { tier: 5 }, - { external_id: "external_id4", auto_renew: true } + { + external_id: "external_id4", + auto_renew: true, + accepted_dpa_version: null, + } ); await createLicense( source, @@ -242,7 +250,6 @@ describe("licenseAlert", () => { { external_id: "external_id5", auto_renew: false, - accepted_dpa_version: null, accepted_eula_version: null, accepted_privacy_notice_version: null, }