Commit 91feff66 authored by lukas.burgey's avatar lukas.burgey
Browse files

Implement the deletion of deployments which are in conflict with the deployment mode

parent c1b50096
Pipeline #110791 passed with stage
in 1 minute and 34 seconds
...@@ -10,6 +10,7 @@ from rest_framework.permissions import AllowAny ...@@ -10,6 +10,7 @@ from rest_framework.permissions import AllowAny
from feudal.backend.views.renderers import PlainTextRenderer from feudal.backend.views.renderers import PlainTextRenderer
from feudal.backend.models import Service from feudal.backend.models import Service
from feudal.backend.models.users import UserPreferences
from feudal.backend.models.serializers import ( from feudal.backend.models.serializers import (
UserStateSerializer, ServiceSerializer, SSHPublicKeySerializer, UserStateSerializer, ServiceSerializer, SSHPublicKeySerializer,
DeploymentSerializer, DeploymentStateSerializer, DeploymentSerializer, DeploymentStateSerializer,
...@@ -94,10 +95,22 @@ class UserPreferencesView(generics.RetrieveUpdateAPIView): ...@@ -94,10 +95,22 @@ class UserPreferencesView(generics.RetrieveUpdateAPIView):
def perform_update(self, serializer): def perform_update(self, serializer):
serializer.save() preferences = serializer.save()
LOGGER.debug(self.request.user.msg('Updated preferences')) LOGGER.debug(self.request.user.msg('Updated preferences'))
if preferences.deployment_mode == UserPreferences.DEPLOYMENT_MODE_SERVICES_ONLY:
qs = self.request.user.deployments.instance_of(VODeployment)
if qs.exists():
LOGGER.debug(self.request.user.msg('Removing my VODeployments because of a new preference'))
qs.delete()
elif preferences.deployment_mode == UserPreferences.DEPLOYMENT_MODE_VOS_ONLY:
qs = self.request.user.deployments.instance_of(ServiceDeployment)
if qs.exists():
LOGGER.debug(self.request.user.msg('Removing my ServiceDeployments because of a new preference'))
qs.delete()
class ServiceListView(generics.ListAPIView): class ServiceListView(generics.ListAPIView):
permission_classes = PERMISSION_CLASSES permission_classes = PERMISSION_CLASSES
......
...@@ -7,7 +7,7 @@ from django.urls import reverse ...@@ -7,7 +7,7 @@ from django.urls import reverse
from feudal.backend.models import Service from feudal.backend.models import Service
from feudal.backend.models.users import SSHPublicKey, User, UserPreferences from feudal.backend.models.users import SSHPublicKey, User, UserPreferences
from feudal.backend.models.deployments import ( from feudal.backend.models.deployments import (
VODeployment, ServiceDeployment, DEPLOYED, NOT_DEPLOYED, QUESTIONNAIRE Deployment, VODeployment, ServiceDeployment, DEPLOYED, NOT_DEPLOYED, QUESTIONNAIRE
) )
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
...@@ -41,7 +41,11 @@ def test_user_prefs_fetch(user_test_client, user): ...@@ -41,7 +41,11 @@ def test_user_prefs_fetch(user_test_client, user):
assert response.status_code == 200 assert response.status_code == 200
assert response.json()['deployment_mode'] == user.preferences.deployment_mode assert response.json()['deployment_mode'] == user.preferences.deployment_mode
def test_user_prefs_patch(user_test_client): def test_user_pref_ddeployment_mode_services_only(user_test_client, deployed_vo_deployment):
# default mode is 'both'
dep, _ = deployed_vo_deployment()
dep_pk = dep.pk
response = user_test_client.patch( response = user_test_client.patch(
reverse('user-prefs'), reverse('user-prefs'),
{ {
...@@ -51,6 +55,26 @@ def test_user_prefs_patch(user_test_client): ...@@ -51,6 +55,26 @@ def test_user_prefs_patch(user_test_client):
) )
assert response.status_code == 200 assert response.status_code == 200
# the deployment should've been deleted when we switched into a mode which prohibits its existence
assert not Deployment.objects.filter(pk=dep_pk).exists()
def test_user_pref_deployment_mode_vos_only(user_test_client, deployed_service_deployment):
# default mode is 'both'
dep, _ = deployed_service_deployment()
dep_pk = dep.pk
response = user_test_client.patch(
reverse('user-prefs'),
{
'deployment_mode': UserPreferences.DEPLOYMENT_MODE_VOS_ONLY,
},
format='json',
)
assert response.status_code == 200
# the deployment should've been deleted when we switched into a mode which prohibits its existence
assert not Deployment.objects.filter(pk=dep_pk).exists()
## SERVICES ## SERVICES
def test_service_list(user_test_client, user): def test_service_list(user_test_client, user):
......
Supports Markdown
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