[Kimchi-devel] [PATCH] [WoK] Bug fix #187: Fixing redirect with non-root login

Aline Manera alinefm at linux.vnet.ibm.com
Mon Dec 12 12:23:03 UTC 2016



On 12/12/2016 09:48 AM, Daniel Henrique Barboza wrote:
>
>
> On 12/09/2016 03:48 PM, Aline Manera wrote:
>>
>>
>> On 12/09/2016 01:19 PM, dhbarboza82 at gmail.com wrote:
>>> From: Daniel Henrique Barboza <danielhb at 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 at 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.
>
>
> I agree on not hard-coding the 'tabs/settings.html' and instead using 
> a more generic
> approach to the problem. I'll fix that in v2.
>
> About "getting the first element of orderedTabs", I am not doing that 
> - I am not even using the
> 'orderedTabs' variable. I am retrieving the existing tabs in the HTML 
> by doing:
>

I know you are not getting the value from orderedTabs, but the current 
upstream is doing that so I think the root cause of the problem is that. =)

So replacing the code where orderedTabs is being used to the below code 
will fix the issue.

> location.hash = '#' + $('#tabPanel a').attr('href');
>
> Which is simply an easier way of writing
>
> location.hash = '#' + $('#tabPanel a')[0].attr('href');
>
>
> $('#tabPanel a') retrieves the generated HTMLs, already considering 
> the scenario where
> the plug-ins might not render some tabs due to user type restrictions.
>
>
>
> Daniel
>
>>
>>
>>
>>
>>>           }
>>>           //Remove the tab arrow indicator for no plugin
>>>           if (url == 'wok-empty.html') {
>>
>




More information about the Kimchi-devel mailing list