Commit 7200a7bd authored by lukas.burgey's avatar lukas.burgey

Add a local copy of the userinfos to the DeploymentState

parent 385f2387
Pipeline #110410 passed with stage
in 1 minute and 22 seconds
Subproject commit bae91cf9d381642e078df1fee96668eace4916b0
Subproject commit 4ad18a9f26a1e7b914a2bf4f0c5c0806e17b2fdd
# Generated by Django 3.0.8 on 2020-09-22 10:48
from django.db import migrations
import django_mysql.models
import feudal.backend.models.deployments
class Migration(migrations.Migration):
dependencies = [
('backend', '0018_auto_20200617_2036'),
]
operations = [
migrations.AddField(
model_name='deploymentstate',
name='userinfo',
field=django_mysql.models.JSONField(blank=True, default=feudal.backend.models.deployments.user_info_default, editable=False, null=True),
),
]
......@@ -55,6 +55,9 @@ def answers_default(): # pragma: no cover
def credential_default(): # pragma: no cover
return {}
def user_info_default(): # pragma: no cover
return {}
def get_deployment(user, vo=None, service=None):
if vo is not None and service is not None:
......@@ -225,6 +228,7 @@ class VODeployment(Deployment):
for service in self.services:
state, created = DeploymentState.objects.get_or_create(
user=self.user,
userinfo=self.user.userinfo,
site=service.site,
service=service,
service_name=service.name,
......@@ -255,6 +259,7 @@ class VODeployment(Deployment):
LOGGER.debug(self.msg('Adding service {}'.format(service)))
state, created = DeploymentState.objects.get_or_create(
user=self.user,
userinfo=self.user.userinfo,
site=service.site,
service=service,
service_name=service.name,
......@@ -307,6 +312,7 @@ class ServiceDeployment(Deployment):
def _assure_states_exist(self):
state, created = DeploymentState.objects.get_or_create(
user=self.user,
userinfo=self.user.userinfo,
site=self.service.site,
service=self.service,
service_name=self.service.name,
......@@ -349,6 +355,13 @@ class DeploymentState(models.Model):
null=True,
)
userinfo = JSONField(
default=user_info_default,
null=True,
blank=True,
editable=False,
)
site = models.ForeignKey(
Site,
related_name='states',
......@@ -585,7 +598,11 @@ class DeploymentState(models.Model):
credential_state.set(NOT_DEPLOYED)
# called by the user when the userinfo was changed (and should be updated at the services)
def userinfo_changed(self):
def userinfo_changed(self, new_userinfo):
# update our local copy of the userinfo
self.userinfo = new_userinfo
self.save()
LOGGER.debug(self.msg('Userinfo changed'))
state_transitions = {
DEPLOYED: {
......
......@@ -41,9 +41,7 @@ class UserSerializer(ModelSerializer):
model = User
fields = [
'credentials',
'email',
'userinfo',
'vos',
]
......@@ -110,6 +108,7 @@ class CredentialStateSerializer(ModelSerializer):
class DeploymentStateSerializer(ModelSerializer):
user = UserSerializer()
userinfo = JSONField()
service = ServiceSerializer()
answers = JSONField()
questionnaire = JSONField()
......@@ -120,6 +119,7 @@ class DeploymentStateSerializer(ModelSerializer):
fields = (
'id',
'user',
'userinfo',
'state',
'state_target',
'credentials',
......
......@@ -14,7 +14,7 @@ from feudal.backend.models.auth.vos import VO, Group, Entitlement
LOGGER = logging.getLogger(__name__)
def user_info_default():
def user_info_default(): # pragma: no cover
return {}
......@@ -390,7 +390,7 @@ class User(AbstractUser):
# deployments need to get the new userinfo
if changed:
for state in self.states.all():
state.userinfo_changed()
state.userinfo_changed(new_userinfo)
def __str__(self):
name = ''
......
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