@hmcts/ccd-case-ui-toolkit 7.3.74-multiple-role-categories → 7.3.74-user-by-idam-rework

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.
@@ -1856,13 +1856,13 @@ function getUserDetails(sessionStorageService) {
1856
1856
  }
1857
1857
  function isInternalUser(sessionStorageService) {
1858
1858
  const userDetails = getUserDetails(sessionStorageService);
1859
- return userDetails && userDetails?.roles
1859
+ return !!userDetails?.roles
1860
1860
  && !(userDetails.roles.includes(PUI_CASE_MANAGER)
1861
1861
  || userDetails.roles.some((role) => role.toLowerCase().includes(JUDGE)));
1862
1862
  }
1863
1863
  function isJudiciaryUser(sessionStorageService) {
1864
1864
  const userDetails = getUserDetails(sessionStorageService);
1865
- return userDetails && userDetails?.roles
1865
+ return !!userDetails?.roles
1866
1866
  && (userDetails.roles.some((role) => role.toLowerCase().includes(JUDGE)));
1867
1867
  }
1868
1868
 
@@ -8675,29 +8675,28 @@ class CaseAccessUtils {
8675
8675
  getMappedRoleCategories(roles = []) {
8676
8676
  const roleKeywords = roles.join().split('-').join().split(',');
8677
8677
  const roleCategoryList = [];
8678
- if (this.roleOrCategoryExists(CaseAccessUtils.JUDGE_ROLE, roleKeywords)) {
8678
+ if (this.roleHasKeyword(CaseAccessUtils.JUDGE_ROLE, roleKeywords)) {
8679
8679
  roleCategoryList.push(CaseAccessUtils.JUDGE_ROLE_CATEGORY);
8680
8680
  }
8681
- if (this.roleOrCategoryExists(CaseAccessUtils.PROFESSIONAL_ROLE, roleKeywords)) {
8681
+ if (this.roleHasKeyword(CaseAccessUtils.PROFESSIONAL_ROLE, roleKeywords)) {
8682
8682
  roleCategoryList.push(CaseAccessUtils.PROFESSIONAL_ROLE_CATEGORY);
8683
8683
  }
8684
- if (this.roleOrCategoryExists(CaseAccessUtils.CITIZEN_ROLE, roleKeywords)) {
8684
+ if (this.roleHasKeyword(CaseAccessUtils.CITIZEN_ROLE, roleKeywords)) {
8685
8685
  roleCategoryList.push(CaseAccessUtils.CITIZEN_ROLE_CATEGORY);
8686
8686
  }
8687
- if (this.roleOrCategoryExists(CaseAccessUtils.ADMIN_ROLE, roleKeywords)) {
8687
+ if (this.roleHasKeyword(CaseAccessUtils.ADMIN_ROLE, roleKeywords)) {
8688
8688
  roleCategoryList.push(CaseAccessUtils.ADMIN_ROLE_CATEGORY);
8689
8689
  }
8690
- if (this.roleOrCategoryExists(CaseAccessUtils.CTSC_ROLE, roleKeywords)) {
8690
+ if (this.roleHasKeyword(CaseAccessUtils.CTSC_ROLE, roleKeywords)) {
8691
8691
  roleCategoryList.push(CaseAccessUtils.CTSC_ROLE_CATEGORY);
8692
8692
  }
8693
- if (this.roleOrCategoryExists(CaseAccessUtils.LEGAL_OPERATIONS_ROLE, roleKeywords)) {
8693
+ if (this.roleHasKeyword(CaseAccessUtils.LEGAL_OPERATIONS_ROLE, roleKeywords)) {
8694
8694
  roleCategoryList.push(CaseAccessUtils.LEGAL_OPERATIONS_ROLE_CATEGORY);
8695
8695
  }
8696
8696
  return roleCategoryList;
8697
8697
  }
8698
- roleOrCategoryExists(roleKeyword, roleKeywords) {
8699
- const keywordExists = roleKeywords.indexOf(roleKeyword) > -1;
8700
- return keywordExists;
8698
+ roleHasKeyword(keyword, roleWords) {
8699
+ return roleWords.includes(keyword);
8701
8700
  }
8702
8701
  getAMRoleName(accessType, aMRole) {
8703
8702
  let roleName = '';
@@ -9127,10 +9126,10 @@ class CaseworkerService {
9127
9126
  this.appConfig = appConfig;
9128
9127
  this.errorService = errorService;
9129
9128
  }
9130
- getCaseworkers(serviceId) {
9131
- const url = `${this.appConfig.getWorkAllocationApiUrl()}/caseworker/getUsersByServiceName`;
9129
+ getUserByIdamId(idamId) {
9130
+ const url = `${this.appConfig.getWorkAllocationApiUrl()}/caseworker/getUserByIdamId`;
9132
9131
  return this.http
9133
- .post(url, { services: [serviceId] })
9132
+ .post(url, idamId)
9134
9133
  .pipe(catchError(error => {
9135
9134
  this.errorService.setError(error);
9136
9135
  return throwError(error);
@@ -10582,17 +10581,16 @@ class CasesService {
10582
10581
  }
10583
10582
  createChallengedAccessRequest(caseId, request) {
10584
10583
  // Assignment API endpoint
10585
- const userInfoStr = this.sessionStorageService.getItem('userDetails');
10586
10584
  const camUtils = new CaseAccessUtils();
10587
- let userInfo;
10588
- userInfo = userInfoStr ? JSON.parse(userInfoStr) : null;
10585
+ let userInfo = getUserDetails(this.sessionStorageService);
10589
10586
  if (!userInfo) {
10590
10587
  return throwError(() => new Error('User info not found in session storage'));
10591
10588
  }
10592
10589
  // EXUI-4758 - getMappedRoleCategories no longer returns a single string, checks all roles to get the most likely roleCategory
10593
10590
  // Unsure whether we should be using mapped role categories any more - should trust the roleCategories from userInfo if they exist
10594
10591
  const roleCategories = userInfo.roleCategories || camUtils.getMappedRoleCategories(userInfo.roles);
10595
- const roleName = camUtils.getAMRoleName('challenged', roleCategories[0]);
10592
+ // If user has no role categories, default to LEGAL_OPERATIONS
10593
+ const roleName = camUtils.getAMRoleName('challenged', roleCategories?.length > 0 ? roleCategories[0] : "LEGAL_OPERATIONS");
10596
10594
  const beginTime = new Date();
10597
10595
  const endTime = new Date(new Date().setUTCHours(23, 59, 59, 999));
10598
10596
  const id = userInfo.id ? userInfo.id : userInfo.uid;
@@ -10603,18 +10601,15 @@ class CasesService {
10603
10601
  return this.http.post(`/api/challenged-access-request`, payload);
10604
10602
  }
10605
10603
  createSpecificAccessRequest(caseId, sar) {
10606
- // Assignment API endpoint
10607
- const userInfoStr = this.sessionStorageService.getItem('userDetails');
10608
10604
  const camUtils = new CaseAccessUtils();
10609
- let userInfo;
10610
- userInfo = userInfoStr ? JSON.parse(userInfoStr) : null;
10605
+ let userInfo = getUserDetails(this.sessionStorageService);
10611
10606
  if (!userInfo) {
10612
10607
  return throwError(() => new Error('User info not found in session storage'));
10613
10608
  }
10614
10609
  // EXUI-4758 - See above comment
10615
10610
  const roleCategories = userInfo.roleCategories || camUtils.getMappedRoleCategories(userInfo.roles);
10616
- // EXUI-4758 - Return first roleCategory as the roleCategory for now
10617
- const roleCategory = roleCategories[0];
10611
+ // EXUI-4758 - Return first roleCategory as the roleCategory for now, unless not present, in which case default to LEGAL_OPERATIONS
10612
+ const roleCategory = roleCategories?.length > 0 ? roleCategories[0] : "LEGAL_OPERATIONS";
10618
10613
  const roleName = camUtils.getAMRoleName('specific', roleCategory);
10619
10614
  const id = userInfo.id ? userInfo.id : userInfo.uid;
10620
10615
  const payload = camUtils.getAMPayload(null, id, roleName, roleCategory, 'SPECIFIC', caseId, sar, null, null, true);
@@ -12709,12 +12704,9 @@ class CaseEventCompletionTaskReassignedComponent {
12709
12704
  this.jurisdiction = task.jurisdiction;
12710
12705
  this.caseType = task.case_type_id;
12711
12706
  // Current user is a caseworker?
12712
- this.caseworkerSubscription = this.caseworkerService.getCaseworkers(task.jurisdiction).subscribe(result => {
12713
- if (result && result[0].service === task.jurisdiction && result[0].caseworkers) {
12714
- const caseworker = result[0].caseworkers.find(x => x.idamId === task.assignee);
12715
- if (caseworker) {
12716
- this.assignedUserName = `${caseworker.firstName} ${caseworker.lastName}`;
12717
- }
12707
+ this.caseworkerSubscription = this.caseworkerService.getUserByIdamId(task.assignee).subscribe(caseworker => {
12708
+ if (caseworker) {
12709
+ this.assignedUserName = `${caseworker.firstName} ${caseworker.lastName}`;
12718
12710
  }
12719
12711
  if (!this.assignedUserName) {
12720
12712
  // Current user is a judicial user?
@@ -37838,12 +37830,9 @@ class TaskAssignedComponent {
37838
37830
  // Current user is a caseworker?
37839
37831
  this.jurisdiction = this.task.jurisdiction;
37840
37832
  this.caseType = this.task.case_type_id;
37841
- this.caseworkerSubscription = this.caseworkerService.getCaseworkers(this.task.jurisdiction).subscribe(result => {
37842
- if (result && result[0].service === this.task.jurisdiction && result[0].caseworkers) {
37843
- const caseworker = result[0].caseworkers.find(x => x.idamId === this.task.assignee);
37844
- if (caseworker) {
37845
- this.assignedUserName = `${caseworker.firstName} ${caseworker.lastName}`;
37846
- }
37833
+ this.caseworkerSubscription = this.caseworkerService.getUserByIdamId(this.task.assignee).subscribe(caseworker => {
37834
+ if (caseworker) {
37835
+ this.assignedUserName = `${caseworker.firstName} ${caseworker.lastName}`;
37847
37836
  }
37848
37837
  if (!this.assignedUserName) {
37849
37838
  // Current user is a judicial user?