Skip to content

Conversation

@D-GopalKrishna
Copy link
Contributor

@D-GopalKrishna D-GopalKrishna commented Jan 28, 2026

Closes CH-220

Implemented solution

  • Two models to support - Organization and OrganizationMember (to relate which user is linked to which organization)

  • add three sync service methods - sync_kc_organizations and sync_kc_organization and sync_kc_user_organizations

  • extend - Keycloak AuthClient - to support - get_organization_members, get_user_organizations and get_organizations - NOTE - these are only introduced in the 5.4.0 or later version of python-keycloak package.

  • Add admin sync support using - CHOrganizationAdmin -> sync button supports sync (using sync_kc_organizations) to sync the django organizations with what's currently in Keycloak.

...

How to test this PR

...

Sanity checks:

  • The pull request is explicitly linked to the relevant issue(s)
  • The issue is well described: clearly states the problem and the general proposed solution(s)
  • In this PR it is explicitly stated how to test the current change
  • The labels in the issue set the scope and the type of issue (bug, feature, etc.)
  • The relevant components are indicated in the issue (if any)
  • All the automated test checks are passing
  • All the linked issues are included in one Sprint
  • All the linked issues are in the Review state
  • All the linked issues are assigned

Breaking changes (select one):

  • The present changes do not change the preexisting api in any way
  • This PR and the issue are tagged as a breaking-change and the migration procedure is well described above

Possible deployment updates issues (select one):

  • There is no reason why deployments based on CloudHarness may break after the current update
  • This PR and the issue are tagged as alert:deployment

Test coverage (select one):

  • Tests for the relevant cases are included in this pr
  • The changes included in this pr are out of the current test coverage scope

Documentation (select one):

  • The documentation has been updated to match the current changes
  • The changes included in this PR are out of the current documentation scope

Nice to have (if relevant):

  • Screenshots of the changes
  • Explanatory video/animated gif

is_superuser = any([admin_user for admin_user in all_admin_users if admin_user["id"] == kc_user["id"]])
self.sync_kc_user(kc_user, is_superuser)

# sync the groups
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method is used in the admin - for sync_keycloak in both - User page or in Group page. To continue using that, i have added the sync of the organization within the same scope.

That being said, i don't like the naming of the method in that case (since its doing a lot more than just sync groups). Do you think changing the name of the method is a good idea?

I understand this will be part of a new release - but will we need a deprecated method in such case?

def sync_keycloak(self, request):
from cloudharness_django.services import get_user_service
get_user_service().sync_kc_users_groups()
get_user_service().sync_kc_groups()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this sync_kc_groups() - was removed from sync_kc_users_groups - so there's no way to sync groups if users are not already assigned to groups. This will ensure groups can be synced in the group admin panel

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to sync groups that are not assigned to users

})
return True
return False

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these additions are unnecessary, as the pattern is to lazily sync groups/organizations together with users (and organizations were coming already)

return False

@with_refreshtoken
def get_organizations(self, with_members=False) -> List[dict]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no much use in typing when returning a List[dict] where a proper type can be used. CloudHarness defines a type for organizations

@filippomc
Copy link
Collaborator

Closing as implemented by other means

@filippomc filippomc closed this Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants