Commit 89d5e857 authored by Lukas Burgey's avatar Lukas Burgey
Browse files

Add receivers for user (de-)activation

parent d6c09c5b
......@@ -246,8 +246,22 @@ class User(AbstractUser):
choices=TYPE_CHOICES,
default='oidcuser',
)
sub = models.CharField(max_length=150, blank=True, null=True)
password = models.CharField(max_length=150, blank=True, null=True)
sub = models.CharField(
max_length=150,
blank=True,
null=True,
)
password = models.CharField(
max_length=150,
blank=True,
null=True,
)
# the real state of the user
# (self.is_active is the supposed state of the user)
_is_active = models.BooleanField(
default=True,
editable=False,
)
# we hide deleted keys here
# the full list of ssh keys is self._ssh_keys
......@@ -280,12 +294,13 @@ class User(AbstractUser):
self.delete()
def activate(self):
if self.is_active:
if self._is_active:
logger.error(self.msg('already activated'))
return
if self.user_type == 'oidcuser':
self.is_active = True
self._is_active = True
self.save()
for dep in self.deployments.all():
......@@ -295,12 +310,13 @@ class User(AbstractUser):
# oidcuser: withdraw all credentials
def deactivate(self):
if not self.is_active:
if not self._is_active:
logger.error(self.msg('already deactivated'))
return
if self.user_type == 'oidcuser':
self.is_active = False
self._is_active = False
self.save()
for dep in self.deployments.all():
......@@ -678,3 +694,21 @@ def deregister_at_rabbitmq(
sender, instance=None, **kwargs):
RabbitMQInstance().deregister_site(instance)
@receiver(post_save, sender=User)
def deactivate_user(sender, instance=None, created=False, **kwargs):
if created:
return
if not instance.is_active and instance._is_active:
instance.deactivate()
@receiver(post_save, sender=User)
def activate_user(sender, instance=None, created=False, **kwargs):
if created:
return
if instance.is_active and not instance._is_active:
instance.activate()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment