|
42 | 42 | use OCA\User_LDAP\User\Manager; |
43 | 43 | use OCA\User_LDAP\Mapping\AbstractMapping; |
44 | 44 | use OCA\User_LDAP\Attributes\ConverterHub; |
| 45 | +use OCA\User_LDAP\Attributes\ConverterException; |
45 | 46 | use OCP\Util; |
46 | 47 |
|
47 | 48 | /** |
@@ -1549,12 +1550,21 @@ private function getAdvancedFilterPartForSearch($search, $searchAttributes) { |
1549 | 1550 | } |
1550 | 1551 | $searchWords = \explode(' ', \trim($search)); |
1551 | 1552 | $wordFilters = []; |
| 1553 | + $converterHub = ConverterHub::getDefaultConverterHub(); |
1552 | 1554 | foreach ($searchWords as $word) { |
1553 | | - $word = $this->prepareSearchTerm($word); |
| 1555 | + $preparedWord = $this->prepareSearchTerm($word); |
1554 | 1556 | //every word needs to appear at least once |
1555 | 1557 | $wordMatchOneAttrFilters = []; |
1556 | 1558 | foreach ($searchAttributes as $attr) { |
1557 | | - $wordMatchOneAttrFilters[] = "$attr=$word"; |
| 1559 | + if ($converterHub->hasConverter($attr)) { |
| 1560 | + try { |
| 1561 | + $wordMatchOneAttrFilters[] = "$attr=" . $this->prepareSearchTerm($converterHub->str2filter($attr, $word)); |
| 1562 | + } catch (ConverterException $e) { |
| 1563 | + $wordMatchOneAttrFilters[] = "$attr=$preparedWord"; |
| 1564 | + } |
| 1565 | + } else { |
| 1566 | + $wordMatchOneAttrFilters[] = "$attr=$preparedWord"; |
| 1567 | + } |
1558 | 1568 | } |
1559 | 1569 | $wordFilters[] = $this->combineFilterWithOr($wordMatchOneAttrFilters); |
1560 | 1570 | } |
@@ -1583,15 +1593,33 @@ private function getFilterPartForSearch($search, $searchAttributes, $fallbackAtt |
1583 | 1593 | } |
1584 | 1594 | } |
1585 | 1595 |
|
1586 | | - $search = $this->prepareSearchTerm($search); |
| 1596 | + $preparedSearch = $this->prepareSearchTerm($search); |
| 1597 | + $converterHub = ConverterHub::getDefaultConverterHub(); |
1587 | 1598 | if (!\is_array($searchAttributes) || \count($searchAttributes) === 0) { |
1588 | 1599 | if ($fallbackAttribute === '') { |
1589 | 1600 | return ''; |
1590 | 1601 | } |
1591 | | - $filter[] = "$fallbackAttribute=$search"; |
| 1602 | + if ($converterHub->hasConverter($fallbackAttribute)) { |
| 1603 | + try { |
| 1604 | + $filter[] = "$fallbackAttribute=" . $this->prepareSearchTerm($converterHub->str2filter($fallbackAttribute, $search)); |
| 1605 | + } catch (ConverterException $e) { |
| 1606 | + // if failed to convert, then do no convert |
| 1607 | + $filter[] = "$fallbackAttribute=$preparedSearch"; |
| 1608 | + } |
| 1609 | + } else { |
| 1610 | + $filter[] = "$fallbackAttribute=$preparedSearch"; |
| 1611 | + } |
1592 | 1612 | } else { |
1593 | 1613 | foreach ($searchAttributes as $attribute) { |
1594 | | - $filter[] = "$attribute=$search"; |
| 1614 | + if ($converterHub->hasConverter($attribute)) { |
| 1615 | + try { |
| 1616 | + $filter[] = "$attribute=" . $this->prepareSearchTerm($converterHub->str2filter($attribute, $search)); |
| 1617 | + } catch (ConverterException $e) { |
| 1618 | + $filter[] = "$attribute=$preparedSearch"; |
| 1619 | + } |
| 1620 | + } else { |
| 1621 | + $filter[] = "$attribute=$preparedSearch"; |
| 1622 | + } |
1595 | 1623 | } |
1596 | 1624 | } |
1597 | 1625 | if (\count($filter) === 1) { |
|
0 commit comments