feat: add organization settings and invitations
This commit is contained in:
@@ -24,6 +24,11 @@ function readString(source: Record<string, unknown>, key: string): string {
|
||||
return typeof value === "string" ? value.trim() : "";
|
||||
}
|
||||
|
||||
function readBoolean(source: Record<string, unknown>, key: string): boolean | null {
|
||||
const value = source[key];
|
||||
return typeof value === "boolean" ? value : null;
|
||||
}
|
||||
|
||||
function readStatus(value: unknown): OrganizationStatus | null {
|
||||
if (typeof value !== "string") {
|
||||
return null;
|
||||
@@ -51,12 +56,41 @@ export async function PATCH(request: Request, context: RouteContext): Promise<Re
|
||||
|
||||
const name = readString(body, "name");
|
||||
const slug = readString(body, "slug");
|
||||
const oidcIssuerUrl = readString(body, "oidcIssuerUrl");
|
||||
const oidcClientId = readString(body, "oidcClientId");
|
||||
const oidcClientSecret = readString(body, "oidcClientSecret");
|
||||
const oidcScopes = readString(body, "oidcScopes");
|
||||
const oidcRedirectUri = readString(body, "oidcRedirectUri");
|
||||
const status = "status" in body ? readStatus(body.status) : null;
|
||||
if ("status" in body && !status) {
|
||||
return jsonFailure("机构状态无效");
|
||||
}
|
||||
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;
|
||||
if ("registrationEnabled" in body && registrationEnabled === null) {
|
||||
return jsonFailure("注册开关无效");
|
||||
}
|
||||
if ("oidcEnabled" in body && oidcEnabled === null) {
|
||||
return jsonFailure("OIDC开关无效");
|
||||
}
|
||||
if ("oidcAutoProvision" in body && oidcAutoProvision === null) {
|
||||
return jsonFailure("OIDC自动开户配置无效");
|
||||
}
|
||||
|
||||
if (!name && !slug && !status) {
|
||||
if (
|
||||
!name &&
|
||||
!slug &&
|
||||
!status &&
|
||||
registrationEnabled === null &&
|
||||
oidcEnabled === null &&
|
||||
!oidcIssuerUrl &&
|
||||
!oidcClientId &&
|
||||
!oidcClientSecret &&
|
||||
!oidcScopes &&
|
||||
!oidcRedirectUri &&
|
||||
oidcAutoProvision === null
|
||||
) {
|
||||
return jsonFailure("请至少填写一个要更新的字段");
|
||||
}
|
||||
|
||||
@@ -64,6 +98,14 @@ export async function PATCH(request: Request, context: RouteContext): Promise<Re
|
||||
name?: string;
|
||||
slug?: string;
|
||||
status?: OrganizationStatus;
|
||||
registrationEnabled?: boolean;
|
||||
oidcEnabled?: boolean;
|
||||
oidcIssuerUrl?: string;
|
||||
oidcClientId?: string;
|
||||
oidcClientSecret?: string;
|
||||
oidcScopes?: string;
|
||||
oidcRedirectUri?: string;
|
||||
oidcAutoProvision?: boolean;
|
||||
updatedAt: Date;
|
||||
} = {
|
||||
updatedAt: new Date(),
|
||||
@@ -78,6 +120,30 @@ export async function PATCH(request: Request, context: RouteContext): Promise<Re
|
||||
if (status) {
|
||||
updateValues.status = status;
|
||||
}
|
||||
if (registrationEnabled !== null) {
|
||||
updateValues.registrationEnabled = registrationEnabled;
|
||||
}
|
||||
if (oidcEnabled !== null) {
|
||||
updateValues.oidcEnabled = oidcEnabled;
|
||||
}
|
||||
if (oidcIssuerUrl) {
|
||||
updateValues.oidcIssuerUrl = oidcIssuerUrl;
|
||||
}
|
||||
if (oidcClientId) {
|
||||
updateValues.oidcClientId = oidcClientId;
|
||||
}
|
||||
if (oidcClientSecret) {
|
||||
updateValues.oidcClientSecret = oidcClientSecret;
|
||||
}
|
||||
if (oidcScopes) {
|
||||
updateValues.oidcScopes = oidcScopes;
|
||||
}
|
||||
if (oidcRedirectUri) {
|
||||
updateValues.oidcRedirectUri = oidcRedirectUri;
|
||||
}
|
||||
if (oidcAutoProvision !== null) {
|
||||
updateValues.oidcAutoProvision = oidcAutoProvision;
|
||||
}
|
||||
|
||||
const database = getDatabase();
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user