-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8621859
commit 4f0daf9
Showing
32 changed files
with
699 additions
and
316 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 32 additions & 5 deletions
37
src/app/core/config/dynamic-components/dynamic-component-config.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,35 @@ | ||
/** | ||
* Object specifying one dynamic component | ||
* as stored in the config database | ||
* This interface is set on the `data` property of the route. | ||
* It contains static data which are used to build components and manage permissions. | ||
* The generic type defines the interface for the component specific configuration. | ||
* | ||
* The properties given in the `config` object here are automatically assigned to the component as `@Input()` properties. | ||
* e.g. for an DynamicComponentConfig `{ config: { "entityType: "Child", "filtered": true } }` | ||
* your component `MyViewComponent` will receive the values mapped to its properties: | ||
* ```javascript | ||
* class MyViewComponent { | ||
* @Input() entityType: string; | ||
* @Input() filtered: boolean; | ||
* } | ||
* ``` | ||
*/ | ||
export interface DynamicComponentConfig { | ||
component: string; | ||
config?: any; | ||
export interface DynamicComponentConfig<T = any> { | ||
/** | ||
* string id/name of the component to be displaying this view. | ||
* The component id has to be registered in the component map. | ||
* | ||
* (optional) if the `ladyLoaded` is true, this is not required (and will be ignored) | ||
* This allows hard-coded lazy-loaded components to be dynamically extended with config or permissions. | ||
*/ | ||
component?: string; | ||
|
||
/** optional object providing any kind of config to be interpreted by the component for this view */ | ||
config?: T; | ||
|
||
/** | ||
* Allows to restrict the route to the given list of user roles. | ||
* If set, the route can only be visited by users which have a role which is in the list. | ||
* If not set, all logged-in users can visit the route. | ||
*/ | ||
permittedUserRoles?: string[]; | ||
} |
23 changes: 23 additions & 0 deletions
23
src/app/core/config/dynamic-routing/route-permissions.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { TestBed } from "@angular/core/testing"; | ||
|
||
import { RoutePermissionsService } from "./route-permissions.service"; | ||
import { UserRoleGuard } from "../../permissions/permission-guard/user-role.guard"; | ||
import { EntityPermissionGuard } from "../../permissions/permission-guard/entity-permission.guard"; | ||
|
||
describe("RoutePermissionsService", () => { | ||
let service: RoutePermissionsService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [ | ||
{ provide: UserRoleGuard, useValue: {} }, | ||
{ provide: EntityPermissionGuard, useValue: {} }, | ||
], | ||
}); | ||
service = TestBed.inject(RoutePermissionsService); | ||
}); | ||
|
||
it("should be created", () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
src/app/core/config/dynamic-routing/route-permissions.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Injectable } from "@angular/core"; | ||
import { UserRoleGuard } from "../../permissions/permission-guard/user-role.guard"; | ||
import { EntityPermissionGuard } from "../../permissions/permission-guard/entity-permission.guard"; | ||
import { MenuItem } from "../../ui/navigation/menu-item"; | ||
|
||
/** | ||
* Service that checks permissions for routes. | ||
*/ | ||
@Injectable({ | ||
providedIn: "root", | ||
}) | ||
export class RoutePermissionsService { | ||
constructor( | ||
private roleGuard: UserRoleGuard, | ||
private permissionGuard: EntityPermissionGuard, | ||
) {} | ||
|
||
/** | ||
* Filters menu items based on the route and entity permissions on the link. | ||
*/ | ||
async filterPermittedRoutes(items: MenuItem[]): Promise<MenuItem[]> { | ||
const accessibleRoutes: MenuItem[] = []; | ||
for (const item of items) { | ||
if (await this.isAccessibleRouteForUser(item.link)) { | ||
accessibleRoutes.push(item); | ||
} | ||
} | ||
return accessibleRoutes; | ||
} | ||
|
||
private async isAccessibleRouteForUser(path: string) { | ||
return ( | ||
(await this.roleGuard.checkRoutePermissions(path)) && | ||
(await this.permissionGuard.checkRoutePermissions(path)) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/app/core/dashboard/dashboard-widget/dashboard-widget.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Abstract class for dashboard widgets | ||
*/ | ||
export abstract class DashboardWidget { | ||
/** | ||
* Implement this if the dashboard depends on the user having access to a certain entity. | ||
* If an array of strings is returned, the dashboard is shown if the user has access to at least one of them. | ||
* | ||
* @param config same of the normal config that will later be passed to the inputs | ||
* @return ENTITY_TYPE which a user needs to have | ||
*/ | ||
static getRequiredEntities(config: any): string | string[] { | ||
return; | ||
} | ||
} |
Oops, something went wrong.