From a217f617d86e94cdece1c23440487eb576f5308e Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Tue, 28 May 2024 01:05:35 +0200 Subject: [PATCH] Remove profile.attributesByName from the kcContext --- ..._object_to_js_code_declaring_an_object.ftl | 3 +++ src/login/kcContext/KcContext.ts | 1 - src/login/kcContext/createGetKcContext.ts | 11 ++-------- src/login/kcContext/kcContextMocks.ts | 20 ++++--------------- 4 files changed, 9 insertions(+), 26 deletions(-) diff --git a/src/bin/keycloakify/generateFtl/ftl_object_to_js_code_declaring_an_object.ftl b/src/bin/keycloakify/generateFtl/ftl_object_to_js_code_declaring_an_object.ftl index cf96ef8a..dd247579 100644 --- a/src/bin/keycloakify/generateFtl/ftl_object_to_js_code_declaring_an_object.ftl +++ b/src/bin/keycloakify/generateFtl/ftl_object_to_js_code_declaring_an_object.ftl @@ -286,6 +286,9 @@ function decodeHtmlEntities(htmlStr){ <#-- Remove realmAttributes added by https://github.com/jcputney/keycloak-theme-additional-info-extension for peace of mind. --> are_same_path(path, []) && 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*/"]> diff --git a/src/login/kcContext/KcContext.ts b/src/login/kcContext/KcContext.ts index eac734bc..834faf1b 100644 --- a/src/login/kcContext/KcContext.ts +++ b/src/login/kcContext/KcContext.ts @@ -586,7 +586,6 @@ export declare namespace KcContext { export type UserProfile = { attributes: Attribute[]; - attributesByName: Record; html5DataAnnotations?: Record; }; diff --git a/src/login/kcContext/createGetKcContext.ts b/src/login/kcContext/createGetKcContext.ts index 678c2339..b051d652 100644 --- a/src/login/kcContext/createGetKcContext.ts +++ b/src/login/kcContext/createGetKcContext.ts @@ -39,9 +39,9 @@ export function createGetKcContext< if (mockPageId !== undefined && realKcContext === undefined) { //TODO maybe trow if no mock fo custom page - warn_that_mock_is_enbaled: { + warn_that_mock_is_enabled: { if (isStorybook) { - break warn_that_mock_is_enbaled; + break warn_that_mock_is_enabled; } console.log( @@ -118,7 +118,6 @@ export function createGetKcContext< const { attributes } = kcContextDefaultMock.profile; id(kcContext).profile.attributes = []; - id(kcContext).profile.attributesByName = {}; const partialAttributes = [ ...(( @@ -153,9 +152,6 @@ export function createGetKcContext< id(kcContext).profile.attributes.push( augmentedAttribute ); - id(kcContext).profile.attributesByName[ - augmentedAttribute.name - ] = augmentedAttribute; }); partialAttributes @@ -174,9 +170,6 @@ export function createGetKcContext< id(kcContext).profile.attributes.push( partialAttribute as any ); - id(kcContext).profile.attributesByName[ - name - ] = partialAttribute as any; }); } } diff --git a/src/login/kcContext/kcContextMocks.ts b/src/login/kcContext/kcContextMocks.ts index 8802a346..9d81ecc9 100644 --- a/src/login/kcContext/kcContextMocks.ts +++ b/src/login/kcContext/kcContextMocks.ts @@ -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`; export const kcContextCommonMock: KcContext.Common = { @@ -269,8 +265,7 @@ export const kcContextMocks = [ recaptchaRequired: false, pageId: "register.ftl", profile: { - attributes, - attributesByName + attributes }, scripts: [ //"https://www.google.com/recaptcha/api.js" @@ -421,8 +416,7 @@ export const kcContextMocks = [ ...kcContextCommonMock, pageId: "login-update-profile.ftl", profile: { - attributes, - attributesByName + attributes } }), id({ @@ -478,20 +472,14 @@ export const kcContextMocks = [ ...kcContextCommonMock, pageId: "idp-review-user-profile.ftl", profile: { - attributes, - attributesByName + attributes } }), id({ ...kcContextCommonMock, pageId: "update-email.ftl", profile: { - attributes: attributes.filter(attribute => attribute.name === "email"), - attributesByName: Object.fromEntries( - attributes - .filter(attribute => attribute.name === "email") - .map(attribute => [attribute.name, attribute]) - ) + attributes: attributes.filter(attribute => attribute.name === "email") } }), id({