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,66 +41,77 @@ actionSelectChangeFnc = (modalId, actionsList, context) ->
|
||||
gui.servicesPools.actionsCalendars = (servPool, info) ->
|
||||
actionsApi = api.servicesPools.detail(servPool.id, "actions", { permission: servPool.permission })
|
||||
actionsCalendars = new GuiElement(actionsApi, "actions")
|
||||
actionsCalendarsTable = actionsCalendars.table(
|
||||
doNotLoadData: true
|
||||
icon: 'assigned'
|
||||
container: "actions-placeholder"
|
||||
rowSelect: "multi"
|
||||
buttons: [
|
||||
"new"
|
||||
"edit"
|
||||
{
|
||||
text: gettext("Launch Now")
|
||||
css: "disabled"
|
||||
disabled: true
|
||||
click: (val, value, btn, tbl, refreshFnc) ->
|
||||
if val.length != 1
|
||||
# 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'
|
||||
container: "actions-placeholder"
|
||||
rowSelect: "multi"
|
||||
buttons: [
|
||||
"new"
|
||||
"edit"
|
||||
{
|
||||
text: gettext("Launch Now")
|
||||
css: "disabled"
|
||||
disabled: true
|
||||
click: (val, value, btn, tbl, refreshFnc) ->
|
||||
if val.length != 1
|
||||
return
|
||||
|
||||
gui.forms.confirmModal gettext("Execute action"), gettext("Launch action execution right now?"),
|
||||
onYes: ->
|
||||
actionsApi.invoke val[0].id + "/execute", ->
|
||||
refreshFnc()
|
||||
return
|
||||
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", ->
|
||||
refreshFnc()
|
||||
return
|
||||
return
|
||||
select: (vals, self, btn, tbl, refreshFnc) ->
|
||||
unless vals.length == 1
|
||||
$(btn).addClass "disabled"
|
||||
$(btn).prop('disabled', true)
|
||||
return
|
||||
|
||||
select: (vals, self, btn, tbl, refreshFnc) ->
|
||||
unless vals.length == 1
|
||||
$(btn).addClass "disabled"
|
||||
$(btn).prop('disabled', true)
|
||||
val = vals[0]
|
||||
|
||||
$(btn).removeClass("disabled").prop('disabled', false)
|
||||
# $(btn).addClass("disabled").prop('disabled', true)
|
||||
return
|
||||
}
|
||||
"delete"
|
||||
"xls"
|
||||
]
|
||||
|
||||
val = vals[0]
|
||||
onCheck: (action, selected) ->
|
||||
if action == 'edit'
|
||||
return true
|
||||
for v in selected
|
||||
if v.id == -1
|
||||
return false # No action allowed on DEFAULT
|
||||
|
||||
$(btn).removeClass("disabled").prop('disabled', false)
|
||||
# $(btn).addClass("disabled").prop('disabled', true)
|
||||
return
|
||||
}
|
||||
"delete"
|
||||
"xls"
|
||||
]
|
||||
|
||||
onCheck: (action, selected) ->
|
||||
if action == 'edit'
|
||||
return true
|
||||
for v in selected
|
||||
if v.id == -1
|
||||
return false # No action allowed on DEFAULT
|
||||
|
||||
return true
|
||||
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')
|
||||
|
||||
onData: (data) ->
|
||||
$.each data, (index, value) ->
|
||||
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) ->
|
||||
onNew: (value, table, refreshFnc) ->
|
||||
api.templates.get "pool_add_action", (tmpl) ->
|
||||
api.calendars.overview (data) ->
|
||||
api.servicesPools.actionsList servPool.id, (actionsList) ->
|
||||
modalId = gui.launchModal(gettext("Add scheduled action"), api.templates.evaluate(tmpl,
|
||||
calendars: data
|
||||
@ -139,26 +149,19 @@ gui.servicesPools.actionsCalendars = (servPool, info) ->
|
||||
return
|
||||
return
|
||||
return
|
||||
return
|
||||
|
||||
onEdit: (value, event, table, refreshFnc) ->
|
||||
api.templates.get "pool_add_action", (tmpl) ->
|
||||
api.servicesPools.actionsList servPool.id, (actionsList) ->
|
||||
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]
|
||||
onEdit: (value, event, table, refreshFnc) ->
|
||||
api.templates.get "pool_add_action", (tmpl) ->
|
||||
api.servicesPools.actionsList servPool.id, (actionsList) ->
|
||||
actionsCalendars.rest.item value.id, (item) ->
|
||||
for i in actionsList
|
||||
if i['id'] == item.action
|
||||
for j in Object.keys(item.params)
|
||||
for k in i['params']
|
||||
if k['name'] == j
|
||||
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,15 +192,15 @@ 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"))
|
||||
)
|
||||
onDelete: gui.methods.del(actionsCalendars, gettext("Remove access calendar"), gettext("Access calendar removal error"))
|
||||
)
|
||||
|
||||
return [actionsCalendarsTable]
|
||||
|
Loading…
Reference in New Issue
Block a user