{ "version": 3, "sources": ["src/app/modules/core/authentication/guards/user-security.guard.ts"], "sourcesContent": ["import { Injectable } from \"@angular/core\";\r\nimport { ActivatedRouteSnapshot, RouterStateSnapshot, Router } from \"@angular/router\";\r\nimport { Observable } from \"rxjs\";\r\nimport { AccountInfoService, AlertsService, AuthDataModel, SessionInfoService } from \"degarmo-lib\";\r\n\r\n@Injectable({\r\n providedIn: 'root'\r\n})\r\nexport class UserSecurityGuard {\r\n constructor(\r\n private sessionInfoService: SessionInfoService,\r\n private accountInfoService: AccountInfoService,\r\n private alertsService: AlertsService,\r\n private router: Router\r\n ) {}\r\n\r\n canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable | Promise | boolean {\r\n const allowedUserGroups: string[] = route.data.allowedUserGroups as Array;\r\n const allowedSecurityLevelIDs: number[] = route.data.allowedSecurityLevelIDs as Array;\r\n const allowedCompanyIDs: number[] = route.data.allowedCompanyIDs as Array;\r\n const authenticate: boolean = route.data.authenticate as boolean;\r\n const auth: AuthDataModel = this.sessionInfoService.getAuthenticationInformation();\r\n const userLoginInfo = this.accountInfoService.getUserLoginInfo();\r\n\r\n let approved = false;\r\n\r\n if (authenticate) {\r\n // const menuItem: MenuItem = this.userRouteMenuService.getMenuItemWrapper(state.url);\r\n \r\n if (userLoginInfo) {\r\n const userType = userLoginInfo.userType;\r\n const securityLevelID = userLoginInfo.securityLevelID;\r\n \r\n if (!allowedUserGroups || (allowedUserGroups && !allowedUserGroups.length))\r\n approved = true;\r\n else if (allowedUserGroups && allowedUserGroups.length > 0) { \r\n // check for allowedUserGroups\r\n for (const group of allowedUserGroups) {\r\n if (group === userType) {\r\n approved = true;\r\n break;\r\n }\r\n }\r\n }\r\n \r\n // check for allowedSecurityLevelIDs\r\n if (approved && allowedSecurityLevelIDs && userLoginInfo.isProctor) {\r\n approved = allowedSecurityLevelIDs.indexOf(securityLevelID) !== -1;\r\n }\r\n \r\n /* Temp fix to hide routes from certain companies */\r\n if (approved && allowedCompanyIDs && userLoginInfo.isProctor) {\r\n const companyID = userLoginInfo.companyID;\r\n approved = allowedCompanyIDs.indexOf(companyID) !== -1;\r\n }\r\n }\r\n } else {\r\n approved = true;\r\n }\r\n\r\n if (!approved) {\r\n this.alertsService.error('You are not permitted to view that resource', 'Permissions Error');\r\n let prevURL: string = '';\r\n\r\n if (auth && auth.isLoggedIn)\r\n prevURL = '';\r\n else \r\n prevURL = '/account/login';\r\n \r\n this.router.navigate([prevURL]);\r\n }\r\n\r\n return approved;\r\n }\r\n}"], "mappings": ";;;;;;;;;;AAQM,IAAO,qBAAP,MAAO,mBAAiB;EAC1B,YACY,oBACA,oBACA,eACA,QAAc;AAHd,SAAA,qBAAA;AACA,SAAA,qBAAA;AACA,SAAA,gBAAA;AACA,SAAA,SAAA;EACT;EAEH,YAAY,OAA+B,OAA0B;AACjE,UAAM,oBAA8B,MAAM,KAAK;AAC/C,UAAM,0BAAoC,MAAM,KAAK;AACrD,UAAM,oBAA8B,MAAM,KAAK;AAC/C,UAAM,eAAwB,MAAM,KAAK;AACzC,UAAM,OAAsB,KAAK,mBAAmB,6BAA4B;AAChF,UAAM,gBAAgB,KAAK,mBAAmB,iBAAgB;AAE9D,QAAI,WAAW;AAEf,QAAI,cAAc;AAGd,UAAI,eAAe;AACf,cAAM,WAAW,cAAc;AAC/B,cAAM,kBAAkB,cAAc;AAEtC,YAAI,CAAC,qBAAsB,qBAAqB,CAAC,kBAAkB;AAC/D,qBAAW;iBACN,qBAAqB,kBAAkB,SAAS,GAAG;AAExD,qBAAW,SAAS,mBAAmB;AACnC,gBAAI,UAAU,UAAU;AACpB,yBAAW;AACX;YACJ;UACJ;QACJ;AAGA,YAAI,YAAY,2BAA2B,cAAc,WAAW;AAChE,qBAAW,wBAAwB,QAAQ,eAAe,MAAM;QACpE;AAGA,YAAI,YAAY,qBAAqB,cAAc,WAAW;AAC1D,gBAAM,YAAY,cAAc;AAChC,qBAAW,kBAAkB,QAAQ,SAAS,MAAM;QACxD;MACJ;IACJ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