Commit a6ae9e38 authored by Lukas Burgey's avatar Lukas Burgey

Rename withdraw into remove

parent 8aa8b7e6
......@@ -83,7 +83,7 @@ def _webpage_client_valid(request):
def user_endpoint(request):
if _webpage_client_valid(request):
LOGGER.info('Authenticated webpage client')
#LOGGER.info('Authenticated webpage client')
return ALLOW
user = authenticate(
......
......@@ -141,7 +141,7 @@ class AuthCallback(View):
class LogoutView(views.APIView):
def post(self, request):
LOGGER.debug('logged out %s', request.user)
LOGGER.info('Logging out %s', request.user)
logout(request)
return Response(state_view_data(request))
......
......@@ -25,11 +25,11 @@ class DeploymentSerializer(serializers.ModelSerializer):
user = UserSerializer()
service = ServiceSerializer()
ssh_keys = backend_serializers.SSHPublicKeySerializer(many=True)
ssh_keys_to_withdraw = backend_serializers.SSHPublicKeySerializer(many=True)
ssh_keys_to_remove = backend_serializers.SSHPublicKeySerializer(many=True)
class Meta:
model = models.Deployment
fields = ['user', 'service', 'ssh_keys', 'ssh_keys_to_withdraw']
fields = ['user', 'service', 'ssh_keys', 'ssh_keys_to_remove']
class DeploymentsSerializer(serializers.Serializer):
......
......@@ -64,7 +64,7 @@ class DeploymentStateSerializer(serializers.ModelSerializer):
class DeploymentSerializer(serializers.ModelSerializer):
service = ServiceSerializer()
ssh_keys = backend_serializers.SSHPublicKeySerializer(many=True)
ssh_keys_to_withdraw = backend_serializers.SSHPublicKeySerializer(many=True)
ssh_keys_to_remove = backend_serializers.SSHPublicKeySerializer(many=True)
states = DeploymentStateSerializer(many=True)
class Meta:
......@@ -72,7 +72,7 @@ class DeploymentSerializer(serializers.ModelSerializer):
fields = [
'service',
'ssh_keys',
'ssh_keys_to_withdraw',
'ssh_keys_to_remove',
'states',
'id',
]
......
......@@ -169,4 +169,4 @@ class UserDeletionView(views.APIView):
# this also logs out the user
request.user.remove()
logout(request)
return _api_state_response(request)
return Response({'deleted': True})
......@@ -364,7 +364,7 @@ class User(AbstractUser):
def msg(self, msg):
return '[{}] {}'.format(self, msg)
# oidcuser: withdraw and delete all credentials and delete the user
# oidcuser: remove and delete all credentials and delete the user
def remove(self):
if self.user_type == 'oidcuser':
self.deactivate()
......@@ -400,7 +400,7 @@ class User(AbstractUser):
self.save()
LOGGER.info(self.msg('deactivated'))
# oidcuser: withdraw all credentials
# oidcuser: remove all credentials
if self.user_type == 'oidcuser':
for dep in self.deployments.all():
......@@ -501,9 +501,9 @@ class SSHPublicKey(models.Model):
return True
return False
# does not directly delete the key if the key is deployed or withdrawn
# does not directly delete the key if the key is deployed or removen
# somewhere
# the receiver 'delete_withdrawn_ssh_key' does the actual deletion
# the receiver 'delete_removen_ssh_key' does the actual deletion
def delete_key(self):
# if this key is not deployed anywhere we delete it now
if not self.deployed_anywhere:
......@@ -515,16 +515,16 @@ class SSHPublicKey(models.Model):
self.deleted = True
self.save()
# delete implies withdrawing the key from all clients
# delete implies removeing the key from all clients
for deployment in self.deployments.all():
deployment.remove_key(self)
# when a key is withdrawn by a client we try to finally delete it
# when a key is removen by a client we try to finally delete it
def try_final_deletion(self):
if self.deleted:
if not self.deployed_anywhere:
LOGGER.info(self.msg('All clients have withdrawn this key. Final deletion'))
LOGGER.info(self.msg('All clients have removen this key. Final deletion'))
self._final_deletion()
def _final_deletion(self):
......@@ -568,9 +568,9 @@ class Deployment(models.Model):
related_name='deployments',
blank=True,
)
ssh_keys_to_withdraw = models.ManyToManyField(
ssh_keys_to_remove = models.ManyToManyField(
SSHPublicKey,
related_name='withdrawn_deployments',
related_name='removen_deployments',
blank=True,
)
is_active = models.BooleanField(
......@@ -609,7 +609,7 @@ class Deployment(models.Model):
self.save()
LOGGER.info(self.msg('activated'))
# withdraw all credentials
# remove all credentials
def deactivate(self):
if not self.is_active:
LOGGER.error(self.msg('already deactivated'))
......@@ -631,22 +631,22 @@ class Deployment(models.Model):
self.ssh_keys.add(key)
if key in self.ssh_keys_to_withdraw.all():
self.ssh_keys_to_withdraw.remove(key)
if key in self.ssh_keys_to_remove.all():
self.ssh_keys_to_remove.remove(key)
self.save()
self._deploy_key(key)
# withdraw key and track changes in the key lists
# remove key and track changes in the key lists
def remove_key(self, key):
if not self.is_active:
LOGGER.error(self.msg('cannot withdraw while deactivated'))
LOGGER.error(self.msg('cannot remove while deactivated'))
raise Exception('deployment deactivated')
self.ssh_keys.remove(key)
# keys which are to be withdrawn by the clients
self.ssh_keys_to_withdraw.add(key)
# keys which are to be removen by the clients
self.ssh_keys_to_remove.add(key)
self.save()
self._remove_key(key)
......@@ -763,24 +763,26 @@ class DeploymentState(models.Model):
# each state item publishes its state to the user
def publish_to_client(self):
# mitigating circular dependencies here
from .clientapi.serializers import DeploymentStateSerializer
msg = json.dumps(DeploymentStateSerializer(self).data)
RabbitMQInstance.load().publish_by_service(
self.service,
msg,
)
if self.service is not None:
# mitigating circular dependencies here
from .clientapi.serializers import DeploymentStateSerializer
msg = json.dumps(DeploymentStateSerializer(self).data)
RabbitMQInstance.load().publish_by_service(
self.service,
msg,
)
# update the state of the remote webpage
def publish_to_user(self):
from .frontend.views import user_state
content = {
'user_state': user_state(self.user),
}
RabbitMQInstance.load().publish_to_user(
self.user,
content,
)
if self.user is not None:
from .frontend.views import user_state
content = {
'user_state': user_state(self.user),
}
RabbitMQInstance.load().publish_to_user(
self.user,
content,
)
def msg(self, msg):
return '[DState:{}] {}'.format(self, msg)
......
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