@hmcts/ccd-case-ui-toolkit 7.3.74-user-by-idam-rework → 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.
@@ -1856,13 +1856,13 @@ function getUserDetails(sessionStorageService) {
1856
1856
  }
1857
1857
  function isInternalUser(sessionStorageService) {
1858
1858
  const userDetails = getUserDetails(sessionStorageService);
1859
- return !!userDetails?.roles
1859
+ return userDetails && 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?.roles
1865
+ return userDetails && userDetails?.roles
1866
1866
  && (userDetails.roles.some((role) => role.toLowerCase().includes(JUDGE)));
1867
1867
  }
1868
1868
 
@@ -8671,32 +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.roleHasKeyword(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.roleHasKeyword(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.roleHasKeyword(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.roleHasKeyword(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.roleHasKeyword(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.roleHasKeyword(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
- roleHasKeyword(keyword, roleWords) {
8699
- return roleWords.includes(keyword);
8695
+ roleOrCategoryExists(roleKeyword, roleCategory, roleKeywords, roleCategories) {
8696
+ const categoryExists = roleCategories.indexOf(roleCategory) > -1;
8697
+ const keywordExists = roleKeywords.indexOf(roleKeyword) > -1;
8698
+ return categoryExists ? categoryExists : keywordExists;
8700
8699
  }
8701
8700
  getAMRoleName(accessType, aMRole) {
8702
8701
  let roleName = '';
@@ -9126,10 +9125,10 @@ class CaseworkerService {
9126
9125
  this.appConfig = appConfig;
9127
9126
  this.errorService = errorService;
9128
9127
  }
9129
- getUserByIdamId(idamId) {
9130
- const url = `${this.appConfig.getWorkAllocationApiUrl()}/caseworker/getUserByIdamId`;
9128
+ getCaseworkers(serviceId) {
9129
+ const url = `${this.appConfig.getWorkAllocationApiUrl()}/caseworker/getUsersByServiceName`;
9131
9130
  return this.http
9132
- .post(url, idamId)
9131
+ .post(url, { services: [serviceId] })
9133
9132
  .pipe(catchError(error => {
9134
9133
  this.errorService.setError(error);
9135
9134
  return throwError(error);
@@ -10581,35 +10580,30 @@ class CasesService {
10581
10580
  }
10582
10581
  createChallengedAccessRequest(caseId, request) {
10583
10582
  // Assignment API endpoint
10583
+ const userInfoStr = this.sessionStorageService.getItem('userDetails');
10584
10584
  const camUtils = new CaseAccessUtils();
10585
- let userInfo = getUserDetails(this.sessionStorageService);
10586
- if (!userInfo) {
10587
- return throwError(() => new Error('User info not found in session storage'));
10588
- }
10589
- // EXUI-4758 - getMappedRoleCategories no longer returns a single string, checks all roles to get the most likely roleCategory
10590
- // Unsure whether we should be using mapped role categories any more - should trust the roleCategories from userInfo if they exist
10591
- const roleCategories = userInfo.roleCategories || camUtils.getMappedRoleCategories(userInfo.roles);
10592
- // If user has no role categories, default to LEGAL_OPERATIONS
10593
- const roleName = camUtils.getAMRoleName('challenged', roleCategories?.length > 0 ? roleCategories[0] : "LEGAL_OPERATIONS");
10585
+ let userInfo;
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);
10594
10591
  const beginTime = new Date();
10595
10592
  const endTime = new Date(new Date().setUTCHours(23, 59, 59, 999));
10596
10593
  const id = userInfo.id ? userInfo.id : userInfo.uid;
10597
10594
  const isNew = true;
10598
- const payload = camUtils.getAMPayload(id, id, roleName,
10599
- // EXUI-4758 - Return first roleCategory as the roleCategory
10600
- roleCategories[0], 'CHALLENGED', caseId, request, beginTime, endTime, isNew);
10595
+ const payload = camUtils.getAMPayload(id, id, roleName, roleCategory, 'CHALLENGED', caseId, request, beginTime, endTime, isNew);
10601
10596
  return this.http.post(`/api/challenged-access-request`, payload);
10602
10597
  }
10603
10598
  createSpecificAccessRequest(caseId, sar) {
10599
+ // Assignment API endpoint
10600
+ const userInfoStr = this.sessionStorageService.getItem('userDetails');
10604
10601
  const camUtils = new CaseAccessUtils();
10605
- let userInfo = getUserDetails(this.sessionStorageService);
10606
- if (!userInfo) {
10607
- return throwError(() => new Error('User info not found in session storage'));
10608
- }
10609
- // EXUI-4758 - See above comment
10610
- const roleCategories = userInfo.roleCategories || camUtils.getMappedRoleCategories(userInfo.roles);
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";
10602
+ let userInfo;
10603
+ if (userInfoStr) {
10604
+ userInfo = JSON.parse(userInfoStr);
10605
+ }
10606
+ const roleCategory = userInfo.roleCategory || camUtils.getMappedRoleCategory(userInfo.roles, userInfo.roleCategories);
10613
10607
  const roleName = camUtils.getAMRoleName('specific', roleCategory);
10614
10608
  const id = userInfo.id ? userInfo.id : userInfo.uid;
10615
10609
  const payload = camUtils.getAMPayload(null, id, roleName, roleCategory, 'SPECIFIC', caseId, sar, null, null, true);
@@ -12704,9 +12698,12 @@ class CaseEventCompletionTaskReassignedComponent {
12704
12698
  this.jurisdiction = task.jurisdiction;
12705
12699
  this.caseType = task.case_type_id;
12706
12700
  // Current user is a caseworker?
12707
- this.caseworkerSubscription = this.caseworkerService.getUserByIdamId(task.assignee).subscribe(caseworker => {
12708
- if (caseworker) {
12709
- this.assignedUserName = `${caseworker.firstName} ${caseworker.lastName}`;
12701
+ this.caseworkerSubscription = this.caseworkerService.getCaseworkers(task.jurisdiction).subscribe(result => {
12702
+ if (result && result[0].service === task.jurisdiction && result[0].caseworkers) {
12703
+ const caseworker = result[0].caseworkers.find(x => x.idamId === task.assignee);
12704
+ if (caseworker) {
12705
+ this.assignedUserName = `${caseworker.firstName} ${caseworker.lastName}`;
12706
+ }
12710
12707
  }
12711
12708
  if (!this.assignedUserName) {
12712
12709
  // Current user is a judicial user?
@@ -37830,9 +37827,12 @@ class TaskAssignedComponent {
37830
37827
  // Current user is a caseworker?
37831
37828
  this.jurisdiction = this.task.jurisdiction;
37832
37829
  this.caseType = this.task.case_type_id;
37833
- this.caseworkerSubscription = this.caseworkerService.getUserByIdamId(this.task.assignee).subscribe(caseworker => {
37834
- if (caseworker) {
37835
- this.assignedUserName = `${caseworker.firstName} ${caseworker.lastName}`;
37830
+ this.caseworkerSubscription = this.caseworkerService.getCaseworkers(this.task.jurisdiction).subscribe(result => {
37831
+ if (result && result[0].service === this.task.jurisdiction && result[0].caseworkers) {
37832
+ const caseworker = result[0].caseworkers.find(x => x.idamId === this.task.assignee);
37833
+ if (caseworker) {
37834
+ this.assignedUserName = `${caseworker.firstName} ${caseworker.lastName}`;
37835
+ }
37836
37836
  }
37837
37837
  if (!this.assignedUserName) {
37838
37838
  // Current user is a judicial user?