Commit 1d8eac79 authored by Lukas Burgey's avatar Lukas Burgey

Enhance user admin

parent c2d1f0e5
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from . import models
from .auth.v1.models import OIDCConfig
admin.site.register(models.User)
class TypeFilter(admin.SimpleListFilter):
title = 'Type'
parameter_name = 'user_type'
def lookups(self, request, model_admin):
return models.User.TYPE_CHOICES
def queryset(self, request, queryset):
if self.value():
return queryset.filter(user_type=self.value())
return queryset
class ClientAdmin(UserAdmin):
list_filter = (TypeFilter,)
admin.site.register(models.User, ClientAdmin)
admin.site.register(models.Site)
admin.site.register(models.Service)
admin.site.register(models.RabbitMQInstance)
......
......@@ -142,7 +142,7 @@ class User(AbstractUser):
user_type = models.CharField(
max_length=20,
choices=TYPE_CHOICES,
default='oidcuser',
default='apiclient',
)
sub = models.CharField(
max_length=150,
......@@ -262,6 +262,16 @@ class User(AbstractUser):
userinfo=user_info,
)
@classmethod
def construct_client(cls, username, password):
LOGGER.debug('APICLIENT: new client %s', username)
client = cls(
username=username,
user_type='apiclient',
)
client.set_password(password)
return client
class Site(models.Model):
client = models.OneToOneField(
......@@ -622,7 +632,11 @@ class DeploymentTaskItem(models.Model):
@receiver(post_save, sender=User)
def upgrade_password(sender, instance=None, created=False, **kwargs):
if created and instance is not None and instance.user_type == 'apiclient':
if (
instance is not None
and instance.user_type == 'apiclient'
and not instance.password.startswith('pbkdf2_sha256')
):
instance.set_password(instance.password)
instance.save()
......
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