route the pages removed in kc 24 at low level

This commit is contained in:
Joseph Garrone 2024-05-13 03:35:24 +02:00
parent 78517164d4
commit 8d21425ae0
6 changed files with 56 additions and 13 deletions

View File

@ -1,12 +1,12 @@
import { assert } from "tsafe/assert";
import { assert, type Equals } from "tsafe/assert";
import type { KeycloakAccountV1Version, KeycloakThemeAdditionalInfoExtensionVersion } from "./extensionVersions";
import { join as pathJoin } from "path";
import { join as pathJoin, dirname as pathDirname } from "path";
import { transformCodebase } from "../../tools/transformCodebase";
import type { BuildOptions } from "../buildOptions";
import * as fs from "fs/promises";
import { accountV1ThemeName } from "../../constants";
import { generatePom, BuildOptionsLike as BuildOptionsLike_generatePom } from "./generatePom";
import { existsSync } from "fs";
import { existsSync, readFileSync } from "fs";
import { isInside } from "../../tools/isInside";
import child_process from "child_process";
@ -37,9 +37,9 @@ export async function buildJar(params: {
await fs.writeFile(pathJoin(buildOptions.keycloakifyBuildDirPath, ".gitignore"), Buffer.from("*", "utf8"));
}
{
const srcMainResourcesRelativeDirPath = pathJoin("src", "main", "resources");
{
const keycloakThemesJsonFilePath = pathJoin(srcMainResourcesRelativeDirPath, "META-INF", "keycloak-themes.json");
const themePropertiesFilePathSet = new Set(
@ -87,6 +87,53 @@ export async function buildJar(params: {
});
}
route_legacy_pages: {
// NOTE: If there's no account theme there is no special target for keycloak 24 and up so we create
// the pages anyway. If there is an account pages, since we know that account-v1 is only support keycloak
// 24 in version 0.4 and up, we can safely break the route for legacy pages.
const doBreak: boolean = (() => {
switch (keycloakAccountV1Version) {
case null:
return false;
case "0.3":
return false;
default:
return true;
}
})();
if (doBreak) {
break route_legacy_pages;
}
(["register.ftl", "login-update-profile.ftl"] as const).forEach(pageId =>
buildOptions.themeNames.map(themeName => {
const ftlFilePath = pathJoin(srcMainResourcesRelativeDirPath, "themes", themeName, "login", pageId);
const ftlFileContent = readFileSync(ftlFilePath).toString("utf8");
const realPageId = (() => {
switch (pageId) {
case "register.ftl":
return "register-user-profile.ftl";
case "login-update-profile.ftl":
return "update-user-profile.ftl";
}
assert<Equals<typeof pageId, never>>(false);
})();
const modifiedFtlFileContent = ftlFileContent.replace(
`out["pageId"] = "${pageId}";`,
`out["pageId"] = "${pageId}"; out["realPageId"] = "${realPageId}";`
);
assert(modifiedFtlFileContent !== ftlFileContent);
fs.writeFile(pathJoin(pathDirname(ftlFilePath), realPageId), Buffer.from(modifiedFtlFileContent, "utf8"));
})
);
}
{
const { pomFileCode } = generatePom({
buildOptions,

View File

@ -5,7 +5,6 @@ export const loginThemePageIds = [
"webauthn-authenticate.ftl",
"webauthn-register.ftl",
"register.ftl",
"register-user-profile.ftl",
"info.ftl",
"error.ftl",
"login-reset-password.ftl",
@ -21,7 +20,6 @@ export const loginThemePageIds = [
"login-page-expired.ftl",
"login-config-totp.ftl",
"logout-confirm.ftl",
"update-user-profile.ftl",
"idp-review-user-profile.ftl",
"update-email.ftl",
"select-authenticator.ftl",

View File

@ -55,7 +55,6 @@ export default function Fallback(props: FallbackProps) {
case "login.ftl":
return <Login kcContext={kcContext} {...rest} />;
case "register.ftl":
case "register-user-profile.ftl":
return <Register kcContext={kcContext} {...rest} />;
case "info.ftl":
return <Info kcContext={kcContext} {...rest} />;
@ -84,7 +83,6 @@ export default function Fallback(props: FallbackProps) {
case "login-update-password.ftl":
return <LoginUpdatePassword kcContext={kcContext} {...rest} />;
case "login-update-profile.ftl":
case "update-user-profile.ftl":
return <LoginUpdateProfile kcContext={kcContext} {...rest} />;
case "login-idp-link-confirm.ftl":
return <LoginIdpLinkConfirm kcContext={kcContext} {...rest} />;

View File

@ -183,7 +183,7 @@ export declare namespace KcContext {
};
export type Register = Common & {
pageId: "register.ftl" | "register-user-profile.ftl";
pageId: "register.ftl";
profile: UserProfile;
url: {
registrationAction: string;
@ -452,7 +452,7 @@ export declare namespace KcContext {
};
export type LoginUpdateProfile = Common & {
pageId: "login-update-profile.ftl" | "update-user-profile.ftl";
pageId: "login-update-profile.ftl";
profile: UserProfile;
};

View File

@ -7,7 +7,7 @@ import type { I18n } from "../i18n";
import type { LazyOrNot } from "keycloakify/tools/LazyOrNot";
import type { UserProfileFormFieldsProps } from "keycloakify/login/UserProfileFormFields";
type LoginUpdateProfileProps = PageProps<Extract<KcContext, { pageId: "login-update-profile.ftl" | "update-user-profile.ftl" }>, I18n> & {
type LoginUpdateProfileProps = PageProps<Extract<KcContext, { pageId: "login-update-profile.ftl" }>, I18n> & {
UserProfileFormFields: LazyOrNot<(props: UserProfileFormFieldsProps) => JSX.Element>;
};

View File

@ -9,7 +9,7 @@ import { Markdown } from "keycloakify/tools/Markdown";
import type { KcContext } from "../kcContext";
import type { I18n } from "../i18n";
type RegisterProps = PageProps<Extract<KcContext, { pageId: "register.ftl" | "register-user-profile.ftl" }>, I18n> & {
type RegisterProps = PageProps<Extract<KcContext, { pageId: "register.ftl" }>, I18n> & {
UserProfileFormFields: LazyOrNot<(props: UserProfileFormFieldsProps) => JSX.Element>;
};