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

minor fixes for 2.2 version

This commit is contained in:
Adolfo Gómez García 2020-05-26 21:29:39 +02:00
parent 2c10e9445b
commit 56553a70a1
4 changed files with 137 additions and 105 deletions

View File

@ -92,6 +92,10 @@ class ServicesPools(ModelHandler):
custom_methods = [('setFallbackAccess', True), ('actionsList', True)] custom_methods = [('setFallbackAccess', True), ('actionsList', True)]
def getItems(self, *args, **kwargs):
return super(ServicesPools, self).getItems(overview=kwargs.get('overview', True), prefetch=['service', 'service__provider', 'servicesPoolGroup', 'image', 'tags'])
# return super(ServicesPools, self).getItems(overview)
def item_as_dict(self, item): def item_as_dict(self, item):
summary = 'summarize' in self._params summary = 'summarize' in self._params
# if item does not have an associated service, hide it (the case, for example, for a removed service) # if item does not have an associated service, hide it (the case, for example, for a removed service)
@ -162,106 +166,106 @@ class ServicesPools(ModelHandler):
g = self.addDefaultFields([], ['name', 'short_name', 'comments', 'tags']) g = self.addDefaultFields([], ['name', 'short_name', 'comments', 'tags'])
for f in [{ for f in [{
'name': 'service_id', 'name': 'service_id',
'values': [gui.choiceItem(-1, '')] + gui.sortedChoices([gui.choiceItem(v.uuid, v.provider.name + '\\' + v.name) for v in Service.objects.all()]), 'values': [gui.choiceItem(-1, '')] + gui.sortedChoices([gui.choiceItem(v.uuid, v.provider.name + '\\' + v.name) for v in Service.objects.all()]),
'label': ugettext('Base service'), 'label': ugettext('Base service'),
'tooltip': ugettext('Service used as base of this service pool'), 'tooltip': ugettext('Service used as base of this service pool'),
'type': gui.InputField.CHOICE_TYPE, 'type': gui.InputField.CHOICE_TYPE,
'rdonly': True, 'rdonly': True,
'order': 100, # Ensueres is At end 'order': 100, # Ensueres is At end
}, { }, {
'name': 'osmanager_id', 'name': 'osmanager_id',
'values': [gui.choiceItem(-1, '')] + gui.sortedChoices([gui.choiceItem(v.uuid, v.name) for v in OSManager.objects.all()]), 'values': [gui.choiceItem(-1, '')] + gui.sortedChoices([gui.choiceItem(v.uuid, v.name) for v in OSManager.objects.all()]),
'label': ugettext('OS Manager'), 'label': ugettext('OS Manager'),
'tooltip': ugettext('OS Manager used as base of this service pool'), 'tooltip': ugettext('OS Manager used as base of this service pool'),
'type': gui.InputField.CHOICE_TYPE, 'type': gui.InputField.CHOICE_TYPE,
'rdonly': True, 'rdonly': True,
'order': 101, 'order': 101,
}, { }, {
'name': 'show_transports', 'name': 'show_transports',
'value': True, 'value': True,
'label': ugettext('Show transports'), 'label': ugettext('Show transports'),
'tooltip': ugettext('If active, alternative transports for user will be shown'), 'tooltip': ugettext('If active, alternative transports for user will be shown'),
'type': gui.InputField.CHECKBOX_TYPE, 'type': gui.InputField.CHECKBOX_TYPE,
'order': 110, 'order': 110,
'tab': ugettext('Advanced'), 'tab': ugettext('Advanced'),
}, { }, {
'name': 'allow_users_remove', 'name': 'allow_users_remove',
'value': False, 'value': False,
'label': ugettext('Allow removal by users'), 'label': ugettext('Allow removal by users'),
'tooltip': ugettext('If active, the user will be allowed to remove the service "manually". Be careful with this, because the user will have the "power" to delete it\'s own service'), 'tooltip': ugettext('If active, the user will be allowed to remove the service "manually". Be careful with this, because the user will have the "power" to delete it\'s own service'),
'type': gui.InputField.CHECKBOX_TYPE, 'type': gui.InputField.CHECKBOX_TYPE,
'order': 111, 'order': 111,
'tab': ugettext('Advanced'), 'tab': ugettext('Advanced'),
}, { }, {
'name': 'allow_users_reset', 'name': 'allow_users_reset',
'value': False, 'value': False,
'label': ugettext('Allow reset by users'), 'label': ugettext('Allow reset by users'),
'tooltip': ugettext('If active, the user will be allowed to reset the service'), 'tooltip': ugettext('If active, the user will be allowed to reset the service'),
'type': gui.InputField.CHECKBOX_TYPE, 'type': gui.InputField.CHECKBOX_TYPE,
'order': 112, 'order': 112,
'tab': ugettext('Advanced'), 'tab': ugettext('Advanced'),
}, { }, {
'name': 'ignores_unused', 'name': 'ignores_unused',
'value': False, 'value': False,
'label': ugettext('Ignores unused'), 'label': ugettext('Ignores unused'),
'tooltip': ugettext('If the option is enabled, UDS will not attempt to detect and remove the user services assigned but not in use.'), 'tooltip': ugettext('If the option is enabled, UDS will not attempt to detect and remove the user services assigned but not in use.'),
'type': gui.InputField.CHECKBOX_TYPE, 'type': gui.InputField.CHECKBOX_TYPE,
'order': 113, 'order': 113,
'tab': ugettext('Advanced'), 'tab': ugettext('Advanced'),
}, { }, {
'name': 'image_id', 'name': 'image_id',
'values': [gui.choiceImage(-1, '--------', DEFAULT_THUMB_BASE64)] + gui.sortedChoices([gui.choiceImage(v.uuid, v.name, v.thumb64) for v in Image.objects.all()]), 'values': [gui.choiceImage(-1, '--------', DEFAULT_THUMB_BASE64)] + gui.sortedChoices([gui.choiceImage(v.uuid, v.name, v.thumb64) for v in Image.objects.all()]),
'label': ugettext('Associated Image'), 'label': ugettext('Associated Image'),
'tooltip': ugettext('Image assocciated with this service'), 'tooltip': ugettext('Image assocciated with this service'),
'type': gui.InputField.IMAGECHOICE_TYPE, 'type': gui.InputField.IMAGECHOICE_TYPE,
'order': 120, 'order': 120,
'tab': ugettext('Display'), 'tab': ugettext('Display'),
}, { }, {
'name': 'servicesPoolGroup_id', 'name': 'servicesPoolGroup_id',
'values': [gui.choiceImage(-1, _('Default'), DEFAULT_THUMB_BASE64)] + gui.sortedChoices([gui.choiceImage(v.uuid, v.name, v.thumb64) for v in ServicesPoolGroup.objects.all()]), 'values': [gui.choiceImage(-1, _('Default'), DEFAULT_THUMB_BASE64)] + gui.sortedChoices([gui.choiceImage(v.uuid, v.name, v.thumb64) for v in ServicesPoolGroup.objects.all()]),
'label': ugettext('Pool group'), 'label': ugettext('Pool group'),
'tooltip': ugettext('Pool group for this pool (for pool classify on display)'), 'tooltip': ugettext('Pool group for this pool (for pool classify on display)'),
'type': gui.InputField.IMAGECHOICE_TYPE, 'type': gui.InputField.IMAGECHOICE_TYPE,
'order': 121, 'order': 121,
'tab': ugettext('Display'), 'tab': ugettext('Display'),
}, { }, {
'name': 'initial_srvs', 'name': 'initial_srvs',
'value': '0', 'value': '0',
'minValue': '0', 'minValue': '0',
'label': ugettext('Initial available services'), 'label': ugettext('Initial available services'),
'tooltip': ugettext('Services created initially for this service pool'), 'tooltip': ugettext('Services created initially for this service pool'),
'type': gui.InputField.NUMERIC_TYPE, 'type': gui.InputField.NUMERIC_TYPE,
'order': 130, 'order': 130,
'tab': ugettext('Availability'), 'tab': ugettext('Availability'),
}, { }, {
'name': 'cache_l1_srvs', 'name': 'cache_l1_srvs',
'value': '0', 'value': '0',
'minValue': '0', 'minValue': '0',
'label': ugettext('Services to keep in cache'), 'label': ugettext('Services to keep in cache'),
'tooltip': ugettext('Services kept in cache for improved user service assignation'), 'tooltip': ugettext('Services kept in cache for improved user service assignation'),
'type': gui.InputField.NUMERIC_TYPE, 'type': gui.InputField.NUMERIC_TYPE,
'order': 131, 'order': 131,
'tab': ugettext('Availability'), 'tab': ugettext('Availability'),
}, { }, {
'name': 'cache_l2_srvs', 'name': 'cache_l2_srvs',
'value': '0', 'value': '0',
'minValue': '0', 'minValue': '0',
'label': ugettext('Services to keep in L2 cache'), 'label': ugettext('Services to keep in L2 cache'),
'tooltip': ugettext('Services kept in cache of level2 for improved service generation'), 'tooltip': ugettext('Services kept in cache of level2 for improved service generation'),
'type': gui.InputField.NUMERIC_TYPE, 'type': gui.InputField.NUMERIC_TYPE,
'order': 132, 'order': 132,
'tab': ugettext('Availability'), 'tab': ugettext('Availability'),
}, { }, {
'name': 'max_srvs', 'name': 'max_srvs',
'value': '0', 'value': '0',
'minValue': '1', 'minValue': '1',
'label': ugettext('Maximum number of services to provide'), 'label': ugettext('Maximum number of services to provide'),
'tooltip': ugettext('Maximum number of service (assigned and L1 cache) that can be created for this service'), 'tooltip': ugettext('Maximum number of service (assigned and L1 cache) that can be created for this service'),
'type': gui.InputField.NUMERIC_TYPE, 'type': gui.InputField.NUMERIC_TYPE,
'order': 133, 'order': 133,
'tab': ugettext('Availability'), 'tab': ugettext('Availability'),
}]: }]:
self.addField(g, f) self.addField(g, f)
return g return g

