Skip to content

Commit c5cf62d

Browse files
committed
dont sync organizations form keycloak
1 parent bacdceb commit c5cf62d

File tree

1 file changed

+3
-36
lines changed

1 file changed

+3
-36
lines changed

api/utils/keycloak_utils.py

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -361,16 +361,16 @@ def sync_user_from_keycloak(
361361
self,
362362
user_info: Dict[str, Any],
363363
roles: List[str],
364-
organizations: List[Dict[str, Any]],
364+
organizations: Optional[List[Dict[str, Any]]] = None,
365365
) -> Optional[User]:
366366
"""
367367
Synchronize user information from Keycloak to Django.
368-
Creates or updates the User and UserOrganization records.
368+
Creates or updates the User record.
369369
370370
Args:
371371
user_info: User information from Keycloak
372372
roles: User roles from Keycloak
373-
organizations: User organization memberships from Keycloak
373+
organizations: Deprecated - organizations are managed in DataSpace
374374
375375
Returns:
376376
The synchronized User object or None if failed
@@ -406,39 +406,6 @@ def sync_user_from_keycloak(
406406

407407
user.save()
408408

409-
# Update organization memberships
410-
# First, get all existing organization memberships
411-
existing_memberships = OrganizationMembership.objects.filter(user=user)
412-
existing_org_ids = {
413-
membership.organization_id for membership in existing_memberships # type: ignore[attr-defined]
414-
}
415-
416-
# Process organizations from Keycloak
417-
for org_info in organizations:
418-
org_id = org_info.get("organization_id")
419-
role = org_info.get("role", "viewer") # Default to viewer if role not specified
420-
421-
# Try to get the organization
422-
try:
423-
organization = Organization.objects.get(id=org_id) # type: ignore[misc]
424-
425-
# Create or update the membership
426-
OrganizationMembership.objects.update_or_create(
427-
user=user, organization=organization, defaults={"role": role}
428-
)
429-
430-
# Remove from the set of existing memberships
431-
if org_id in existing_org_ids:
432-
existing_org_ids.remove(org_id)
433-
except Organization.DoesNotExist:
434-
logger.warning(f"Organization with ID {org_id} does not exist")
435-
436-
# Remove memberships that no longer exist in Keycloak
437-
if existing_org_ids:
438-
OrganizationMembership.objects.filter(
439-
user=user, organization_id__in=existing_org_ids
440-
).delete()
441-
442409
return user
443410
except Exception as e:
444411
logger.error(f"Error synchronizing user from Keycloak: {e}")

0 commit comments

Comments
 (0)