{ "version": 3, "sources": ["src/app/shared/enums/permission.ts", "src/app/modules/user-profile/const/menu-items.const.ts", "src/app/services/utils/permission.service.ts", "src/app/guards/permission.guard.ts"], "sourcesContent": ["export enum Permission {\n browse = 'b2b_portal_browse',\n apiKeys = 'account_api_keys_manage',\n users = 'account_users_manage',\n}\n", "import { UserProfileNavigationItem } from '@shared/interfaces/profile/user-profile-navigation-item';\nimport { Permission } from '@shared/enums/permission';\n\nexport const MenuItems: UserProfileNavigationItem[] = [\n {\n label: 'USER_PROFILE.GENERAL_INFORMATION',\n items: [\n { label: 'USER_PROFILE.PERSONAL_INFORMATION', routerLink: '/user-profile/personal-information' },\n { label: 'USER_PROFILE.ABOUT_COMPANY', routerLink: '/user-profile/about-company' },\n { label: 'USER_PROFILE.WAREHOUSES', routerLink: '/user-profile/warehouses' },\n ],\n },\n {\n label: 'USER_PROFILE.SETTINGS',\n items: [\n { label: 'USER_PROFILE.API_KEYS_MANAGEMENT', routerLink: '/user-profile/api-key', permissions: [Permission.apiKeys] },\n { label: 'USER_PROFILE.MARKUPS', routerLink: '/user-profile/markups' },\n { label: 'USER_PROFILE.FILTERS', routerLink: '/user-profile/filters' },\n ],\n },\n {\n label: 'USER_PROFILE.MY_EMPLOYEES',\n items: [{ label: 'USER_PROFILE.ACCOUNTS', routerLink: '/user-profile/accounts', permissions: [Permission.users] }],\n },\n {\n label: 'USER_PROFILE.LOYALTY_PROGRAMS',\n items: [{ label: 'USER_PROFILE.MY_LOYALTY_PROGRAMS', routerLink: '/user-profile/loyalties' }],\n },\n {\n label: 'USER_PROFILE.CHANGE_LANGUAGE',\n items: [{ label: 'USER_PROFILE.SELECT_SYSTEM_LANGUAGE', routerLink: '/user-profile/change-language' }],\n },\n];\n", "import { Injectable } from '@angular/core';\nimport { UserProfileNavigationItem } from '@shared/interfaces/profile/user-profile-navigation-item';\nimport { MenuItems } from '../../modules/user-profile/const/menu-items.const';\nimport { Permission } from '@shared/enums/permission';\nimport { catchError, map, Observable, of } from 'rxjs';\nimport { UsersService } from '@services/api/internal/users.service';\nimport { GetMeResponse } from '@shared/interfaces';\n\n@Injectable({\n providedIn: 'root',\n})\nexport class PermissionService {\n constructor(private userService: UsersService) {}\n\n hasUserPermissions(permissions: Permission[]): Observable {\n return this.fetchUserPermissions().pipe(\n map(userPermissions => {\n return this.checkPermissions(userPermissions, permissions);\n }),\n );\n }\n\n filterUserProfileNavigationItems(\n permissions: Permission[],\n allowChangeMarkup: boolean,\n menuItems: UserProfileNavigationItem[] = structuredClone(MenuItems),\n ): UserProfileNavigationItem[] {\n return menuItems.filter(menuItem => {\n if (menuItem.permissions) {\n return menuItem.permissions.some(permission => permissions.includes(permission));\n }\n\n if (menuItem.items) {\n menuItem.items = this.filterUserProfileNavigationItems(permissions, allowChangeMarkup, menuItem.items);\n return menuItem.items.length > 0;\n }\n\n if (menuItem.label === 'USER_PROFILE.MARKUPS') {\n return allowChangeMarkup;\n }\n\n return true;\n });\n }\n\n private checkPermissions(userPermissions: Permission[], requiredPermissions: Permission[]): boolean {\n return requiredPermissions.every(permission => userPermissions.includes(permission));\n }\n\n private fetchUserPermissions(): Observable {\n return this.userService.getMe().pipe(\n map((response: GetMeResponse) => response.permissions || []),\n catchError(() => {\n return of([]);\n }),\n );\n }\n}\n", "import { inject } from '@angular/core';\nimport { ActivatedRouteSnapshot, CanActivateFn, Router, UrlTree } from '@angular/router';\nimport { map, Observable } from 'rxjs';\nimport { Permission } from '@shared/enums/permission';\nimport { AlertType } from '@shared/enums/notifications/notifications.enum';\nimport { PermissionService } from '@services/utils/permission.service';\nimport { AlertService } from '@services/utils/alert.service';\n\nexport const PermissionGuard: CanActivateFn = (\n route: ActivatedRouteSnapshot,\n): Observable | Promise | boolean | UrlTree => {\n {\n const { permissions, routerLink }: { permissions?: Permission[]; routerLink?: string } = route.data;\n\n if (!permissions) {\n return true;\n }\n\n const permissionsService = inject(PermissionService);\n const alertService = inject(AlertService);\n const router = inject(Router);\n\n return permissionsService.hasUserPermissions(permissions).pipe(\n map(hasUserPermissions => {\n if (!hasUserPermissions) {\n alertService.show({\n severity: AlertType.Error,\n detail: 'PERMISSION_GUARD.NO_ACCESS',\n });\n\n return router.createUrlTree([routerLink ? routerLink : '/']);\n }\n return hasUserPermissions;\n }),\n );\n }\n};\n"], "mappings": "6MAAA,IAAYA,EAAZ,SAAYA,EAAU,CACpBA,OAAAA,EAAA,OAAA,oBACAA,EAAA,QAAA,0BACAA,EAAA,MAAA,uBAHUA,CAIZ,EAJYA,GAAU,CAAA,CAAA,ECGf,IAAMC,EAAyC,CACpD,CACEC,MAAO,mCACPC,MAAO,CACL,CAAED,MAAO,oCAAqCE,WAAY,oCAAoC,EAC9F,CAAEF,MAAO,6BAA8BE,WAAY,6BAA6B,EAChF,CAAEF,MAAO,0BAA2BE,WAAY,0BAA0B,CAAE,GAGhF,CACEF,MAAO,wBACPC,MAAO,CACL,CAAED,MAAO,mCAAoCE,WAAY,wBAAyBC,YAAa,CAACC,EAAWC,OAAO,CAAC,EACnH,CAAEL,MAAO,uBAAwBE,WAAY,uBAAuB,EACpE,CAAEF,MAAO,uBAAwBE,WAAY,uBAAuB,CAAE,GAG1E,CACEF,MAAO,4BACPC,MAAO,CAAC,CAAED,MAAO,wBAAyBE,WAAY,yBAA0BC,YAAa,CAACC,EAAWE,KAAK,CAAC,CAAE,GAEnH,CACEN,MAAO,gCACPC,MAAO,CAAC,CAAED,MAAO,mCAAoCE,WAAY,yBAAyB,CAAE,GAE9F,CACEF,MAAO,+BACPC,MAAO,CAAC,CAAED,MAAO,sCAAuCE,WAAY,+BAA+B,CAAE,EACtG,ECpBH,IAAaK,GAAiB,IAAA,CAAxB,MAAOA,CAAiB,CAC5BC,YAAoBC,EAAyB,CAAzB,KAAAA,YAAAA,CAA4B,CAEhDC,mBAAmBC,EAAyB,CAC1C,OAAO,KAAKC,qBAAoB,EAAGC,KACjCC,EAAIC,GACK,KAAKC,iBAAiBD,EAAiBJ,CAAW,CAC1D,CAAC,CAEN,CAEAM,iCACEN,EACAO,EACAC,EAAyCC,gBAAgBC,CAAS,EAAC,CAEnE,OAAOF,EAAUG,OAAOC,GAClBA,EAASZ,YACJY,EAASZ,YAAYa,KAAKC,GAAcd,EAAYe,SAASD,CAAU,CAAC,EAG7EF,EAASI,OACXJ,EAASI,MAAQ,KAAKV,iCAAiCN,EAAaO,EAAmBK,EAASI,KAAK,EAC9FJ,EAASI,MAAMC,OAAS,GAG7BL,EAASM,QAAU,uBACdX,EAGF,EACR,CACH,CAEQF,iBAAiBD,EAA+Be,EAAiC,CACvF,OAAOA,EAAoBC,MAAMN,GAAcV,EAAgBW,SAASD,CAAU,CAAC,CACrF,CAEQb,sBAAoB,CAC1B,OAAO,KAAKH,YAAYuB,MAAK,EAAGnB,KAC9BC,EAAKmB,GAA4BA,EAAStB,aAAe,CAAA,CAAE,EAC3DuB,EAAW,IACFC,EAAG,CAAA,CAAE,CACb,CAAC,CAEN,iDA7CW5B,GAAiB6B,EAAAC,CAAA,CAAA,CAAA,CAAA,iCAAjB9B,EAAiB+B,QAAjB/B,EAAiBgC,UAAAC,WAFhB,MAAM,CAAA,CAAA,SAEPjC,CAAiB,GAAA,ECHvB,IAAMkC,EACXC,GACkF,CAClF,CACE,GAAM,CAAEC,YAAAA,EAAaC,WAAAA,CAAU,EAA0DF,EAAMG,KAE/F,GAAI,CAACF,EACH,MAAO,GAGT,IAAMG,EAAqBC,EAAOC,CAAiB,EAC7CC,EAAeF,EAAOG,CAAY,EAClCC,EAASJ,EAAOK,CAAM,EAE5B,OAAON,EAAmBO,mBAAmBV,CAAW,EAAEW,KACxDC,EAAIF,GACGA,IACHJ,EAAaO,KAAK,CAChBC,SAAUC,EAAUC,MACpBC,OAAQ,6BACT,EAEMT,EAAOU,cAAc,CAACjB,GAA0B,GAAG,CAAC,EAG9D,CAAC,CAEN,CACF", "names": ["Permission", "MenuItems", "label", "items", "routerLink", "permissions", "Permission", "apiKeys", "users", "PermissionService", "constructor", "userService", "hasUserPermissions", "permissions", "fetchUserPermissions", "pipe", "map", "userPermissions", "checkPermissions", "filterUserProfileNavigationItems", "allowChangeMarkup", "menuItems", "structuredClone", "MenuItems", "filter", "menuItem", "some", "permission", "includes", "items", "length", "label", "requiredPermissions", "every", "getMe", "response", "catchError", "of", "\u0275\u0275inject", "UsersService", "factory", "\u0275fac", "providedIn", "PermissionGuard", "route", "permissions", "routerLink", "data", "permissionsService", "inject", "PermissionService", "alertService", "AlertService", "router", "Router", "hasUserPermissions", "pipe", "map", "show", "severity", "AlertType", "Error", "detail", "createUrlTree"] }