1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-23 22:50:09 +03:00

Merge remote-tracking branch 'origin/feature-4604'

This commit is contained in:
Carlos Martín 2016-07-01 12:20:38 +02:00
commit 57779b33e4
21 changed files with 468 additions and 47 deletions

View File

@ -93,6 +93,7 @@ tabs:
User.refresh: true
User.create_dialog: true
User.update_password: true
User.login_token: true
User.quotas_dialog: true
User.groups_dialog: true
User.chgrp: true

View File

@ -91,6 +91,7 @@ tabs:
User.refresh: true
User.create_dialog: true
User.update_password: true
User.login_token: true
User.quotas_dialog: true
User.groups_dialog: true
User.chgrp: true

View File

@ -80,6 +80,11 @@ tabs:
user_showback_tab: true
actions:
User.quotas_dialog: false
# Buttons inside the settings-tab panel user_info_tab
users-tab:
actions:
User.update_password: true
User.login_token: true
vms-tab:
actions: *provisionactions
images-tab:

View File

@ -80,6 +80,11 @@ tabs:
user_showback_tab: true
actions:
User.quotas_dialog: false
# Buttons inside the settings-tab panel user_info_tab
users-tab:
actions:
User.update_password: true
User.login_token: true
vms-tab:
actions: *provisionactions
images-tab:

View File

@ -91,6 +91,7 @@ tabs:
User.refresh: true
User.create_dialog: true
User.update_password: true
User.login_token: true
User.quotas_dialog: true
User.groups_dialog: false
User.chgrp: false

View File

@ -91,6 +91,7 @@ tabs:
User.refresh: true
User.create_dialog: true
User.update_password: true
User.login_token: true
User.quotas_dialog: true
User.groups_dialog: false
User.chgrp: false

View File

@ -90,6 +90,7 @@ tabs:
User.refresh: true
User.create_dialog: true
User.update_password: true
User.login_token: true
User.quotas_dialog: true
User.groups_dialog: true
User.chgrp: true

View File

@ -45,6 +45,7 @@ module OpenNebulaJSON
when "set_quota" then self.set_quota(action_hash['params'])
when "addgroup" then self.addgroup(action_hash['params'])
when "delgroup" then self.delgroup(action_hash['params'])
when "login" then self.login(action_hash['params'])
else
error_msg = "#{action_hash['perform']} action not " <<
" available for this resource"
@ -86,5 +87,13 @@ module OpenNebulaJSON
super(params['group_id'].to_i)
end
def login(params=Hash.new)
username = params['username'].nil? ? "" : params['username']
token = params['token'].nil? ? "" : params['token']
expire = params['expire'].nil? ? 36000 : params['expire']
super(username, token, expire)
end
end
end

View File

