Skip to content

Commit

Permalink
allow admin to enable medial search on group and user
Browse files Browse the repository at this point in the history
  • Loading branch information
karakayasemi authored and gitmate-bot committed Mar 15, 2019
1 parent 4ac13e2 commit 7fe2f35
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
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

0 comments on commit 7fe2f35

Please sign in to comment.