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 <noreply@anthropic.com>
This commit is contained in:
nickviljoen 2026-02-02 13:27:47 +02:00
parent 8bc1256e82
commit cd8345e193

View file

@ -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