@ -76,6 +76,13 @@ define(function(require) {
var action_obj = {"password": params.data.extra_param};
OpenNebulaAction.simple_action(params, RESOURCE, "passwd", action_obj);
},
"login": function(params) {
var action_obj = {"username": params.data.username,
"token": params.data.token,
"expire": params.data.expire};
OpenNebulaAction.simple_action(params, RESOURCE, "login", action_obj);
},
"chgrp" : function(params) {
var action_obj = {"group_id": params.data.extra_param};
OpenNebulaAction.simple_action(params, RESOURCE, "chgrp", action_obj);

View File

@ -610,6 +610,10 @@ define(function(require) {
}
}
var _getTab = function() {
return $(".tab:visible").attr("id");
}
var _showElement = function(tabName, infoAction, elementId) {
_showTab(tabName);
@ -1099,6 +1103,7 @@ define(function(require) {
'showTab': _showTab,
"showElement" : _showElement,
"getTab": _getTab,
"showFormPanel": _showFormPanel,
"resetFormPanel": _resetFormPanel,

View File

@ -29,7 +29,8 @@ define(function(require) {
};
var _dialogs = [
require('tabs/users-tab/dialogs/password')
require('tabs/users-tab/dialogs/password'),
require('./users-tab/dialogs/login-token')
];
var _panels = [

View File

@ -26,6 +26,7 @@ define(function(require) {
var TemplateUtils = require('utils/template-utils');
var Sunstone = require('sunstone');
var Notifier = require('utils/notifier');
var Humanize = require('utils/humanize');
/*
TEMPLATES
@ -91,6 +92,15 @@ define(function(require) {
$('#provision_user_views_select option[value="' + config['user_config']["default_view"] + '"]', context).attr('selected', 'selected');
var login_token = this.element.LOGIN_TOKEN.TOKEN;
if (login_token && login_token.length) {
$(".provision_login_token_current", context).show();
$(".provision_login_token_valid", context).text(Humanize.prettyTime(this.element.LOGIN_TOKEN.EXPIRATION_TIME));
$(".provision_login_token_value", context).text(this.element.LOGIN_TOKEN.TOKEN);
} else {
$(".provision_login_token_current", context).hide();
}
$("#provision_change_password_form").submit(function() {
var pw = $('#provision_new_password', this).val();
var confirm_password = $('#provision_new_confirm_password', this).val();
@ -126,6 +136,37 @@ define(function(require) {
return false;
});
$("#provision_login_token_form", context).submit(function() {
$(".provision_login_token_button", context).html('<i class="fa fa-spinner fa-spin"/>')
OpenNebula.User.login({
data : {
id: "-1",
'username': that.element.NAME,
//token
//expire
},
success: function(req, response){
OpenNebula.User.show({
data : {
id: that.element.ID
},
success: function(request, user_json){
$(".provision_login_token_button", context).text(Locale.tr("Get a login token"));
$(".provision_login_token_current", context).show();
$(".provision_login_token_valid", context).text(Humanize.prettyTime(user_json.USER.LOGIN_TOKEN.EXPIRATION_TIME));
$(".provision_login_token_value", context).text(user_json.USER.LOGIN_TOKEN.TOKEN);
},
error: Notifier.onError
});
},
error: Notifier.onError
});
return false;
});
$("#provision_change_view_form").submit(function() {
var sunstone_setting = {DEFAULT_VIEW : $('#provision_user_views_select', this).val()};
Sunstone.runAction("User.append_sunstone_setting_refresh", that.element.ID, sunstone_setting);

View File

@ -197,3 +197,54 @@
</form>
</div>
</div>
<div class="row">
<div class="large-6 columns">
<div class="row">
<div class="large-12 large-centered columns">
<dl class="accordion" data-accordion>
<dd class="accordion-item" data-accordion-item>
<a href="#provision_login_token_accordion" class="text-center accordion-title">
<div class="row only-not-active">
<div class="large-12 large-centered columns">
<div class="text-center">
<span class="fa-stack fa-3x">
<i class="fa fa-cloud fa-stack-2x"></i>
<i class="fa fa-unlock-alt fa-stack-1x fa-inverse"></i>
</span>
</div>
</div>
</div>
<br class="only-not-active">
<i class="fa fa-lg fa-unlock-alt only-active"></i>
{{tr "Login Token"}}
</a>
<div id="provision_login_token_accordion" class="accordion-content" data-tab-content>
<br>
<form id="provision_login_token_form">
<br/>
<p>
{{tr "A login token acts as a password and can be used to authenticate with OpenNebula through Sunstone, the CLI, or the API"}}
</p>
<div class="provision_login_token_current">
<p>{{tr "Current login token, valid until"}} <span class="provision_login_token_valid"></span></p>
<br/>
<pre class="text-center provision_login_token_value"></pre>
<br/>
<br/>
<p class="label secondary radius float-center text-center">
<i class="fa fa-warning"/> {{tr "Getting a new token will invalidate the current one"}}
</p>
</div>
<div class="row">
<div class="large-12 columns">
<button href"#" type="submit" class="button large radius large-12 small-12 provision_login_token_button">{{tr "Get a login token"}}</button>
</div>
</div>
</form>
</div>
</dd>
</dl>
</div>
</div>
</div>
</div>

View File

@ -27,7 +27,8 @@ define(function(require) {
require('./users-tab/dialogs/password'),
require('./users-tab/dialogs/auth-driver'),
require('./users-tab/dialogs/quotas'),
require('./users-tab/dialogs/groups')
require('./users-tab/dialogs/groups'),
require('./users-tab/dialogs/login-token')
];
var _panels = [

View File

@ -0,0 +1,129 @@
/* -------------------------------------------------------------------------- */
/* 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 BaseDialog = require('utils/dialogs/dialog');
var TemplateHTML = require('hbs!./login-token/html');
var Sunstone = require('sunstone');
var Notifier = require('utils/notifier');
var Locale = require('utils/locale');
var OpenNebula = require('opennebula');
//var Config = require('sunstone-config');
/*
CONSTANTS
*/
var DIALOG_ID = require('./login-token/dialogId');
var USERS_TAB_ID = require('../tabId');
/*
CONSTRUCTOR
*/
function Dialog() {
this.dialogId = DIALOG_ID;
BaseDialog.call(this);
}
Dialog.DIALOG_ID = DIALOG_ID;
Dialog.prototype = Object.create(BaseDialog.prototype);
Dialog.prototype.constructor = Dialog;
Dialog.prototype.html = _html;
Dialog.prototype.onShow = _onShow;
Dialog.prototype.setup = _setup;
Dialog.prototype.setParams = _setParams;
return Dialog;
/*
FUNCTION DEFINITIONS
*/
/**
* @param {object} params
* - params.element : user element
*/
function _setParams(params) {
this.element = params.element;
}
function _html() {
return TemplateHTML({
'dialogId': this.dialogId,
'element': this.element
});
}
function _setup(context) {
var that = this;
$("#token_btn", context).click(function(){
$("#token_btn", context).html('<i class="fa fa-spinner fa-spin"/>')
OpenNebula.User.login({
data : {
id: "-1",
'username': that.element.NAME,
//token
//expire
},
success: function(req, response){
OpenNebula.User.show({
data : {
id: that.element.ID
},
success: function(request, user_json){
Sunstone.getDialog(DIALOG_ID).hide();
Sunstone.getDialog(DIALOG_ID).setParams({element: user_json.USER});
Sunstone.getDialog(DIALOG_ID).reset();
Sunstone.getDialog(DIALOG_ID).show();
if (Sunstone.getTab() == USERS_TAB_ID){
Sunstone.runAction('User.refresh');
} else {
Sunstone.runAction('Settings.refresh');
}
},
error: function(request, error_json){
Sunstone.getDialog(DIALOG_ID).hide();
Notifier.onError(request, error_json);
}
});
},
error: Notifier.onError
});
});
return false;
}
function _onShow(context) {
var tabId = Sunstone.getTab();
if (tabId == USERS_TAB_ID){
this.setNames( Sunstone.getDataTable(USERS_TAB_ID).elements({names: true}) );
}
return false;
}
});

View File

@ -0,0 +1,19 @@
/* -------------------------------------------------------------------------- */
/* 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){
return 'userLoginTokenDialog';
});

View File

@ -0,0 +1,62 @@
{{! -------------------------------------------------------------------------- }}
{{! 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. }}
{{! -------------------------------------------------------------------------- }}
<div id="{{dialogId}}" class="reveal" role="dialog" data-reveal >
<div class="row">
<div class="large-12 columns">
<h3 class="subheader">{{tr "Login Token"}}</h3>
</div>
</div>
<div class="confirm-resources-header"></div>
<div class="reveal-body">
<div class="row">
<div class="large-12 columns">
<br/>
<p>
{{tr "A login token acts as a password and can be used to authenticate with OpenNebula through Sunstone, the CLI, or the API"}}
</p>
</div>
</div>
{{#if element.LOGIN_TOKEN.TOKEN}}
<div class="row">
<div class="large-12 columns">
<p>{{tr "Current login token, valid until"}} {{humanizeTime element.LOGIN_TOKEN.EXPIRATION_TIME}}</p>
<br/>
<pre class="text-center">{{element.LOGIN_TOKEN.TOKEN}}</pre>
<br/>
<br/>
</div>
</div>
{{/if}}
<div class="row">
<div class="large-12 columns">
{{#if element.LOGIN_TOKEN.TOKEN}}
<p class="label secondary radius right">
<i class="fa fa-warning"/> {{tr "Getting a new token will invalidate the current one"}}
</p>
{{/if}}
</div>
</div>
<div class="row">
<button id="token_btn" type="button" class="button radius right">
{{tr "Get a new token"}}
</button>
</div>
<button class="close-button" data-close aria-label="{{tr "Close modal"}}" type="button">
<span aria-hidden="true">&times;</span>
</button>
</div>
</div>

View File

@ -32,7 +32,7 @@ define(function(require) {
*/
var DIALOG_ID = require('./password/dialogId');
var TAB_ID = require('../tabId');
var USERS_TAB_ID = require('../tabId');
/*
CONSTRUCTOR
@ -93,8 +93,10 @@ define(function(require) {
Sunstone.getDialog(DIALOG_ID).hide();
Sunstone.getDialog(DIALOG_ID).reset();
if (Config.isTabEnabled("users-tab")){
if (Sunstone.getTab() == USERS_TAB_ID){
Sunstone.runAction('User.refresh');
} else {
Sunstone.runAction('Settings.refresh');
}
})
.on("submit", function(ev) {
@ -105,7 +107,11 @@ define(function(require) {
}
function _onShow(context) {
this.setNames( Sunstone.getDataTable(TAB_ID).elements({names: true}) );
var tabId = Sunstone.getTab();
if (tabId == USERS_TAB_ID){
this.setNames( Sunstone.getDataTable(USERS_TAB_ID).elements({names: true}) );
}
return false;
}

View File

@ -42,6 +42,7 @@ define(function(require) {
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');
/*
CONSTRUCTOR
@ -125,14 +126,6 @@ define(function(require) {
}
});
// 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();
});
// Password button
context.off("click", "#update_password");
context.on("click", "#update_password", function(){
@ -142,6 +135,22 @@ define(function(require) {
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();
});
// 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())+'"';

View File

@ -16,7 +16,7 @@
<div class="row">
<div class="large-6 columns">
<table id="info_user_table" class="dataTable" cellpadding="0" cellspacing="0" border="0">
<table class="dataTable" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th colspan="3">{{tr "Information"}}</th>
@ -34,19 +34,6 @@
<td></td>
</tr>
{{{groupTrHTML}}}
<tr>
<td class="key_td">{{tr "Authentication driver"}}</td>
<td class="value_td">{{element.AUTH_DRIVER}}</td>
<td></td>
</tr>
<tr>
<td class="key_td">{{tr "Password"}}</td>
<td class="value_td" colspan="2">
<button id="update_password" type="button" class="button small radius secondary" >
{{tr "Update password"}} <i class="fa fa-pencil-square-o"/>
</button>
</td>
</tr>
<tr>
<td class="key_td">{{tr "Table Order"}}</td>
<td class="value_td_table_order">{{valOrDefault sunstone_template.TABLE_ORDER "-"}}</td>
@ -78,26 +65,70 @@
</table>
</div>
<div class="large-6 columns">
<table class="dataTable" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th>{{tr "Public SSH Key"}}</th>
<th>
<a class="user_ssh_public_key_edit right" href="#"><i class="fa fa-pencil-square-o"></i></a>
</th>
</tr>
</thead>
</table>
<textarea rows="6" type="text" id="user_ssh_public_key_textarea" name="ssh_public_key" hidden>
{{~element.TEMPLATE.SSH_PUBLIC_KEY~}}
</textarea>
<p id="user_ssh_public_key_text" class="ellipsis" name="ssh_public_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}}
</p>
<div class="row">
<div class="large-12 columns">
<table class="dataTable">
<thead>
<tr>
<th colspan="2">{{tr "Authentication"}}</th>
</tr>
</thead>
<tbody>
<tr>
<td class="key_td">{{tr "Authentication driver"}}</td>
<td class="value_td">{{element.AUTH_DRIVER}}</td>
<td></td>
</tr>
{{#isTabActionEnabled "users-tab" "User.update_password"}}
<tr class="passsword_edit">
<td class="key_td">{{tr "Password"}}</td>
<td class="value_td">
<button id="update_password" type="button" class="button small radius secondary" style="min-width:80%">
{{tr "Update password"}} <i class="fa fa-pencil-square-o"/>
</button>
</td>
</tr>
{{/isTabActionEnabled}}
{{#isTabActionEnabled "users-tab" "User.login_token"}}
<tr class="login_token">
<td class="key_td">{{tr "Login token"}}</td>
<td class="value_td">
<button id="login_token" type="button" class="button small radius secondary" style="min-width:80%">
{{tr "Get a login token"}}
</button>
</td>
</tr>
{{/isTabActionEnabled}}
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<table class="dataTable" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th>{{tr "Public SSH Key"}}</th>
<th>
<a class="user_ssh_public_key_edit right" href="#"><i class="fa fa-pencil-square-o"></i></a>
</th>
</tr>
</thead>
</table>
<td>
<textarea rows="6" type="text" id="user_ssh_public_key_textarea" name="ssh_public_key" hidden>
{{~element.TEMPLATE.SSH_PUBLIC_KEY~}}
</textarea>
<p id="user_ssh_public_key_text" class="ellipsis" name="ssh_public_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}}
</p>
</td>
</div>
</div>
</div>
</div>
<div class="row">

View File

@ -0,0 +1,35 @@
/* -------------------------------------------------------------------------- */
/* 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) {
var Handlebars = require('hbs/handlebars');
var Humanize = require('utils/humanize');
/**
* Turns a Unix-formatted time into a human readable string
*/
var humanizeTime = function(seconds) {
if (seconds == undefined || seconds == ""){
return "-";
}
return Humanize.prettyTime(seconds);
};
Handlebars.registerHelper('humanizeTime', humanizeTime);
return humanizeTime;
});