On 12/09/2016 01:19 PM, dhbarboza82(a)gmail.com wrote:
From: Daniel Henrique Barboza <danielhb(a)linux.vnet.ibm.com>
The 'WoK User Activity Log' tab isn't available when running
as regular (non-root) user. But, at the same time, it is acting
as the default URL when opening WoK.
This patch redirects the default URL when logged as a regular
user as follows:
- if no plug-ins are installed, a warning message is displayed.
- if at least one plug-in is installed, the default URL is redirected
to the first plug-in. Considering the existing WoK plug-ins at the time
this patch was created, it will be redirected to Gingerbase Dashboard.
Signed-off-by: Daniel Henrique Barboza <danielhb(a)linux.vnet.ibm.com>
---
ui/js/src/wok.main.js | 27 ++++++++++++++++++++++++---
1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/ui/js/src/wok.main.js b/ui/js/src/wok.main.js
index 4b36400..260951c 100644
--- a/ui/js/src/wok.main.js
+++ b/ui/js/src/wok.main.js
@@ -209,9 +209,30 @@ wok.main = function() {
* and clear location.hash to jump to home page.
*/
var tab = $('#tabPanel a[href="' + url + '"]');
- if (tab.length === 0 && url !=
'wok-empty.html') {
- location.hash = '#';
- return;
+ if (tab.length === 0) {
+ if (url === "tabs/settings.html") {
+ /*
+ * This scenario means that the WoK tab isn't avaiable for the
+ * current user (probably because it's a regular non-sudo user).
+ * If there are other tabs to fall back to, redirect to them.
Otherwise,
+ * if running WoK without plug-ins, put an informative message.
+ */
+ if ($('#tabPanel a').length === 0) {
+ var warning_msg = "Unable to access WoK User Activity Log
feature as a non-root user.<br>No plugins installed currently. You can download the
available plugins <a
href='https://github.com/kimchi-project/kimchi'>Kimchi</a> and <a
href='https://github.com/kimchi-project/ginger'>Ginger</a> from
Github."
+
$('#main').html(warning_msg).addClass('noPluginMessage');
+ } else {
+ location.hash = '#' + $('#tabPanel
a').attr('href');
+ var lastIndex = location.hash.lastIndexOf(".html");
+ if (lastIndex != -1) {
+ location.hash = location.hash.substring(0, lastIndex);
+ }
+ }
+ return;
+ }
+ if (url != 'wok-empty.html') {
+ location.hash = '#';
+ return;
+ }
Seems hard coding 'tabs/settings.html' is not the right solution.
From what I understood from the current code, the problem is on where
to select the first tab after login.
Check line 167 from wok.main.js
if(tabs.length===0){
DEFAULT_HASH = 'wok-empty';
} else {
var defaultTab = orderedTabs[0]
var defaultTabPath = defaultTab && defaultTab['path']
// Remove file extension from 'defaultTabPath'
DEFAULT_HASH = defaultTabPath &&
defaultTabPath.substring(0,
defaultTabPath.lastIndexOf('.'))
}
genTabs(orderedTabs);
wok.getHostname();
wok.logos('ul#plugins',true);
wok.logos('ul#wok-about',false);
callback && callback();
}, function(data) {
wok.message.error(data.responseJSON.reason);
}, true);
As you can see when there is no tab, the user will see the wok-empty
content.
Otherwise, the defaultTab will be the first one from the list *BUT*
'orderedTabs has all the tabs specified for a plugin. But maybe not all
them will be generated as some of them may have configuration to do not
be shown to a normal user (as the case of this bug).
So instead of getting the first element of orderedTabs we need to get
the first tab really built on HTML.
Something like $(.tabPanel > ul li a).attr('href') to get the first
tab. All the current flow should keep the same.
}
//Remove the tab arrow indicator for no plugin
if (url == 'wok-empty.html') {