mirror of
https://github.com/dkmstr/openuds.git
synced 2024-12-24 21:34:41 +03:00
Fixed meta pools non being correctly checked
This commit is contained in:
parent
27d158f514
commit
8d93144e24
@ -154,7 +154,7 @@ class MetaAssignedService(DetailHandler):
|
||||
return UserService.objects.filter(
|
||||
uuid=processUuid(userServiceId),
|
||||
cache_level=0,
|
||||
eployed_service__in=[i.pool for i in metaPool.members.all()],
|
||||
deployed_service__in=[i.pool for i in metaPool.members.all()],
|
||||
)[0]
|
||||
except Exception:
|
||||
pass
|
||||
|
@ -702,23 +702,27 @@ class UserServiceManager(metaclass=singleton.Singleton):
|
||||
logger.debug('Kind of service: %s, idService: %s', kind, uuidService)
|
||||
userService: typing.Optional[UserService] = None
|
||||
|
||||
if kind == 'A': # This is an assigned service
|
||||
if kind in 'A': # This is an assigned service
|
||||
logger.debug('Getting A service %s', uuidService)
|
||||
userService = UserService.objects.get(uuid=uuidService, user=user)
|
||||
typing.cast(UserService, userService).deployed_service.validateUser(user)
|
||||
else:
|
||||
servicePool: ServicePool = ServicePool.objects.get(uuid=uuidService)
|
||||
# We first do a sanity check for this, if the user has access to this service
|
||||
# If it fails, will raise an exception
|
||||
servicePool.validateUser(user)
|
||||
try:
|
||||
servicePool: ServicePool = ServicePool.objects.get(uuid=uuidService)
|
||||
# We first do a sanity check for this, if the user has access to this service
|
||||
# If it fails, will raise an exception
|
||||
servicePool.validateUser(user)
|
||||
|
||||
# Now we have to locate an instance of the service, so we can assign it to user.
|
||||
if (
|
||||
create
|
||||
): # getAssignation, if no assignation is found, tries to create one
|
||||
userService = self.getAssignationForUser(servicePool, user)
|
||||
else: # Sometimes maybe we only need to locate the existint user service
|
||||
userService = self.getExistingAssignationForUser(servicePool, user)
|
||||
# Now we have to locate an instance of the service, so we can assign it to user.
|
||||
if (
|
||||
create
|
||||
): # getAssignation, if no assignation is found, tries to create one
|
||||
userService = self.getAssignationForUser(servicePool, user)
|
||||
else: # Sometimes maybe we only need to locate the existint user service
|
||||
userService = self.getExistingAssignationForUser(servicePool, user)
|
||||
except ServicePool.DoesNotExist:
|
||||
logger.debug('Service pool does not exist')
|
||||
return None
|
||||
|
||||
logger.debug('Found service: %s', userService)
|
||||
|
||||
@ -900,6 +904,33 @@ class UserServiceManager(metaclass=singleton.Singleton):
|
||||
code=serviceNotReadyCode, userService=userService, transport=transport
|
||||
)
|
||||
|
||||
def isMetaService(self, metaId: str) -> bool:
|
||||
return metaId[0] == 'M'
|
||||
|
||||
def locateMetaService(
|
||||
self, user: User, idService: str, create: bool = False
|
||||
) -> typing.Optional[UserService]:
|
||||
kind, uuidMetapool = idService[0], idService[1:]
|
||||
if kind != 'M':
|
||||
return None
|
||||
|
||||
meta: MetaPool = MetaPool.objects.get(uuid=uuidMetapool)
|
||||
# Get pool members. Just pools "visible" and "usable"
|
||||
pools = [
|
||||
p.pool for p in meta.members.all() if p.pool.isVisible() and p.pool.isUsable()
|
||||
]
|
||||
# look for an existing user service in the pool
|
||||
try:
|
||||
return UserService.objects.filter(
|
||||
deployed_service__in=pools,
|
||||
state__in=State.VALID_STATES,
|
||||
user=user,
|
||||
cache_level=0,
|
||||
).order_by('deployed_service__name')[0]
|
||||
except IndexError:
|
||||
return None
|
||||
|
||||
|
||||
def getMeta(
|
||||
self,
|
||||
user: User,
|
||||
|
@ -51,6 +51,7 @@ from uds.web.util import services
|
||||
# Not imported at runtime, just for type checking
|
||||
if typing.TYPE_CHECKING:
|
||||
from uds.core.util.request import ExtendedHttpRequest, ExtendedHttpRequestWithUser
|
||||
from uds.models import UserService
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -155,12 +156,17 @@ def userServiceStatus(
|
||||
Note:
|
||||
'''
|
||||
ip: typing.Union[str, None, bool]
|
||||
userService = None
|
||||
userService: typing.Optional['UserService'] = None
|
||||
status = 'running'
|
||||
# If service exists
|
||||
userService = userServiceManager().locateUserService(
|
||||
user=request.user, idService=idService, create=False
|
||||
)
|
||||
# If service exists (meta or not)
|
||||
if userServiceManager().isMetaService(idService):
|
||||
userService = userServiceManager().locateMetaService(
|
||||
user=request.user, idService=idService
|
||||
)
|
||||
else:
|
||||
userService = userServiceManager().locateUserService(
|
||||
user=request.user, idService=idService, create=False
|
||||
)
|
||||
if userService:
|
||||
# Service exists...
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user