Skip to content

Commit

Permalink
georchestra#174 georchestra#158 - change o or set user's rg if orgUni…
Browse files Browse the repository at this point in the history
…queId don't match
  • Loading branch information
Debian committed Feb 3, 2025
1 parent 2a36294 commit daee66c
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,13 @@ protected void createInternal(GeorchestraUser mapped) throws DuplicatedEmailFoun
}

try {
ensureOrgExists(newAccount);
String providerName = newAccount.getOAuth2Provider();
if (providerName.isEmpty() || providerName == null) {
ensureOrgExists(newAccount);
}
if (providerName.equals("proconnect")) {
ensureOrgUniqueIdExists(newAccount);
}
} catch (IllegalStateException orgError) {
log.error("Error when trying to create / update the organisation {}, reverting the account creation",
newAccount.getOrg(), orgError);
Expand Down Expand Up @@ -254,7 +260,11 @@ protected Optional<Org> findOrg(String orgId) {

private Optional<Org> findByOrgUniqueId(String orgUniqueId) {
try {
return Optional.of(orgsDao.findByOrgUniqueId(orgUniqueId));
Org existingOrg = orgsDao.findByOrgUniqueId(orgUniqueId);
if (existingOrg == null) {
return Optional.empty();
}
return Optional.of(orgsDao.findByCommonName(existingOrg.getId()));
} catch (NameNotFoundException e) {
return Optional.empty();
}
Expand Down

0 comments on commit daee66c

Please sign in to comment.