Skip to content

Commit

Permalink
feat(stark-rbac): upgrade to Angular 12
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperITMan committed Aug 25, 2021
1 parent 367c2b2 commit d07c680
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 25 deletions.
6 changes: 3 additions & 3 deletions packages/stark-rbac/base.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ if ((<any>window).NodeList && !NodeList.prototype.forEach) {
}

/* tslint:disable:no-import-side-effect */
import "zone.js/dist/zone";
import "zone.js/dist/zone-testing";
import "zone.js/dist/long-stack-trace-zone";
import "zone.js";
import "zone.js/testing";
import "zone.js/plugins/long-stack-trace-zone";
/* tslint:enable:no-import-side-effect */

// define global environment variable (used in some places in stark-core and stark-ui)
Expand Down
3 changes: 2 additions & 1 deletion packages/stark-rbac/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
"docs": "compodoc",
"docs:coverage": "npm run docs -- --coverageTest 85 --coverageTestThresholdFail true",
"docs:serve": "npm run docs -- --watch --serve --port 4321",
"ng": "../../node_modules/.bin/ng",
"ng": "ng",
"ngc": "node ../../node_modules/@angular/compiler-cli/src/main.js -p ./tsconfig.json",
"ngcc": "ngcc",
"lint": "npm run lint-ts && npm run lint-css",
"lint-ts": "node ../../node_modules/tslint/bin/tslint --config ./tslint.json --project ./tsconfig.spec.json --format codeFrame",
"lint-ts:fix": "node --max_old_space_size=4096 ../../node_modules/tslint/bin/tslint --config ./tslint.json --project ./tsconfig.spec.json --format codeFrame --fix",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class StarkRBACAuthorizationModule {
* See {@link https://v7.angular.io/guide/singleton-services#the-forroot-pattern|Angular docs: The forRoot() pattern}
* @returns A module with providers
*/
public static forRoot(): ModuleWithProviders {
public static forRoot(): ModuleWithProviders<StarkRBACAuthorizationModule> {
return {
ngModule: StarkRBACAuthorizationModule,
providers: [{ provide: STARK_RBAC_AUTHORIZATION_SERVICE, useClass: StarkRBACAuthorizationServiceImpl }]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,19 @@ const directiveName = "[starkHideOnPermission]";
selector: directiveName
})
export class StarkHideOnPermissionDirective implements OnInit, OnDestroy {
/**
* @ignore
* @internal
*/
private _isValidInput = false;

/**
* {@link StarkRBACDirectivePermission} object containing any of the roles that the user must not have in order to display the element that this directive is applied to.
*/
@Input()
public set starkHideOnPermission(value: StarkRBACDirectivePermission) {
if (!value || typeof value.roles === "undefined") {
throw new Error(directiveName + ": Passed object must contain 'roles'.");
}
// Checks whether the value is valid and contains `roles` property
this._isValidInput = !(!value || typeof value.roles === "undefined");

if (!this.authorizationService.hasAnyRole(value.roles)) {
if (!this.viewRef) {
Expand Down Expand Up @@ -75,6 +80,10 @@ export class StarkHideOnPermissionDirective implements OnInit, OnDestroy {
* Component lifecycle hook
*/
public ngOnInit(): void {
if (!this._isValidInput) {
throw new Error(directiveName + ": Passed object must contain 'roles'.");
}

this.logger.debug(directiveName + ": directive initialized");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,19 @@ const directiveName = "[starkShowOnPermission]";
selector: directiveName
})
export class StarkShowOnPermissionDirective implements OnInit, OnDestroy {
/**
* @ignore
* @internal
*/
private _isValidInput = false;

/**
* {@link StarkRBACDirectivePermission} object containing any of the roles that the user must have in order to display the element that this directive is applied to.
*/
@Input()
public set starkShowOnPermission(value: StarkRBACDirectivePermission) {
if (!value || typeof value.roles === "undefined") {
throw new Error(directiveName + ": Passed object must contain 'roles'.");
}
// Checks whether the value is valid and contains `roles` property
this._isValidInput = !(!value || typeof value.roles === "undefined");

if (this.authorizationService.hasAnyRole(value.roles)) {
if (!this.viewRef) {
Expand Down Expand Up @@ -75,6 +80,9 @@ export class StarkShowOnPermissionDirective implements OnInit, OnDestroy {
* Component lifecycle hook
*/
public ngOnInit(): void {
if (!this._isValidInput) {
throw new Error(directiveName + ": Passed object must contain 'roles'.");
}
this.logger.debug(directiveName + ": directive initialized");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,19 +519,19 @@ describe("StarkRBACAuthorizationService", () => {
});

class AuthorizationServiceHelper extends StarkRBACAuthorizationServiceImpl {
public registerTransitionHook(): void {
public override registerTransitionHook(): void {
super.registerTransitionHook();
}

public isNavigationAuthorized(permissions: StarkRBACStatePermissions): boolean {
public override isNavigationAuthorized(permissions: StarkRBACStatePermissions): boolean {
return super.isNavigationAuthorized(permissions);
}

public handleUnauthorizedNavigation(permissions: StarkRBACStatePermissions, transition: Transition): TargetState {
public override handleUnauthorizedNavigation(permissions: StarkRBACStatePermissions, transition: Transition): TargetState {
return super.handleUnauthorizedNavigation(permissions, transition);
}

public redirectNavigation(redirectTo: StarkStateRedirection | StarkStateRedirectionFn, transition: Transition): TargetState {
public override redirectNavigation(redirectTo: StarkStateRedirection | StarkStateRedirectionFn, transition: Transition): TargetState {
return super.redirectNavigation(redirectTo, transition);
}
}
10 changes: 8 additions & 2 deletions packages/stark-rbac/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"extends": "@nationalbankbelgium/code-style/tsconfig/3.5.x/ng8",
"extends": "@nationalbankbelgium/code-style/tsconfig/4.3.x/ng12",
"compilerOptions": {
"baseUrl": ".",
"rootDir": ".",
"typeRoots": ["../../node_modules/@types", "../stark-build/typings"],
"lib": ["dom", "dom.iterable", "es2017"],
"paths": {
"@nationalbankbelgium/stark-core": ["../../dist/packages/stark-core"],
"@nationalbankbelgium/stark-core/testing": ["../../dist/packages/stark-core/testing"],
Expand All @@ -13,5 +12,12 @@
"environments/environment": ["../../dist/packages/stark-core/src/common/environment"]
},
"outDir": "../../dist/packages/stark-rbac"
},
"angularCompilerOptions": {
"annotateForClosureCompiler": true,
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"enableResourceInlining": true,
"compilationMode": "partial"
}
}
10 changes: 2 additions & 8 deletions packages/stark-rbac/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
{
"extends": "./tsconfig.json",
"angularCompilerOptions": {
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"fullTemplateTypeCheck": true,
"enableResourceInlining": true
"trace": true
},
"buildOnSave": false,
"compileOnSave": false,
"compilerOptions": {
"outDir": "AUTOGENERATED",
"declarationDir": "AUTOGENERATED",
"inlineSourceMap": true
},
"exclude": ["node_modules", "dist", "**/*.spec.ts"],
"files": ["AUTOGENERATED"]
"exclude": ["node_modules", "dist", "**/*.spec.ts"]
}

0 comments on commit d07c680

Please sign in to comment.