Skip to content

Commit

Permalink
set a default firstName and lastName for org admin user
Browse files Browse the repository at this point in the history
  • Loading branch information
xgp committed Feb 13, 2025
1 parent df97653 commit ec4938a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static io.phasetwo.service.resource.OrganizationAdminAuth.ROLE_VIEW_ORGANIZATION;

import com.google.auto.service.AutoService;
import com.google.common.base.Strings;
import io.phasetwo.service.model.OrganizationModel;
import io.phasetwo.service.model.OrganizationProvider;
import io.phasetwo.service.model.OrganizationRoleModel;
Expand Down Expand Up @@ -200,9 +201,10 @@ private void organizationCreation(OrganizationModel.OrganizationCreationEvent ev
.addUser(
event.getRealm(), KeycloakModelUtils.generateId(), adminUsername, true, false);
user.setEnabled(true);
// other defaults? email? emailVerified? attributes?
user.setEmail(String.format("%s@noreply.phasetwo.io", adminUsername)); // todo dynamic email?
user.setEmailVerified(true);
user.setFirstName(getDisplayName(org));
user.setLastName("Org Admin User");
org.grantMembership(user);
for (String role : DEFAULT_ORG_ROLES) {
OrganizationRoleModel roleModel = org.getRoleByName(role);
Expand All @@ -211,6 +213,10 @@ private void organizationCreation(OrganizationModel.OrganizationCreationEvent ev
}
}

private static String getDisplayName(OrganizationModel org) {
return Strings.isNullOrEmpty(org.getDisplayName()) ? org.getName() : org.getDisplayName();
}

private void organizationRemoved(OrganizationModel.OrganizationRemovedEvent event) {
// TODO anything else to do? does cascade take care of it?

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/io/phasetwo/service/LegacySimpleHttp.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ private HttpRequestBase createHttpRequest() {
case "PATCH":
return new HttpPatch(appendParameterToUrl(url));
case "POST":
// explicit fall through as we want POST to be the default HTTP method
// explicit fall through as we want POST to be the default HTTP method
default:
return new HttpPost(url);
}
Expand Down

0 comments on commit ec4938a

Please sign in to comment.