Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* DST-17829
UMT: Export Users: Story asks for column 'Role Description' (eg Manage AP Referrals) but shows 'Role Names' (eg CABT010)

* Fixing test
  • Loading branch information
paulmiller-bcl authored Sep 5, 2024
1 parent d82e9da commit e87820e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ public final class ExportResult {
@CsvBindByPosition(position = 16)
private String provider;
@CsvBindByPosition(position = 17)
private String roleNames;
private String roleDescriptions;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public interface UserRoleService
{
Set<RoleEntry> getRolesICanAssign();
Set<RoleEntry> getUserRoles(String username);
Set<String> getUserRoleNames(String username);
List<String> getAllUsersWithRole(String role);
Set<RoleEntry> getClientRoles(String clientId);
Set<String> getUserInteractions(String username);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,6 @@ public Set<RoleEntry> getUserRoles(String username) {
return getAssignedRoles(username, usersBase);
}

@Override
public Set<String> getUserRoleNames(String username) {
return stream(getAssignedRoleAssociations(username, usersBase).spliterator(), false)
.map(RoleAssociationEntry::getCn)
.collect(toSet());
}

@Override
public Set<RoleEntry> getClientRoles(String clientId) {
return getAssignedRoles(clientId, clientsBase);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -151,7 +152,14 @@ public Optional<User> 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())))
Expand Down Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down

0 comments on commit e87820e

Please sign in to comment.