1
0
mirror of https://github.com/dkmstr/openuds.git synced 2025-01-01 21:17:58 +03:00

Added support for checking id the service pool is active before trying to create "new" userservices

This commit is contained in:
Adolfo Gómez García 2024-12-25 00:52:32 +01:00
parent a881509502
commit 9b3caed641
No known key found for this signature in database
GPG Key ID: DD1ABF20724CDA23
2 changed files with 16 additions and 2 deletions

View File

@ -558,6 +558,9 @@ class UserServiceManager(metaclass=singleton.Singleton):
if servicepool.is_restrained():
raise InvalidServiceException(_('The requested service is restrained'))
if servicepool.can_create_userservices() is False:
raise InvalidServiceException(_('Cannot create user services for this service'))
if servicepool.uses_cache:
cache: typing.Optional[UserService] = None
# Now try to locate 1 from cache already "ready" (must be usable and at level 1)
@ -1101,7 +1104,9 @@ class UserServiceManager(metaclass=singleton.Singleton):
meta: MetaPool = MetaPool.objects.get(uuid=uuid_metapool)
# Get pool members. Just pools enabled, that are "visible" and "usable"
pools = [p.pool for p in meta.members.filter(enabled=True) if p.pool.is_visible() and p.pool.is_usable()]
pools = [
p.pool for p in meta.members.filter(enabled=True) if p.pool.is_visible() and p.pool.is_usable()
]
# look for an existing user service in the pool
try:
return UserService.objects.filter(
@ -1132,7 +1137,9 @@ class UserServiceManager(metaclass=singleton.Singleton):
raise ServiceAccessDeniedByCalendar()
# Get pool members. Just pools "visible" and "usable"
metapool_members = [p for p in meta.members.filter(enabled=True) if p.pool.is_visible() and p.pool.is_usable()]
metapool_members = [
p for p in meta.members.filter(enabled=True) if p.pool.is_visible() and p.pool.is_usable()
]
# Sort pools array. List of tuples with (priority, pool)
pools_sorted: list[tuple[int, ServicePool]]
# Sort pools based on meta selection

View File

@ -256,6 +256,13 @@ class ServicePool(UUIDModel, TaggingMixin):
if self.short_name and str(self.short_name).strip():
return str(self.short_name.strip())
return str(self.name)
def can_create_userservices(self) -> bool:
"""
If the service pool is in a state that allows to create user services
True if the state is ACTIVE, False otherwise
"""
return self.state == types.states.State.ACTIVE
def is_restrained(self) -> bool:
"""