From 1681abc0dba5b2323ea96f6bae8a33b8d26a5bdf Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 28 Jan 2026 11:43:44 +0100 Subject: [PATCH] fix(context_variables): update tags parsing to match API v4 response format --- .../lib/forest_admin_agent/utils/context_variables.rb | 8 +++++--- .../utils/context_variables_injector_spec.rb | 4 ++-- .../forest_admin_agent/utils/context_variables_spec.rb | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/forest_admin_agent/lib/forest_admin_agent/utils/context_variables.rb b/packages/forest_admin_agent/lib/forest_admin_agent/utils/context_variables.rb index 785981d7c..8a418cb3d 100644 --- a/packages/forest_admin_agent/lib/forest_admin_agent/utils/context_variables.rb +++ b/packages/forest_admin_agent/lib/forest_admin_agent/utils/context_variables.rb @@ -30,9 +30,11 @@ def get_current_user_data(context_variable_key) if context_variable_key.start_with?(USER_VALUE_TAG_PREFIX) tag_key = context_variable_key[USER_VALUE_TAG_PREFIX.length..] - user[:tags].each do |tag| - return tag['value'] if tag['key'] == tag_key - end + tags = user[:tags] + return nil if tags.nil? + + value = tags[tag_key] || tags[tag_key.to_sym] + return value end user[context_variable_key[USER_VALUE_PREFIX.length..].to_sym] diff --git a/packages/forest_admin_agent/spec/lib/forest_admin_agent/utils/context_variables_injector_spec.rb b/packages/forest_admin_agent/spec/lib/forest_admin_agent/utils/context_variables_injector_spec.rb index 8234c7f65..b0f074562 100644 --- a/packages/forest_admin_agent/spec/lib/forest_admin_agent/utils/context_variables_injector_spec.rb +++ b/packages/forest_admin_agent/spec/lib/forest_admin_agent/utils/context_variables_injector_spec.rb @@ -12,7 +12,7 @@ module Utils 'lastName' => 'Doe', 'fullName' => 'John Doe', 'email' => 'john.doe@domain.com', - 'tags' => [{ 'key' => 'planet', 'value' => 'Death Star' }], + 'tags' => { 'planet' => 'Death Star' }, 'roleId' => 1, 'permissionLevel' => 'admin' } @@ -89,7 +89,7 @@ module Utils { key: 'id', expected_value: user['id'] }, { key: 'permissionLevel', expected_value: user['permissionLevel'] }, { key: 'roleId', expected_value: user['roleId'] }, - { key: 'tags.planet', expected_value: user['tags'][0]['value'] }, + { key: 'tags.planet', expected_value: user['tags']['planet'] }, { key: 'team.id', expected_value: team['id'] }, { key: 'team.name', expected_value: team['name'] } ].each do |value| diff --git a/packages/forest_admin_agent/spec/lib/forest_admin_agent/utils/context_variables_spec.rb b/packages/forest_admin_agent/spec/lib/forest_admin_agent/utils/context_variables_spec.rb index 6ac7af465..54f807366 100644 --- a/packages/forest_admin_agent/spec/lib/forest_admin_agent/utils/context_variables_spec.rb +++ b/packages/forest_admin_agent/spec/lib/forest_admin_agent/utils/context_variables_spec.rb @@ -10,7 +10,7 @@ module Utils lastName: 'Doe', fullName: 'John Doe', email: 'johndoe@forestadmin.com', - tags: [{ 'key' => 'foo', 'value' => 'bar' }], + tags: { 'foo' => 'bar' }, roleId: 1, permissionLevel: 'admin' }