View File

@ -732,8 +732,28 @@ class ModelHandler(BaseModelHandler):
return method() return method()
def getItems(self, overview=True, *args, **kwargs): def getItems(self, *args, **kwargs):
for item in self.model.objects.filter(*args, **kwargs): if 'overview' in kwargs:
overview = kwargs['overview']
del kwargs['overview']
else:
overview = False
if 'prefetch' in kwargs:
prefetch = kwargs['prefetch']
logger.debug('Prefetching %s', prefetch)
del kwargs['prefetch']
else:
prefetch = []
if 'query' in kwargs:
query = kwargs['query']
del kwargs['query']
else:
logger.debug('Args: %s, kwargs: %s', args, kwargs)
query = self.model.objects.filter(*args, **kwargs).prefetch_related(*prefetch)
for item in query:
try: try:
if permissions.checkPermissions(self._user, item, permissions.PERMISSION_READ) is False: if permissions.checkPermissions(self._user, item, permissions.PERMISSION_READ) is False:
continue continue

View File

@ -115,7 +115,8 @@ class CalendarAction(UUIDModel):
self.service_pool.save() self.service_pool.save()
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
self.next_execution = calendar.CalendarChecker(self.calendar).nextEvent(checkFrom=self.last_execution, startEvent=self.at_start, offset=self.offset) lastExecution = self.last_execution or getSqlDatetime()
self.next_execution = calendar.CalendarChecker(self.calendar).nextEvent(checkFrom=lastExecution-self.offset, startEvent=self.at_start) + self.offset
return UUIDModel.save(self, *args, **kwargs) return UUIDModel.save(self, *args, **kwargs)

View File

@ -191,10 +191,17 @@ def index(request):
else: else:
tbrt = '' tbrt = ''
left = ''
# try:
# if svr.max_srvs > 0:
# left = ' (max {})'.format(svr.max_srvs - svr.assignedUserServices().filter(UserServiceManager.getStateFilter()).count())
# except Exception:
# logger.exception('Error')
services.append({ services.append({
'id': 'F' + svr.uuid, 'id': 'F' + svr.uuid,
'name': svr.name, 'name': svr.name + left,
'visual_name': svr.visual_name, 'visual_name': svr.visual_name + left,
'description': svr.comments, 'description': svr.comments,
'group': group, 'group': group,
'transports': trans, 'transports': trans,