Skip to content
Snippets Groups Projects
Commit 6aefcade authored by srosse's avatar srosse
Browse files

OO-1590: better check input of the javascript auto completer

parent 7f312f07
No related branches found
No related tags found
No related merge requests found
...@@ -26,7 +26,7 @@ import java.util.List; ...@@ -26,7 +26,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.olat.basesecurity.BaseSecurityManager; import org.olat.basesecurity.BaseSecurity;
import org.olat.basesecurity.BaseSecurityModule; import org.olat.basesecurity.BaseSecurityModule;
import org.olat.basesecurity.events.SingleIdentityChosenEvent; import org.olat.basesecurity.events.SingleIdentityChosenEvent;
import org.olat.core.gui.UserRequest; import org.olat.core.gui.UserRequest;
...@@ -112,6 +112,8 @@ public class UserSearchFlexiController extends FlexiAutoCompleterController { ...@@ -112,6 +112,8 @@ public class UserSearchFlexiController extends FlexiAutoCompleterController {
@Autowired @Autowired
private UserManager userManager; private UserManager userManager;
@Autowired @Autowired
private BaseSecurity securityManager;
@Autowired
private BaseSecurityModule securityModule; private BaseSecurityModule securityModule;
/** /**
...@@ -247,23 +249,21 @@ public class UserSearchFlexiController extends FlexiAutoCompleterController { ...@@ -247,23 +249,21 @@ public class UserSearchFlexiController extends FlexiAutoCompleterController {
@Override @Override
protected void doFireSelection(UserRequest ureq, List<String> res) { protected void doFireSelection(UserRequest ureq, List<String> res) {
// if we get the event, we have a result or an incorrect selection see OLAT-5114 -> check for empty
String mySel = res.isEmpty() ? null : res.get(0); String mySel = res.isEmpty() ? null : res.get(0);
if (( mySel == null) || mySel.trim().equals("")) { if(StringHelper.containsNonWhitespace(mySel) && StringHelper.isLong(mySel)) {
getWindowControl().setWarning(translate("error.search.form.notempty")); try {
return; Long key = Long.valueOf(mySel);
} if (key > 0) {
Long key = -1l; // default not found Identity chosenIdent = securityManager.loadIdentityByKey(key);
try { if(chosenIdent != null) {
key = Long.valueOf(mySel); fireEvent(ureq, new SingleIdentityChosenEvent(chosenIdent));
if (key > 0) { }
Identity chosenIdent = BaseSecurityManager.getInstance().loadIdentityByKey(key); }
// No need to check for null, exception is thrown when identity does not exist which really } catch (NumberFormatException e) {
// should not happen at all. Tell that an identity has been chosen getWindowControl().setWarning(translate("error.no.user.found"));
fireEvent(ureq, new SingleIdentityChosenEvent(chosenIdent));
} }
} catch (NumberFormatException e) { } else {
getWindowControl().setWarning(translate("error.no.user.found")); getWindowControl().setWarning(translate("error.search.form.notempty"));
} }
} }
...@@ -434,7 +434,7 @@ public class UserSearchFlexiController extends FlexiAutoCompleterController { ...@@ -434,7 +434,7 @@ public class UserSearchFlexiController extends FlexiAutoCompleterController {
* @return * @return
*/ */
private List<Identity> searchUsers(String login, Map<String, String> userPropertiesSearch, boolean userPropertiesAsIntersectionSearch) { private List<Identity> searchUsers(String login, Map<String, String> userPropertiesSearch, boolean userPropertiesAsIntersectionSearch) {
return BaseSecurityManager.getInstance().getVisibleIdentitiesByPowerSearch( return securityManager.getVisibleIdentitiesByPowerSearch(
(login.equals("") ? null : login), (login.equals("") ? null : login),
userPropertiesSearch, userPropertiesAsIntersectionSearch, // in normal search fields are intersected userPropertiesSearch, userPropertiesAsIntersectionSearch, // in normal search fields are intersected
null, null, null, null, null); null, null, null, null, null);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment