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

Added visible attribute to services pools

This commit is contained in:
Adolfo Gómez García 2017-04-06 20:30:49 +02:00
parent f2523fa8f2
commit d6539dc543
6 changed files with 37 additions and 12 deletions

View File

@ -84,7 +84,8 @@ class ServicesPools(ModelHandler):
'cache_l1_srvs',
'cache_l2_srvs',
'max_srvs',
'show_transports'
'show_transports',
'visible'
]
remove_fields = ['osmanager_id', 'service_id']
@ -94,7 +95,7 @@ class ServicesPools(ModelHandler):
{'state': {'title': _('status'), 'type': 'dict', 'dict': State.dictionary()}},
{'user_services_count': {'title': _('User services'), 'type': 'number'}},
{'user_services_in_preparation': {'title': _('In Preparation')}},
{'show_transports': {'title': _('Shows transports'), 'type': 'callback'}},
{'visible': {'title': _('Visible'), 'type': 'callback'}},
{'pool_group_name': {'title': _('Pool Group')}},
{'parent': {'title': _('Parent Service')}},
{'tags': {'title': _('tags'), 'visible': False}},
@ -150,6 +151,7 @@ class ServicesPools(ModelHandler):
'user_services_in_preparation': item.userServices.filter(state=State.PREPARING).count(),
'restrained': item.isRestrained(),
'show_transports': item.show_transports,
'visible': item.visible,
'fallbackAccess': item.fallbackAccess,
'permission': permissions.getEffectivePermission(self._user, item),
'info': Services.serviceInfo(item.service),
@ -201,6 +203,14 @@ class ServicesPools(ModelHandler):
'type': gui.InputField.IMAGECHOICE_TYPE,
'order': 106,
'tab': ugettext('Display'),
}, {
'name': 'visible',
'value': True,
'label': ugettext('Visible'),
'tooltip': ugettext('If active, transport will be visible for users'),
'type': gui.InputField.CHECKBOX_TYPE,
'order': 107,
'tab': ugettext('Display'),
}, {
'name': 'initial_srvs',
'value': '0',

View File

@ -51,7 +51,7 @@ import requests
import json
import logging
__updated__ = '2017-03-22'
__updated__ = '2017-04-06'
logger = logging.getLogger(__name__)
traceLogger = logging.getLogger('traceLog')
@ -236,7 +236,7 @@ class UserServiceManager(object):
dsp.cachedDeployedService.filter(state__in=State.INFO_STATES).delete()
def getExistingAssignationForUser(self, ds, user):
existing = ds.assignedUserServices().filter(user=user, state__in=State.VALID_STATES)
existing = ds.assignedUserServices().filter(user=user, state__in=State.VALID_STATES, deployed_service__visible=True)
lenExisting = existing.count()
if lenExisting > 0: # Already has 1 assigned
logger.debug('Found assigned service from {0} to user {1}'.format(ds, user.name))
@ -513,6 +513,10 @@ class UserServiceManager(object):
if userService.isInMaintenance() is True:
raise ServiceInMaintenanceMode()
# If service is not visible, do not allow it to be used
if userService.deployed_service.isVisible() is False:
raise InvalidServiceException()
if userService.deployed_service.isAccessAllowed() is False:
raise ServiceAccessDeniedByCalendar()

View File

@ -33,4 +33,4 @@
from __future__ import unicode_literals
# pylint: disable=unused-import
from .common import ERROR, USABLE # @UnusedImport
from .common import ERROR, USABLE, REMOVABLE, REMOVED, CANCELED, LAUNCHING, PREPARING # @UnusedImport

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-01-31 08:03
# Generated by Django 1.10.6 on 2017-04-06 19:58
from __future__ import unicode_literals
import datetime
@ -63,6 +63,11 @@ class Migration(migrations.Migration):
'db_table': 'uds_proxies',
},
),
migrations.AddField(
model_name='deployedservice',
name='visible',
field=models.BooleanField(default=True),
),
migrations.AddField(
model_name='ticketstore',
name='owner',

View File

@ -63,7 +63,7 @@ from datetime import datetime, timedelta
import logging
import pickle
__updated__ = '2017-01-23'
__updated__ = '2017-04-06'
logger = logging.getLogger(__name__)
@ -83,6 +83,7 @@ class DeployedService(UUIDModel, TaggingMixin):
state = models.CharField(max_length=1, default=states.servicePool.ACTIVE, db_index=True)
state_date = models.DateTimeField(default=NEVER)
show_transports = models.BooleanField(default=True)
visible = models.BooleanField(default=True)
image = models.ForeignKey(Image, null=True, blank=True, related_name='deployedServices', on_delete=models.SET_NULL)
servicesPoolGroup = models.ForeignKey(ServicesPoolGroup, null=True, blank=True, related_name='servicesPools', on_delete=models.SET_NULL)
@ -199,10 +200,13 @@ class DeployedService(UUIDModel, TaggingMixin):
def isInMaintenance(self):
return self.service is not None and self.service.isInMaintenance()
def isVisible(self):
return self.visible
def toBeReplaced(self):
# return datetime.now()
activePub = self.activePublication()
if activePub is None or activePub.revision == self.current_pub_revision - 1:
if activePub is None or activePub.revision <= self.current_pub_revision - 1:
return None
# Return the date
@ -414,10 +418,10 @@ class DeployedService(UUIDModel, TaggingMixin):
from uds.core import services
# Get services that HAS publications
list1 = DeployedService.objects.filter(assignedGroups__in=groups, assignedGroups__state=states.group.ACTIVE,
state=states.servicePool.ACTIVE).distinct().annotate(cuenta=models.Count('publications')).exclude(cuenta=0)
state=states.servicePool.ACTIVE, visible=True).distinct().annotate(cuenta=models.Count('publications')).exclude(cuenta=0)
# Now get deployed services that DO NOT NEED publication
doNotNeedPublishing = [t.type() for t in services.factory().servicesThatDoNotNeedPublication()]
list2 = DeployedService.objects.filter(assignedGroups__in=groups, assignedGroups__state=states.group.ACTIVE, service__data_type__in=doNotNeedPublishing, state=states.servicePool.ACTIVE)
list2 = DeployedService.objects.filter(assignedGroups__in=groups, assignedGroups__state=states.group.ACTIVE, service__data_type__in=doNotNeedPublishing, state=states.servicePool.ACTIVE, visible=True)
# And generate a single list without duplicates
return list(set([r for r in list1] + [r for r in list2]))

View File

@ -149,10 +149,12 @@ gui.servicesPools.link = (event) ->
# Callback for custom fields
renderer = (fld, data, type, record) ->
# Display "custom" fields of rules table
if fld == "show_transports"
console.log(fld)
console.log(data)
if fld == "show_transports" or fld == "visible"
if data
return gettext('Yes')
gettext('No')
return gettext('No')
return fld
api.templates.get "services_pool", (tmpl) ->