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

[stable10] allow admins to enable medial search on group and user #34779

Merged
merged 1 commit into from
Mar 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,13 @@
*/
'accounts.enable_medial_search' => true,

/**
* Allow medial search on the group id. Allows finding 'test' when searching for 'es'.
* This is only used in the DB group backend (local groups), and won't be used against LDAP
* Shibboleth or any other group backend.
*/
'groups.enable_medial_search' => true,

/**
* Defines the minimum characters entered before a search returns results for
* users or groups in the share autocomplete form. Lower values increase search
Expand Down
27 changes: 25 additions & 2 deletions lib/private/Group/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,21 @@ class Database extends \OC\Group\Backend {
/** @var \OCP\IDBConnection */
private $dbConn;

/** @var \OCP\IConfig */
private $config;

/**
* \OC\Group\Database constructor.
*
* @param \OCP\IDBConnection|null $dbConn
* @param \OCP\IConfig|null $config
*/
public function __construct(\OCP\IDBConnection $dbConn = null) {
public function __construct(
\OCP\IDBConnection $dbConn = null,
\OCP\IConfig $config = null
) {
$this->dbConn = $dbConn;
$this->config = $config;
}

/**
Expand All @@ -66,6 +74,9 @@ private function fixDI() {
if ($this->dbConn === null) {
$this->dbConn = \OC::$server->getDatabaseConnection();
}
if ($this->config === null) {
$this->config = \OC::$server->getConfig();
}
}

/**
Expand Down Expand Up @@ -231,10 +242,18 @@ public function getUserGroups($uid) {
* Returns a list with all groups
*/
public function getGroups($search = '', $limit = null, $offset = null) {
$this->fixDI();

$parameters = [];
$searchLike = '';
if ($search !== '') {
$parameters[] = '%' . $search . '%';
$search = $this->dbConn->escapeLikeParameter($search);
$allowMedialSearches = $this->config->getSystemValue("groups.enable_medial_search", true);
if ($allowMedialSearches) {
$parameters[] = '%' . $search . '%';
} else {
$parameters[] = $search . '%';
}
$searchLike = ' WHERE LOWER(`gid`) LIKE LOWER(?)';
}

Expand Down Expand Up @@ -284,6 +303,8 @@ public function groupExists($gid) {
* @return array an array of user ids
*/
public function usersInGroup($gid, $search = '', $limit = null, $offset = null) {
$this->fixDI();

$parameters = [$gid];
$searchLike = '';
if ($search !== '') {
Expand All @@ -310,6 +331,8 @@ public function usersInGroup($gid, $search = '', $limit = null, $offset = null)
* @throws \OC\DatabaseException
*/
public function countUsersInGroup($gid, $search = '') {
$this->fixDI();

$parameters = [$gid];
$searchLike = '';
if ($search !== '') {
Expand Down