mirror of
https://github.com/dkmstr/openuds.git
synced 2025-01-08 21:18:00 +03:00
Advancing on calendar access & scheduling
This commit is contained in:
parent
cbb809db77
commit
7b9c835562
@ -43,6 +43,7 @@ from uds.REST.model import ModelHandler
|
||||
from uds.REST import RequestError, ResponseError
|
||||
from uds.core.ui.UserInterface import gui
|
||||
from .user_services import AssignedService, CachedService, Groups, Transports, Publications, Changelog
|
||||
from .services_pool_calendars import AccessCalendars
|
||||
from .services import Services
|
||||
|
||||
import logging
|
||||
@ -61,7 +62,8 @@ class ServicesPools(ModelHandler):
|
||||
'groups': Groups,
|
||||
'transports': Transports,
|
||||
'publications': Publications,
|
||||
'changelog': Changelog
|
||||
'changelog': Changelog,
|
||||
'access': AccessCalendars,
|
||||
}
|
||||
|
||||
save_fields = ['name', 'comments', 'tags', 'service_id', 'osmanager_id', 'image_id', 'servicesPoolGroup_id', 'initial_srvs', 'cache_l1_srvs', 'cache_l2_srvs', 'max_srvs', 'show_transports']
|
||||
@ -103,6 +105,7 @@ class ServicesPools(ModelHandler):
|
||||
'user_services_count': item.userServices.count(),
|
||||
'restrained': item.isRestrained(),
|
||||
'show_transports': item.show_transports,
|
||||
'allowAccessByDefault': item.fallbackAccessAllow,
|
||||
'permission': permissions.getEffectivePermission(self._user, item),
|
||||
'info': Services.serviceInfo(item.service),
|
||||
}
|
||||
|
@ -44,7 +44,6 @@ from uds.models import ServicePool, UserService, getSqlDatetime, Transport
|
||||
from uds.core import services
|
||||
from uds.core.services import Service
|
||||
from uds.core.util.stats import events
|
||||
from uds.core.util.calendar import CalendarChecker
|
||||
|
||||
from .userservice.opchecker import UserServiceOpChecker
|
||||
|
||||
@ -52,7 +51,7 @@ import requests
|
||||
import json
|
||||
import logging
|
||||
|
||||
__updated__ = '2016-02-17'
|
||||
__updated__ = '2016-02-18'
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -421,22 +420,6 @@ class UserServiceManager(object):
|
||||
uService.setState(State.PREPARING)
|
||||
UserServiceOpChecker.makeUnique(uService, ui, state)
|
||||
|
||||
def accessAllowed(self, servicePool, chkDateTime=None):
|
||||
'''
|
||||
Checks if the access for a service pool is allowed or not (based esclusively on associated calendars)
|
||||
'''
|
||||
if chkDateTime is None:
|
||||
chkDateTime = getSqlDatetime()
|
||||
|
||||
allow = servicePool.fallbackAccessAllow
|
||||
# Let's see if we can access by current datetime
|
||||
for ac in servicePool.accessCalendars.all():
|
||||
if CalendarChecker(ac.calender).check(chkDateTime) is True:
|
||||
allow = ac.allow
|
||||
|
||||
return allow
|
||||
|
||||
|
||||
def getService(self, user, srcIp, idService, idTransport, doTest=True):
|
||||
'''
|
||||
Get service info from
|
||||
|
@ -32,7 +32,8 @@
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
from django.db import transaction
|
||||
from uds.models import Cache as dbCache, getSqlDatetime
|
||||
import uds.models.Cache
|
||||
from uds.models import getSqlDatetime
|
||||
from datetime import datetime, timedelta
|
||||
import hashlib
|
||||
import logging
|
||||
@ -58,13 +59,13 @@ class Cache(object):
|
||||
# logger.debug('Requesting key "%s" for cache "%s"' % (skey, self._owner,))
|
||||
try:
|
||||
key = self.__getKey(skey)
|
||||
c = dbCache.objects.get(pk=key) # @UndefinedVariable
|
||||
c = uds.models.Cache.objects.get(pk=key) # @UndefinedVariable
|
||||
expired = now > c.created + timedelta(seconds=c.validity)
|
||||
if expired:
|
||||
return defValue
|
||||
val = pickle.loads(c.value.decode(Cache.CODEC))
|
||||
return val
|
||||
except dbCache.DoesNotExist: # @UndefinedVariable
|
||||
except uds.models.Cache.DoesNotExist: # @UndefinedVariable
|
||||
logger.debug('key not found: {}'.format(skey))
|
||||
return defValue
|
||||
|
||||
@ -76,9 +77,9 @@ class Cache(object):
|
||||
# logger.debug('Removing key "%s" for uService "%s"' % (skey, self._owner))
|
||||
try:
|
||||
key = self.__getKey(skey)
|
||||
dbCache.objects.get(pk=key).delete() # @UndefinedVariable
|
||||
uds.models.Cache.objects.get(pk=key).delete() # @UndefinedVariable
|
||||
return True
|
||||
except dbCache.DoesNotExist: # @UndefinedVariable
|
||||
except uds.models.Cache.DoesNotExist: # @UndefinedVariable
|
||||
logger.debug('key not found')
|
||||
return False
|
||||
|
||||
@ -93,10 +94,10 @@ class Cache(object):
|
||||
value = pickle.dumps(value).encode(Cache.CODEC)
|
||||
now = getSqlDatetime()
|
||||
try:
|
||||
dbCache.objects.create(owner=self._owner, key=key, value=value, created=now, validity=validity) # @UndefinedVariable
|
||||
uds.models.Cache.objects.create(owner=self._owner, key=key, value=value, created=now, validity=validity) # @UndefinedVariable
|
||||
except Exception:
|
||||
# Already exists, modify it
|
||||
c = dbCache.objects.get(pk=key) # @UndefinedVariable
|
||||
c = uds.models.Cache.objects.get(pk=key) # @UndefinedVariable
|
||||
c.owner = self._owner
|
||||
c.key = key
|
||||
c.value = value
|
||||
@ -108,26 +109,26 @@ class Cache(object):
|
||||
# logger.debug('Refreshing key "%s" for cache "%s"' % (skey, self._owner,))
|
||||
try:
|
||||
key = self.__getKey(skey)
|
||||
c = dbCache.objects.get(pk=key) # @UndefinedVariable
|
||||
c = uds.models.Cache.objects.get(pk=key) # @UndefinedVariable
|
||||
c.created = getSqlDatetime()
|
||||
c.save()
|
||||
except dbCache.DoesNotExist: # @UndefinedVariable
|
||||
except uds.models.Cache.DoesNotExist: # @UndefinedVariable
|
||||
logger.debug('Can\'t refresh cache key %s because it doesn\'t exists' % skey)
|
||||
return
|
||||
|
||||
@staticmethod
|
||||
def purge():
|
||||
dbCache.objects.all().delete() # @UndefinedVariable
|
||||
uds.models.Cache.objects.all().delete() # @UndefinedVariable
|
||||
|
||||
@staticmethod
|
||||
def cleanUp():
|
||||
dbCache.cleanUp() # @UndefinedVariable
|
||||
uds.models.Cache.cleanUp() # @UndefinedVariable
|
||||
|
||||
@staticmethod
|
||||
def delete(owner=None):
|
||||
# logger.info("Deleting cache items")
|
||||
if owner is None:
|
||||
objects = dbCache.objects.all() # @UndefinedVariable
|
||||
objects = uds.models.Cache.objects.all() # @UndefinedVariable
|
||||
else:
|
||||
objects = dbCache.objects.filter(owner=owner) # @UndefinedVariable
|
||||
objects = uds.models.Cache.objects.filter(owner=owner) # @UndefinedVariable
|
||||
objects.delete()
|
||||
|
@ -1,63 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('uds', '0020_auto_20160216_0509'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='CalendarAccess',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('allow', models.BooleanField(default=True)),
|
||||
('priority', models.IntegerField(default=0, db_index=True)),
|
||||
('calendar', models.ForeignKey(to='uds.Calendar')),
|
||||
],
|
||||
options={
|
||||
'db_table': 'uds_cal_access',
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='CalendarAction',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('action', models.CharField(max_length=64)),
|
||||
('params', models.CharField(max_length=1024)),
|
||||
('calendar', models.ForeignKey(to='uds.Calendar')),
|
||||
],
|
||||
options={
|
||||
'db_table': 'uds_cal_action',
|
||||
},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='deployedservice',
|
||||
name='fallbackAccessAllow',
|
||||
field=models.BooleanField(default=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='calendaraction',
|
||||
name='servicePool',
|
||||
field=models.ForeignKey(to='uds.DeployedService'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='calendaraccess',
|
||||
name='servicePool',
|
||||
field=models.ForeignKey(to='uds.DeployedService'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='deployedservice',
|
||||
name='accessCalendars',
|
||||
field=models.ManyToManyField(related_name='accessSP', through='uds.CalendarAccess', to='uds.Calendar'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='deployedservice',
|
||||
name='actionsCalendars',
|
||||
field=models.ManyToManyField(related_name='actionsSP', through='uds.CalendarAction', to='uds.Calendar'),
|
||||
),
|
||||
]
|
@ -34,12 +34,12 @@
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
__updated__ = '2016-02-17'
|
||||
__updated__ = '2016-02-18'
|
||||
|
||||
from django.db import models
|
||||
from uds.models.UUIDModel import UUIDModel
|
||||
from uds.models.Calendar import Calendar
|
||||
from uds.models.ServicesPool import ServicePool
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
# from django.utils.translation import ugettext_lazy as _, ugettext
|
||||
|
||||
import logging
|
||||
@ -47,7 +47,7 @@ import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class CalendarAccess(models.Model):
|
||||
class CalendarAccess(UUIDModel):
|
||||
calendar = models.ForeignKey(Calendar, on_delete=models.CASCADE)
|
||||
servicePool = models.ForeignKey(ServicePool, on_delete=models.CASCADE)
|
||||
allow = models.BooleanField(default=True)
|
||||
@ -58,5 +58,6 @@ class CalendarAccess(models.Model):
|
||||
Meta class to declare db table
|
||||
'''
|
||||
db_table = 'uds_cal_access'
|
||||
ordering = ('priority',)
|
||||
app_label = 'uds'
|
||||
|
||||
|
@ -34,10 +34,11 @@
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
__updated__ = '2016-02-17'
|
||||
__updated__ = '2016-02-18'
|
||||
|
||||
from django.db import models
|
||||
from uds.models.Calendar import Calendar
|
||||
from uds.models.UUIDModel import UUIDModel
|
||||
from uds.models.ServicesPool import ServicePool
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
# from django.utils.translation import ugettext_lazy as _, ugettext
|
||||
@ -47,7 +48,7 @@ import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class CalendarAction(models.Model):
|
||||
class CalendarAction(UUIDModel):
|
||||
calendar = models.ForeignKey(Calendar, on_delete=models.CASCADE)
|
||||
servicePool = models.ForeignKey(ServicePool, on_delete=models.CASCADE)
|
||||
action = models.CharField(max_length=64)
|
||||
|
@ -55,10 +55,12 @@ from uds.models.Calendar import Calendar
|
||||
from uds.models.Util import NEVER
|
||||
from uds.models.Util import getSqlDatetime
|
||||
|
||||
from uds.core.util.calendar import CalendarChecker
|
||||
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
|
||||
__updated__ = '2016-02-17'
|
||||
__updated__ = '2016-02-18'
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -189,6 +191,22 @@ class DeployedService(UUIDModel, TaggingMixin):
|
||||
def isInMaintenance(self):
|
||||
return self.service is not None and self.service.isInMaintenance()
|
||||
|
||||
def isAccessAllowed(self, chkDateTime=None):
|
||||
'''
|
||||
Checks if the access for a service pool is allowed or not (based esclusively on associated calendars)
|
||||
'''
|
||||
if chkDateTime is None:
|
||||
chkDateTime = getSqlDatetime()
|
||||
|
||||
allow = self.fallbackAccessAllow
|
||||
# Let's see if we can access by current datetime
|
||||
for ac in self.calendaraccess_set.all():
|
||||
if CalendarChecker(ac.calendar).check(chkDateTime) is True:
|
||||
allow = ac.allow
|
||||
|
||||
return allow
|
||||
|
||||
|
||||
def storeValue(self, name, value):
|
||||
'''
|
||||
Stores a value inside custom storage
|
||||
|
@ -22,6 +22,8 @@ gui.servicesPools.link = (event) ->
|
||||
$("#cache-placeholder_log").empty()
|
||||
$("#transports-placeholder").empty()
|
||||
$("#groups-placeholder").empty()
|
||||
$("#access-placeholder").empty()
|
||||
$("#scheduling-placeholder").empty()
|
||||
$("#logs-placeholder").empty()
|
||||
$("#detail-placeholder").addClass "hidden"
|
||||
prevTables = []
|
||||
@ -124,6 +126,8 @@ gui.servicesPools.link = (event) ->
|
||||
transports: "transports-placeholder"
|
||||
publications: "publications-placeholder"
|
||||
changelog: "changelog-placeholder"
|
||||
scheduling: "scheduling-placeholder"
|
||||
access: "access-placeholder"
|
||||
logs: "logs-placeholder"
|
||||
)
|
||||
gui.setLinksEvents()
|
||||
@ -246,7 +250,7 @@ gui.servicesPools.link = (event) ->
|
||||
doNotLoadData: true
|
||||
icon: 'groups'
|
||||
container: "groups-placeholder"
|
||||
rowSelect: "single"
|
||||
rowSelect: "multi"
|
||||
doNotLoadData: true
|
||||
buttons: [
|
||||
"new"
|
||||
@ -323,7 +327,7 @@ gui.servicesPools.link = (event) ->
|
||||
doNotLoadData: true
|
||||
icon: 'assigned'
|
||||
container: "assigned-services-placeholder_tbl"
|
||||
rowSelect: "single"
|
||||
rowSelect: "multi"
|
||||
buttons: (if info.must_assign_manually then [
|
||||
"new"
|
||||
"delete"
|
||||
@ -371,7 +375,7 @@ gui.servicesPools.link = (event) ->
|
||||
icon: 'transports'
|
||||
container: "transports-placeholder"
|
||||
doNotLoadData: true
|
||||
rowSelect: "single"
|
||||
rowSelect: "multi"
|
||||
buttons: [
|
||||
"new"
|
||||
"delete"
|
||||
@ -524,7 +528,24 @@ gui.servicesPools.link = (event) ->
|
||||
|
||||
else
|
||||
$("#publications-placeholder_tab").addClass "hidden"
|
||||
|
||||
|
||||
#
|
||||
# Access calendars
|
||||
#
|
||||
accessCalendars = new GuiElement(api.servicesPools.detail(servPool.id, "access", { permission: servPool.permission }), "access")
|
||||
accessCalendarsTable = accessCalendars.table(
|
||||
doNotLoadData: false
|
||||
icon: 'assigned'
|
||||
container: "access-placeholder"
|
||||
rowSelect: "multi"
|
||||
buttons: [
|
||||
"new"
|
||||
"delete"
|
||||
"xls"
|
||||
]
|
||||
)
|
||||
prevTables.push accessCalendarsTable
|
||||
|
||||
#
|
||||
# * Log table
|
||||
#
|
||||
|
@ -33,6 +33,8 @@
|
||||
<li><a href="#{{ groups }}" data-toggle="tab">{% endverbatim %}{% trans 'Groups' %}{% verbatim %}</a></li>
|
||||
<li><a href="#{{ transports }}" data-toggle="tab">{% endverbatim %}{% trans 'Transports' %}{% verbatim %}</a></li>
|
||||
<li><a id="{{ publications }}_tab" href="#{{ publications }}" data-toggle="tab">{% endverbatim %}{% trans 'Publications' %}{% verbatim %}</a></li>
|
||||
<li><a id="{{ scheduling }}_tab" href="#{{ scheduling }}" data-toggle="tab">{% endverbatim %}{% trans 'Scheduled actions' %}{% verbatim %}</a></li>
|
||||
<li><a id="{{ access }}_tab" href="#{{ access }}" data-toggle="tab">{% endverbatim %}{% trans 'Access Calendars' %}{% verbatim %}</a></li>
|
||||
<li><a href="#{{ logs }}" data-toggle="tab">{% endverbatim %}{% trans 'Logs' %}{% verbatim %}</a></li>
|
||||
</ul>
|
||||
<div class="tab-content">
|
||||
@ -72,6 +74,8 @@
|
||||
<div id="{{ changelog }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="tab-pane fade" id="{{ scheduling }}">...</div>
|
||||
<div class="tab-pane fade" id="{{ access }}">...</div>
|
||||
<div class="tab-pane fade" id="{{ logs }}">...</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -23,9 +23,11 @@
|
||||
{% if ser.transports %}
|
||||
<div class="service-container">
|
||||
{% with trans=ser.transports|first numTransports=ser.transports|length %}
|
||||
<div class="service{% if ser.maintenance %} maintenance{% endif %}{% if ser.in_use %} inuse{% endif %}"
|
||||
<div class="service{% if ser.maintenance %} maintenance{% endif %}{% if ser.not_accesible %} notaccesible{% endif %}{% if ser.in_use %} inuse{% endif %}"
|
||||
{% if ser.maintenance %}
|
||||
data-content="{% trans "Under maintenance" %}"
|
||||
{% elif ser.not_accesible %}
|
||||
data-content="{% trans "Access limited by calendar" %}"
|
||||
{% elif ser.in_use %}
|
||||
data-content="{%trans "Currently in use" %}"
|
||||
{% endif %}
|
||||
@ -88,6 +90,23 @@
|
||||
</div><!-- /.modal-dialog -->
|
||||
</div><!-- /.modal -->
|
||||
|
||||
<div class="modal fade" id="notaccesible-dialog">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h4 class="modal-title">{% trans "Service access not allowed" %}</h4>
|
||||
</div>
|
||||
<div class="modal-body text-center">
|
||||
<p>{% trans "This service is currently not accesible due to schedule restrictions" %}</p>
|
||||
<p>{% trans "Please, retry access in a while." %}</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
||||
</div>
|
||||
</div><!-- /.modal-content -->
|
||||
</div><!-- /.modal-dialog -->
|
||||
</div><!-- /.modal -->
|
||||
|
||||
|
||||
{% if user.isStaff %}
|
||||
@ -277,7 +296,7 @@
|
||||
|
||||
$('.inuse').popover({container: 'body', trigger: 'hover', delay: { show: 500, hide: 100 }, placement: 'auto top'});
|
||||
|
||||
$('div.service:not(.maintenance)').on("click", function (event){
|
||||
$('div.service:not(.maintenance, .notaccesible)').on("click", function (event){
|
||||
var url, el;
|
||||
event.preventDefault();
|
||||
|
||||
@ -310,7 +329,7 @@
|
||||
return false;
|
||||
})
|
||||
|
||||
$('div.service:not(.maintenance) > span.gear > span.fa').on("click", function (event) {
|
||||
$('div.service:not(.maintenance, .notaccesible) > span.gear > span.fa').on("click", function (event) {
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
$(this).parent().parent().next().modal();
|
||||
@ -324,6 +343,13 @@
|
||||
return false;
|
||||
});
|
||||
|
||||
$(".notaccesible").click( function(event) {
|
||||
$('#notaccesible-dialog').modal({
|
||||
keyboard: false
|
||||
})
|
||||
return false;
|
||||
});
|
||||
|
||||
if( autorun ) {
|
||||
if( $('.service').length > 0)
|
||||
launchURL($('.service')[0]);
|
||||
|
@ -51,7 +51,7 @@ import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
__updated__ = '2016-02-16'
|
||||
__updated__ = '2016-02-18'
|
||||
|
||||
|
||||
def about(request):
|
||||
@ -131,6 +131,7 @@ def index(request):
|
||||
'imageId': imageId,
|
||||
'show_transports': svr.deployed_service.show_transports,
|
||||
'maintenance': svr.deployed_service.isInMaintenance(),
|
||||
'not_accesible': not svr.deployed_service.isAccessAllowed(),
|
||||
'in_use': svr.in_use,
|
||||
})
|
||||
|
||||
@ -175,6 +176,7 @@ def index(request):
|
||||
'imageId': imageId,
|
||||
'show_transports': svr.show_transports,
|
||||
'maintenance': svr.isInMaintenance(),
|
||||
'not_accesible': not svr.isAccessAllowed(),
|
||||
'in_use': in_use,
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user