@hmcts/ccd-case-ui-toolkit 7.3.74-multiple-role-categories → 7.3.74

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8671,33 +8671,31 @@ class CaseAccessUtils {
8671
8671
  static CTSC_ROLE = 'ctsc';
8672
8672
  static CTSC_ROLE_CATEGORY = 'CTSC';
8673
8673
  static CTSC_ROLE_NAME = 'ctsc';
8674
- // fallback purely if roleCategories is not available in
8675
- getMappedRoleCategories(roles = []) {
8674
+ getMappedRoleCategory(roles = [], roleCategories = []) {
8676
8675
  const roleKeywords = roles.join().split('-').join().split(',');
8677
- const roleCategoryList = [];
8678
- if (this.roleOrCategoryExists(CaseAccessUtils.JUDGE_ROLE, roleKeywords)) {
8679
- roleCategoryList.push(CaseAccessUtils.JUDGE_ROLE_CATEGORY);
8676
+ if (this.roleOrCategoryExists(CaseAccessUtils.JUDGE_ROLE, CaseAccessUtils.JUDGE_ROLE_CATEGORY, roleKeywords, roleCategories)) {
8677
+ return CaseAccessUtils.JUDGE_ROLE_CATEGORY;
8680
8678
  }
8681
- if (this.roleOrCategoryExists(CaseAccessUtils.PROFESSIONAL_ROLE, roleKeywords)) {
8682
- roleCategoryList.push(CaseAccessUtils.PROFESSIONAL_ROLE_CATEGORY);
8679
+ else if (this.roleOrCategoryExists(CaseAccessUtils.PROFESSIONAL_ROLE, CaseAccessUtils.PROFESSIONAL_ROLE_CATEGORY, roleKeywords, roleCategories)) {
8680
+ return CaseAccessUtils.PROFESSIONAL_ROLE_CATEGORY;
8683
8681
  }
8684
- if (this.roleOrCategoryExists(CaseAccessUtils.CITIZEN_ROLE, roleKeywords)) {
8685
- roleCategoryList.push(CaseAccessUtils.CITIZEN_ROLE_CATEGORY);
8682
+ else if (this.roleOrCategoryExists(CaseAccessUtils.CITIZEN_ROLE, CaseAccessUtils.CITIZEN_ROLE_CATEGORY, roleKeywords, roleCategories)) {
8683
+ return CaseAccessUtils.CITIZEN_ROLE_CATEGORY;
8686
8684
  }
8687
- if (this.roleOrCategoryExists(CaseAccessUtils.ADMIN_ROLE, roleKeywords)) {
8688
- roleCategoryList.push(CaseAccessUtils.ADMIN_ROLE_CATEGORY);
8685
+ else if (this.roleOrCategoryExists(CaseAccessUtils.ADMIN_ROLE, CaseAccessUtils.ADMIN_ROLE_CATEGORY, roleKeywords, roleCategories)) {
8686
+ return CaseAccessUtils.ADMIN_ROLE_CATEGORY;
8689
8687
  }
8690
- if (this.roleOrCategoryExists(CaseAccessUtils.CTSC_ROLE, roleKeywords)) {
8691
- roleCategoryList.push(CaseAccessUtils.CTSC_ROLE_CATEGORY);
8688
+ else if (this.roleOrCategoryExists(CaseAccessUtils.CTSC_ROLE, CaseAccessUtils.CTSC_ROLE_CATEGORY, roleKeywords, roleCategories)) {
8689
+ return CaseAccessUtils.CTSC_ROLE_CATEGORY;
8692
8690
  }
8693
- if (this.roleOrCategoryExists(CaseAccessUtils.LEGAL_OPERATIONS_ROLE, roleKeywords)) {
8694
- roleCategoryList.push(CaseAccessUtils.LEGAL_OPERATIONS_ROLE_CATEGORY);
8691
+ else {
8692
+ return CaseAccessUtils.LEGAL_OPERATIONS_ROLE_CATEGORY;
8695
8693
  }
8696
- return roleCategoryList;
8697
8694
  }
8698
- roleOrCategoryExists(roleKeyword, roleKeywords) {
8695
+ roleOrCategoryExists(roleKeyword, roleCategory, roleKeywords, roleCategories) {
8696
+ const categoryExists = roleCategories.indexOf(roleCategory) > -1;
8699
8697
  const keywordExists = roleKeywords.indexOf(roleKeyword) > -1;
8700
- return keywordExists;
8698
+ return categoryExists ? categoryExists : keywordExists;
8701
8699
  }
8702
8700
  getAMRoleName(accessType, aMRole) {
8703
8701
  let roleName = '';
@@ -10585,21 +10583,16 @@ class CasesService {
10585
10583
  const userInfoStr = this.sessionStorageService.getItem('userDetails');
10586
10584
  const camUtils = new CaseAccessUtils();
10587
10585
  let userInfo;
10588
- userInfo = userInfoStr ? JSON.parse(userInfoStr) : null;
10589
- if (!userInfo) {
10590
- return throwError(() => new Error('User info not found in session storage'));
10591
- }
10592
- // EXUI-4758 - getMappedRoleCategories no longer returns a single string, checks all roles to get the most likely roleCategory
10593
- // Unsure whether we should be using mapped role categories any more - should trust the roleCategories from userInfo if they exist
10594
- const roleCategories = userInfo.roleCategories || camUtils.getMappedRoleCategories(userInfo.roles);
10595
- const roleName = camUtils.getAMRoleName('challenged', roleCategories[0]);
10586
+ if (userInfoStr) {
10587
+ userInfo = JSON.parse(userInfoStr);
10588
+ }
10589
+ const roleCategory = userInfo.roleCategory || camUtils.getMappedRoleCategory(userInfo.roles, userInfo.roleCategories);
10590
+ const roleName = camUtils.getAMRoleName('challenged', roleCategory);
10596
10591
  const beginTime = new Date();
10597
10592
  const endTime = new Date(new Date().setUTCHours(23, 59, 59, 999));
10598
10593
  const id = userInfo.id ? userInfo.id : userInfo.uid;
10599
10594
  const isNew = true;
10600
- const payload = camUtils.getAMPayload(id, id, roleName,
10601
- // EXUI-4758 - Return first roleCategory as the roleCategory
10602
- roleCategories[0], 'CHALLENGED', caseId, request, beginTime, endTime, isNew);
10595
+ const payload = camUtils.getAMPayload(id, id, roleName, roleCategory, 'CHALLENGED', caseId, request, beginTime, endTime, isNew);
10603
10596
  return this.http.post(`/api/challenged-access-request`, payload);
10604
10597
  }
10605
10598
  createSpecificAccessRequest(caseId, sar) {
@@ -10607,14 +10600,10 @@ class CasesService {
10607
10600
  const userInfoStr = this.sessionStorageService.getItem('userDetails');
10608
10601
  const camUtils = new CaseAccessUtils();
10609
10602
  let userInfo;
10610
- userInfo = userInfoStr ? JSON.parse(userInfoStr) : null;
10611
- if (!userInfo) {
10612
- return throwError(() => new Error('User info not found in session storage'));
10613
- }
10614
- // EXUI-4758 - See above comment
10615
- const roleCategories = userInfo.roleCategories || camUtils.getMappedRoleCategories(userInfo.roles);
10616
- // EXUI-4758 - Return first roleCategory as the roleCategory for now
10617
- const roleCategory = roleCategories[0];
10603
+ if (userInfoStr) {
10604
+ userInfo = JSON.parse(userInfoStr);
10605
+ }
10606
+ const roleCategory = userInfo.roleCategory || camUtils.getMappedRoleCategory(userInfo.roles, userInfo.roleCategories);
10618
10607
  const roleName = camUtils.getAMRoleName('specific', roleCategory);
10619
10608
  const id = userInfo.id ? userInfo.id : userInfo.uid;
10620
10609
  const payload = camUtils.getAMPayload(null, id, roleName, roleCategory, 'SPECIFIC', caseId, sar, null, null, true);