Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

user menu without authorization #791

Merged
20 changes: 14 additions & 6 deletions core/src/Authorization.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
>{userInfo.name ? userInfo.name : userInfo.email}</span>
</li>
{/if}
{/if}
{#each profileNav.items as profileItem}
<li
on:click="onActionClick(profileItem)"
Expand All @@ -35,6 +36,7 @@
</a>
</li>
{/each}
{#if isAuthorizationEnabled}
<li on:click="onLogoutClick()" data-testid="{getTestId(profileNav.logout)}">
<a aria-label="Logout" class="fd-menu__item">
{#if profileNav.logout.icon}
Expand All @@ -52,11 +54,12 @@
<span>{$getTranslation(profileNav.logout.label)}</span>
</a>
</li>
{:else}
{#if !isLoggedIn}
<li on:click="startAuthorization()">
<a aria-label="Login" class="fd-menu__item">Login</a>
</li>
{/if}
{/if}
</ul>
</nav>
{/if}
Expand Down Expand Up @@ -131,9 +134,12 @@
},
async oncreate() {
if (!LuigiAuth.isAuthorizationEnabled()) {
this.set({ isAuthorizationEnabled: false });
this.setProfileNavData();
return;
} else {
this.set({ isAuthorizationEnabled: true });
}

const idpProviderName = LuigiConfig.getConfigValue('auth.use');
const idpProviderSettings = LuigiConfig.getConfigValue(
`auth.${idpProviderName}`
Expand Down Expand Up @@ -269,15 +275,17 @@
'navigation.profile.logout'
);
const profileNavData = {
logout: {
...TOP_NAV_DEFAULTS.logout,
...logoutItem
},
items:
(await LuigiConfig.getConfigValueAsync(
'navigation.profile.items'
)) || []
};
if (this.get().isAuthorizationEnabled) {
profileNavData['logout'] = {
...TOP_NAV_DEFAULTS.logout,
...logoutItem
};
}
this.set({ profileNav: profileNavData });
},
['navigation.profile']
Expand Down
6 changes: 5 additions & 1 deletion core/src/navigation/TopNav.html
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@
{/if}
{/if}
<!-- closes {#if children && pathData.length > 0} -->
{#if authorizationEnabled}
{#if authorizationEnabled || profileItemsAvailable}
<div
class="fd-shellbar__action fd-shellbar__action--show-always"
data-testid="luigi-topnav-profile"
Expand Down Expand Up @@ -338,6 +338,9 @@
() => {
this.set({
authorizationEnabled: LuigiAuth.isAuthorizationEnabled(),
profileItemsAvailable: LuigiConfig.getConfigValue(
'navigation.profile.items'
),
autologinEnabled: !Boolean(
LuigiConfig.getConfigValue('auth.disableAutoLogin')
),
Expand All @@ -355,6 +358,7 @@
},
['navigation']
);
debugger;
this.set({
urlAuthError: AuthHelpers.parseUrlAuthErrors()
});
Expand Down
6 changes: 3 additions & 3 deletions docs/navigation-parameters-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ The context switcher is a drop-down list available in the top navigation bar. It

## Profile

The profile section is a configurable drop-down list available in the top navigation bar. Within the configuration, you can override the logout item content and/or add links to Luigi navigation nodes. To do so, add the **profile** property to the **navigation** object using the following optional properties:
The profile section is a configurable drop-down list available in the top navigation bar. Within the configuration, you can override the logout item content (if authorization is configured) and/or add links to Luigi navigation nodes. To do so, add the **profile** property to the **navigation** object using the following optional properties:

- **logout** overrides the content of the logout item.
- **label** overrides the text for the logout item. The default value is "Sign Out".
Expand All @@ -262,7 +262,7 @@ The profile section is a configurable drop-down list available in the top naviga
- **externalLink** is an object which indicates that the node links to an external URL. If this parameter is defined, the **link** parameter is ignored. It has the following properties:
- **sameWindow** defines if the external URL is opened in the current tab or in a new one. The default value for this parameter is `false`.
- **url** is the external URL that the link leads to.

>**NOTE:** Neither authorization nor profile property are configured if the profile section in the top navigation bar is not visible.

## Product switcher

Expand All @@ -278,4 +278,4 @@ The product switcher is a pop-up window available in the top navigation bar. It
- **link** defines an absolute link to a **node**.
- **externalLink** is an object which indicates that the node links to an external URL. If this parameter is defined, the **link** parameter is ignored. It has the following properties:
- **sameWindow** defines if the external URL is opened in the current tab or in a new one. The default value for this parameter is `false`.
- **url** is the external URL that the link leads to.
- **url** is the external URL that the link leads to.