@hmcts/ccd-case-ui-toolkit 7.3.74-user-by-idam-rework → 7.3.75-case-search

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
 
@@ -8123,6 +8123,9 @@ class RequestOptionsBuilder {
8123
8123
  * @param value The value to be assessed.
8124
8124
  */
8125
8125
  static includeParam(value) {
8126
+ if (Array.isArray(value)) {
8127
+ return value.some(item => RequestOptionsBuilder.includeParam(item));
8128
+ }
8126
8129
  /* istanbul ignore else */
8127
8130
  if (value) {
8128
8131
  /* istanbul ignore else */
@@ -8133,6 +8136,36 @@ class RequestOptionsBuilder {
8133
8136
  }
8134
8137
  return false;
8135
8138
  }
8139
+ static sanitiseValue(value) {
8140
+ const trimmedValue = value.trim ? value.trim() : value;
8141
+ return trimmedValue.replace ? trimmedValue.replace(/’/i, `'`) : trimmedValue;
8142
+ }
8143
+ static getValueByPath(value, path) {
8144
+ return path.split('.').reduce((currentValue, pathPart) => {
8145
+ if (currentValue === undefined || currentValue === null) {
8146
+ return undefined;
8147
+ }
8148
+ return currentValue[pathPart];
8149
+ }, value);
8150
+ }
8151
+ static getCollectionValues(value, criterion) {
8152
+ if (!Array.isArray(value) ||
8153
+ !criterion.includes('.value.') ||
8154
+ value.some(item => item === null || typeof item !== 'object' || !Object.hasOwn(item, 'value'))) {
8155
+ return value;
8156
+ }
8157
+ const valuePath = criterion.substring(criterion.indexOf('.value.') + 1);
8158
+ return value.map(item => RequestOptionsBuilder.getValueByPath(item, valuePath));
8159
+ }
8160
+ static appendParam(params, key, value) {
8161
+ if (Array.isArray(value)) {
8162
+ const values = value
8163
+ .filter(item => RequestOptionsBuilder.includeParam(item))
8164
+ .map(item => RequestOptionsBuilder.sanitiseValue(item));
8165
+ return params.set(key, `[${values.join(', ')}]`);
8166
+ }
8167
+ return params.set(key, RequestOptionsBuilder.sanitiseValue(value));
8168
+ }
8136
8169
  buildOptions(metaCriteria, caseCriteria, view) {
8137
8170
  // TODO: This should probably be the now built-in URLSearchParams but it
8138
8171
  // requires a bigger refactor and there are bigger fish to fry right now.
@@ -8157,8 +8190,7 @@ class RequestOptionsBuilder {
8157
8190
  /* istanbul ignore else */
8158
8191
  if (RequestOptionsBuilder.includeParam(caseCriteria[criterion])) {
8159
8192
  const key = RequestOptionsBuilder.FIELD_PREFIX + criterion;
8160
- const value = caseCriteria[criterion].trim ? caseCriteria[criterion].trim() : caseCriteria[criterion];
8161
- params = params.set(key, value.replace(/’/i, `'`));
8193
+ params = RequestOptionsBuilder.appendParam(params, key, RequestOptionsBuilder.getCollectionValues(caseCriteria[criterion], criterion));
8162
8194
  }
8163
8195
  }
8164
8196
  }
@@ -8671,32 +8703,31 @@ class CaseAccessUtils {
8671
8703
  static CTSC_ROLE = 'ctsc';
8672
8704
  static CTSC_ROLE_CATEGORY = 'CTSC';
8673
8705
  static CTSC_ROLE_NAME = 'ctsc';
8674
- // fallback purely if roleCategories is not available in
8675
- getMappedRoleCategories(roles = []) {
8706
+ getMappedRoleCategory(roles = [], roleCategories = []) {
8676
8707
  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);
8708
+ if (this.roleOrCategoryExists(CaseAccessUtils.JUDGE_ROLE, CaseAccessUtils.JUDGE_ROLE_CATEGORY, roleKeywords, roleCategories)) {
8709
+ return CaseAccessUtils.JUDGE_ROLE_CATEGORY;
8680
8710
  }
8681
- if (this.roleHasKeyword(CaseAccessUtils.PROFESSIONAL_ROLE, roleKeywords)) {
8682
- roleCategoryList.push(CaseAccessUtils.PROFESSIONAL_ROLE_CATEGORY);
8711
+ else if (this.roleOrCategoryExists(CaseAccessUtils.PROFESSIONAL_ROLE, CaseAccessUtils.PROFESSIONAL_ROLE_CATEGORY, roleKeywords, roleCategories)) {
8712
+ return CaseAccessUtils.PROFESSIONAL_ROLE_CATEGORY;
8683
8713
  }
8684
- if (this.roleHasKeyword(CaseAccessUtils.CITIZEN_ROLE, roleKeywords)) {
8685
- roleCategoryList.push(CaseAccessUtils.CITIZEN_ROLE_CATEGORY);
8714
+ else if (this.roleOrCategoryExists(CaseAccessUtils.CITIZEN_ROLE, CaseAccessUtils.CITIZEN_ROLE_CATEGORY, roleKeywords, roleCategories)) {
8715
+ return CaseAccessUtils.CITIZEN_ROLE_CATEGORY;
8686
8716
  }
8687
- if (this.roleHasKeyword(CaseAccessUtils.ADMIN_ROLE, roleKeywords)) {
8688
- roleCategoryList.push(CaseAccessUtils.ADMIN_ROLE_CATEGORY);
8717
+ else if (this.roleOrCategoryExists(CaseAccessUtils.ADMIN_ROLE, CaseAccessUtils.ADMIN_ROLE_CATEGORY, roleKeywords, roleCategories)) {
8718
+ return CaseAccessUtils.ADMIN_ROLE_CATEGORY;
8689
8719
  }
8690
- if (this.roleHasKeyword(CaseAccessUtils.CTSC_ROLE, roleKeywords)) {
8691
- roleCategoryList.push(CaseAccessUtils.CTSC_ROLE_CATEGORY);
8720
+ else if (this.roleOrCategoryExists(CaseAccessUtils.CTSC_ROLE, CaseAccessUtils.CTSC_ROLE_CATEGORY, roleKeywords, roleCategories)) {
8721
+ return CaseAccessUtils.CTSC_ROLE_CATEGORY;
8692
8722
  }
8693
- if (this.roleHasKeyword(CaseAccessUtils.LEGAL_OPERATIONS_ROLE, roleKeywords)) {
8694
- roleCategoryList.push(CaseAccessUtils.LEGAL_OPERATIONS_ROLE_CATEGORY);
8723
+ else {
8724
+ return CaseAccessUtils.LEGAL_OPERATIONS_ROLE_CATEGORY;
8695
8725
  }
8696
- return roleCategoryList;
8697
8726
  }
8698
- roleHasKeyword(keyword, roleWords) {
8699
- return roleWords.includes(keyword);
8727
+ roleOrCategoryExists(roleKeyword, roleCategory, roleKeywords, roleCategories) {
8728
+ const categoryExists = roleCategories.indexOf(roleCategory) > -1;
8729
+ const keywordExists = roleKeywords.indexOf(roleKeyword) > -1;
8730
+ return categoryExists ? categoryExists : keywordExists;
8700
8731
  }
8701
8732
  getAMRoleName(accessType, aMRole) {
8702
8733
  let roleName = '';
@@ -9126,10 +9157,10 @@ class CaseworkerService {
9126
9157
  this.appConfig = appConfig;
9127
9158
  this.errorService = errorService;
9128
9159
  }
9129
- getUserByIdamId(idamId) {
9130
- const url = `${this.appConfig.getWorkAllocationApiUrl()}/caseworker/getUserByIdamId`;
9160
+ getCaseworkers(serviceId) {
9161
+ const url = `${this.appConfig.getWorkAllocationApiUrl()}/caseworker/getUsersByServiceName`;
9131
9162
  return this.http
9132
- .post(url, idamId)
9163
+ .post(url, { services: [serviceId] })
9133
9164
  .pipe(catchError(error => {
9134
9165
  this.errorService.setError(error);
9135
9166
  return throwError(error);
@@ -10581,35 +10612,30 @@ class CasesService {
10581
10612
  }
10582
10613
  createChallengedAccessRequest(caseId, request) {
10583
10614
  // Assignment API endpoint
10615
+ const userInfoStr = this.sessionStorageService.getItem('userDetails');
10584
10616
  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");
10617
+ let userInfo;
10618
+ if (userInfoStr) {
10619
+ userInfo = JSON.parse(userInfoStr);
10620
+ }
10621
+ const roleCategory = userInfo.roleCategory || camUtils.getMappedRoleCategory(userInfo.roles, userInfo.roleCategories);
10622
+ const roleName = camUtils.getAMRoleName('challenged', roleCategory);
10594
10623
  const beginTime = new Date();
10595
10624
  const endTime = new Date(new Date().setUTCHours(23, 59, 59, 999));
10596
10625
  const id = userInfo.id ? userInfo.id : userInfo.uid;
10597
10626
  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);
10627
+ const payload = camUtils.getAMPayload(id, id, roleName, roleCategory, 'CHALLENGED', caseId, request, beginTime, endTime, isNew);
10601
10628
  return this.http.post(`/api/challenged-access-request`, payload);
10602
10629
  }
10603
10630
  createSpecificAccessRequest(caseId, sar) {
10631
+ // Assignment API endpoint
10632
+ const userInfoStr = this.sessionStorageService.getItem('userDetails');
10604
10633
  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";
10634
+ let userInfo;
10635
+ if (userInfoStr) {
10636
+ userInfo = JSON.parse(userInfoStr);
10637
+ }
10638
+ const roleCategory = userInfo.roleCategory || camUtils.getMappedRoleCategory(userInfo.roles, userInfo.roleCategories);
10613
10639
  const roleName = camUtils.getAMRoleName('specific', roleCategory);
10614
10640
  const id = userInfo.id ? userInfo.id : userInfo.uid;
10615
10641
  const payload = camUtils.getAMPayload(null, id, roleName, roleCategory, 'SPECIFIC', caseId, sar, null, null, true);
@@ -12704,9 +12730,12 @@ class CaseEventCompletionTaskReassignedComponent {
12704
12730
  this.jurisdiction = task.jurisdiction;
12705
12731
  this.caseType = task.case_type_id;
12706
12732
  // 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}`;
12733
+ this.caseworkerSubscription = this.caseworkerService.getCaseworkers(task.jurisdiction).subscribe(result => {
12734
+ if (result && result[0].service === task.jurisdiction && result[0].caseworkers) {
12735
+ const caseworker = result[0].caseworkers.find(x => x.idamId === task.assignee);
12736
+ if (caseworker) {
12737
+ this.assignedUserName = `${caseworker.firstName} ${caseworker.lastName}`;
12738
+ }
12710
12739
  }
12711
12740
  if (!this.assignedUserName) {
12712
12741
  // Current user is a judicial user?
@@ -37830,9 +37859,12 @@ class TaskAssignedComponent {
37830
37859
  // Current user is a caseworker?
37831
37860
  this.jurisdiction = this.task.jurisdiction;
37832
37861
  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}`;
37862
+ this.caseworkerSubscription = this.caseworkerService.getCaseworkers(this.task.jurisdiction).subscribe(result => {
37863
+ if (result && result[0].service === this.task.jurisdiction && result[0].caseworkers) {
37864
+ const caseworker = result[0].caseworkers.find(x => x.idamId === this.task.assignee);
37865
+ if (caseworker) {
37866
+ this.assignedUserName = `${caseworker.firstName} ${caseworker.lastName}`;
37867
+ }
37836
37868
  }
37837
37869
  if (!this.assignedUserName) {
37838
37870
  // Current user is a judicial user?