From e87820e07d78252934ef1a74f4dc2f3908e19310 Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Thu, 5 Sep 2024 11:26:37 +0100 Subject: [PATCH] DST-17829 (#821) * DST-17829 UMT: Export Users: Story asks for column 'Role Description' (eg Manage AP Referrals) but shows 'Role Names' (eg CABT010) * Fixing test --- .../uk/co/bconline/ndelius/model/ExportResult.java | 2 +- .../co/bconline/ndelius/service/UserRoleService.java | 1 - .../ndelius/service/impl/UserRoleServiceImpl.java | 7 ------- .../ndelius/transformer/UserTransformer.java | 12 ++++++++++-- .../ndelius/controller/UserControllerExportTest.java | 6 +++--- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/uk/co/bconline/ndelius/model/ExportResult.java b/src/main/java/uk/co/bconline/ndelius/model/ExportResult.java index f8bdecc3..1718e5be 100644 --- a/src/main/java/uk/co/bconline/ndelius/model/ExportResult.java +++ b/src/main/java/uk/co/bconline/ndelius/model/ExportResult.java @@ -52,5 +52,5 @@ public final class ExportResult { @CsvBindByPosition(position = 16) private String provider; @CsvBindByPosition(position = 17) - private String roleNames; + private String roleDescriptions; } diff --git a/src/main/java/uk/co/bconline/ndelius/service/UserRoleService.java b/src/main/java/uk/co/bconline/ndelius/service/UserRoleService.java index 90841d5c..9fc125c8 100644 --- a/src/main/java/uk/co/bconline/ndelius/service/UserRoleService.java +++ b/src/main/java/uk/co/bconline/ndelius/service/UserRoleService.java @@ -9,7 +9,6 @@ public interface UserRoleService { Set getRolesICanAssign(); Set getUserRoles(String username); - Set getUserRoleNames(String username); List getAllUsersWithRole(String role); Set getClientRoles(String clientId); Set getUserInteractions(String username); diff --git a/src/main/java/uk/co/bconline/ndelius/service/impl/UserRoleServiceImpl.java b/src/main/java/uk/co/bconline/ndelius/service/impl/UserRoleServiceImpl.java index 93096050..88799176 100644 --- a/src/main/java/uk/co/bconline/ndelius/service/impl/UserRoleServiceImpl.java +++ b/src/main/java/uk/co/bconline/ndelius/service/impl/UserRoleServiceImpl.java @@ -90,13 +90,6 @@ public Set getUserRoles(String username) { return getAssignedRoles(username, usersBase); } - @Override - public Set getUserRoleNames(String username) { - return stream(getAssignedRoleAssociations(username, usersBase).spliterator(), false) - .map(RoleAssociationEntry::getCn) - .collect(toSet()); - } - @Override public Set getClientRoles(String clientId) { return getAssignedRoles(clientId, clientsBase); diff --git a/src/main/java/uk/co/bconline/ndelius/transformer/UserTransformer.java b/src/main/java/uk/co/bconline/ndelius/transformer/UserTransformer.java index 0e23e3e7..95fd776b 100644 --- a/src/main/java/uk/co/bconline/ndelius/transformer/UserTransformer.java +++ b/src/main/java/uk/co/bconline/ndelius/transformer/UserTransformer.java @@ -14,6 +14,7 @@ import uk.co.bconline.ndelius.model.entity.*; import uk.co.bconline.ndelius.model.entity.export.*; import uk.co.bconline.ndelius.model.entry.ClientEntry; +import uk.co.bconline.ndelius.model.entry.RoleEntry; import uk.co.bconline.ndelius.model.entry.UserEntry; import uk.co.bconline.ndelius.service.*; import uk.co.bconline.ndelius.util.LdapUtils; @@ -151,7 +152,14 @@ public Optional map(UserEntry user) public ExportResult combine(UserExportEntity db, UserEntry ldap) { if (ldap == null) return null; DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - val userRoles = ofNullable(ldap.getUsername()).map(userRoleService::getUserRoleNames).orElse(emptySet()); + val userRoles = ofNullable(ldap.getUsername()).map(userRoleService::getUserRoles).orElse(emptySet()); + String userRoleDescriptions = Optional.of(userRoles).map(l -> l.stream() + .map(RoleEntry::getDescription) + .distinct() + .sorted() + .collect(joining(","))) + .orElse(null); + return ExportResult.builder() .username(ofNullable(ldap.getUsername()).orElseGet(db::getUsername)) .forenames(ofNullable(ldap.getForenames()).orElseGet(() -> combineNames(db.getForename(), db.getForename2()))) @@ -185,7 +193,7 @@ public ExportResult combine(UserExportEntity db, UserEntry ldap) { .map(BoroughExportEntity::getProbationArea) .map(ProbationAreaExportEntity::getExportDescription) .filter(Objects::nonNull).distinct().sorted().collect(joining(","))).orElse(null)) - .roleNames(userRoles.stream().sorted().collect(joining(","))) + .roleDescriptions(userRoleDescriptions) .build(); } diff --git a/src/test/java/uk/co/bconline/ndelius/controller/UserControllerExportTest.java b/src/test/java/uk/co/bconline/ndelius/controller/UserControllerExportTest.java index 31df2632..87060b98 100644 --- a/src/test/java/uk/co/bconline/ndelius/controller/UserControllerExportTest.java +++ b/src/test/java/uk/co/bconline/ndelius/controller/UserControllerExportTest.java @@ -187,15 +187,15 @@ public void fullExportIsRestrictedToNationalAdmins() throws Exception { @Test public void dataIsDisplayedCorrectlyForFullExport() throws Exception { - String expectedHeader = "\"Username\",\"Forenames\",\"Surname\",\"Email\",\"Telephone Number\",\"Start Date\",\"End Date\",\"Last Accessed Delius\",\"Home Area\",\"Datasets\",\"Sector\",\"Staff Code\",\"Staff Grade\",\"Team\",\"LAU\",\"PDU\",\"Provider\",\"Role Names\""; + String expectedHeader = "\"Username\",\"Forenames\",\"Surname\",\"Email\",\"Telephone Number\",\"Start Date\",\"End Date\",\"Last Accessed Delius\",\"Home Area\",\"Datasets\",\"Sector\",\"Staff Code\",\"Staff Grade\",\"Team\",\"LAU\",\"PDU\",\"Provider\",\"Role Descriptions\""; String expectedStartDate = now().minusDays(10).format(ISO_LOCAL_DATE); String expectedLoginDate = now().format(ISO_LOCAL_DATE);// see data.sql String[] expectedUsers = { "\n\"Abdul.Austria\",\"Abdul\",\"Austria\",\"\",\"\",\"" + expectedStartDate + "\",\"\",\"\",\"N01\",\"\",\"Public\",\"N01A168\",\"GRADE1\",\"\",\"\",\"\",\"\",\"\"", "\n\"Leia.Leaman\",\"Leia\",\"Leaman\",\"\",\"\",\"" + expectedStartDate + "\",\"\",\"\",\"N01\",\"\",\"Public\",\"N01A086\",\"GRADE1\",\"\",\"\",\"\",\"\",\"\"", "\n\"Zina.Zenon\",\"Zina\",\"Zenon\",\"\",\"\",\"" + expectedStartDate + "\",\"\",\"\",\"N01\",\"\",\"Public\",\"N01A131\",\"GRADE1\",\"\",\"\",\"\",\"\",\"\"", - "\n\"test.user\",\"Test\",\"User\",\"test.user@test.com\",\"0123 456 789\",\"2000-01-02\",\"\",\"" + expectedLoginDate + " 00:00:00\",\"N01\",\"N01,N02,N03\",\"Public\",\"N01A001\",\"GRADE1\",\"Another (N03TST),Other team (N02TST),Test team (N01TST)\",\"Local Admin Unit A (LAU1),Local Admin Unit B (LAU2)\",\"Borough A (B1) [Inactive],Borough B (B2)\",\"NPS London (N01),NPS North East (N02)\",\"APBT001,APBT002,RDBT001,SPGADBT005,UABT0050,UMBT001,UMBT003\"", - "\n\"test.user.private\",\"Test\",\"User (Private)\",\"test.user.private@test.com\",\"\",\"\",\"\",\"" + expectedLoginDate + " 00:00:00\",\"C01\",\"C01,C02\",\"Public\",\"\",\"\",\"\",\"\",\"\",\"\",\"UABT0052,UMBT001\""}; + "\n\"test.user\",\"Test\",\"User\",\"test.user@test.com\",\"0123 456 789\",\"2000-01-02\",\"\",\"" + expectedLoginDate + " 00:00:00\",\"N01\",\"N01,N02,N03\",\"Public\",\"N01A001\",\"GRADE1\",\"Another (N03TST),Other team (N02TST),Test team (N01TST)\",\"Local Admin Unit A (LAU1),Local Admin Unit B (LAU2)\",\"Borough A (B1) [Inactive],Borough B (B2)\",\"NPS London (N01),NPS North East (N02)\",\"AP Vacancy Tracker API Admin,Local AP Admin,National AP Admin,National Public Reference Data Admin,National Reference Code List Maintenance,User Administrator\"", + "\n\"test.user.private\",\"Test\",\"User (Private)\",\"test.user.private@test.com\",\"\",\"\",\"\",\"" + expectedLoginDate + " 00:00:00\",\"C01\",\"C01,C02\",\"Public\",\"\",\"\",\"\",\"\",\"\",\"\",\"Private RBAC Admin,User Administrator\""}; MvcResult asyncResult = mvc.perform(get("/api/users/export/all") .header("Authorization", "Bearer " + token(mvc)))