From aabd17e302ad5ceb337079769a9d5ba8713cddb9 Mon Sep 17 00:00:00 2001 From: juanmont Date: Tue, 3 Jan 2017 16:16:42 +0100 Subject: [PATCH 1/2] B #4961 Added the possibility to introduce an empty ssh key --- .../public/app/tabs/settings-tab/panels/user-config.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/sunstone/public/app/tabs/settings-tab/panels/user-config.js b/src/sunstone/public/app/tabs/settings-tab/panels/user-config.js index 97d57100baf..466e83d814a 100644 --- a/src/sunstone/public/app/tabs/settings-tab/panels/user-config.js +++ b/src/sunstone/public/app/tabs/settings-tab/panels/user-config.js @@ -124,11 +124,6 @@ define(function(require) { $("#provision_add_ssh_key_form").submit(function() { var keypair = $('#provision_ssh_key', this).val(); - if (!keypair.length) { - Notifier.notifyError(Locale.tr("You have to provide an SSH key")); - return false; - } - var template_str = 'SSH_PUBLIC_KEY = "'+TemplateUtils.escapeDoubleQuotes(keypair)+'"'; Sunstone.runAction("User.append_template", "-1", template_str); From 5e80f72bf3027f9603a00ef54b1eb6e019329cc2 Mon Sep 17 00:00:00 2001 From: juanmont Date: Wed, 4 Jan 2017 15:43:58 +0100 Subject: [PATCH 2/2] B #4960 Settings field can be disabled --- .../app/tabs/settings-tab/panels/auth.js | 46 ++++ .../tabs/settings-tab/panels/auth/html.hbs | 91 ++++++++ .../app/tabs/settings-tab/panels/info.js | 2 +- .../tabs/settings-tab/panels/info/html.hbs | 75 +++++++ .../app/tabs/users-tab/panels/auth-common.js | 197 ++++++++++++++++++ .../app/tabs/users-tab/panels/info-common.js | 7 +- 6 files changed, 416 insertions(+), 2 deletions(-) create mode 100644 src/sunstone/public/app/tabs/settings-tab/panels/auth.js create mode 100644 src/sunstone/public/app/tabs/settings-tab/panels/auth/html.hbs create mode 100644 src/sunstone/public/app/tabs/settings-tab/panels/info/html.hbs create mode 100644 src/sunstone/public/app/tabs/users-tab/panels/auth-common.js diff --git a/src/sunstone/public/app/tabs/settings-tab/panels/auth.js b/src/sunstone/public/app/tabs/settings-tab/panels/auth.js new file mode 100644 index 00000000000..4cf777ff399 --- /dev/null +++ b/src/sunstone/public/app/tabs/settings-tab/panels/auth.js @@ -0,0 +1,46 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2016, OpenNebula Project, OpenNebula Systems */ +/* */ +/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ +/* not use this file except in compliance with the License. You may obtain */ +/* a copy of the License at */ +/* */ +/* http://www.apache.org/licenses/LICENSE-2.0 */ +/* */ +/* Unless required by applicable law or agreed to in writing, software */ +/* distributed under the License is distributed on an "AS IS" BASIS, */ +/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ +/* See the License for the specific language governing permissions and */ +/* limitations under the License. */ +/* -------------------------------------------------------------------------- */ + +define(function(require) { + /* + DEPENDENCIES + */ + + var BasePanel = require('tabs/users-tab/panels/auth-common'); + + /* + CONSTANTS + */ + + var TAB_ID = require('../tabId'); + var PANEL_ID = require('./auth/panelId'); + + /* + CONSTRUCTOR + */ + + function Panel(info) { + this.tabId = TAB_ID; + info.tabId = this.tabId; + return BasePanel.call(this, info); + }; + + Panel.PANEL_ID = PANEL_ID; + Panel.prototype = Object.create(BasePanel.prototype); + Panel.prototype.constructor = Panel; + + return Panel; +}); diff --git a/src/sunstone/public/app/tabs/settings-tab/panels/auth/html.hbs b/src/sunstone/public/app/tabs/settings-tab/panels/auth/html.hbs new file mode 100644 index 00000000000..be58439a694 --- /dev/null +++ b/src/sunstone/public/app/tabs/settings-tab/panels/auth/html.hbs @@ -0,0 +1,91 @@ +{{! -------------------------------------------------------------------------- }} +{{! Copyright 2002-2016, OpenNebula Project, OpenNebula Systems }} +{{! }} +{{! Licensed under the Apache License, Version 2.0 (the "License"); you may }} +{{! not use this file except in compliance with the License. You may obtain }} +{{! a copy of the License at }} +{{! }} +{{! http://www.apache.org/licenses/LICENSE-2.0 }} +{{! }} +{{! Unless required by applicable law or agreed to in writing, software }} +{{! distributed under the License is distributed on an "AS IS" BASIS, }} +{{! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. }} +{{! See the License for the specific language governing permissions and }} +{{! limitations under the License. }} +{{! -------------------------------------------------------------------------- }} + +
+
+
+
+ + + + + + + + + + + + + + + + + + + {{#isTabActionEnabled tabId "Settings.login_token"}} + + + + + {{/isTabActionEnabled}} + +
{{tr "Authentication"}}
{{tr "Authentication driver"}}{{element.AUTH_DRIVER}}
{{tr "Password"}} + + + {{#isTabActionEnabled tabId "Settings.change_password"}} + + {{/isTabActionEnabled}} +
+
+
+
+
+ + + + + {{#isTabActionEnabled tabId "Settings.ssh_key"}} + + {{/isTabActionEnabled}} + + +
{{tr "Public SSH Key"}} + +
+ + +

+ {{#if element.TEMPLATE.SSH_PUBLIC_KEY}} + {{element.TEMPLATE.SSH_PUBLIC_KEY}} + {{else}} + {{tr "You can provide a SSH Key for this User clicking on the edit button"}} + {{/if}} +

+ +
+
+
+
diff --git a/src/sunstone/public/app/tabs/settings-tab/panels/info.js b/src/sunstone/public/app/tabs/settings-tab/panels/info.js index 7a0d18fe398..ad21b07eef9 100644 --- a/src/sunstone/public/app/tabs/settings-tab/panels/info.js +++ b/src/sunstone/public/app/tabs/settings-tab/panels/info.js @@ -34,7 +34,7 @@ define(function(require) { function Panel(info) { this.tabId = TAB_ID; - + info.tabId = this.tabId; return BasePanel.call(this, info); }; diff --git a/src/sunstone/public/app/tabs/settings-tab/panels/info/html.hbs b/src/sunstone/public/app/tabs/settings-tab/panels/info/html.hbs new file mode 100644 index 00000000000..b465f70c65d --- /dev/null +++ b/src/sunstone/public/app/tabs/settings-tab/panels/info/html.hbs @@ -0,0 +1,75 @@ +{{! -------------------------------------------------------------------------- }} +{{! Copyright 2002-2016, OpenNebula Project, OpenNebula Systems }} +{{! }} +{{! Licensed under the Apache License, Version 2.0 (the "License"); you may }} +{{! not use this file except in compliance with the License. You may obtain }} +{{! a copy of the License at }} +{{! }} +{{! http://www.apache.org/licenses/LICENSE-2.0 }} +{{! }} +{{! Unless required by applicable law or agreed to in writing, software }} +{{! distributed under the License is distributed on an "AS IS" BASIS, }} +{{! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. }} +{{! See the License for the specific language governing permissions and }} +{{! limitations under the License. }} +{{! -------------------------------------------------------------------------- }} + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{{tr "Information"}}
{{tr "ID"}}{{element.ID}}
{{tr "Name"}}{{element.NAME}}
{{tr "Table Order"}}{{valOrDefault sunstone_template.TABLE_ORDER "-"}} +
+ +
+
{{tr "Language"}}{{valOrDefault sunstone_template.LANG "-"}} + {{#isTabActionEnabled tabId "Settings.change_language"}} +
+ +
+ {{/isTabActionEnabled}} +
{{tr "View"}}{{valOrDefault sunstone_template.DEFAULT_VIEW "-"}} + {{#isTabActionEnabled tabId "Settings.change_view"}} +
+ +
+ {{/isTabActionEnabled}} +
+
+
+
+
+ {{{templateTableHTML}}} +
+
diff --git a/src/sunstone/public/app/tabs/users-tab/panels/auth-common.js b/src/sunstone/public/app/tabs/users-tab/panels/auth-common.js new file mode 100644 index 00000000000..3a3a852585b --- /dev/null +++ b/src/sunstone/public/app/tabs/users-tab/panels/auth-common.js @@ -0,0 +1,197 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2016, OpenNebula Project, OpenNebula Systems */ +/* */ +/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ +/* not use this file except in compliance with the License. You may obtain */ +/* a copy of the License at */ +/* */ +/* http://www.apache.org/licenses/LICENSE-2.0 */ +/* */ +/* Unless required by applicable law or agreed to in writing, software */ +/* distributed under the License is distributed on an "AS IS" BASIS, */ +/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ +/* See the License for the specific language governing permissions and */ +/* limitations under the License. */ +/* -------------------------------------------------------------------------- */ + +define(function(require) { + /* + DEPENDENCIES + */ + + var TemplateInfo = require('hbs!./auth/html'); + var TemplateInfoSettings = require('hbs!tabs/settings-tab/panels/auth/html'); + var ResourceSelect = require('utils/resource-select'); + var TemplateUtils = require('utils/template-utils'); + var Locale = require('utils/locale'); + var OpenNebulaUser = require('opennebula/user'); + var Sunstone = require('sunstone'); + var UserCreation = require('tabs/users-tab/utils/user-creation'); + + /* + TEMPLATES + */ + + var TemplateTable = require('utils/panel/template-table'); + + /* + CONSTANTS + */ + + var RESOURCE = "User"; + var XML_ROOT = "USER"; + var PASSWORD_DIALOG_ID = require('tabs/users-tab/dialogs/password/dialogId'); + var LOGIN_TOKEN_DIALOG_ID = require('tabs/users-tab/dialogs/login-token/dialogId'); + var CONFIRM_DIALOG_ID = require('utils/dialogs/generic-confirm/dialogId'); + + /* + CONSTRUCTOR + */ + + function Panel(info) { + this.title = Locale.tr("Auth"); + this.icon = "fa-key"; + + if(info.tabId == "settings-tab") + TemplateInfo = TemplateInfoSettings; + + this.element = info[XML_ROOT]; + this.userCreation = new UserCreation(this.tabId, {name: false, password: false, group_select: false}); + return this; + } + + Panel.prototype.html = _html; + Panel.prototype.setup = _setup; + + return Panel; + + /* + FUNCTION DEFINITIONS + */ + + function _html() { + + // TODO: simplify interface? + var strippedTemplate = $.extend({}, this.element.TEMPLATE); + delete strippedTemplate["SSH_PUBLIC_KEY"]; + delete strippedTemplate["SUNSTONE"]; + + var templateTableHTML = TemplateTable.html(strippedTemplate, RESOURCE, + Locale.tr("Attributes")); + //==== + + + return TemplateInfo({ + 'element': this.element, + 'tabId': this.tabId, + 'templateTableHTML': templateTableHTML, + 'userCreationHTML': this.userCreation.html() + }); + } + + function _setup(context) { + var that = this; + this.userCreation.setup(context); + // Template update + // TODO: simplify interface? + var strippedTemplate = $.extend({}, this.element.TEMPLATE); + delete strippedTemplate["SSH_PUBLIC_KEY"]; + delete strippedTemplate["SUNSTONE"]; + + var hiddenValues = {}; + + if (this.element.TEMPLATE.SSH_PUBLIC_KEY != undefined) { + hiddenValues.SSH_PUBLIC_KEY = this.element.TEMPLATE.SSH_PUBLIC_KEY; + } + if (this.element.TEMPLATE.SUNSTONE != undefined) { + hiddenValues.SUNSTONE = this.element.TEMPLATE.SUNSTONE; + } + + TemplateTable.setup(strippedTemplate, RESOURCE, this.element.ID, context, hiddenValues); + //=== + + // View password button + context.off("click", "#view_password"); + context.on("click", "#view_password", function(){ + Sunstone.getDialog(CONFIRM_DIALOG_ID).setParams({ + header : Locale.tr("Password"), + headerTabId: that.tabId, + body: '' + + '
'+that.element.PASSWORD+'
', + question : '', + buttons : [ + Locale.tr("Close"), + ], + submit : [ + function(){ + return false; + } + ] + }); + + Sunstone.getDialog(CONFIRM_DIALOG_ID).reset(); + Sunstone.getDialog(CONFIRM_DIALOG_ID).show(); + }); + + // Edit password button + context.off("click", "#update_password"); + context.on("click", "#update_password", function(){ + Sunstone.getDialog(PASSWORD_DIALOG_ID).setParams( + {selectedElements: [that.element.ID]}); + Sunstone.getDialog(PASSWORD_DIALOG_ID).reset(); + Sunstone.getDialog(PASSWORD_DIALOG_ID).show(); + }); + + // Login token button + context.off("click", "#login_token"); + context.on("click", "#login_token", function(){ + Sunstone.getDialog(LOGIN_TOKEN_DIALOG_ID).setParams({element: that.element}); + Sunstone.getDialog(LOGIN_TOKEN_DIALOG_ID).reset(); + Sunstone.getDialog(LOGIN_TOKEN_DIALOG_ID).show(); + }); + + context.off("click", "#div_edit_auth_driver_link"); + context.on("click", "#div_edit_auth_driver_link", function() { + $("#show_auth_driver").hide(); + $("#label_auth").hide(); + $("#change_auth_driver").show(); + $("#users-tab_driver").val(that.element.AUTH_DRIVER); + }); + + context.off("change", "#users-tab_driver"); + context.on("change", "#users-tab_driver", function() { + var newAuthDriver= $(this).val(); + if (newAuthDriver != "") { + Sunstone.runAction(RESOURCE + ".chauth", [that.element.ID], newAuthDriver); + $("#change_auth_driver").hide(); + $("#show_auth_driver").show(); + Sunstone.runAction(RESOURCE + ".refresh"); + } + }); + + // SSH input + + context.off("click", ".user_ssh_public_key_edit"); + context.on("click", ".user_ssh_public_key_edit", function() { + $("#user_ssh_public_key_text", context).hide(); + $("#user_ssh_public_key_textarea", context).show().focus(); + }); + + context.off("change", "#user_ssh_public_key_textarea"); + context.on("change", "#user_ssh_public_key_textarea", function() { + var template_str = 'SSH_PUBLIC_KEY = "'+TemplateUtils.escapeDoubleQuotes($(this).val())+'"'; + + Sunstone.runAction("User.append_template", that.element.ID, template_str); + }); + + context.off("focusout", "#user_ssh_public_key_textarea"); + context.on("focusout", "#user_ssh_public_key_textarea", function() { + $("#user_ssh_public_key_text", context).show(); + $("#user_ssh_public_key_textarea", context).hide(); + }); + + $("#user_ssh_public_key_text", context).show(); + $("#user_ssh_public_key_textarea", context).hide(); + return false; + } +}); diff --git a/src/sunstone/public/app/tabs/users-tab/panels/info-common.js b/src/sunstone/public/app/tabs/users-tab/panels/info-common.js index 12f5bedc219..9cb1c22ae0a 100644 --- a/src/sunstone/public/app/tabs/users-tab/panels/info-common.js +++ b/src/sunstone/public/app/tabs/users-tab/panels/info-common.js @@ -20,7 +20,11 @@ define(function(require) { */ var TemplateInfo = require('hbs!./info/html'); +<<<<<<< HEAD var TemplateChgrpTr = require('hbs!./info/chgrp-tr'); +======= + var TemplateInfoSettings = require('hbs!tabs/settings-tab/panels/info/html'); +>>>>>>> ae6bbca... B #4960 Settings field can be disabled var ResourceSelect = require('utils/resource-select'); var TemplateUtils = require('utils/template-utils'); var Locale = require('utils/locale'); @@ -50,7 +54,8 @@ define(function(require) { function Panel(info) { this.title = Locale.tr("Info"); this.icon = "fa-info-circle"; - + if(info.tabId == "settings-tab") + TemplateInfo = TemplateInfoSettings; this.element = info[XML_ROOT]; return this;