Skip to content

Commit e62062f

Browse files
server: fix exception while list users with keyword (#7169)
1 parent 147ea06 commit e62062f

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

server/src/main/java/com/cloud/api/query/QueryManagerImpl.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
133133
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
134134
import org.apache.commons.collections.CollectionUtils;
135+
import org.apache.commons.lang3.EnumUtils;
135136
import org.apache.commons.lang3.StringUtils;
136137
import org.apache.log4j.Logger;
137138
import org.springframework.stereotype.Component;
@@ -531,7 +532,7 @@ public ListResponse<UserResponse> searchForUsers(Long domainId, boolean recursiv
531532
Object type = null;
532533
String accountName = null;
533534
Object state = null;
534-
Object keyword = null;
535+
String keyword = null;
535536

536537
Pair<List<UserAccountJoinVO>, Integer> result = getUserListInternal(caller, permittedAccounts, listAll, id, username, type, accountName, state, keyword, domainId, recursive,
537538
null);
@@ -560,7 +561,7 @@ private Pair<List<UserAccountJoinVO>, Integer> searchForUsersInternal(ListUsersC
560561
Object type = cmd.getAccountType();
561562
String accountName = cmd.getAccountName();
562563
Object state = cmd.getState();
563-
Object keyword = cmd.getKeyword();
564+
String keyword = cmd.getKeyword();
564565

565566
Long domainId = cmd.getDomainId();
566567
boolean recursive = cmd.isRecursive();
@@ -573,7 +574,7 @@ private Pair<List<UserAccountJoinVO>, Integer> searchForUsersInternal(ListUsersC
573574
}
574575

575576
private Pair<List<UserAccountJoinVO>, Integer> getUserListInternal(Account caller, List<Long> permittedAccounts, boolean listAll, Long id, Object username, Object type,
576-
String accountName, Object state, Object keyword, Long domainId, boolean recursive, Filter searchFilter) {
577+
String accountName, Object state, String keyword, Long domainId, boolean recursive, Filter searchFilter) {
577578
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(domainId, recursive, null);
578579
_accountMgr.buildACLSearchParameters(caller, id, accountName, null, permittedAccounts, domainIdRecursiveListProject, listAll, false);
579580
domainId = domainIdRecursiveListProject.first();
@@ -617,7 +618,9 @@ private Pair<List<UserAccountJoinVO>, Integer> getUserListInternal(Account calle
617618
ssc.addOr("email", Op.LIKE, "%" + keyword + "%");
618619
ssc.addOr("state", Op.LIKE, "%" + keyword + "%");
619620
ssc.addOr("accountName", Op.LIKE, "%" + keyword + "%");
620-
ssc.addOr("accountType", Op.LIKE, "%" + keyword + "%");
621+
if (EnumUtils.isValidEnum(Account.Type.class, keyword.toUpperCase())) {
622+
ssc.addOr("accountType", Op.EQ, EnumUtils.getEnum(Account.Type.class, keyword.toUpperCase()));
623+
}
621624

622625
sc.addAnd("username", Op.SC, ssc);
623626
}

0 commit comments

Comments
 (0)