From 8934d978feecfa0025d2736a82f31396398b7c92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez=20Garc=C3=ADa?= Date: Tue, 23 Feb 2016 11:23:49 +0100 Subject: [PATCH] Almost finished calendars access --- .../REST/methods/services_pool_calendars.py | 2 +- server/src/uds/REST/methods/services_pools.py | 12 +- server/src/uds/static/adm/js/api.coffee | 7 + .../js/gui-d-servicespools-calendars.coffee | 33 +++- server/src/uds/static/adm/js/gui.coffee | 157 ------------------ server/src/uds/templates/uds/admin/index.html | 2 + .../uds/admin/tmpl/pool_access_default.html | 15 ++ .../uds/admin/tmpl/pool_add_access.html | 5 +- 8 files changed, 68 insertions(+), 165 deletions(-) create mode 100644 server/src/uds/templates/uds/admin/tmpl/pool_access_default.html diff --git a/server/src/uds/REST/methods/services_pool_calendars.py b/server/src/uds/REST/methods/services_pool_calendars.py index 92502a568..525a853c0 100644 --- a/server/src/uds/REST/methods/services_pool_calendars.py +++ b/server/src/uds/REST/methods/services_pool_calendars.py @@ -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): diff --git a/server/src/uds/REST/methods/services_pools.py b/server/src/uds/REST/methods/services_pools.py index ef803ead7..a873d5226 100644 --- a/server/src/uds/REST/methods/services_pools.py +++ b/server/src/uds/REST/methods/services_pools.py @@ -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 '' \ No newline at end of file diff --git a/server/src/uds/static/adm/js/api.coffee b/server/src/uds/static/adm/js/api.coffee index c15a94174..286f75db6 100644 --- a/server/src/uds/static/adm/js/api.coffee +++ b/server/src/uds/static/adm/js/api.coffee @@ -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") diff --git a/server/src/uds/static/adm/js/gui-d-servicespools-calendars.coffee b/server/src/uds/static/adm/js/gui-d-servicespools-calendars.coffee index e6f739569..4676d285a 100644 --- a/server/src/uds/static/adm/js/gui-d-servicespools-calendars.coffee +++ b/server/src/uds/static/adm/js/gui-d-servicespools-calendars.coffee @@ -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 diff --git a/server/src/uds/static/adm/js/gui.coffee b/server/src/uds/static/adm/js/gui.coffee index f2e985a71..ab3aea581 100644 --- a/server/src/uds/static/adm/js/gui.coffee +++ b/server/src/uds/static/adm/js/gui.coffee @@ -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}" - 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 + " " + value.name + "" - 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") + " " + parent.types[type].name + "" 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:') + " " + names + "" - modalId = gui.launchModal(modalTitle, content, - actionButton: "" - ) - - # Will show results once - msgs = [] - count = values.length - deletedFnc = (name, errorMsg) -> - count -= 1 - if errorMsg? - msgs.push gettext("Error deleting") + " " + name + ': ' + errorMsg + '' - else - msgs.push gettext("Successfully deleted") + " " + name + "" - - if count == 0 - gui.tools.unblockUI() - refreshFnc() - gui.launchModal gettext('Deletion results'), '', - actionButton: " " - closeButton: '' - - - - $(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 diff --git a/server/src/uds/templates/uds/admin/index.html b/server/src/uds/templates/uds/admin/index.html index a1153fd32..f9cc11a3e 100644 --- a/server/src/uds/templates/uds/admin/index.html +++ b/server/src/uds/templates/uds/admin/index.html @@ -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' %} diff --git a/server/src/uds/templates/uds/admin/tmpl/pool_access_default.html b/server/src/uds/templates/uds/admin/tmpl/pool_access_default.html new file mode 100644 index 000000000..d94fa8559 --- /dev/null +++ b/server/src/uds/templates/uds/admin/tmpl/pool_access_default.html @@ -0,0 +1,15 @@ +{% load i18n %} +{% verbatim %} +
+
+ +
+ +
+
+
+{% endverbatim %} diff --git a/server/src/uds/templates/uds/admin/tmpl/pool_add_access.html b/server/src/uds/templates/uds/admin/tmpl/pool_add_access.html index 8e4d0af1c..4d68fad66 100644 --- a/server/src/uds/templates/uds/admin/tmpl/pool_add_access.html +++ b/server/src/uds/templates/uds/admin/tmpl/pool_add_access.html @@ -24,8 +24,9 @@