Skip to content

Commit

Permalink
feat: prevent virtual users (external & deleted) to be removed
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 a809c42 commit 3a4184e
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions backend/users/management/commands/sync_users.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from django.config import settings
from django.contrib.auth import get_user_model
from django.contrib.auth.password_validation import validate_password
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 Down Expand Up @@ -53,6 +52,6 @@ def update_password(self, element: UserElement) -> models.Model:
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)
# Prevent the deletion of virtual users
discarded_keys.difference_update(settings.VIRTUAL_USERNAMES.values())
super().delete(discarded_keys)

0 comments on commit 3a4184e

Please sign in to comment.