Skip to content

Commit

Permalink
chore: manually change compute plan user when deleting
Browse files Browse the repository at this point in the history
Signed-off-by: Guilhem Barthés <guilhem.barthes@owkin.com>
  • Loading branch information
guilhem-barthes committed Sep 27, 2024
1 parent dbc5e9b commit a809c42
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion backend/users/management/commands/sync_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from django.core.exceptions import ValidationError
from django.db import models

from api.models import ComputePlan
from api.models.computeplan import _get_or_create_deleted_user
from organization.management.commands.base_sync import BaseSyncCommand
from organization.management.commands.base_sync import Element
from users.models import UserChannel
Expand All @@ -15,10 +17,13 @@ class UserElement(Element):

class Command(BaseSyncCommand):
help = "Sync users"
model = get_user_model()
model_name = "User"
field_key = "username"

def __init__(self, *args, **kwargs):
self.model = get_user_model()
super().__init__(*args, **kwargs)

def parse_line(self, line: str) -> UserElement:
(key, password, channel) = line.split(" ")

Expand Down Expand Up @@ -46,3 +51,8 @@ def update_password(self, element: UserElement) -> models.Model:
user_channel.save()
self.stdout.write(f"User channel updated: {element.key}")
return user

def delete(self, discarded_keys: set[str]) -> None:
deleted_user = _get_or_create_deleted_user()
ComputePlan.objects.filter(creator__username__in=discarded_keys).update(creator_id=deleted_user.id)
super().delete(discarded_keys)

0 comments on commit a809c42

Please sign in to comment.