Improved user search in the relation rule node
This commit is contained in:
parent
d0179c4cd3
commit
18678cae49
@ -33,6 +33,8 @@ public interface UserService {
|
||||
|
||||
User findUserByEmail(TenantId tenantId, String email);
|
||||
|
||||
User findUserByTenantIdAndEmail(TenantId tenantId, String email);
|
||||
|
||||
User saveUser(User user);
|
||||
|
||||
UserCredentials findUserCredentialsByUserId(TenantId tenantId, UserId userId);
|
||||
|
||||
@ -60,6 +60,11 @@ public class JpaUserDao extends JpaAbstractSearchTextDao<UserEntity, User> imple
|
||||
return DaoUtil.getData(userRepository.findByEmail(email));
|
||||
}
|
||||
|
||||
@Override
|
||||
public User findByTenantIdAndEmail(TenantId tenantId, String email) {
|
||||
return DaoUtil.getData(userRepository.findByTenantIdAndEmail(tenantId.getId(), email));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageData<User> findByTenantId(UUID tenantId, PageLink pageLink) {
|
||||
return DaoUtil.toPageData(
|
||||
|
||||
@ -20,6 +20,7 @@ import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.security.Authority;
|
||||
import org.thingsboard.server.dao.model.sql.UserEntity;
|
||||
|
||||
@ -32,6 +33,8 @@ public interface UserRepository extends JpaRepository<UserEntity, UUID> {
|
||||
|
||||
UserEntity findByEmail(String email);
|
||||
|
||||
UserEntity findByTenantIdAndEmail(UUID tenantId, String email);
|
||||
|
||||
@Query("SELECT u FROM UserEntity u WHERE u.tenantId = :tenantId " +
|
||||
"AND u.customerId = :customerId AND u.authority = :authority " +
|
||||
"AND LOWER(u.searchText) LIKE LOWER(CONCAT('%', :searchText, '%'))")
|
||||
@ -48,4 +51,5 @@ public interface UserRepository extends JpaRepository<UserEntity, UUID> {
|
||||
Pageable pageable);
|
||||
|
||||
Long countByTenantId(UUID tenantId);
|
||||
|
||||
}
|
||||
|
||||
@ -42,6 +42,15 @@ public interface UserDao extends Dao<User>, TenantEntityDao {
|
||||
*/
|
||||
User findByEmail(TenantId tenantId, String email);
|
||||
|
||||
/**
|
||||
* Find user by tenant id and email.
|
||||
*
|
||||
* @param tenantId the tenant id
|
||||
* @param email the email
|
||||
* @return the user entity
|
||||
*/
|
||||
User findByTenantIdAndEmail(TenantId tenantId, String email);
|
||||
|
||||
/**
|
||||
* Find users by tenantId and page link.
|
||||
*
|
||||
@ -69,4 +78,5 @@ public interface UserDao extends Dao<User>, TenantEntityDao {
|
||||
* @return the list of user entities
|
||||
*/
|
||||
PageData<User> findCustomerUsers(UUID tenantId, UUID customerId, PageLink pageLink);
|
||||
|
||||
}
|
||||
|
||||
@ -87,6 +87,14 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public User findUserByTenantIdAndEmail(TenantId tenantId, String email) {
|
||||
log.trace("Executing findUserByTenantIdAndEmail [{}][{}]", tenantId, email);
|
||||
validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
|
||||
validateString(email, "Incorrect email " + email);
|
||||
return userDao.findByTenantIdAndEmail(tenantId, email);
|
||||
}
|
||||
|
||||
@Override
|
||||
public User findUserById(TenantId tenantId, UserId userId) {
|
||||
log.trace("Executing findUserById [{}]", userId);
|
||||
|
||||
@ -258,7 +258,7 @@ public abstract class TbAbstractRelationActionNode<C extends TbAbstractRelationA
|
||||
break;
|
||||
case USER:
|
||||
UserService userService = ctx.getUserService();
|
||||
User user = userService.findUserByEmail(ctx.getTenantId(), entitykey.getEntityName());
|
||||
User user = userService.findUserByTenantIdAndEmail(ctx.getTenantId(), entitykey.getEntityName());
|
||||
if (user != null) {
|
||||
targetEntity.setEntityId(user.getId());
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user