mirror of
https://github.com/dkmstr/openuds.git
synced 2025-01-10 01:17:59 +03:00
Simplified code. Removed "assignedUserService" logic because pools will
allow only one userService per user, so everything can be located using "pool"
This commit is contained in:
parent
64faeec13c
commit
e88256a892
@ -86,37 +86,10 @@ class Connection(Handler):
|
||||
# We look for services for this authenticator groups. User is logged in in just 1 authenticator, so his groups must coincide with those assigned to ds
|
||||
groups = list(self._user.getGroups())
|
||||
availServices = DeployedService.getDeployedServicesForGroups(groups)
|
||||
availUserServices = UserService.getUserAssignedServices(self._user)
|
||||
|
||||
# Extract required data to show to user
|
||||
services = []
|
||||
# Select assigned user services
|
||||
for svr in availUserServices:
|
||||
# Skip maintenance services...
|
||||
trans = []
|
||||
for t in svr.transports.all().order_by('priority'):
|
||||
if t.validForIp(self._request.ip) and t.getType().providesConnetionInfo():
|
||||
trans.append({'id': t.uuid, 'name': t.name})
|
||||
|
||||
servicePool = svr.deployed_service
|
||||
|
||||
services.append({'id': 'A' + svr.uuid,
|
||||
'name': servicePool.name,
|
||||
'description': servicePool.comments,
|
||||
'visual_name': servicePool.visual_name,
|
||||
'group': servicePool.servicesPoolGroup if servicePool.servicesPoolGroup is not None else ServicesPoolGroup.default().as_dict,
|
||||
'thumb': servicePool.image.thumb64 if servicePool.image is not None else DEFAULT_THUMB_BASE64,
|
||||
'show_transports': servicePool.show_transports,
|
||||
'allow_users_remove': servicePool.allow_users_remove,
|
||||
'not_accesible': not servicePool.isAccessAllowed(),
|
||||
'to_be_replaced': False, # Manually assigned will not be autoremoved never
|
||||
'transports': trans,
|
||||
'maintenance': servicePool.isInMaintenance(),
|
||||
'in_use': servicePool.in_use})
|
||||
|
||||
logger.debug(services)
|
||||
|
||||
# Now generic user service
|
||||
# User services
|
||||
for servicePool in availServices:
|
||||
trans = []
|
||||
for t in servicePool.transports.all().order_by('priority'):
|
||||
|
@ -57,7 +57,7 @@ from uds.core.services import UserDeployment
|
||||
|
||||
import logging
|
||||
|
||||
__updated__ = '2018-09-26'
|
||||
__updated__ = '2019-02-05'
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -451,26 +451,6 @@ class UserService(UUIDModel):
|
||||
from uds.core.managers.UserServiceManager import UserServiceManager
|
||||
UserServiceManager.manager().moveToLevel(self, cacheLevel)
|
||||
|
||||
@staticmethod
|
||||
def getUserAssignedServices(user):
|
||||
"""
|
||||
Return DeployedUserServices (not deployed services) that this user owns and are assignable
|
||||
For this to happen, we locate all user services assigned to this user, and we keep those that:
|
||||
* Must assign service manually
|
||||
This method is probably not the best in performance, but the number of assigned services will never be "high" (maybe a couple dozens at most?)
|
||||
@returns and array of dicts with id, name and transports
|
||||
"""
|
||||
logger.debug("Filtering assigned services for user {0}".format(user))
|
||||
res = []
|
||||
for us in UserService.objects.filter(user=user):
|
||||
if us.deployed_service.state != State.ACTIVE: # Do not show removing or removed services
|
||||
continue
|
||||
usi = us.getInstance()
|
||||
if usi.service().mustAssignManually is False:
|
||||
continue
|
||||
res.append({'id': us.id, 'name': usi.getName(), 'transports': us.deployed_service.transports, 'service': us})
|
||||
return res
|
||||
|
||||
def getProperty(self, propName, default=None):
|
||||
try:
|
||||
val = self.properties.get(name=propName).value
|
||||
|
@ -43,7 +43,7 @@ import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
__updated__ = '2018-11-28'
|
||||
__updated__ = '2019-02-05'
|
||||
|
||||
|
||||
def getServicesData(request):
|
||||
@ -53,7 +53,6 @@ def getServicesData(request):
|
||||
# We look for services for this authenticator groups. User is logged in in just 1 authenticator, so his groups must coincide with those assigned to ds
|
||||
groups = list(request.user.getGroups())
|
||||
availServices = DeployedService.getDeployedServicesForGroups(groups)
|
||||
availUserServices = UserService.getUserAssignedServices(request.user)
|
||||
|
||||
# Information for administrators
|
||||
nets = ''
|
||||
@ -69,60 +68,7 @@ def getServicesData(request):
|
||||
tt.append(t.name)
|
||||
validTrans = ','.join(tt)
|
||||
|
||||
# Extract required data to show to user
|
||||
services = []
|
||||
# Select assigned user services (manually assigned)
|
||||
for svr in availUserServices:
|
||||
trans = []
|
||||
for t in svr.transports.all().order_by('priority'):
|
||||
typeTrans = t.getType()
|
||||
if t.validForIp(request.ip) and typeTrans.supportsOs(os['OS']) and t.validForOs(os['OS']):
|
||||
if typeTrans.ownLink is True:
|
||||
link = reverse('TransportOwnLink', args=('A' + svr.uuid, t.uuid))
|
||||
else:
|
||||
link = html.udsAccessLink(request, 'A' + svr.uuid, t.uuid)
|
||||
trans.append(
|
||||
{
|
||||
'id': t.uuid,
|
||||
'name': t.name,
|
||||
'link': link
|
||||
}
|
||||
)
|
||||
|
||||
# If empty transports, do not include it on list
|
||||
if not trans:
|
||||
continue
|
||||
|
||||
servicePool = svr.deployed_service
|
||||
|
||||
if servicePool.image is not None:
|
||||
imageId = servicePool.image.uuid
|
||||
else:
|
||||
imageId = 'x' # Invalid
|
||||
|
||||
# Extract app group
|
||||
group = servicePool.servicesPoolGroup if servicePool.servicesPoolGroup is not None else ServicesPoolGroup.default().as_dict
|
||||
|
||||
services.append({
|
||||
'id': 'A' + svr.uuid,
|
||||
'name': servicePool.name,
|
||||
'visual_name': servicePool.visual_name,
|
||||
'description': servicePool.comments,
|
||||
'group': group,
|
||||
'transports': trans,
|
||||
'imageId': imageId,
|
||||
'show_transports': servicePool.show_transports,
|
||||
'allow_users_remove': servicePool.allow_users_remove,
|
||||
'allow_users_reset': servicePool.allow_users_reset,
|
||||
'maintenance': servicePool.isInMaintenance(),
|
||||
'not_accesible': not servicePool.isAccessAllowed(),
|
||||
'in_use': svr.in_use,
|
||||
'to_be_replaced': False, # Manually assigned will not be autoremoved never
|
||||
'comments': servicePool.comments,
|
||||
})
|
||||
|
||||
logger.debug(services)
|
||||
|
||||
# Now generic user service
|
||||
for svr in availServices:
|
||||
trans = []
|
||||
|
Loading…
Reference in New Issue
Block a user