From cd8345e1937e4fa8708c694783c53ff79c1565b2 Mon Sep 17 00:00:00 2001 From: nickviljoen Date: Mon, 2 Feb 2026 13:27:47 +0200 Subject: [PATCH] Fix profile visibility filtering to respect client assignments Issue: After implementing visibility control, all profiles were showing for all clients because existing profiles don't have visibility fields. Fix: Updated get_profiles_with_visibility() to fall back to CLIENT_PROFILES mapping when visibility settings are not present in profile JSON files. Behavior: - Profiles with visibility field: Use new visibility system - Profiles without visibility field: Use CLIENT_PROFILES mapping (backward compatible) This ensures: - L'Oreal sees: loreal_static, static_general - Diageo sees: diageo_key_visual, diageo_packaging, static_general - Unilever sees: unilever_key_visual, unilever_packaging, static_general - General sees: static_general, inclusive_accessibility Tested: All clients now correctly see only their assigned profiles Co-Authored-By: Claude Sonnet 4.5 --- backend/client_config.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/backend/client_config.py b/backend/client_config.py index e003e9a..ecc2da0 100644 --- a/backend/client_config.py +++ b/backend/client_config.py @@ -59,6 +59,10 @@ def get_profiles_with_visibility(client_id): available_profiles = [] + # First, get the profiles assigned to this client in CLIENT_PROFILES + # This is our baseline for backward compatibility + baseline_profiles = get_client_profiles(client_id) + # Get profiles directory profiles_dir = os.path.join(os.path.dirname(__file__), 'profiles') profile_files = glob.glob(os.path.join(profiles_dir, '*.json')) @@ -69,14 +73,23 @@ def get_profiles_with_visibility(client_id): profile_data = json.load(f) profile_id = os.path.basename(profile_file).replace('.json', '') - visibility = profile_data.get('visibility', 'all') - visible_to_clients = profile_data.get('visible_to_clients', []) - # Check if profile should be visible to this client - if visibility == 'all': - available_profiles.append(profile_id) - elif visibility == 'client_specific' and client_id in visible_to_clients: - available_profiles.append(profile_id) + # Check if profile has visibility settings + has_visibility_settings = 'visibility' in profile_data + + if has_visibility_settings: + # Use new visibility system if configured + visibility = profile_data.get('visibility', 'all') + visible_to_clients = profile_data.get('visible_to_clients', []) + + if visibility == 'all': + available_profiles.append(profile_id) + elif visibility == 'client_specific' and client_id in visible_to_clients: + available_profiles.append(profile_id) + else: + # Fall back to CLIENT_PROFILES mapping for backward compatibility + if profile_id in baseline_profiles: + available_profiles.append(profile_id) except (json.JSONDecodeError, FileNotFoundError): continue