mirror of
https://github.com/dkmstr/openuds.git
synced 2025-01-08 21:18:00 +03:00
Almost finished calendars access
This commit is contained in:
parent
8376e81532
commit
8934d978fe
@ -78,7 +78,7 @@ class AccessCalendars(DetailHandler):
|
||||
i = CalendarAccess.objects.get(uuid=processUuid(item))
|
||||
return AccessCalendars.as_dict(i)
|
||||
except Exception:
|
||||
raise InvalidItemException()
|
||||
self.invalidItemException()
|
||||
|
||||
|
||||
def getTitle(self, parent):
|
||||
|
@ -43,7 +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, ALLOW, DENY
|
||||
from .services_pool_calendars import AccessCalendars
|
||||
from .services import Services
|
||||
|
||||
import logging
|
||||
@ -81,6 +81,8 @@ class ServicesPools(ModelHandler):
|
||||
# Field from where to get "class" and prefix for that class, so this will generate "row-state-A, row-state-X, ....
|
||||
table_row_style = {'field': 'state', 'prefix': 'row-state-'}
|
||||
|
||||
custom_methods = [('setFallbackAccess', True)]
|
||||
|
||||
def item_as_dict(self, item):
|
||||
# if item does not have an associated service, hide it (the case, for example, for a removed service)
|
||||
# Access from dict will raise an exception, and item will be skipped
|
||||
@ -268,3 +270,11 @@ class ServicesPools(ModelHandler):
|
||||
return log.getLogs(item)
|
||||
except Exception:
|
||||
return []
|
||||
|
||||
# Set fallback status
|
||||
def setFallbackAccess(self, item):
|
||||
fallback = self._params.get('fallbackAccess')
|
||||
logger.debug('Setting fallback of {} to {}'.format(item.name, fallback))
|
||||
item.fallbackAccess = fallback
|
||||
item.save()
|
||||
return ''
|
@ -425,7 +425,14 @@ api.authenticators.search = (id, type, term, success_fnc, fail_fnc) ->
|
||||
api.osmanagers = new BasicModelRest("osmanagers")
|
||||
api.transports = new BasicModelRest("transports")
|
||||
api.networks = new BasicModelRest("networks")
|
||||
|
||||
api.servicesPools = new BasicModelRest("servicespools")
|
||||
api.servicesPools.setFallbackAccess = (id, fallbackAccess, success_fnc, fail_fnc) ->
|
||||
@get
|
||||
id: id + '/setFallbackAccess?fallbackAccess=' + fallbackAccess
|
||||
success: success_fnc
|
||||
fail: fail_fnc
|
||||
|
||||
api.configuration = new BasicModelRest("config")
|
||||
api.gallery = new BasicModelRest("gallery/images")
|
||||
api.sPoolGroups = new BasicModelRest("gallery/servicespoolgroups")
|
||||
|
@ -1,4 +1,5 @@
|
||||
gui.servicesPools.accessCalendars = (servPool, info) ->
|
||||
accessList = ['ALLOW', 'DENY']
|
||||
accessCalendars = new GuiElement(api.servicesPools.detail(servPool.id, "access", { permission: servPool.permission }), "access")
|
||||
accessCalendarsTable = accessCalendars.table(
|
||||
doNotLoadData: true
|
||||
@ -36,6 +37,7 @@ gui.servicesPools.accessCalendars = (servPool, info) ->
|
||||
calendars: data
|
||||
priority: 1
|
||||
calendarId: ''
|
||||
accessList: accessList
|
||||
access: 'ALLOW'
|
||||
))
|
||||
$(modalId + " .button-accept").on "click", (event) ->
|
||||
@ -64,7 +66,20 @@ gui.servicesPools.accessCalendars = (servPool, info) ->
|
||||
|
||||
onEdit: (value, event, table, refreshFnc) ->
|
||||
if value.id == -1
|
||||
alert('Changing default')
|
||||
api.templates.get "pool_access_default", (tmpl) ->
|
||||
modalId = gui.launchModal(gettext("Default fallback access"), api.templates.evaluate(tmpl,
|
||||
accessList: accessList
|
||||
access: servPool.fallbackAccess
|
||||
))
|
||||
$(modalId + " .button-accept").on "click", (event) ->
|
||||
access = $(modalId + " #id_access_select").val()
|
||||
servPool.fallbackAccess = access
|
||||
gui.servicesPools.rest.setFallbackAccess servPool.id, access, (data) ->
|
||||
$(modalId).modal "hide"
|
||||
refreshFnc()
|
||||
return
|
||||
# Makes form "beautyfull" :-)
|
||||
gui.tools.applyCustoms modalId
|
||||
return
|
||||
api.templates.get "pool_add_access", (tmpl) ->
|
||||
accessCalendars.rest.item value.id, (item) ->
|
||||
@ -74,12 +89,22 @@ gui.servicesPools.accessCalendars = (servPool, info) ->
|
||||
calendars: data
|
||||
priority: item.priority
|
||||
calendarId: item.calendarId
|
||||
accessList: accessList
|
||||
access: item.access
|
||||
))
|
||||
$(modalId + " .button-accept").on "click", (event) ->
|
||||
alert('Saving')
|
||||
$(modalId).modal "hide"
|
||||
refreshFnc()
|
||||
priority = $(modalId + " #id_priority").val()
|
||||
calendar = $(modalId + " #id_calendar_select").val()
|
||||
access = $(modalId + " #id_access_select").val()
|
||||
accessCalendars.rest.save
|
||||
id: item.id
|
||||
calendarId: calendar
|
||||
access: access
|
||||
priority: priority
|
||||
, (data) ->
|
||||
$(modalId).modal "hide"
|
||||
refreshFnc()
|
||||
return
|
||||
return
|
||||
# Makes form "beautyfull" :-)
|
||||
gui.tools.applyCustoms modalId
|
||||
|
@ -260,7 +260,6 @@
|
||||
max: $.validator.format(gettext("Please enter a value less than or equal to {0}."))
|
||||
min: $.validator.format(gettext("Please enter a value greater than or equal to {0}."))
|
||||
|
||||
|
||||
# Set blockui params
|
||||
$.blockUI.defaults.baseZ = 2000
|
||||
$.fn.dataTableExt.oSort["uds-date-pre"] = (s) ->
|
||||
@ -288,161 +287,5 @@
|
||||
gui.showDashboard = ->
|
||||
gui.dashboard.link()
|
||||
return
|
||||
|
||||
# Generic "methods" for editing, creating, etc...
|
||||
gui.methods = {}
|
||||
gui.methods.typedTestButton = (rest, text, css, type) ->
|
||||
[
|
||||
text: text
|
||||
css: css
|
||||
action: (event, form_selector, closeFnc) ->
|
||||
fields = gui.forms.read(form_selector)
|
||||
gui.doLog "Fields: ", fields
|
||||
rest.test type, fields, ((data) ->
|
||||
if data == 'ok'
|
||||
text = gettext("Test passed successfully")
|
||||
kind = 'success'
|
||||
else
|
||||
text = gettext("Test failed:") + " #{data}</b>"
|
||||
kind = 'danger'
|
||||
gui.notify text, kind
|
||||
# gui.launchModal gettext("Test result"), text,
|
||||
# actionButton: " "
|
||||
|
||||
return
|
||||
), gui.failRequestModalFnc(gettext("Test error"))
|
||||
return
|
||||
]
|
||||
|
||||
|
||||
# "Generic" edit method to set onEdit table
|
||||
gui.methods.typedEdit = (parent, modalTitle, modalErrorMsg, options) ->
|
||||
options = options or {}
|
||||
(value, event, table, refreshFnc) ->
|
||||
gui.tools.blockUI()
|
||||
parent.rest.gui value.type, ((guiDefinition) ->
|
||||
buttons = gui.methods.typedTestButton(parent.rest, options.testButton.text, options.testButton.css, value.type) if options.testButton
|
||||
tabs = (if options.guiProcessor then options.guiProcessor(guiDefinition) else guiDefinition) # Preprocess fields (probably generate tabs...)
|
||||
parent.rest.item value.id, (item) ->
|
||||
gui.tools.unblockUI()
|
||||
gui.forms.launchModal
|
||||
title: modalTitle + " <b>" + value.name + "</b>"
|
||||
fields: tabs
|
||||
item: item
|
||||
preprocessor: options.preprocessor
|
||||
buttons: buttons
|
||||
success: (form_selector, closeFnc) ->
|
||||
fields = gui.forms.read(form_selector)
|
||||
fields.data_type = value.type
|
||||
fields = (if options.fieldsProcessor then options.fieldsProcessor(fields) else fields)
|
||||
parent.rest.save fields, ((data) -> # Success on put
|
||||
closeFnc()
|
||||
refreshFnc()
|
||||
gui.notify gettext("Edition successfully done"), "success"
|
||||
return
|
||||
), gui.failRequestModalFnc(modalErrorMsg, true) # Fail on put, show modal message
|
||||
return
|
||||
|
||||
return
|
||||
|
||||
return
|
||||
), gui.failRequestModalFnc(modalErrorMsg, true)
|
||||
return
|
||||
|
||||
gui.methods.typedShow = (parent, value, placeholder, modalErrorMsg, options) ->
|
||||
options = options or {}
|
||||
parent.rest.gui value.type, ((guiDefinition) ->
|
||||
formId = gui.genRamdonId('ovw-')
|
||||
parent.rest.item value.id, (item) ->
|
||||
gui.doLog "Item", item, "Gui", guiDefinition
|
||||
data = []
|
||||
flds = gui.forms.fieldsToHtml(guiDefinition, item, "readonly")
|
||||
gui.doLog(flds)
|
||||
html = api.templates.evaluate "tmpl_comp_overview_record",
|
||||
id: formId
|
||||
legend: gettext('Overview')
|
||||
fields: flds.html
|
||||
$(placeholder).html(html)
|
||||
gui.tools.applyCustoms '#' + formId
|
||||
return
|
||||
), gui.failRequestModalFnc(modalErrorMsg, true)
|
||||
return
|
||||
|
||||
|
||||
# "Generic" new method to set onNew table
|
||||
gui.methods.typedNew = (parent, modalTitle, modalErrorMsg, options) ->
|
||||
options = options or {}
|
||||
(type, table, refreshFnc) ->
|
||||
gui.tools.blockUI()
|
||||
parent.rest.gui type, ((guiDefinition) ->
|
||||
gui.tools.unblockUI()
|
||||
buttons = gui.methods.typedTestButton(parent.rest, options.testButton.text, options.testButton.css, type) if options.testButton
|
||||
tabs = (if options.guiProcessor then options.guiProcessor(guiDefinition) else guiDefinition) # Preprocess fields (probably generate tabs...)
|
||||
title = modalTitle
|
||||
title += " " + gettext("of type") + " <b>" + parent.types[type].name + "</b>" if parent.types[type]?
|
||||
gui.forms.launchModal
|
||||
title: title
|
||||
fields: tabs
|
||||
item: null
|
||||
preprocessor: options.preprocessor
|
||||
buttons: buttons
|
||||
success: (form_selector, closeFnc) ->
|
||||
fields = gui.forms.read(form_selector)
|
||||
fields.data_type = type if parent.types[type]?
|
||||
fields = (if options.fieldsProcessor then options.fieldsProcessor(fields) else fields) # Process fields before creating?
|
||||
parent.rest.create fields, ((data) -> # Success on put
|
||||
closeFnc()
|
||||
refreshFnc()
|
||||
gui.notify gettext("Creation successfully done"), "success"
|
||||
return
|
||||
), gui.failRequestModalFnc(modalErrorMsg, true) # Fail on put, show modal message
|
||||
return
|
||||
|
||||
return
|
||||
), gui.failRequestModalFnc(modalErrorMsg, true)
|
||||
return
|
||||
|
||||
gui.methods.del = (parent, modalTitle, modalErrorMsg) ->
|
||||
(values, type, table, refreshFnc) ->
|
||||
names = ((value.name or value.friendly_name) for value in values).join(', ')
|
||||
content = gettext("Are you sure do you want to delete ") + values.length + ' ' + gettext('items:') + " <b>" + names + "</b>"
|
||||
modalId = gui.launchModal(modalTitle, content,
|
||||
actionButton: "<button type=\"button\" class=\"btn btn-danger button-accept\">" + gettext("Delete") + "</button>"
|
||||
)
|
||||
|
||||
# Will show results once
|
||||
msgs = []
|
||||
count = values.length
|
||||
deletedFnc = (name, errorMsg) ->
|
||||
count -= 1
|
||||
if errorMsg?
|
||||
msgs.push gettext("Error deleting") + " <b>" + name + '</b>: <span class="text-danger">' + errorMsg + '</span>'
|
||||
else
|
||||
msgs.push gettext("Successfully deleted") + " <b>" + name + "</b>"
|
||||
|
||||
if count == 0
|
||||
gui.tools.unblockUI()
|
||||
refreshFnc()
|
||||
gui.launchModal gettext('Deletion results'), '<ul><li>' + msgs.join('</li><li>') + '</li></ul>',
|
||||
actionButton: " "
|
||||
closeButton: '<button type="button" class="btn btn-default" data-dismiss="modal">Ok</button>'
|
||||
|
||||
|
||||
|
||||
$(modalId + " .button-accept").click ->
|
||||
$(modalId).modal "hide"
|
||||
gui.tools.blockUI()
|
||||
for value in values
|
||||
((value) ->
|
||||
name = value.name or value.friendly_name
|
||||
parent.rest.del value.id, (->
|
||||
deletedFnc name
|
||||
return
|
||||
), (jqXHR, textStatus, errorThrown) -> # fail on delete
|
||||
deletedFnc(name, jqXHR.responseText))(value)
|
||||
return
|
||||
|
||||
return
|
||||
|
||||
return
|
||||
) window.gui = window.gui or {}, jQuery
|
||||
|
@ -194,6 +194,8 @@
|
||||
{% js_template 'osmanagers' %}
|
||||
{% js_template 'connectivity' %}
|
||||
{% js_template 'services_pool' %}
|
||||
{% js_template 'pool_access_default' %}
|
||||
{% js_template 'pool_add_access' %}
|
||||
{% js_template 'configuration' %}
|
||||
{% js_template 'gallery' %}
|
||||
{% js_template 'permissions' %}
|
||||
|
@ -0,0 +1,15 @@
|
||||
{% load i18n %}
|
||||
{% verbatim %}
|
||||
<form class="form-horizontal" role="form">
|
||||
<div class="form-group">
|
||||
<label for="id_action_select" class="col-sm-2 control-label">{% endverbatim %}{% trans 'Access action' %}{% verbatim %}</label>
|
||||
<div class="col-sm-10">
|
||||
<select id="id_access_select" class="selectpicker show-menu-arrow show-tick modal_field_data" data-style="btn-default" data-width="100%">
|
||||
{{# each accessList }}
|
||||
<option value="{{ this }}"{{# ifequals this ../access }} selected{{/ ifequals }}>{{ this }}</option>
|
||||
{{/ each }}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
{% endverbatim %}
|
@ -24,8 +24,9 @@
|
||||
<label for="id_action_select" class="col-sm-2 control-label">{% endverbatim %}{% trans 'Access action' %}{% verbatim %}</label>
|
||||
<div class="col-sm-10">
|
||||
<select id="id_access_select" class="selectpicker show-menu-arrow show-tick modal_field_data" data-style="btn-default" data-width="100%">
|
||||
<option value="ALLOW">ALLOW</option>
|
||||
<option value="DENY">DENY</option>
|
||||
{{# each accessList }}
|
||||
<option value="{{ this }}"{{# ifequals this ../access }} selected{{/ ifequals }}>{{ this }}</option>
|
||||
{{/ each }}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user