From alinefm at linux.vnet.ibm.com Fri Dec 9 17:49:04 2016 Content-Type: multipart/mixed; boundary="===============4386852280006154823==" MIME-Version: 1.0 From: Aline Manera To: kimchi-devel at ovirt.org Subject: Re: [Kimchi-devel] [PATCH] [WoK] Bug fix #187: Fixing redirect with non-root login Date: Fri, 09 Dec 2016 15:48:55 -0200 Message-ID: <8651ac13-48a9-ba0d-7c61-21b65816217c@linux.vnet.ibm.com> In-Reply-To: 1481296780-30291-1-git-send-email-dhbarboza82@gmail.com --===============4386852280006154823== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable On 12/09/2016 01:19 PM, dhbarboza82(a)gmail.com wrote: > From: Daniel Henrique Barboza > > 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 > --- > 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 =3D function() { > * and clear location.hash to jump to home page. > */ > var tab =3D $('#tabPanel a[href=3D"' + url + '"]'); > - if (tab.length =3D=3D=3D 0 && url !=3D 'wok-empty.html') { > - location.hash =3D '#'; > - return; > + if (tab.length =3D=3D=3D 0) { > + if (url =3D=3D=3D "tabs/settings.html") { > + /* > + * This scenario means that the WoK tab isn't avaiable f= or the > + * current user (probably because it's a regular non-sud= o user). > + * If there are other tabs to fall back to, redirect to = them. Otherwise, > + * if running WoK without plug-ins, put an informative m= essage. > + */ > + if ($('#tabPanel a').length =3D=3D=3D 0) { > + var warning_msg =3D "Unable to access WoK User Activ= ity Log feature as a non-root user.
No plugins installed currently. You = can download the available plugins Kimchi and Ginger from Github." > + $('#main').html(warning_msg).addClass('noPluginMessa= ge'); > + } else { > + location.hash =3D '#' + $('#tabPanel a').attr('href'= ); > + var lastIndex =3D location.hash.lastIndexOf(".html"); > + if (lastIndex !=3D -1) { > + location.hash =3D location.hash.substring(0, las= tIndex); > + } > + } > + return; > + } > + if (url !=3D 'wok-empty.html') { > + location.hash =3D '#'; > + 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=3D=3D=3D0){ DEFAULT_HASH =3D 'wok-empty'; } else { var defaultTab =3D orderedTabs[0] var defaultTabPath =3D defaultTab && defaultTab['path'] // Remove file extension from 'defaultTabPath' DEFAULT_HASH =3D 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 =3D=3D 'wok-empty.html') { --===============4386852280006154823==--