Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve readability #1658

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading