fix: use real settings data boundaries
This commit is contained in:
@@ -37,6 +37,10 @@ function readStatus(value: unknown): OrganizationStatus | null {
|
||||
return ORGANIZATION_STATUSES.find((status) => status === value) ?? null;
|
||||
}
|
||||
|
||||
function isValidSlug(value: string): boolean {
|
||||
return /^[a-z0-9][a-z0-9-]{1,47}$/.test(value) && !value.endsWith("-");
|
||||
}
|
||||
|
||||
export async function PATCH(request: Request, context: RouteContext): Promise<Response> {
|
||||
const { id } = await context.params;
|
||||
const auth = await requirePermission("organization:manage", {
|
||||
@@ -55,7 +59,7 @@ export async function PATCH(request: Request, context: RouteContext): Promise<Re
|
||||
}
|
||||
|
||||
const name = readString(body, "name");
|
||||
const slug = readString(body, "slug");
|
||||
const slug = readString(body, "slug").toLowerCase();
|
||||
const oidcIssuerUrl = readString(body, "oidcIssuerUrl");
|
||||
const oidcClientId = readString(body, "oidcClientId");
|
||||
const oidcClientSecret = readString(body, "oidcClientSecret");
|
||||
@@ -66,6 +70,12 @@ export async function PATCH(request: Request, context: RouteContext): Promise<Re
|
||||
if ("status" in body && !status) {
|
||||
return jsonFailure("机构状态无效");
|
||||
}
|
||||
if ("slug" in body && !slug) {
|
||||
return jsonFailure("机构标识不能为空");
|
||||
}
|
||||
if (slug && !isValidSlug(slug)) {
|
||||
return jsonFailure("机构标识仅支持小写字母、数字和连字符,长度 2-48 位,且不能以连字符结尾");
|
||||
}
|
||||
const registrationEnabled = "registrationEnabled" in body ? readBoolean(body, "registrationEnabled") : null;
|
||||
const oidcEnabled = "oidcEnabled" in body ? readBoolean(body, "oidcEnabled") : null;
|
||||
const oidcAutoProvision = "oidcAutoProvision" in body ? readBoolean(body, "oidcAutoProvision") : null;
|
||||
|
||||
Reference in New Issue
Block a user