diff --git a/backend/core/src/main/java/org/opencdmp/service/user/UserServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/user/UserServiceImpl.java index c1ee1471e..548909b83 100644 --- a/backend/core/src/main/java/org/opencdmp/service/user/UserServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/user/UserServiceImpl.java @@ -1028,16 +1028,18 @@ public class UserServiceImpl implements UserService { UserCredentialEntity userCredential = this.queryFactory.query(UserCredentialQuery.class).disableTracking().userIds(userId).first(); if (userCredential == null) throw new MyApplicationException(); - TenantUserEntity tenantUserEntity = new TenantUserEntity(); - tenantUserEntity.setId(UUID.randomUUID()); - tenantUserEntity.setUserId(userId); - tenantUserEntity.setIsActive(IsActive.Active); - if (tenant != null) tenantUserEntity.setTenantId(tenant.getId()); - else tenantUserEntity.setTenantId(null); - tenantUserEntity.setCreatedAt(Instant.now()); - tenantUserEntity.setUpdatedAt(Instant.now()); - this.entityManager.persist(tenantUserEntity); - this.eventBroker.emit(new UserAddedToTenantEvent(tenantUserEntity.getUserId(), tenantUserEntity.getTenantId())); + if (tenant != null){ + TenantUserEntity tenantUserEntity = new TenantUserEntity(); + tenantUserEntity.setId(UUID.randomUUID()); + tenantUserEntity.setUserId(userId); + tenantUserEntity.setIsActive(IsActive.Active); + tenantUserEntity.setTenantId(tenant.getId()); + tenantUserEntity.setCreatedAt(Instant.now()); + tenantUserEntity.setUpdatedAt(Instant.now()); + this.entityManager.persist(tenantUserEntity); + this.eventBroker.emit(new UserAddedToTenantEvent(tenantUserEntity.getUserId(), tenantUserEntity.getTenantId())); + } + for (String role: userInviteToTenantRequest.getRoles()) { UserRoleEntity item = new UserRoleEntity();