Skip to content

Commit

Permalink
fix: Unsearchable disabled users by their email or name - EXO-69348 - M…
Browse files Browse the repository at this point in the history
…eeds-io/meeds#1827 .

Before this change, when set user as a disabled user, select disabled filter and search for usera by his name or his email, user isn't displayed in the result list. To fix this problem, first apply the search by email and then change in the search query the conditions apply in the WHERE line, they are based on the fields email and username must be both like the search term but with this change will be based on one of the two fields either being like this term and this change will only be applied if the search done by the keyword and the user status is disabled.
After this change, user is displayed in the result list.
  • Loading branch information
akhanfir committed Apr 19, 2024
1 parent 96d4e11 commit abe47f2
Showing 1 changed file with 98 additions and 44 deletions.
Expand Up @@ -661,17 +661,67 @@ public Collection<IdentityObject> findIdentityObject(IdentityStoreInvocationCont
}
/* END SOC-6210 */
/* BEGIN CAL-1225: User picker in Participants tab is case sensitive */
String enabledValue = null;
boolean isFiltredByEmail = false ;
if (criteria != null && criteria.getFilter() != null) {
String attrValue = criteria.getFilter().replace("\\*", "%").replace("*", "%");
String operator = "=";
if (attrValue.contains("%")) {
operator = "like";
}
if (criteria.getValues() != null && criteria.getValues().containsKey("enabled") &&
criteria.getValues().get("enabled").length != 0 && !criteria.getValues().containsKey("email")) {

enabledValue = criteria.getValues().get("enabled")[0];
}
if ("USER".equals(hibernateTypeName) && criteria.isFiltered() && "false".equals(enabledValue)) {
isFiltredByEmail = true;
criteria.getValues().put("email", new String[]{attrValue});
int i = criteria.getValues().size();
String mappedAttributeName = null;
try {
mappedAttributeName = resolveAttributeStoreMapping(hibernateType, "email");
} catch (IdentityException e) {
// Nothing
}
String attrTableJoinName = "attrs" + i;
String textValuesTableJoinName = "textValues" + i;
String attrParamName = "attr" + i;
String textValueParamName = "textValue" + i;

hqlBuilderSelect.append(" join io.attributes as " + attrTableJoinName);
hqlBuilderSelect.append(" join " + attrTableJoinName + ".textValues as " + textValuesTableJoinName);
/*
* BEGIN CAL-1225: User picker in Participants tab is case
* sensitive
*/

hqlBuilderConditions.append(" and (( ");
hqlBuilderConditions.append(attrTableJoinName + ".name = :" + attrParamName);
if (isAllowNotCaseSensitiveSearch()) {
hqlBuilderConditions.append(" and lower(" + textValuesTableJoinName + ") " + operator + " :"
+ textValueParamName + " ) or ( ");
} else {
hqlBuilderConditions.append(" and " + textValuesTableJoinName + " " + operator + " :" + textValueParamName + " ) or ( ");
}
/*
* END CAL-1225: User picker in Participants tab is case sensitive
*/

queryParams.put(attrParamName, mappedAttributeName);
queryParams.put(textValueParamName, attrValue);
} else {
hqlBuilderConditions.append(" and ");
}

if (isAllowNotCaseSensitiveSearch()) {
attrValue = attrValue.toLowerCase();
hqlBuilderConditions.append(" and lower(io.name) " + operator + " :ioName");
hqlBuilderConditions.append("(lower(io.name) " + operator + " :ioName)");
} else {
hqlBuilderConditions.append(" and io.name " + operator + " :ioName");
hqlBuilderConditions.append("(io.name " + operator + " :ioName)");
}
if (isFiltredByEmail) {
hqlBuilderConditions.append("))");
}
queryParams.put("ioName", attrValue);
}
Expand All @@ -693,59 +743,63 @@ public Collection<IdentityObject> findIdentityObject(IdentityStoreInvocationCont
String attrTableJoinName = "attrs" + i;
String attrParamName = "attr" + i;
hqlBuilderConditions.append(" and not exists(from io.attributes as " + attrTableJoinName + " where "
+ attrTableJoinName + ".name = :" + attrParamName + ")");
+ attrTableJoinName + ".name = :" + attrParamName+ ")");
queryParams.put(attrParamName, mappedAttributeName);
/** End eXo customization **/
} else {
Set<String> given = new HashSet<>(Arrays.asList(entry.getValue()));

for (String attrValue : given) {
attrValue = attrValue.replace("\\*", "%").replace("*", "%");

/*
* BEGIN CAL-1225: User picker in Participants tab is case
* sensitive
*/
String operator = "=";
if (attrValue.contains("%")) {
operator = "like";

if (!isFiltredByEmail || isFiltredByEmail && !"email".equals(entry.getKey())) {
attrValue = attrValue.replace("\\*", "%").replace("*", "%");

/*
* BEGIN CAL-1225: User picker in Participants tab is case
* sensitive
*/
String operator = "=";
if (attrValue.contains("%")) {
operator = "like";
}
if (isAllowNotCaseSensitiveSearch()) {
attrValue = attrValue.toLowerCase();
}
/*
* END CAL-1225: User picker in Participants tab is case sensitive
*/
i++;
String attrTableJoinName = "attrs" + i;
String textValuesTableJoinName = "textValues" + i;
String attrParamName = "attr" + i;
String textValueParamName = "textValue" + i;

hqlBuilderSelect.append(" join io.attributes as " + attrTableJoinName);
hqlBuilderSelect.append(" join " + attrTableJoinName + ".textValues as " + textValuesTableJoinName);
/*
* BEGIN CAL-1225: User picker in Participants tab is case
* sensitive
*/

hqlBuilderConditions.append(" and " +attrTableJoinName + ".name = :" + attrParamName);
if (isAllowNotCaseSensitiveSearch()) {
hqlBuilderConditions.append(" and lower(" + textValuesTableJoinName + ") " + operator + " :"
+ textValueParamName);
} else {
hqlBuilderConditions.append(" and " + textValuesTableJoinName + " " + operator + " :" + textValueParamName);
}
/*
* END CAL-1225: User picker in Participants tab is case sensitive
*/

queryParams.put(attrParamName, mappedAttributeName);
queryParams.put(textValueParamName, attrValue);
}
if (isAllowNotCaseSensitiveSearch()) {
attrValue = attrValue.toLowerCase();
}
/*
* END CAL-1225: User picker in Participants tab is case sensitive
*/
i++;
String attrTableJoinName = "attrs" + i;
String textValuesTableJoinName = "textValues" + i;
String attrParamName = "attr" + i;
String textValueParamName = "textValue" + i;

hqlBuilderSelect.append(" join io.attributes as " + attrTableJoinName);
hqlBuilderSelect.append(" join " + attrTableJoinName + ".textValues as " + textValuesTableJoinName);
/*
* BEGIN CAL-1225: User picker in Participants tab is case
* sensitive
*/
hqlBuilderConditions.append(" and " + attrTableJoinName + ".name = :" + attrParamName);
if (isAllowNotCaseSensitiveSearch()) {
hqlBuilderConditions.append(" and lower(" + textValuesTableJoinName + ") " + operator + " :"
+ textValueParamName);
} else {
hqlBuilderConditions.append(" and " + textValuesTableJoinName + " " + operator + " :" + textValueParamName);
}
/*
* END CAL-1225: User picker in Participants tab is case sensitive
*/

queryParams.put(attrParamName, mappedAttributeName);
queryParams.put(textValueParamName, attrValue);
}
}
}
}

if (criteria != null && criteria.isSorted()) {
if (criteria.isAscending()) {
hqlBuilderConditions.append(" order by io.name asc");
Expand Down

0 comments on commit abe47f2

Please sign in to comment.