mirror of
https://github.com/dkmstr/openuds.git
synced 2024-12-22 13:34:04 +03:00
Now we can add/remove transports from an scheduled action
This commit is contained in:
parent
0b201eada9
commit
0e4e1e860d
@ -37,7 +37,6 @@ from __future__ import unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
|
||||
from uds.models import CalendarAccess, CalendarAction, Calendar
|
||||
from uds.models.CalendarAction import CALENDAR_ACTION_DICT
|
||||
from uds.core.util.State import State
|
||||
@ -60,6 +59,7 @@ class AccessCalendars(DetailHandler):
|
||||
"""
|
||||
Processes the transports detail requests of a Service Pool
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def as_dict(item):
|
||||
return {
|
||||
@ -80,7 +80,6 @@ class AccessCalendars(DetailHandler):
|
||||
except Exception:
|
||||
self.invalidItemException()
|
||||
|
||||
|
||||
def getTitle(self, parent):
|
||||
return _('Access restrictions by calendar')
|
||||
|
||||
@ -123,15 +122,17 @@ class ActionsCalendars(DetailHandler):
|
||||
|
||||
@staticmethod
|
||||
def as_dict(item):
|
||||
action = CALENDAR_ACTION_DICT[item.action]
|
||||
params = json.loads(item.params)
|
||||
return {
|
||||
'id': item.uuid,
|
||||
'calendarId': item.calendar.uuid,
|
||||
'calendar': item.calendar.name,
|
||||
'action': item.action,
|
||||
'actionDescription': CALENDAR_ACTION_DICT[item.action]['description'],
|
||||
'actionDescription': action['description'],
|
||||
'atStart': item.at_start,
|
||||
'eventsOffset': item.events_offset,
|
||||
'params': json.loads(item.params),
|
||||
'params': params,
|
||||
'nextExecution': item.next_execution,
|
||||
'lastExecution': item.last_execution
|
||||
}
|
||||
|
@ -38,10 +38,10 @@ from django.utils.translation import ugettext_lazy as _
|
||||
from django.db import models
|
||||
from uds.models.Calendar import Calendar
|
||||
from uds.models.UUIDModel import UUIDModel
|
||||
from uds.models.Util import NEVER, getSqlDatetime
|
||||
from uds.models.Util import getSqlDatetime
|
||||
from uds.core.util import calendar
|
||||
from uds.models.ServicesPool import ServicePool
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
from uds.models.Transport import Transport
|
||||
# from django.utils.translation import ugettext_lazy as _, ugettext
|
||||
|
||||
import datetime
|
||||
@ -69,7 +69,6 @@ CALENDAR_ACTION_DICT = dict(list((c['id'], c) for c in (
|
||||
)))
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class CalendarAction(UUIDModel):
|
||||
calendar = models.ForeignKey(Calendar, on_delete=models.CASCADE)
|
||||
service_pool = models.ForeignKey(ServicePool, on_delete=models.CASCADE)
|
||||
@ -111,8 +110,17 @@ class CalendarAction(UUIDModel):
|
||||
self.service_pool.publish(changeLog='Scheduled publication action')
|
||||
saveServicePool = False
|
||||
elif CALENDAR_ACTION_ADD_TRANSPORT['id'] == self.action:
|
||||
# TODO: Insert transport
|
||||
pass
|
||||
try:
|
||||
t = Transport.objects.get(uuid=params['transport'])
|
||||
self.service_pool.transports.add(t)
|
||||
except Exception:
|
||||
self.service_pool.log('Scheduled action not executed because transport is not available anymore')
|
||||
elif CALENDAR_ACTION_DEL_TRANSPORT['id'] == self.action:
|
||||
try:
|
||||
t = Transport.objects.get(uuid=params['transport'])
|
||||
self.service_pool.transports.remove(t)
|
||||
except Exception:
|
||||
self.service_pool.log('Scheduled action not executed because transport is not available anymore')
|
||||
|
||||
# On save, will regenerate nextExecution
|
||||
if save:
|
||||
|
@ -63,7 +63,7 @@ import logging
|
||||
import pickle
|
||||
import six
|
||||
|
||||
__updated__ = '2018-03-14'
|
||||
__updated__ = '2018-05-09'
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -482,6 +482,10 @@ class DeployedService(UUIDModel, TaggingMixin):
|
||||
def testServer(self, host, port, timeout=4):
|
||||
return self.service.testServer(host, port, timeout)
|
||||
|
||||
# Utility for logging
|
||||
def log(self, message, level=log.INFO):
|
||||
log.doLog(self, level, message, log.INTERNAL)
|
||||
|
||||
@staticmethod
|
||||
def beforeDelete(sender, **kwargs):
|
||||
"""
|
||||
|
@ -5,7 +5,6 @@ readParamsFromInputs = (modalId) ->
|
||||
return a
|
||||
|
||||
actionSelectChangeFnc = (modalId, actionsList, context) ->
|
||||
gui.doLog "onChange"
|
||||
action = $(modalId + " #id_action_select").val()
|
||||
if action == '-1'
|
||||
return
|
||||
@ -42,6 +41,17 @@ actionSelectChangeFnc = (modalId, actionsList, context) ->
|
||||
gui.servicesPools.actionsCalendars = (servPool, info) ->
|
||||
actionsApi = api.servicesPools.detail(servPool.id, "actions", { permission: servPool.permission })
|
||||
actionsCalendars = new GuiElement(actionsApi, "actions")
|
||||
# Get transports
|
||||
api.transports.overview (oTrans) ->
|
||||
dctTrans = {}
|
||||
trans = []
|
||||
# Keep only valid transports for this service pool
|
||||
for t in oTrans
|
||||
if (t.protocol in servPool.info.allowedProtocols)
|
||||
trans.push(t)
|
||||
dctTrans[t.id] = t.name
|
||||
|
||||
# Now we create the table
|
||||
actionsCalendarsTable = actionsCalendars.table(
|
||||
doNotLoadData: true
|
||||
icon: 'assigned'
|
||||
@ -58,7 +68,6 @@ gui.servicesPools.actionsCalendars = (servPool, info) ->
|
||||
if val.length != 1
|
||||
return
|
||||
|
||||
gui.doLog val, val[0]
|
||||
gui.forms.confirmModal gettext("Execute action"), gettext("Launch action execution right now?"),
|
||||
onYes: ->
|
||||
actionsApi.invoke val[0].id + "/execute", ->
|
||||
@ -93,15 +102,16 @@ gui.servicesPools.actionsCalendars = (servPool, info) ->
|
||||
|
||||
onData: (data) ->
|
||||
$.each data, (index, value) ->
|
||||
for k in Object.keys(value.params)
|
||||
if k == 'transport'
|
||||
value.params[k] = dctTrans[value.params[k]]
|
||||
value.params = ( k + "=" + value.params[k] for k in Object.keys(value.params)).toString()
|
||||
value.atStart = if value.atStart then gettext('Beginning') else gettext('Ending')
|
||||
value.calendar = gui.fastLink(value.calendar, value.calendarId, 'gui.servicesPools.fastLink', 'goCalendarLink')
|
||||
|
||||
onNew: (value, table, refreshFnc) ->
|
||||
|
||||
api.templates.get "pool_add_action", (tmpl) ->
|
||||
api.calendars.overview (data) ->
|
||||
api.transports.overview (trans) ->
|
||||
api.servicesPools.actionsList servPool.id, (actionsList) ->
|
||||
modalId = gui.launchModal(gettext("Add scheduled action"), api.templates.evaluate(tmpl,
|
||||
calendars: data
|
||||
@ -139,7 +149,6 @@ gui.servicesPools.actionsCalendars = (servPool, info) ->
|
||||
return
|
||||
return
|
||||
return
|
||||
return
|
||||
|
||||
onEdit: (value, event, table, refreshFnc) ->
|
||||
api.templates.get "pool_add_action", (tmpl) ->
|
||||
@ -147,18 +156,12 @@ gui.servicesPools.actionsCalendars = (servPool, info) ->
|
||||
actionsCalendars.rest.item value.id, (item) ->
|
||||
for i in actionsList
|
||||
if i['id'] == item.action
|
||||
gui.doLog "Found ", i
|
||||
for j in Object.keys(item.params)
|
||||
gui.doLog "Testing ", j
|
||||
for k in i['params']
|
||||
gui.doLog 'Checking ', k
|
||||
if k['name'] == j
|
||||
gui.doLog 'Setting value'
|
||||
k['default'] = item.params[j]
|
||||
|
||||
api.transports.overview (trans) ->
|
||||
api.calendars.overview (data) ->
|
||||
gui.doLog "Item: ", item
|
||||
modalId = gui.launchModal(gettext("Edit access calendar"), api.templates.evaluate(tmpl,
|
||||
calendars: data
|
||||
calendarId: item.calendarId
|
||||
@ -189,14 +192,14 @@ gui.servicesPools.actionsCalendars = (servPool, info) ->
|
||||
actionSelectChangeFnc(modalId, actionsList, {'transports': trans })
|
||||
|
||||
# Triggers the event manually
|
||||
actionSelectChangeFnc(modalId, actionsList)
|
||||
actionSelectChangeFnc(modalId, actionsList, {'transports': trans })
|
||||
# Makes form "beautyfull" :-)
|
||||
gui.tools.applyCustoms modalId
|
||||
return
|
||||
return
|
||||
return
|
||||
return
|
||||
|
||||
return
|
||||
onDelete: gui.methods.del(actionsCalendars, gettext("Remove access calendar"), gettext("Access calendar removal error"))
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user