diff --git a/packages/admin-ui/src/lib/core/src/providers/dashboard-widget/dashboard-widget.service.ts b/packages/admin-ui/src/lib/core/src/providers/dashboard-widget/dashboard-widget.service.ts index cd5c98b22f..e68230c8bf 100644 --- a/packages/admin-ui/src/lib/core/src/providers/dashboard-widget/dashboard-widget.service.ts +++ b/packages/admin-ui/src/lib/core/src/providers/dashboard-widget/dashboard-widget.service.ts @@ -1,6 +1,8 @@ import { Injectable } from '@angular/core'; import { notNullOrUndefined } from '@vendure/common/lib/shared-utils'; +import { Permission } from '../../common/generated-types'; + import { DashboardWidgetConfig, DashboardWidgetWidth, @@ -26,8 +28,19 @@ export class DashboardWidgetService { this.registry.set(id, config); } - getAvailableIds(): string[] { - return [...this.registry.keys()]; + getAvailableIds(currentUserPermissions: Permission[]): string[] { + const hasAllPermissions = (requiredPerms: string[], userPerms: string[]): boolean => { + return requiredPerms.every(p => userPerms.includes(p)); + }; + + return [...this.registry.entries()] + .filter(([id, config]) => { + return ( + !config.requiresPermissions || + hasAllPermissions(config.requiresPermissions, currentUserPermissions) + ); + }) + .map(([id]) => id); } getWidgetById(id: string) { diff --git a/packages/admin-ui/src/lib/dashboard/src/components/dashboard/dashboard.component.html b/packages/admin-ui/src/lib/dashboard/src/components/dashboard/dashboard.component.html index c81d75c066..66c2c33747 100644 --- a/packages/admin-ui/src/lib/dashboard/src/components/dashboard/dashboard.component.html +++ b/packages/admin-ui/src/lib/dashboard/src/components/dashboard/dashboard.component.html @@ -8,7 +8,7 @@