Commit 3aa931af authored by lukas.burgey's avatar lukas.burgey

Add UserPreferences model

parent f43065aa
# Generated by Django 3.0.8 on 2020-09-24 09:38
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('backend', '0020_auto_20200922_1333'),
]
operations = [
migrations.CreateModel(
name='UserPreferences',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('deployment_mode', models.CharField(choices=[('both', 'Pick a combination of services and VOs for deployment.'), ('services-only', 'Pick individual services for deployment'), ('vos-only', 'Pick individual VOs for deployment')], default='both', max_length=20)),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='preferences', to=settings.AUTH_USER_MODEL)),
],
),
]
......@@ -6,7 +6,7 @@ import copy
from django.urls import reverse
from feudal.backend.models import Service
from feudal.backend.models.users import User, SSHPublicKey
from feudal.backend.models.users import User, SSHPublicKey, UserPreferences
from feudal.backend.models.deployments import DEPLOYED, NOT_DEPLOYED, CredentialState, Deployment, DeploymentState
from feudal.backend.models.auth.vos import Group, Entitlement
......@@ -259,3 +259,16 @@ def test_construct_from_userinfo(idp, userinfo):
}
user = User.construct_from_userinfo(userinfo, idp)
assert user.userinfo['test_value'] == test_value
assert user.preferences.deployment_mode == UserPreferences.DEPLOYMENT_MODE_BOTH
def test_user_deletion_cascade(user):
""" the user deletion must cascade to its preferences """
prefs_pk = user.preferences.pk
assert UserPreferences.objects.filter(pk=prefs_pk).exists()
user.delete()
assert not UserPreferences.objects.filter(pk=prefs_pk).exists()
......@@ -141,6 +141,13 @@ class User(AbstractUser):
user.update_userinfo(userinfo)
user.save()
_, createdPrefs = UserPreferences.objects.get_or_create(
user=user,
)
if createdPrefs:
LOGGER.info('construct_from_userinfo: Created preferences for user %s', user)
return user
@classmethod
......@@ -554,3 +561,28 @@ def activate_user(sender, instance=None, created=False, **kwargs):
if instance.is_active and not instance.is_active_at_clients:
instance.activate()
class UserPreferences(models.Model):
user = models.OneToOneField(
User,
related_name='preferences',
on_delete=models.CASCADE,
)
DEPLOYMENT_MODE_BOTH = 'both'
DEPLOYMENT_MODE_SERVICES_ONLY = 'services-only'
DEPLOYMENT_MODE_VOS_ONLY = 'vos-only'
DEPLOYMENT_MODE_CHOICES = (
(DEPLOYMENT_MODE_BOTH, 'Pick a combination of services and VOs for deployment.'),
(DEPLOYMENT_MODE_SERVICES_ONLY, 'Pick individual services for deployment'),
(DEPLOYMENT_MODE_VOS_ONLY, 'Pick individual VOs for deployment'),
)
deployment_mode = models.CharField(
max_length=20,
choices=DEPLOYMENT_MODE_CHOICES,
default=DEPLOYMENT_MODE_BOTH,
)
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