From 1915224063e6031437465ffd46022b0271e939eb Mon Sep 17 00:00:00 2001 From: Bai Date: Mon, 28 Sep 2020 20:02:30 +0800 Subject: [PATCH] =?UTF-8?q?fix(terminal):=20=E4=BF=AE=E5=A4=8D=E6=AD=A3?= =?UTF-8?q?=E5=9C=A8=E4=BD=BF=E7=94=A8=E7=9A=84=E5=91=BD=E4=BB=A4/?= =?UTF-8?q?=E5=BD=95=E5=83=8F=E5=AD=98=E5=82=A8=E5=8F=AF=E4=BB=A5=E8=A2=AB?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/terminal/api/storage.py | 5 ++++- apps/terminal/models.py | 8 ++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/apps/terminal/api/storage.py b/apps/terminal/api/storage.py index ec85b95f7..0687e213f 100644 --- a/apps/terminal/api/storage.py +++ b/apps/terminal/api/storage.py @@ -20,9 +20,12 @@ class BaseStorageViewSetMixin: def destroy(self, request, *args, **kwargs): instance = self.get_object() - if not instance.can_delete(): + if instance.in_defaults(): data = {'msg': _('Deleting the default storage is not allowed')} return Response(data=data, status=status.HTTP_400_BAD_REQUEST) + if instance.is_using(): + data = {'msg': _('Cannot delete storage that is being used')} + return Response(data=data, status=status.HTTP_400_BAD_REQUEST) return super().destroy(request, *args, **kwargs) diff --git a/apps/terminal/models.py b/apps/terminal/models.py index f4b43291f..dc747c370 100644 --- a/apps/terminal/models.py +++ b/apps/terminal/models.py @@ -405,8 +405,8 @@ class CommandStorage(CommonModelMixin): storage = jms_storage.get_log_storage(self.config) return storage.ping() - def can_delete(self): - return not self.in_defaults() + def is_using(self): + return Terminal.objects.filter(command_storage=self.name).exists() class ReplayStorage(CommonModelMixin): @@ -458,5 +458,5 @@ class ReplayStorage(CommonModelMixin): src = os.path.join(settings.BASE_DIR, 'common', target) return storage.is_valid(src, target) - def can_delete(self): - return not self.in_defaults() + def is_using(self): + return Terminal.objects.filter(replay_storage=self.name).exists()