Commit 2991bcf8 authored by Lukas Burgey's avatar Lukas Burgey
Browse files

Change webpage message transition

parent 9ffd9126
......@@ -20,9 +20,18 @@ class ServiceSerializer(serializers.ModelSerializer):
exclude = []
class DeploymentTaskSerializer(serializers.ModelSerializer):
class Meta:
model = models.DeploymentTask
fields = ['action', 'key']
class DeploymentSerializer(serializers.Serializer):
service = ServiceSerializer()
ssh_keys = backend_serializers.SSHPublicKeySerializer(many=True)
ssh_keys_to_withdraw = backend_serializers.SSHPublicKeySerializer(many=True)
deploys = DeploymentTaskSerializer(many=True)
withdrawals = DeploymentTaskSerializer(many=True)
class Meta:
model = models.Deployment
......@@ -38,13 +47,15 @@ class DeploymentSerializerB(serializers.Serializer):
class UserSerializer(serializers.ModelSerializer):
groups = backend_serializers.GroupSerializer(many=True)
auth_groups = backend_serializers.AuthGroupSerializer(many=True)
ssh_keys = backend_serializers.SSHPublicKeySerializer(many=True)
deployments = DeploymentSerializer(many=True)
auth_groups = backend_serializers.AuthGroupSerializer(many=True)
deployment_tasks = DeploymentTaskSerializer(many=True)
class Meta:
model = models.User
fields = ['id', 'email', 'userinfo', 'ssh_keys', 'groups', 'deployments', 'auth_groups']
fields = ['id', 'email', 'userinfo', 'ssh_keys', 'groups', 'deployments', 'auth_groups',
'deployment_tasks']
class ClientSerializer(serializers.HyperlinkedModelSerializer):
......
......@@ -25,6 +25,8 @@ def user_services(user):
def _api_error_response():
return Response({'ok': False}, status=status.HTTP_400_BAD_REQUEST)
def user_state_dict(user):
return serializers.UserSerializer(user).data
# Response for StateView, LogoutView, and all post requests
def _api_state_response(request):
......@@ -37,7 +39,7 @@ def _api_state_response(request):
response = {
'logged_in': True,
'user': serializers.UserSerializer(request.user).data,
'user': user_state_dict(request.user),
'services': serializers.ServiceSerializer(
user_services(request.user),
many=True,
......
......@@ -2,7 +2,6 @@
# pylint: disable=unused-argument
import json
import time
import logging
import pika
from requests.auth import HTTPBasicAuth
......@@ -16,9 +15,6 @@ from .auth.v1.models import OIDCConfig
LOGGER = logging.getLogger(__name__)
# TODO dirty
RECONNECT_TIMEOUT = 5
RECONNECT_RETRIES = 3
RABBITMQ_CONNECTION = None
......@@ -156,12 +152,12 @@ class RabbitMQInstance(SingletonModel):
msg,
)
def publish_to_webpage(self, user):
def publish_to_webpage(self, user, msg):
LOGGER.debug('Signalling webpage of user %s', user)
self._publish(
'update',
str(user.id),
'<got update>',
json.dumps(msg),
)
......@@ -624,6 +620,11 @@ class DeploymentTask(models.Model):
related_name='tasks',
on_delete=models.CASCADE,
)
user = models.ForeignKey(
User,
related_name='deployment_tasks',
on_delete=models.CASCADE,
)
@classmethod
def construct_deployment_task(cls, deployment, key):
......@@ -636,6 +637,7 @@ class DeploymentTask(models.Model):
action='deploy',
deployment=deployment,
key=key,
user=deployment.user,
)
task.save()
LOGGER.debug(task.msg('generated'))
......@@ -662,6 +664,7 @@ class DeploymentTask(models.Model):
action='withdraw',
deployment=deployment,
key=key,
user=deployment.user,
)
task.save()
LOGGER.debug(task.msg('generated'))
......@@ -677,10 +680,6 @@ class DeploymentTask(models.Model):
return task
@property
def user(self):
return self.deployment.user
@property
def service(self):
return self.deployment.service
......@@ -709,25 +708,46 @@ class DeploymentTask(models.Model):
# the client acked the receipt and execution of the task for his site
def item_finished(self, site):
RabbitMQInstance.load().publish_to_webpage(
self.user,
)
item = self.task_items.get(site=site)
LOGGER.debug(item.msg('done'))
# LOGGER.debug(item.msg('done'))
item.delete()
if not self.task_items.exists():
# finished sends its own message
self.finished()
else:
from .frontend.views import user_state_dict
content = {
'user_state': user_state_dict(self.user),
}
RabbitMQInstance.load().publish_to_webpage(
self.user,
content,
)
# maintenance after all task items are done
def finished(self):
LOGGER.info(self.msg('done'))
self.delete()
# check if this was the final withdraw in a key deletion
if self.action == 'withdraw':
self.key.try_final_deletion()
message = 'Completed: ' + str(self.action) + ' ' + str(self.key) + ' '+ str(self.site)
from .frontend.views import user_state_dict
content = {
'user_state': user_state_dict(self.user),
'message': message,
}
RabbitMQInstance.load().publish_to_webpage(
self.user,
content,
)
class DeploymentTaskItem(models.Model):
task = models.ForeignKey(
......
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