From 006ec1bfc03733a14512eed5344b352ed503a99e Mon Sep 17 00:00:00 2001 From: Blake Matthes Date: Wed, 29 Oct 2025 17:01:03 -0500 Subject: [PATCH] feat(user migration): user migration to the new app with a default password that will force reset --- .../app/admin/User/Create user.bru | 11 +++--- .../app/admin/User/Get roles.bru | 27 +++++++++++++++ .../environments/lst.bru | 2 +- app/main.ts | 2 ++ .../internal/auth/controller/userMigrate.ts | 34 +++++++++++++++++++ app/src/internal/auth/routes/register.ts | 2 +- .../system/controller/modules/baseModules.ts | 10 ++++++ .../system/controller/modules/modules.json | 30 ++++++++++++++++ lstV2/server/services/auth/authService.ts | 33 +++++++++--------- 9 files changed, 127 insertions(+), 24 deletions(-) create mode 100644 LogisticsSupportTool_API_DOCS/app/admin/User/Get roles.bru create mode 100644 app/src/internal/auth/controller/userMigrate.ts create mode 100644 app/src/internal/system/controller/modules/baseModules.ts create mode 100644 app/src/internal/system/controller/modules/modules.json diff --git a/LogisticsSupportTool_API_DOCS/app/admin/User/Create user.bru b/LogisticsSupportTool_API_DOCS/app/admin/User/Create user.bru index 2cacd9f..88ea81e 100644 --- a/LogisticsSupportTool_API_DOCS/app/admin/User/Create user.bru +++ b/LogisticsSupportTool_API_DOCS/app/admin/User/Create user.bru @@ -5,17 +5,16 @@ meta { } post { - url: {{url}}/lst/api/admin/users - body: none + url: {{url}}/lst/api/admin/users/new + body: json auth: inherit } body:json { { - "username":"matthes01", - "name":"blake", - "email":"blake.matthes@alpla.com", - "password":"nova0511" + "username":"hardin001", + "email":"ryan.hardin@alpla.com", + "password":"Alpla2025!" } } diff --git a/LogisticsSupportTool_API_DOCS/app/admin/User/Get roles.bru b/LogisticsSupportTool_API_DOCS/app/admin/User/Get roles.bru new file mode 100644 index 0000000..91de1ce --- /dev/null +++ b/LogisticsSupportTool_API_DOCS/app/admin/User/Get roles.bru @@ -0,0 +1,27 @@ +meta { + name: Get roles + type: http + seq: 7 +} + +patch { + url: {{url}}/lst/api/admin/users/:userID/grant + body: json + auth: inherit +} + +params:path { + userID: 0hlO48C7Jw1J804FxrCnonKjQ2zh48R6 +} + +body:json { + { + "module":"siloAdjustments", + "role":"viewer" + } +} + +settings { + encodeUrl: true + timeout: 0 +} diff --git a/LogisticsSupportTool_API_DOCS/environments/lst.bru b/LogisticsSupportTool_API_DOCS/environments/lst.bru index 756bd84..e1d91e8 100644 --- a/LogisticsSupportTool_API_DOCS/environments/lst.bru +++ b/LogisticsSupportTool_API_DOCS/environments/lst.bru @@ -1,5 +1,5 @@ vars { - url: https://usiow2prod.alpla.net + url: http://localhost:4200 session_cookie: urlv2: http://localhost:3000 jwtV2: diff --git a/app/main.ts b/app/main.ts index e2d65fd..a63196a 100644 --- a/app/main.ts +++ b/app/main.ts @@ -9,6 +9,7 @@ import morgan from "morgan"; import os from "os"; import { dirname, join } from "path"; import { fileURLToPath } from "url"; +import { userMigrate } from "./src/internal/auth/controller/userMigrate.js"; import { schedulerManager } from "./src/internal/logistics/controller/schedulerManager.js"; import { printers } from "./src/internal/ocp/printers/printers.js"; import { setupRoutes } from "./src/internal/routerHandler/routeHandler.js"; @@ -188,6 +189,7 @@ const main = async () => { // start up the v1listener v1Listener(); + userMigrate(); }, 5 * 1000); // start the server up diff --git a/app/src/internal/auth/controller/userMigrate.ts b/app/src/internal/auth/controller/userMigrate.ts new file mode 100644 index 0000000..8eb0038 --- /dev/null +++ b/app/src/internal/auth/controller/userMigrate.ts @@ -0,0 +1,34 @@ +import { Client } from "pg"; +import { auth } from "../../../pkg/auth/auth.js"; +import { createLogger } from "../../../pkg/logger/logger.js"; + +export const userMigrate = async () => { + const log = createLogger({ module: "admin", subModule: "migrate users" }); + const client = new Client({ + connectionString: process.env.DATABASE_URL_V1, + }); + + await client.connect(); + + const res = await client.query(` + SELECT username, email + FROM users + `); + + for (const u of res.rows) { + log.info({}, `${u.username}, being transferred`); + try { + await auth.api.signUpEmail({ + body: { + username: u.username, + name: u.username, + email: u.email, + password: "Alpla2025!", + }, + }); + log.info({}, `${u.username}, transferred`); + } catch (e) { + log.info({}, `${u.username}, already existed`); + } + } +}; diff --git a/app/src/internal/auth/routes/register.ts b/app/src/internal/auth/routes/register.ts index 7e10dbe..719e03c 100644 --- a/app/src/internal/auth/routes/register.ts +++ b/app/src/internal/auth/routes/register.ts @@ -53,7 +53,7 @@ router.post("/", async (req: Request, res: Response) => { } if (err instanceof APIError) { - return res.status(400).json({ + return res.status(200).json({ success: false, message: err.message, error: err.status, diff --git a/app/src/internal/system/controller/modules/baseModules.ts b/app/src/internal/system/controller/modules/baseModules.ts new file mode 100644 index 0000000..657e707 --- /dev/null +++ b/app/src/internal/system/controller/modules/baseModules.ts @@ -0,0 +1,10 @@ +import { readFileSync } from "fs"; +import path from "path"; +import { fileURLToPath } from "url"; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +export const baseModules = async () => { + const modulePath = path.resolve(__dirname, "./modules.json"); +}; diff --git a/app/src/internal/system/controller/modules/modules.json b/app/src/internal/system/controller/modules/modules.json new file mode 100644 index 0000000..7fddd2d --- /dev/null +++ b/app/src/internal/system/controller/modules/modules.json @@ -0,0 +1,30 @@ +[ + { + "name": "plantToken", + "value": "test3", + "description": "The plant token for the plant IE: test3 or usday1", + "moduleName": "system", + "roles": ["systemAdmin"] + }, + { + "name": "dbServer", + "value": "usmcd1vms036", + "description": "What is the db server", + "moduleName": "system", + "roles": ["systemAdmin"] + }, + { + "name": "v1Server", + "value": "localhost", + "description": "What is the port the v1app is on", + "moduleName": "system", + "roles": ["systemAdmin"] + }, + { + "name": "v1Port", + "value": "3000", + "description": "What is the port the v1app is on", + "moduleName": "system", + "roles": ["systemAdmin"] + } +] diff --git a/lstV2/server/services/auth/authService.ts b/lstV2/server/services/auth/authService.ts index c6a394a..82ae294 100644 --- a/lstV2/server/services/auth/authService.ts +++ b/lstV2/server/services/auth/authService.ts @@ -1,40 +1,41 @@ import { OpenAPIHono } from "@hono/zod-openapi"; + import login from "./routes/login.js"; import register from "./routes/register.js"; import session from "./routes/session.js"; import getAccess from "./routes/user/getUserRoles.js"; -import setAccess from "./routes/userAdmin/setUserRoles.js"; import profile from "./routes/user/profileUpdate.js"; -import { areRolesIn } from "./utils/roleCheck.js"; import createUser from "./routes/userAdmin/createUser.js"; -import allUsers from "./routes/userAdmin/getUsers.js"; -import updateUser from "./routes/userAdmin/updateUser.js"; import allUserRoles from "./routes/userAdmin/getAllUserRoles.js"; +import allUsers from "./routes/userAdmin/getUsers.js"; +import setAccess from "./routes/userAdmin/setUserRoles.js"; +import updateUser from "./routes/userAdmin/updateUser.js"; import { massAccountCreation } from "./utils/DefaultAccountCreation.js"; +import { areRolesIn } from "./utils/roleCheck.js"; const app = new OpenAPIHono(); // run the role check setTimeout(() => { - areRolesIn(); + areRolesIn(); }, 5000); const routes = [ - login, - register, - session, - profile, - getAccess, - setAccess, - createUser, - allUsers, - allUserRoles, - updateUser, + login, + register, + session, + profile, + getAccess, + setAccess, + createUser, + allUsers, + allUserRoles, + updateUser, ] as const; // app.route("/server", modules); const appRoutes = routes.forEach((route) => { - app.route("/auth", route); + app.route("/auth", route); }); // setTimeout(() => {