Skip to content

Commit

Permalink
Django: Improve db coherence on user sync issues
Browse files Browse the repository at this point in the history
  • Loading branch information
filippomc committed Nov 6, 2024
1 parent d938c97 commit fa4c3fe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.contrib.auth.models import User, Group

from admin_extra_buttons.api import ExtraButtonsMixin, button

from .models import Member
from cloudharness_django.services import get_user_service

# Register your models here.
Expand All @@ -13,8 +13,14 @@
admin.site.unregister(Group)


class MemberAdmin(admin.StackedInline):
model = Member


class CHUserAdmin(ExtraButtonsMixin, UserAdmin):

inlines = [MemberAdmin]

def has_add_permission(self, request):
return settings.DEBUG or settings.USER_CHANGE_ENABLED

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ def sync_kc_user(self, kc_user, is_superuser=False, delete=False):

user, created = User.objects.get_or_create(username=kc_user["username"])

Member.objects.get_or_create(user=user, kc_id=kc_user["id"])
member = Member.objects.get_or_create(user=user)
member.kc_id = kc_user["id"]
member.save()
user = self._map_kc_user(user, kc_user, is_superuser, delete)
user.save()
return user
Expand Down

0 comments on commit fa4c3fe

Please sign in to comment.