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

Client permissions available in the client #678

Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions client/luigi-client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ export declare interface NodeParams {
[key: string]: string;
}

export declare interface ClientPermissions {
[key: string]: any;
}

export declare interface AlertSettings {
text?: string;
type: 'info' | 'success' | 'warning' | 'error';
Expand Down Expand Up @@ -357,6 +361,9 @@ export type getNodeParams = () => NodeParams;
export function getPathParams(): PathParams;
export type getPathParams = () => PathParams;

export function getClientPermissions(): ClientPermissions;
export type getClientPermissions = () => ClientPermissions;

/**
* The Link Manager allows you to navigate to another route. Use it instead of an internal router to:
- Route inside micro front-ends.
Expand Down
9 changes: 9 additions & 0 deletions client/src/lifecycleManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,5 +235,14 @@ class LifecycleManager extends LuigiClientBase {
getPathParams() {
return this.currentContext.pathParams;
}

/**
* Returns the current client permissions as specified in the navigation node. For details, see [Node parameters](navigation-parameters-reference.md).
* @returns {Object} client permissions as specified in the navigation node.
* @memberof Lifecycle
*/
getClientPermissions() {
return this.currentContext.internal.clientPermissions;
}
}
export const lifecycleManager = new LifecycleManager();
3 changes: 3 additions & 0 deletions client/src/luigi-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class LuigiClient {
getPathParams() {
return lifecycleManager.getPathParams();
}
getClientPermissions() {
return lifecycleManager.getClientPermissions();
}
/**
* @private
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ describe('Luigi client ux manager features', () => {
cy.get('[data-cy=luigi-alert]').should('not.exist');
});
});

describe('Luigi Client Localization', () => {
it('set localization in client', () => {
cy.goToUxManagerMethods($iframeBody);
Expand All @@ -336,6 +337,20 @@ describe('Luigi client ux manager features', () => {
.find('[data-cy=luigi-current-locale]')
.should('contain', "'pl_PL'");
});

it('clientPermissions: check if set localization in client is disabled', () => {
cy.visit('/projects/pr1/clientPermissionsTets')
.getIframeBody()
.then(body => {
cy.wrap(body)
.find('[data-cy=luigi-input-locale]')
.should('be.disabled');

cy.wrap(body)
.find('[data-cy=set-current-locale]')
.should('be.disabled');
});
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ <h1 class="fd-section__title">LuigiClient uxManager methods</h1>
name="locale"
placeholder=""
data-cy="luigi-input-locale"
[disabled]="!canChangeLocale"
/>
</div>
</div>
Expand All @@ -155,6 +156,7 @@ <h1 class="fd-section__title">LuigiClient uxManager methods</h1>
class="fd-button"
data-cy="set-current-locale"
(click)="setCurrentLocale()"
[disabled]="!canChangeLocale"
>
Set Current Locale
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Subscription } from 'rxjs';
import {
linkManager,
uxManager,
getClientPermissions,
addContextUpdateListener,
removeContextUpdateListener
} from '@kyma-project/luigi-client';
Expand Down Expand Up @@ -41,6 +42,7 @@ export class ProjectComponent implements OnInit, OnDestroy {
public isDirty = false;
public splitViewHandle;
public currentLocale = '';
public canChangeLocale = false;

public constructor(
private activatedRoute: ActivatedRoute,
Expand Down Expand Up @@ -85,6 +87,9 @@ export class ProjectComponent implements OnInit, OnDestroy {
this.projectId = ctx.context.currentProject;
this.preservedViewCallbackContext = ctx.context.goBackContext;
this.currentLocale = uxManager().getCurrentLocale();
this.canChangeLocale =
getClientPermissions() &&
getClientPermissions().changeCurrentLocale;
// Since Luigi runs outside of Zone.js, changes need
// to be updated manually
// Be sure to check for destroyed ChangeDetectorRef,
Expand All @@ -105,6 +110,8 @@ export class ProjectComponent implements OnInit, OnDestroy {
// this.projectId = updatedContext.currentProject;
// this.preservedViewCallbackContext = updatedContext.goBackContext;
this.currentLocale = uxManager().getCurrentLocale();
this.canChangeLocale =
getClientPermissions() && getClientPermissions().changeCurrentLocale;
console.log('context updated', this.currentLocale, updatedContext);
// Be sure to check for destroyed ChangeDetectorRef,
// else you get runtime Errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ export const projectDetailNavStructure = projectId => [
viewUrl: '/sampleapp.html#/projects/' + projectId + '/developers',
icon: '/assets/favicon-sap.ico'
},
{
pathSegment: 'clientPermissionsTets',
label: 'ClientPermissionsTets',
viewUrl: '/sampleapp.html#/projects/pr1',
hideFromNav: true
},
{
pathSegment: 'on-node-activation',
label: 'Node with node activation hook',
Expand Down
2 changes: 1 addition & 1 deletion core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"test:watch": "npm run test -- --watch",
"bundlesize": "npm run bundle && bundlesize",
"docu": "npm run docu:validate && npm run docu:generate:config && npm run docu:generate:dom-elements && npm run docu:generate:auth && npm run docu:generate:navigation && npm run docu:generate:i18n",
"docu:validate": "documentation lint --shallow src/core-api/config.js src/core-api/elements.js src/core-api/auth.js src/core-api/navigation.js src/core-api/i18n.j",
"docu:validate": "documentation lint --shallow src/core-api/config.js src/core-api/elements.js src/core-api/auth.js src/core-api/navigation.js src/core-api/i18n.js",
"docu:generate:config": "documentation readme src/core-api/config.js --shallow -f md --section='Luigi Config' --readme-file=../docs/luigi-core-api.md --markdown-toc=false --github false --quiet",
"docu:generate:dom-elements": "documentation readme src/core-api/dom-elements.js --shallow -f md --section='Luigi.elements()' --readme-file=../docs/luigi-core-api.md --markdown-toc=false --github false --quiet",
"docu:generate:auth": "documentation readme src/core-api/auth.js --shallow -f md --section='Luigi.auth()' --readme-file=../docs/luigi-core-api.md --markdown-toc=false --github false --quiet",
Expand Down
7 changes: 5 additions & 2 deletions core/src/App.html
Original file line number Diff line number Diff line change
Expand Up @@ -616,11 +616,14 @@
addPreserveView(this, data, config);
Routing.navigateTo(path); //navigate to the raw path. Any errors/alerts are handled later
},
prepareInternalData(config = {}) {
prepareInternalData(config) {
const internalData = {
isNavigateBack: this.get().isNavigateBack,
viewStackSize: this.get().preservedViews.length,
currentLocale: LuigiI18N.getCurrentLocale()
currentLocale: LuigiI18N.getCurrentLocale(),
clientPermissions: config.iframe.luigi.nextViewUrl
? config.iframe.luigi.nextClientPermissions
: config.iframe.luigi.clientPermissions
};
IframeHelpers.specialIframeTypes
.map(o => o.iframeConfigKey)
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ class IframeClass {
),
nodeParams: JSON.stringify(Object.assign({}, componentData.nodeParams)),
pathParams: JSON.stringify(Object.assign({}, componentData.pathParams)),
internal: JSON.stringify(component.prepareInternalData())
internal: JSON.stringify(component.prepareInternalData(config))
};
IframeHelpers.sendMessageToIframe(config.iframe, message);
// clear goBackContext and reset navigateBack after sending it to the client
Expand Down
6 changes: 6 additions & 0 deletions docs/luigi-client-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ All path parameters in the current navigation path (as defined by the active URL

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** path parameters, where the object property name is the path parameter name without the prefix, and its value is the actual value of the path parameter. For example `{productId: 1234, ...}`

### getClientPermissions

Returns the current client permissions as specified in the navigation node. For details, see [Node parameters](navigation-parameters-reference.md).

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** client permissions as specified in the navigation node.

## linkManager

The Link Manager allows you to navigate to another route. Use it instead of an internal router to:
Expand Down