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