fix(admin-portal): drop the direct set-password dialog; the emailed reset stays

An admin could set a colleague's password to a value of their choosing. Only the
emailed temporary-password reset remains.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
ngqileandClaude Opus 5.5 committed 2026-11-26 22:29:38 +08:00
1 parent 92c8ad3b25
commit 816c8bcb5e
11 files changed
+3 -314

No files matched your search

@@ -1,42 +0,0 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
const mocks = vi.hoisted(() => ({ callMobileApi: vi.fn(), getToken: vi.fn() }));
vi.mock("@/app/lib/server/mobileApi", () => ({ callMobileApi: mocks.callMobileApi }));
vi.mock("@/app/lib/server/session", () => ({ getToken: mocks.getToken }));
import { POST } from "./route";
function ctx(id: string) {
return { params: Promise.resolve({ id }) };
}
function req(body: unknown) {
return new Request("http://localhost/api/users/9/change-password", {
method: "POST",
body: JSON.stringify(body),
}) as unknown as Parameters<typeof POST>[0];
}
beforeEach(() => {
mocks.callMobileApi.mockReset();
mocks.getToken.mockReset();
});
describe("POST /api/users/[id]/change-password", () => {
it("requires a password", async () => {
mocks.getToken.mockResolvedValue("jwt-abc");
const res = await POST(req({}), ctx("9"));
expect(res.status).toBe(400);
expect(mocks.callMobileApi).not.toHaveBeenCalled();
});
it("forwards to POST /api/admin/users/{id}/changePassword", async () => {
mocks.getToken.mockResolvedValue("jwt-abc");
mocks.callMobileApi.mockResolvedValue({ ok: true, data: { updated: 1 } });
await POST(req({ password: "N3wPassw0rd!" }), ctx("9"));
expect(mocks.callMobileApi).toHaveBeenCalledWith("/api/admin/users/9/changePassword", {
method: "POST",
body: { password: "N3wPassw0rd!" },
token: "jwt-abc",
});
});
});
@@ -1,23 +0,0 @@
import { NextResponse, type NextRequest } from "next/server";
import { callMobileApi } from "@/app/lib/server/mobileApi";
import { getToken } from "@/app/lib/server/session";
import { errorResponse, unauthorized, badRequest } from "@/app/lib/server/apiRoute";
type Ctx = { params: Promise<{ id: string }> };
export async function POST(req: NextRequest, { params }: Ctx) {
const token = await getToken();
if (!token) return unauthorized();
const { id } = await params;
const body = await req.json().catch(() => ({}));
const password = (body as { password?: string }).password;
if (!password) return badRequest("password is required.");
const result = await callMobileApi<{ updated: number }>(`/api/admin/users/${encodeURIComponent(id)}/changePassword`, {
method: "POST",
body: { password },
token,
});
if (!result.ok) return errorResponse(result);
return NextResponse.json(result.data);
}