1
0
mirror of https://github.com/dkmstr/openuds.git synced 2025-03-20 06:50:23 +03:00

Formatting fixes

This commit is contained in:
Adolfo Gómez García 2021-07-12 12:58:45 +02:00
parent 49ce5622d6
commit cd06597918
2 changed files with 130 additions and 58 deletions

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2014-2019 Virtual Cable S.L.
# Copyright (c) 2014-2021 Virtual Cable S.L.U.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
@ -12,7 +12,7 @@
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# * Neither the name of Virtual Cable S.L. nor the names of its contributors
# * Neither the name of Virtual Cable S.L.U. nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
@ -50,7 +50,15 @@ logger = logging.getLogger(__name__)
class Transports(ModelHandler):
model = Transport
save_fields = ['name', 'comments', 'tags', 'priority', 'nets_positive', 'allowed_oss', 'label']
save_fields = [
'name',
'comments',
'tags',
'priority',
'nets_positive',
'allowed_oss',
'label',
]
table_title = _('Transports')
table_fields = [
@ -58,7 +66,13 @@ class Transports(ModelHandler):
{'name': {'title': _('Name'), 'visible': True, 'type': 'iconType'}},
{'type_name': {'title': _('Type')}},
{'comments': {'title': _('Comments')}},
{'pools_count': {'title': _('Service Pools'), 'type': 'numeric', 'width': '6em'}},
{
'pools_count': {
'title': _('Service Pools'),
'type': 'numeric',
'width': '6em',
}
},
{'allowed_oss': {'title': _('Devices'), 'width': '8em'}},
{'tags': {'title': _('tags'), 'visible': False}},
]
@ -72,52 +86,90 @@ class Transports(ModelHandler):
if not transport:
raise self.invalidItemException()
field = self.addDefaultFields(transport.guiDescription(), ['name', 'comments', 'tags', 'priority'])
field = self.addField(field, {
'name': 'nets_positive',
'value': True,
'label': ugettext('Network access'),
'tooltip': ugettext('If checked, the transport will be enabled for the selected networks. If unchecked, transport will be disabled for selected networks'),
'type': 'checkbox',
'order': 100, # At end
})
field = self.addField(field, {
'name': 'networks',
'value': [],
'values': sorted([{'id': x.uuid, 'text': x.name} for x in Network.objects.all()], key=lambda x: x['text'].lower()),
'label': ugettext('Networks'),
'tooltip': ugettext('Networks associated with this transport. If No network selected, will mean "all networks"'),
'type': 'multichoice',
'order': 101
})
field = self.addField(field, {
'name': 'allowed_oss',
'value': [],
'values': sorted([{'id': x, 'text': x.replace('CrOS', 'Chrome OS')} for x in OsDetector.knownOss], key=lambda x: x['text'].lower()),
'label': ugettext('Allowed Devices'),
'tooltip': ugettext('If empty, any kind of device compatible with this transport will be allowed. Else, only devices compatible with selected values will be allowed'),
'type': 'multichoice',
'order': 102
})
field = self.addField(field, {
'name': 'pools',
'value': [],
'values': [{'id': x.uuid, 'text': x.name} for x in ServicePool.objects.all().order_by('name') if transport.protocol in x.service.getType().allowedProtocols],
'label': ugettext('Service Pools'),
'tooltip': ugettext('Currently assigned services pools'),
'type': 'multichoice',
'order': 103
})
field = self.addField(field, {
'name': 'label',
'length': 32,
'value': '',
'label': ugettext('Label'),
'tooltip': ugettext('Metapool transport label (only used on metapool transports grouping)'),
'type': 'text',
'order': 201,
'tab': gui.ADVANCED_TAB
})
field = self.addDefaultFields(
transport.guiDescription(), ['name', 'comments', 'tags', 'priority']
)
field = self.addField(
field,
{
'name': 'nets_positive',
'value': True,
'label': ugettext('Network access'),
'tooltip': ugettext(
'If checked, the transport will be enabled for the selected networks. If unchecked, transport will be disabled for selected networks'
),
'type': 'checkbox',
'order': 100, # At end
},
)
field = self.addField(
field,
{
'name': 'networks',
'value': [],
'values': sorted(
[{'id': x.uuid, 'text': x.name} for x in Network.objects.all()],
key=lambda x: x['text'].lower(),
),
'label': ugettext('Networks'),
'tooltip': ugettext(
'Networks associated with this transport. If No network selected, will mean "all networks"'
),
'type': 'multichoice',
'order': 101,
},
)
field = self.addField(
field,
{
'name': 'allowed_oss',
'value': [],
'values': sorted(
[
{'id': x, 'text': x.replace('CrOS', 'Chrome OS')}
for x in OsDetector.knownOss
],
key=lambda x: x['text'].lower(),
),
'label': ugettext('Allowed Devices'),
'tooltip': ugettext(
'If empty, any kind of device compatible with this transport will be allowed. Else, only devices compatible with selected values will be allowed'
),
'type': 'multichoice',
'order': 102,
},
)
field = self.addField(
field,
{
'name': 'pools',
'value': [],
'values': [
{'id': x.uuid, 'text': x.name}
for x in ServicePool.objects.all().order_by('name')
if transport.protocol in x.service.getType().allowedProtocols
],
'label': ugettext('Service Pools'),
'tooltip': ugettext('Currently assigned services pools'),
'type': 'multichoice',
'order': 103,
},
)
field = self.addField(
field,
{
'name': 'label',
'length': 32,
'value': '',
'label': ugettext('Label'),
'tooltip': ugettext(
'Metapool transport label (only used on metapool transports grouping)'
),
'type': 'text',
'order': 201,
'tab': gui.ADVANCED_TAB,
},
)
return field
@ -133,14 +185,16 @@ class Transports(ModelHandler):
'nets_positive': item.nets_positive,
'label': item.label,
'networks': [{'id': n.uuid} for n in item.networks.all()],
'allowed_oss': [{'id': x} for x in item.allowed_oss.split(',')] if item.allowed_oss != '' else [],
'allowed_oss': [{'id': x} for x in item.allowed_oss.split(',')]
if item.allowed_oss != ''
else [],
'pools': pools,
'pools_count': len(pools),
'deployed_count': item.deployedServices.count(),
'type': type_.type(),
'type_name': type_.name(),
'protocol': type_.protocol,
'permission': permissions.getEffectivePermission(self._user, item)
'permission': permissions.getEffectivePermission(self._user, item),
}
def beforeSave(self, fields: typing.Dict[str, typing.Any]) -> None:

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2012-2019 Virtual Cable S.L.
# Copyright (c) 2012-2021 Virtual Cable S.L.U.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
@ -12,7 +12,7 @@
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# * Neither the name of Virtual Cable S.L. nor the names of its contributors
# * Neither the name of Virtual Cable S.L.U. nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
@ -50,7 +50,17 @@ iPhone = 'iPhone' # In fact, these are IOS both, but we can diferentiate it...
WYSE = 'WYSE'
Unknown = 'Unknown'
knownOss = (WindowsPhone, Android, Linux, Windows, iPad, iPhone, Macintosh, ChromeOS, WYSE) # Android is linux also, so it is cheched on first place
knownOss = (
WindowsPhone,
Android,
Linux,
Windows,
iPad,
iPhone,
Macintosh,
ChromeOS,
WYSE,
) # Android is linux also, so it is cheched on first place
allOss = knownOss + (Unknown,)
desktopOss = (Linux, Windows, Macintosh)
@ -77,8 +87,14 @@ browsersREs: typing.Dict[str, typing.Tuple] = {
Chrome: (re.compile(r'Chrome/([0-9.]+)'),),
Chromium: (re.compile(r'Chromium/([0-9.]+)'),),
Safari: (re.compile(r'Safari/([0-9.]+)'),),
Opera: (re.compile(r'OPR/([0-9.]+)'), re.compile(r'Opera/([0-9.]+)'),),
IExplorer: (re.compile(r';MSIE ([0-9.]+);'), re.compile(r'Trident/.*rv:([0-9.]+)'),)
Opera: (
re.compile(r'OPR/([0-9.]+)'),
re.compile(r'Opera/([0-9.]+)'),
),
IExplorer: (
re.compile(r';MSIE ([0-9.]+);'),
re.compile(r'Trident/.*rv:([0-9.]+)'),
),
}
browserRules: typing.Dict[str, typing.Tuple] = {
@ -92,7 +108,9 @@ browserRules: typing.Dict[str, typing.Tuple] = {
}
def getOsFromUA(ua: typing.Optional[str]) -> DictAsObj: # pylint: disable=too-many-branches
def getOsFromUA(
ua: typing.Optional[str],
) -> DictAsObj: # pylint: disable=too-many-branches
"""
Basic OS Client detector (very basic indeed :-))
"""