Remove profile.attributesByName from the kcContext

This commit is contained in:
Joseph Garrone
2024-05-28 01:05:35 +02:00
parent fdfcd78f02
commit a217f617d8
4 changed files with 9 additions and 26 deletions

View File

@ -286,6 +286,9 @@ function decodeHtmlEntities(htmlStr){
<#-- Remove realmAttributes added by https://github.com/jcputney/keycloak-theme-additional-info-extension for peace of mind. --> <#-- Remove realmAttributes added by https://github.com/jcputney/keycloak-theme-additional-info-extension for peace of mind. -->
are_same_path(path, []) && are_same_path(path, []) &&
key == "realmAttributes" key == "realmAttributes"
) || (
<#-- attributesByName adds a lot of noise to the output and is not needed -->
are_same_path(path, ["profile"]) && key == "attributesByName"
) )
> >
<#local out_seq += ["/*" + path?join(".") + "." + key + " excluded*/"]> <#local out_seq += ["/*" + path?join(".") + "." + key + " excluded*/"]>

View File

@ -586,7 +586,6 @@ export declare namespace KcContext {
export type UserProfile = { export type UserProfile = {
attributes: Attribute[]; attributes: Attribute[];
attributesByName: Record<string, Attribute>;
html5DataAnnotations?: Record<string, string>; html5DataAnnotations?: Record<string, string>;
}; };

View File

@ -39,9 +39,9 @@ export function createGetKcContext<
if (mockPageId !== undefined && realKcContext === undefined) { if (mockPageId !== undefined && realKcContext === undefined) {
//TODO maybe trow if no mock fo custom page //TODO maybe trow if no mock fo custom page
warn_that_mock_is_enbaled: { warn_that_mock_is_enabled: {
if (isStorybook) { if (isStorybook) {
break warn_that_mock_is_enbaled; break warn_that_mock_is_enabled;
} }
console.log( console.log(
@ -118,7 +118,6 @@ export function createGetKcContext<
const { attributes } = kcContextDefaultMock.profile; const { attributes } = kcContextDefaultMock.profile;
id<KcContext.Register>(kcContext).profile.attributes = []; id<KcContext.Register>(kcContext).profile.attributes = [];
id<KcContext.Register>(kcContext).profile.attributesByName = {};
const partialAttributes = [ const partialAttributes = [
...(( ...((
@ -153,9 +152,6 @@ export function createGetKcContext<
id<KcContext.Register>(kcContext).profile.attributes.push( id<KcContext.Register>(kcContext).profile.attributes.push(
augmentedAttribute augmentedAttribute
); );
id<KcContext.Register>(kcContext).profile.attributesByName[
augmentedAttribute.name
] = augmentedAttribute;
}); });
partialAttributes partialAttributes
@ -174,9 +170,6 @@ export function createGetKcContext<
id<KcContext.Register>(kcContext).profile.attributes.push( id<KcContext.Register>(kcContext).profile.attributes.push(
partialAttribute as any partialAttribute as any
); );
id<KcContext.Register>(kcContext).profile.attributesByName[
name
] = partialAttribute as any;
}); });
} }
} }

View File

@ -75,10 +75,6 @@ const attributes: Attribute[] = [
} }
]; ];
const attributesByName = Object.fromEntries(
attributes.map(attribute => [attribute.name, attribute])
) as any;
const resourcesPath = `${BASE_URL}${keycloak_resources}/login/resources`; const resourcesPath = `${BASE_URL}${keycloak_resources}/login/resources`;
export const kcContextCommonMock: KcContext.Common = { export const kcContextCommonMock: KcContext.Common = {
@ -269,8 +265,7 @@ export const kcContextMocks = [
recaptchaRequired: false, recaptchaRequired: false,
pageId: "register.ftl", pageId: "register.ftl",
profile: { profile: {
attributes, attributes
attributesByName
}, },
scripts: [ scripts: [
//"https://www.google.com/recaptcha/api.js" //"https://www.google.com/recaptcha/api.js"
@ -421,8 +416,7 @@ export const kcContextMocks = [
...kcContextCommonMock, ...kcContextCommonMock,
pageId: "login-update-profile.ftl", pageId: "login-update-profile.ftl",
profile: { profile: {
attributes, attributes
attributesByName
} }
}), }),
id<KcContext.LoginIdpLinkConfirm>({ id<KcContext.LoginIdpLinkConfirm>({
@ -478,20 +472,14 @@ export const kcContextMocks = [
...kcContextCommonMock, ...kcContextCommonMock,
pageId: "idp-review-user-profile.ftl", pageId: "idp-review-user-profile.ftl",
profile: { profile: {
attributes, attributes
attributesByName
} }
}), }),
id<KcContext.UpdateEmail>({ id<KcContext.UpdateEmail>({
...kcContextCommonMock, ...kcContextCommonMock,
pageId: "update-email.ftl", pageId: "update-email.ftl",
profile: { profile: {
attributes: attributes.filter(attribute => attribute.name === "email"), attributes: attributes.filter(attribute => attribute.name === "email")
attributesByName: Object.fromEntries(
attributes
.filter(attribute => attribute.name === "email")
.map(attribute => [attribute.name, attribute])
)
} }
}), }),
id<KcContext.SelectAuthenticator>({ id<KcContext.SelectAuthenticator>({