Commit d38dc754 authored by Lukas Burgey's avatar Lukas Burgey

Add userinfo into the db using a JSONField

parent 44cd3518
......@@ -30,7 +30,7 @@ def _api_state_response(request):
'logged_in': request.user.is_authenticated()
}
if request.user.is_authenticated():
response['user'] = serializers.UserSerializer(request.user).data
response['user'] = request.user.userinfo
response['services'] = serializers.ServiceSerializer(
user_services(request.user),
......@@ -42,6 +42,8 @@ def _api_state_response(request):
# we display errors only once
del request.session['error']
LOGGER.debug('api state: %s', response)
return Response(response)
......@@ -61,6 +63,7 @@ class ServiceViewSet(viewsets.ModelViewSet):
class SSHPublicKeyView(views.APIView):
def post(self, request):
if 'type' not in request.data:
LOGGER.error('SSHPublicKeyView: malformed request %s', request)
return _api_error_response()
request_type = request.data['type']
......@@ -89,6 +92,7 @@ class SSHPublicKeyView(views.APIView):
key.save()
return _api_state_response(request)
LOGGER.error('SSHPublicKeyView: malformed request %s', request)
return _api_error_response()
......
......@@ -12,6 +12,7 @@ from django.core.cache import cache
from django.db import models
from django.db.models.signals import post_save, pre_delete
from django.dispatch import receiver
from django_mysql.models import JSONField
from rest_framework.authtoken.models import Token
from .auth.v1.models import OIDCConfig
......@@ -255,6 +256,10 @@ class RabbitMQInstance(SingletonModel):
)
def user_info_default():
return {}
class User(AbstractUser):
TYPE_CHOICES = (
('apiclient', 'API-Client'),
......@@ -288,6 +293,11 @@ class User(AbstractUser):
related_name='users',
on_delete=models.CASCADE,
)
userinfo = JSONField(
default=user_info_default,
null=True,
blank=True,
)
# we hide deleted keys here
# the full list of ssh keys is self._ssh_keys
......@@ -367,6 +377,7 @@ class User(AbstractUser):
email=user_info.get('email', ''),
username=user_info.get('email', ''),
idp=idp,
userinfo=user_info,
)
......
......@@ -49,6 +49,7 @@ INSTALLED_APPS = [
'rest_framework.authtoken',
'django_backend.backend',
'corsheaders',
'django_mysql',
]
MIDDLEWARE = [
......@@ -93,6 +94,9 @@ DATABASES = {
'USER': os.environ['DB_USER'],
'HOST': 'mysql2g.scc.kit.edu',
'PASSWORD': os.environ['DB_PASSWORD'],
'OPTIONS': {
'init_command': 'SET innodb_strict_mode=1',
}
}
}
......@@ -200,3 +204,9 @@ LOGGING = {
},
},
}
# Silence some warning concerning database collation format
SILENCED_SYSTEM_CHECKS = [
'django_mysql.W003',
]
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