Skip to content

Commit

Permalink
chore: improve readability (#1658)
Browse files Browse the repository at this point in the history
  • Loading branch information
RMCampos authored Oct 3, 2024
1 parent e7c7f91 commit 7a85649
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ public final class Constants {
public static final String INCOMPLETE_SEEDLOT_STATUS = "INC";
public static final String PENDING_SEEDLOT_STATUS = "PND";
public static final String SUBMITTED_SEEDLOT_STATUS = "SUB";
public static final String MINITRY_OF_FORESTS_ID = "00012797";
public static final String MINISTRY_OF_FORESTS_ID = "00012797";
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,28 @@ public static Set<String> getUserRolesFromJwt(Jwt jwtPrincipal) {
*/
public static List<String> getClientIdsFromJwt(Jwt jwtPrincipal) {
List<String> clientIds = new ArrayList<>();
getRolesWithClientIds(jwtPrincipal)
.forEach(
role -> {
if (role.length() >= 9) {
String clientNumber = role.substring(role.length() - 8);
if (clientNumber.replaceAll("[0-9]", "").isEmpty()) {
clientIds.add(clientNumber);
}
}
// Handling concrete roles with no client id affixed
if (concreteRoles.contains(role)
&& !clientIds.contains(Constants.MINITRY_OF_FORESTS_ID)) {
clientIds.add(Constants.MINITRY_OF_FORESTS_ID);
}
});
boolean foundRole = false;

List<String> rolesAndClientIds = getRolesWithClientIds(jwtPrincipal);
for (String role : rolesAndClientIds) {
if (role.length() >= 9) {
String clientNumber = role.substring(role.length() - 8);
if (clientNumber.replaceAll("[0-9]", "").isEmpty()) {
clientIds.add(clientNumber);
}
}

if (concreteRoles.contains(role)) {
foundRole = true;
}
}

// If has role SPAR_MINISTRY_ORCHARD or SPAR_TSC_ADMIN and has no client id
// then add MOF client id
if (foundRole && !clientIds.contains(Constants.MINISTRY_OF_FORESTS_ID)) {
clientIds.add(Constants.MINISTRY_OF_FORESTS_ID);
}

return clientIds;
}

Expand Down

0 comments on commit 7a85649

Please sign in to comment.