From 04c726e96472ba249dfb50a008d15a8384b58afc Mon Sep 17 00:00:00 2001 From: "makabe.t" Date: Thu, 7 Mar 2024 11:47:53 +0000 Subject: [PATCH] =?UTF-8?q?Merged=20PR=20808:=20function=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task3879: function修正](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/3879) - 元PBI or タスクへのリンク(内容・目的などはそちらにあるはず) - 何をどう変更したか、追加したライブラリなど - このPull Requestでの対象/対象外 - 影響範囲(他の機能にも影響があるか) ## レビューポイント - 特にレビューしてほしい箇所 - 軽微なものや自明なものは記載不要 - 修正範囲が大きい場合などに記載 - 全体的にや仕様を満たしているか等は本当に必要な時のみ記載 - 修正箇所がほかの機能に影響していないか ## UIの変更 - Before/Afterのスクショなど - スクショ置き場 ## クエリの変更 - Repositoryを変更し、クエリが変更された場合は変更内容を確認する - Before/Afterのクエリ - クエリ置き場 ## 動作確認状況 - ローカルで確認、develop環境で確認など - 行った修正がデグレを発生させていないことを確認できるか - 具体的にどのような確認をしたか - どのケースに対してどのような手段でデグレがないことを担保しているか ## 補足 - 相談、参考資料などがあれば --- .../src/blobstorage/types/guards.ts | 40 ++++++++++++------- .../src/blobstorage/types/types.ts | 2 - dictation_function/src/constants/index.ts | 6 +-- .../src/functions/importUsers.ts | 15 ++++--- .../src/features/users/users.service.ts | 14 ++++++- 5 files changed, 51 insertions(+), 26 deletions(-) diff --git a/dictation_function/src/blobstorage/types/guards.ts b/dictation_function/src/blobstorage/types/guards.ts index b16a241..c0bbbb0 100644 --- a/dictation_function/src/blobstorage/types/guards.ts +++ b/dictation_function/src/blobstorage/types/guards.ts @@ -1,3 +1,4 @@ +import { InvocationContext } from "@azure/functions"; import { IMPORT_USERS_STAGES } from "../../constants"; import { ErrorRow, ImportData, ImportJson, StageJson } from "./types"; @@ -48,107 +49,116 @@ export const isStageJson = (obj: any): obj is StageJson => { return true; }; -const isImportData = (obj: any): obj is ImportData => { +const isImportData = ( + context: InvocationContext, + obj: any +): obj is ImportData => { if (typeof obj !== "object") return false; const importData = obj as ImportData; if (importData.name === undefined || typeof importData.name !== "string") { + context.log("name is missing or not a string"); return false; } if (importData.email === undefined || typeof importData.email !== "string") { + context.log("email is missing or not a string"); return false; } if (importData.role === undefined || typeof importData.role !== "number") { + context.log("role is missing or not a number"); return false; } if ( importData.author_id !== undefined && typeof importData.author_id !== "string" ) { + context.log("author_id is missing or not a string"); return false; } if ( importData.auto_renew === undefined || typeof importData.auto_renew !== "number" ) { + context.log("auto_renew is missing or not a number"); return false; } if ( importData.notification === undefined || typeof importData.notification !== "number" ) { + context.log("notification is missing or not a number"); return false; } if ( importData.encryption !== undefined && typeof importData.encryption !== "number" ) { + context.log("encryption is missing or not a number"); return false; } if ( importData.encryption_password !== undefined && typeof importData.encryption_password !== "string" ) { + context.log("encryption_password is missing or not a string"); return false; } if ( importData.prompt !== undefined && typeof importData.prompt !== "number" ) { + context.log("prompt is missing or not a number"); return false; } return true; }; -export const isImportJson = (obj: any): obj is ImportJson => { +export const isImportJson = ( + context: InvocationContext, + obj: any +): obj is ImportJson => { if (typeof obj !== "object") return false; const importJson = obj as ImportJson; if ( importJson.account_id === undefined || typeof importJson.account_id !== "number" ) { + context.log("account_id is missing or not a number"); return false; } if ( importJson.user_id === undefined || typeof importJson.user_id !== "number" ) { + context.log("user_id is missing or not a number"); return false; } if ( importJson.user_role === undefined || typeof importJson.user_role !== "string" ) { + context.log("user_role is missing or not a string"); return false; } if ( importJson.external_id === undefined || typeof importJson.external_id !== "string" ) { - return false; - } - if ( - importJson.delegation_account_id !== undefined && - typeof importJson.delegation_account_id !== "number" - ) { - return false; - } - if ( - importJson.delegation_user_id !== undefined && - typeof importJson.delegation_user_id !== "number" - ) { + context.log("external_id is missing or not a string"); return false; } if ( importJson.file_name === undefined || typeof importJson.file_name !== "string" ) { + context.log("file_name is missing or not a string"); return false; } if ( importJson.data === undefined || !Array.isArray(importJson.data) || - !importJson.data.every((x) => isImportData(x)) + !importJson.data.every((x) => isImportData(context, x)) ) { + context.log("data is missing or not an array of ImportData"); return false; } return true; diff --git a/dictation_function/src/blobstorage/types/types.ts b/dictation_function/src/blobstorage/types/types.ts index fec4ed4..97ba857 100644 --- a/dictation_function/src/blobstorage/types/types.ts +++ b/dictation_function/src/blobstorage/types/types.ts @@ -22,8 +22,6 @@ export type ImportJson = { user_id: number; user_role: RoleType; external_id: string; - delegation_account_id?: number | undefined; - delegation_user_id?: number | undefined; file_name: string; date: number; data: ImportData[]; diff --git a/dictation_function/src/constants/index.ts b/dictation_function/src/constants/index.ts index 88e3e3b..f955c2d 100644 --- a/dictation_function/src/constants/index.ts +++ b/dictation_function/src/constants/index.ts @@ -329,9 +329,9 @@ export const IMPORT_USERS_STAGES = { * @const {string} */ export const RoleNumberMap: Record = { - 1: USER_ROLES.NONE, - 2: USER_ROLES.AUTHOR, - 3: USER_ROLES.TYPIST, + 0: USER_ROLES.NONE, + 1: USER_ROLES.AUTHOR, + 2: USER_ROLES.TYPIST, } as const; export const SYSTEM_IMPORT_USERS = "import-users"; diff --git a/dictation_function/src/functions/importUsers.ts b/dictation_function/src/functions/importUsers.ts index 6294c8b..40a281b 100644 --- a/dictation_function/src/functions/importUsers.ts +++ b/dictation_function/src/functions/importUsers.ts @@ -16,6 +16,7 @@ import { createErrorObject } from "../common/errors/utils"; import { sign, getJwtKey } from "../common/jwt"; import { AccessToken, SystemAccessToken } from "../common/jwt/types"; import { isImportJson, isStageJson } from "../blobstorage/types/guards"; +import https from "https"; export async function importUsersProcessing( context: InvocationContext, @@ -128,7 +129,7 @@ export async function importUsersProcessing( // 一括登録ユーザー一覧をメモリ上に展開 const imports = importsData === undefined ? undefined : JSON.parse(importsData); - if (!isImportJson(imports)) { + if (!isImportJson(context, imports)) { throw new Error(`json: ${targetFileName} is invalid`); } @@ -228,6 +229,7 @@ export async function importUsersProcessing( }, { headers: { authorization: `Bearer ${systemToken}` }, + httpsAgent: new https.Agent({ rejectUnauthorized: false }), } ); @@ -317,17 +319,20 @@ export async function addUser( role: RoleNumberMap[user.role], autoRenew: user.auto_renew === 1, notification: user.notification === 1, - authorId: user.author_id, - encryption: user.encryption === 1, - encryptionPassword: user.encryption_password, - prompt: user.prompt === 1, + authorId: user.role === 1 ? user.author_id : undefined, + encryption: user.role === 1 ? user.encryption === 1 : undefined, + encryptionPassword: + user.encryption === 1 ? user.encryption_password : undefined, + prompt: user.role === 1 ? user.prompt === 1 : undefined, }, { headers: { authorization: `Bearer ${token}` }, + httpsAgent: new https.Agent({ rejectUnauthorized: false }), } ); } catch (e) { context.error(e); + context.error(JSON.stringify(e.response?.data)); throw e; } finally { context.log(`[OUT] addUser`); diff --git a/dictation_server/src/features/users/users.service.ts b/dictation_server/src/features/users/users.service.ts index 2df3703..957dde1 100644 --- a/dictation_server/src/features/users/users.service.ts +++ b/dictation_server/src/features/users/users.service.ts @@ -1651,7 +1651,19 @@ export class UsersService { external_id: user.external_id, file_name: fileName, date: Math.floor(now.getTime() / 1000), - data: users, + data: users.map((user) => { + return { + name: user.name, + email: user.email, + role: user.role, + author_id: user.authorId, + auto_renew: user.autoRenew, + notification: user.notification, + encryption: user.encryption, + encryption_password: user.encryptionPassword, + prompt: user.prompt, + }; + }), }); // Blobにファイルをアップロード(ユーザー一括登録用)