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()