Revert "merge: sync GitHub staging to Gitea"
Deploy staging to test server / deploy (push) Failing after 14m49s
Deploy staging to test server / deploy (push) Failing after 14m49s
This reverts commita55c69115d, reversing changes made to02c9c9f3d6.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import type { IdentityUser } from "@/modules/identity/contracts";
|
||||
|
||||
export type AdminRole = "admin" | "viewer";
|
||||
export type AdminRole = "admin";
|
||||
|
||||
export type AdminAccessResult =
|
||||
| { allowed: true; role: AdminRole }
|
||||
@@ -11,13 +11,8 @@ export function authorizeAdminAccess(
|
||||
access: "read" | "write",
|
||||
): AdminAccessResult {
|
||||
if (!user) return { allowed: false, status: 401 };
|
||||
const role: AdminRole | null = user.role.includes("admin")
|
||||
? "admin"
|
||||
: user.role.includes("viewer")
|
||||
? "viewer"
|
||||
: null;
|
||||
if (!role || (access === "write" && role !== "admin")) {
|
||||
if (!user.role.includes("admin")) {
|
||||
return { allowed: false, status: 403 };
|
||||
}
|
||||
return { allowed: true, role };
|
||||
return { allowed: true, role: "admin" };
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ export async function requireAdminSession(
|
||||
|
||||
try {
|
||||
const user = await requireIdentityUser(
|
||||
getIdentityAuthServices().admin.api,
|
||||
getIdentityAuthServices().user.api,
|
||||
new Headers(await headers()),
|
||||
);
|
||||
const authorization = authorizeAdminAccess(user, access);
|
||||
|
||||
@@ -5,35 +5,40 @@ import { Pool, type QueryResultRow } from "pg";
|
||||
import { readDatabaseUrl } from "@/lib/db/config";
|
||||
|
||||
const poolGlobal = globalThis as typeof globalThis & {
|
||||
jyotishaAdminReadPool?: Pool;
|
||||
jyotishaAdminDatabasePool?: Pool;
|
||||
};
|
||||
|
||||
export function adminReadPool(): Pool {
|
||||
export function adminDatabasePool(): Pool {
|
||||
if (
|
||||
process.env.AUTH_PROVIDER?.trim() !== "self-hosted"
|
||||
|| process.env.APP_ENV?.trim() === "production"
|
||||
) {
|
||||
throw new Error("admin reads require the staging self-hosted identity service");
|
||||
throw new Error("admin database requests require the staging self-hosted identity service");
|
||||
}
|
||||
poolGlobal.jyotishaAdminReadPool ??= new Pool({
|
||||
poolGlobal.jyotishaAdminDatabasePool ??= new Pool({
|
||||
connectionString: readDatabaseUrl(process.env, "ADMIN_DATABASE_URL"),
|
||||
max: 10,
|
||||
idleTimeoutMillis: 30_000,
|
||||
connectionTimeoutMillis: 5_000,
|
||||
allowExitOnIdle: true,
|
||||
application_name: "jyotisha-admin-read",
|
||||
application_name: "jyotisha-admin-database",
|
||||
});
|
||||
return poolGlobal.jyotishaAdminReadPool;
|
||||
return poolGlobal.jyotishaAdminDatabasePool;
|
||||
}
|
||||
|
||||
export async function queryAdminRows<T extends QueryResultRow>(
|
||||
sql: string,
|
||||
values: readonly unknown[] = [],
|
||||
): Promise<T[]> {
|
||||
const result = await adminReadPool().query<T>(sql, [...values]);
|
||||
const result = await adminDatabasePool().query<T>(sql, [...values]);
|
||||
return result.rows;
|
||||
}
|
||||
|
||||
export function isPostgresError(error: unknown): error is { code: string } {
|
||||
return typeof error === "object" && error !== null && "code" in error
|
||||
&& typeof (error as { code?: unknown }).code === "string";
|
||||
}
|
||||
|
||||
export type PageResult<T> = { data: T[]; total: number };
|
||||
|
||||
export function pageOffset(page: number, pageSize: number) {
|
||||
|
||||
@@ -18,7 +18,7 @@ export type AdminIdentity = {
|
||||
id: string;
|
||||
email: string;
|
||||
name: string;
|
||||
role: "admin" | "viewer";
|
||||
role: "admin";
|
||||
};
|
||||
|
||||
const apiBase = "/api/admin";
|
||||
@@ -165,7 +165,7 @@ export const adminAccessControlProvider: AccessControlProvider = {
|
||||
}
|
||||
return role === "admin"
|
||||
? { can: true }
|
||||
: { can: false, reason: "viewer 仅可查看" };
|
||||
: { can: false, reason: "无管理员权限" };
|
||||
},
|
||||
options: {
|
||||
buttons: { enableAccessControl: true, hideIfUnauthorized: true },
|
||||
|
||||
Reference in New Issue
Block a user