Skip to content

Commit

Permalink
fix: set current tenant id to new admin
Browse files Browse the repository at this point in the history
  • Loading branch information
idriss.naji committed Nov 29, 2022
1 parent 7388b71 commit a6a8be1
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@
import de.caritas.cob.userservice.api.model.Admin;
import de.caritas.cob.userservice.api.port.out.AdminRepository;
import de.caritas.cob.userservice.api.port.out.IdentityClient;
import de.caritas.cob.userservice.api.tenant.TenantContext;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class CreateAdminService {

@Value("${multitenancy.enabled}")
private boolean multiTenancyEnabled;

private final @NonNull IdentityClient identityClient;
private final @NonNull UserAccountInputValidator userAccountInputValidator;
private final @NonNull UserHelper userHelper;
Expand All @@ -31,6 +36,7 @@ public Admin createNewAdminAgency(final CreateAgencyAdminDTO createAgencyAdminDT
identityClient.updatePassword(keycloakUserId, password);
identityClient.updateRole(keycloakUserId, UserRole.RESTRICTED_AGENCY_ADMIN);
identityClient.updateRole(keycloakUserId, UserRole.USER_ADMIN);
assignCurrentTenantContext(createAgencyAdminDTO);

return adminRepository.save(buildAdmin(createAgencyAdminDTO, keycloakUserId));
}
Expand Down Expand Up @@ -74,4 +80,10 @@ private Admin buildAdmin(
.updateDate(nowInUtc())
.build();
}

private void assignCurrentTenantContext(CreateAgencyAdminDTO createAgencyAdminDTO) {
if (multiTenancyEnabled) {
createAgencyAdminDTO.setTenantId(TenantContext.getCurrentTenant().intValue());
}
}
}

0 comments on commit a6a8be1

Please sign in to comment.