Commit ff82ce54 authored by lukas.burgey's avatar lukas.burgey

Merge branch 'dev'

parents b2cca1a9 ccd3a249
Pipeline #110418 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: {
......
......@@ -30,7 +30,6 @@ class CredentialSerializer(ModelSerializer):
class UserSerializer(ModelSerializer):
vos = VOSerializer(many=True)
userinfo = JSONField()
credentials = DictField(
child=ListField(
......@@ -42,9 +41,7 @@ class UserSerializer(ModelSerializer):
model = User
fields = [
'credentials',
'email',
'userinfo',
'vos',
]
......@@ -111,6 +108,7 @@ class CredentialStateSerializer(ModelSerializer):
class DeploymentStateSerializer(ModelSerializer):
user = UserSerializer()
userinfo = JSONField()
service = ServiceSerializer()
answers = JSONField()
questionnaire = JSONField()
......@@ -121,6 +119,7 @@ class DeploymentStateSerializer(ModelSerializer):
fields = (
'id',
'user',
'userinfo',
'state',
'state_target',
'credentials',
......
......@@ -276,6 +276,7 @@ def test_login_changed_userinfo_redeploy(user, deployed_vo_deployment):
# this should cause the republishing of the deployment
state.refresh_from_db()
assert state.is_pending
assert state.userinfo['name'] == 'new name'
def test_upstream_changed_userinfo_redeploy(user, deployed_vo_deployment, upstream_test_client):
......@@ -293,7 +294,9 @@ def test_upstream_changed_userinfo_redeploy(user, deployed_vo_deployment, upstre
# this should cause the republishing of the deployment
state.refresh_from_db()
assert state.is_pending
assert state.userinfo['name'] == 'new name'
# }}}
# SERIALIZERS {{{
......
......@@ -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 = ''
......
......@@ -208,7 +208,6 @@ def topic_endpoint_apiclient(request, apiclient):
# we strip the group authority from the routing key if it was included
name=Entitlement.extract_name(routing_key),
)
LOGGER.debug('Searching site of %s and vo %s', apiclient, vo)
Site.objects.get(
services__vos=vo,
......
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