Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Unsearchable disabled users by their email or name - EXO-69348 - Meeds-io/meeds#1827 . #858

Merged
merged 1 commit into from Apr 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,54 +743,58 @@ 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 (isAllowNotCaseSensitiveSearch()) {
attrValue = attrValue.toLowerCase();

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);
}
/*
* 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);
}
}
}
Expand Down