ken_nogi/NodeSrv/apps/org-master-sync/scripts/fix-disabled-flags.js
Kenichiro NOGI ce58cb4be4 初回コミット: dev配下(NodeSrv/Pleasanter等)をGitea管理下に統合
GitHub(nextgroup2706/ken_nogi)は今後使わず自社Gitea運用に切替え。
NodeSrvは旧リポジトリの履歴を破棄しファイルのみ統合(Dokploy用サービスアカウントは
別途mygit-admin/NodeSrv.gitに履歴あり)。notepmエクスポート(12GB)とPleasanter
インストーラzip(208MB)はサイズが大きいため.gitignoreで除外。

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-04 15:37:06 +09:00

93 lines
3.4 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use strict";
/*
* import-prod-to-test.js がDisabledフィールドを渡していなかったため、
* テスト環境で本番のDisabled(無効化)状態が未反映になっていたのを事後修正する。
*
* 実行:
* PLEASANTER_TEST_BASE_URL=... PLEASANTER_TEST_API_KEY=... node scripts/fix-disabled-flags.js
*/
const fs = require("fs");
const path = require("path");
const BASE_URL = process.env.PLEASANTER_TEST_BASE_URL;
const API_KEY = process.env.PLEASANTER_TEST_API_KEY;
const DATA_DIR = path.join(__dirname, "..", "data");
if (!BASE_URL || !API_KEY) {
console.error("PLEASANTER_TEST_BASE_URL / PLEASANTER_TEST_API_KEY が未設定");
process.exit(1);
}
function parseCsv(text) {
const rows = [];
let row = [], field = "", inQuotes = false;
const s = text.replace(/^/, "");
for (let i = 0; i < s.length; i++) {
const c = s[i];
if (inQuotes) {
if (c === '"') { if (s[i + 1] === '"') { field += '"'; i++; } else inQuotes = false; }
else field += c;
} else {
if (c === '"') inQuotes = true;
else if (c === ",") { row.push(field); field = ""; }
else if (c === "\n") { row.push(field); rows.push(row); row = []; field = ""; }
else if (c === "\r") { /* skip */ }
else field += c;
}
}
if (field.length || row.length) { row.push(field); rows.push(row); }
const header = rows[0];
return rows.slice(1).filter(r => r.length === header.length).map(r => Object.fromEntries(header.map((h, i) => [h, r[i]])));
}
async function api(pathname, body) {
const res = await fetch(BASE_URL.replace(/\/$/, "") + pathname, {
method: "POST",
headers: { "Content-Type": "application/json; charset=utf-8" },
body: JSON.stringify({ ApiVersion: "1.1", ApiKey: API_KEY, ...body }),
});
const data = await res.json();
if (!res.ok || data.StatusCode !== 200) {
throw new Error(`${pathname} failed: ${res.status} ${JSON.stringify(data)}`);
}
return data;
}
async function main() {
const deptIdMap = JSON.parse(fs.readFileSync(path.join(DATA_DIR, "test-import-maps", "dept-id-map.json"), "utf8"));
const userIdMap = JSON.parse(fs.readFileSync(path.join(DATA_DIR, "test-import-maps", "user-id-map.json"), "utf8"));
const depts = parseCsv(fs.readFileSync(path.join(DATA_DIR, "pleasanter_depts.csv"), "utf8"));
const users = parseCsv(fs.readFileSync(path.join(DATA_DIR, "pleasanter_users.csv"), "utf8"));
let deptOk = 0, deptNg = 0;
for (const d of depts.filter(x => x.Disabled === "true")) {
const newId = deptIdMap[d.DeptId];
if (!newId) { console.error("[dept] マッピング無し", d.DeptId, d.DeptName); deptNg++; continue; }
try {
await api(`/api/depts/${newId}/update`, { Disabled: true });
deptOk++;
} catch (e) {
console.error("[dept]", d.DeptId, "->", newId, e.message);
deptNg++;
}
}
console.log(`Depts Disabled反映: ok=${deptOk} ng=${deptNg}`);
let userOk = 0, userNg = 0;
for (const u of users.filter(x => x.Disabled === "true" && x.UserId !== "1")) {
const newId = userIdMap[u.UserId];
if (!newId) { console.error("[user] マッピング無し", u.UserId, u.LoginId); userNg++; continue; }
try {
await api(`/api/users/${newId}/update`, { Disabled: true });
userOk++;
} catch (e) {
console.error("[user]", u.UserId, "->", newId, e.message);
userNg++;
}
}
console.log(`Users Disabled反映: ok=${userOk} ng=${userNg}`);
}
main().catch(e => { console.error(e); process.exit(1); });