Skip to content

Commit

Permalink
Bug fix kimchi-project#146: Do not display Wok tab for non-admin users
Browse files Browse the repository at this point in the history
The Wok tab is restricted to admin users so do not load it for non-admin
users. It implies in changing the way Wok loads the tabs as all the
children tabs may be hidden for non-admin users and consequently the
pattern tab should not be loaded as well.

Signed-off-by: Aline Manera <[email protected]>
  • Loading branch information
alinefm committed Oct 11, 2016
1 parent ba305be commit 5835544
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/wok/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def get_enabled_plugins():


def get_all_tabs():
files = []
files = [os.path.join(paths.ui_dir, 'config/tab-ext.xml')]

for plugin, _ in get_enabled_plugins():
files.append(os.path.join(PluginPaths(plugin).ui_dir,
Expand Down
31 changes: 11 additions & 20 deletions ui/js/src/wok.main.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ wok.main = function() {
wok.popable();

var genTabs = function(tabs) {
var functionalTabs = [];
var tabsHtml = [];
$(tabs).each(function(i, tab) {
tab_i18n = i18n[tab] ? i18n[tab] : tab;
Expand All @@ -52,9 +53,16 @@ wok.main = function() {
'<input name="helpPath" class="sr-only" value="' + helpPath + '" type="hidden"/>',
'</li>'
);

if (functionalTabs.indexOf(functionality) == -1) {
functionalTabs.push(functionality)
}
}
});
return tabsHtml.join('');

$('#functionalTabPanel ul').append(genFuncTabs(functionalTabs));
$('#tabPanel ul').append(tabsHtml.join(''));
return;
};

var genFuncTabs = function(tabs){
Expand All @@ -73,7 +81,6 @@ wok.main = function() {

var parseTabs = function(xmlData) {
var tabs = [];
var functionalTabs = {};
var functionality = $(xmlData).find('functionality').text();
$(xmlData).find('tab').each(function() {
var $tab = $(this);
Expand Down Expand Up @@ -124,9 +131,7 @@ wok.main = function() {
var pluginI18nUrl = 'plugins/{plugin}/i18n.json';
var DEFAULT_HASH;
var buildTabs = function(callback) {
var tabs = [];
var functionalTabs = [];
var wokTabs = retrieveTabs(wokConfigUrl);
var tabs = retrieveTabs(wokConfigUrl);
wok.listPlugins(function(plugins) {
$(plugins).each(function(i, p) {
var url = wok.substitute(pluginConfigUrl, {
Expand All @@ -140,23 +145,10 @@ wok.main = function() {
}, i18nUrl, true);
var pluginTabs = retrieveTabs(url);
if(pluginTabs.length > 0){
var func = pluginTabs[0].functionality
if (functionalTabs.indexOf(func) == -1) {
functionalTabs.push(pluginTabs[0].functionality)
}
tabs.push.apply(tabs, pluginTabs);
}
});

//ordering of first level tab
functionalTabs.sort();
if(wokTabs.length > 0){
//Adds wok to first index in list
functionalTabs.unshift(wokTabs[0].functionality);
//Adds Wok tabs to the list
tabs.unshift.apply(tabs, wokTabs);
}

//sort second level tab based on their ordering number
var orderedTabs = tabs.slice(0);
orderedTabs.sort(function(a, b) {
Expand All @@ -174,8 +166,7 @@ wok.main = function() {
defaultTabPath.substring(0, defaultTabPath.lastIndexOf('.'))
}

$('#functionalTabPanel ul').append(genFuncTabs(functionalTabs));
$('#tabPanel ul').append(genTabs(orderedTabs));
genTabs(orderedTabs);
wok.getHostname();
wok.logos('ul#plugins',true);
wok.logos('ul#wok-about',false);
Expand Down

0 comments on commit 5835544

Please sign in to comment.