diff --git a/apps/authentication/models/connection_token.py b/apps/authentication/models/connection_token.py index 07fd6483b..fcf1d43c8 100644 --- a/apps/authentication/models/connection_token.py +++ b/apps/authentication/models/connection_token.py @@ -200,7 +200,7 @@ class ConnectionToken(JMSOrgBaseModel): host_account = applet.select_host_account(self.user, self.asset) if not host_account: - raise JMSException({'error': 'No host account available'}) + raise JMSException({'error': 'No host account available, please check the applet, host and account'}) host, account, lock_key = bulk_get(host_account, ('host', 'account', 'lock_key')) gateway = host.domain.select_gateway() if host.domain else None diff --git a/apps/terminal/models/applet/applet.py b/apps/terminal/models/applet/applet.py index 783e09e1d..f4dd1455a 100644 --- a/apps/terminal/models/applet/applet.py +++ b/apps/terminal/models/applet/applet.py @@ -15,6 +15,7 @@ from assets.models import Platform from common.db.models import JMSBaseModel from common.utils import lazyproperty, get_logger from common.utils.yml import yaml_load_with_i18n +from terminal.const import PublishStatus logger = get_logger(__name__) @@ -278,7 +279,9 @@ class Applet(JMSBaseModel): if not host: return None logger.info('Select applet host: {}'.format(host.name)) - + if not self.is_available_on_host(host): + logger.debug('No available applet {} for applet host: {}'.format(self.name, host.name)) + return None valid_accounts = host.accounts.all().filter(is_active=True, privileged=False) account = self.try_to_use_same_account(user, host) if not account: @@ -311,6 +314,14 @@ class Applet(JMSBaseModel): platform.delete() return super().delete(using, keep_parents) + def is_available_on_host(self, host): + publication = AppletPublication.objects.filter(applet=self, host=host).first() + if not publication: + return False + if publication.status in [PublishStatus.pending, PublishStatus.failed]: + return False + return True + class AppletPublication(JMSBaseModel): applet = models.ForeignKey('Applet', on_delete=models.CASCADE, related_name='publications',