summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2020-08-05 16:09:00 +0200
committerGitHub <noreply@github.com>2020-08-05 16:09:00 +0200
commit79fc7e78b7de7ee7bc749294ac79de4566fb04e9 (patch)
tree022cc740e4b3481ca6ef8f760566057200e10595
parent2b4b5db16d7655eb06263fe8fe75983c1833d16f (diff)
parent907d3542dc478a081b95bfaf2811b4381a22c76c (diff)
downloadnextcloud-server-79fc7e78b7de7ee7bc749294ac79de4566fb04e9.tar.gz
nextcloud-server-79fc7e78b7de7ee7bc749294ac79de4566fb04e9.zip
Merge pull request #21138 from nextcloud/fix/noid/search-in-group-displayname-email
Search also the email and displayname in user mangement for groups
-rw-r--r--build/integration/features/bootstrap/Provisioning.php48
-rw-r--r--build/integration/features/provisioning-v2.feature14
-rw-r--r--lib/private/Group/Database.php24
3 files changed, 79 insertions, 7 deletions
diff --git a/build/integration/features/bootstrap/Provisioning.php b/build/integration/features/bootstrap/Provisioning.php
index c6cfa881fb5..daf5b11569c 100644
--- a/build/integration/features/bootstrap/Provisioning.php
+++ b/build/integration/features/bootstrap/Provisioning.php
@@ -70,6 +70,23 @@ trait Provisioning {
}
/**
+ * @Given /^user "([^"]*)" with displayname "([^"]*)" exists$/
+ * @param string $user
+ */
+ public function assureUserWithDisplaynameExists($user, $displayname) {
+ try {
+ $this->userExists($user);
+ } catch (\GuzzleHttp\Exception\ClientException $ex) {
+ $previous_user = $this->currentUser;
+ $this->currentUser = "admin";
+ $this->creatingTheUser($user, $displayname);
+ $this->currentUser = $previous_user;
+ }
+ $this->userExists($user);
+ Assert::assertEquals(200, $this->response->getStatusCode());
+ }
+
+ /**
* @Given /^user "([^"]*)" does not exist$/
* @param string $user
*/
@@ -93,7 +110,7 @@ trait Provisioning {
}
}
- public function creatingTheUser($user) {
+ public function creatingTheUser($user, $displayname = '') {
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users";
$client = new Client();
$options = [];
@@ -105,6 +122,9 @@ trait Provisioning {
'userid' => $user,
'password' => '123456'
];
+ if ($displayname !== '') {
+ $options['form_params']['displayName'] = $displayname;
+ }
$options['headers'] = [
'OCS-APIREQUEST' => 'true',
];
@@ -541,6 +561,20 @@ trait Provisioning {
}
/**
+ * @Then /^detailed users returned are$/
+ * @param \Behat\Gherkin\Node\TableNode|null $usersList
+ */
+ public function theDetailedUsersShouldBe($usersList) {
+ if ($usersList instanceof \Behat\Gherkin\Node\TableNode) {
+ $users = $usersList->getRows();
+ $usersSimplified = $this->simplifyArray($users);
+ $respondedArray = $this->getArrayOfDetailedUsersResponded($this->response);
+ $respondedArray = array_keys($respondedArray);
+ Assert::assertEquals($usersSimplified, $respondedArray);
+ }
+ }
+
+ /**
* @Then /^groups returned are$/
* @param \Behat\Gherkin\Node\TableNode|null $groupsList
*/
@@ -600,6 +634,18 @@ trait Provisioning {
}
/**
+ * Parses the xml answer to get the array of detailed users returned.
+ *
+ * @param ResponseInterface $resp
+ * @return array
+ */
+ public function getArrayOfDetailedUsersResponded($resp) {
+ $listCheckedElements = simplexml_load_string($resp->getBody())->data[0]->users;
+ $extractedElementsArray = json_decode(json_encode($listCheckedElements), 1);
+ return $extractedElementsArray;
+ }
+
+ /**
* Parses the xml answer to get the array of groups returned.
*
* @param ResponseInterface $resp
diff --git a/build/integration/features/provisioning-v2.feature b/build/integration/features/provisioning-v2.feature
index def9b376d21..729c812cb8c 100644
--- a/build/integration/features/provisioning-v2.feature
+++ b/build/integration/features/provisioning-v2.feature
@@ -19,3 +19,17 @@ Feature: provisioning
Then the OCS status code should be "998"
And the HTTP status code should be "404"
+ Scenario: Searching by displayname in groups
+ Given As an "admin"
+ And user "user-in-group" with displayname "specific-name" exists
+ And user "user-in-group2" with displayname "another-name" exists
+ And user "user-not-in-group" with displayname "specific-name" exists
+ And user "user-not-in-group2" with displayname "another-name" exists
+ And group "group-search" exists
+ And user "user-in-group" belongs to group "group-search"
+ And user "user-in-group2" belongs to group "group-search"
+ When sending "GET" to "/cloud/groups/group-search/users/details?offset=0&limit=25&search=ifi"
+ Then the OCS status code should be "200"
+ And the HTTP status code should be "200"
+ And detailed users returned are
+ | user-in-group |
diff --git a/lib/private/Group/Database.php b/lib/private/Group/Database.php
index 8e6181a56cd..97094c67728 100644
--- a/lib/private/Group/Database.php
+++ b/lib/private/Group/Database.php
@@ -348,15 +348,27 @@ class Database extends ABackend implements
$this->fixDI();
$query = $this->dbConn->getQueryBuilder();
- $query->select('uid')
- ->from('group_user')
+ $query->select('g.uid')
+ ->from('group_user', 'g')
->where($query->expr()->eq('gid', $query->createNamedParameter($gid)))
- ->orderBy('uid', 'ASC');
+ ->orderBy('g.uid', 'ASC');
if ($search !== '') {
- $query->andWhere($query->expr()->like('uid', $query->createNamedParameter(
- '%' . $this->dbConn->escapeLikeParameter($search) . '%'
- )));
+ $query->leftJoin('g', 'users', 'u', $query->expr()->eq('g.uid', 'u.uid'))
+ ->leftJoin('u', 'preferences', 'p', $query->expr()->andX(
+ $query->expr()->eq('p.userid', 'u.uid'),
+ $query->expr()->eq('p.appid', $query->expr()->literal('settings')),
+ $query->expr()->eq('p.configkey', $query->expr()->literal('email')))
+ )
+ // sqlite doesn't like re-using a single named parameter here
+ ->andWhere(
+ $query->expr()->orX(
+ $query->expr()->ilike('g.uid', $query->createNamedParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%')),
+ $query->expr()->ilike('u.displayname', $query->createNamedParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%')),
+ $query->expr()->ilike('p.configvalue', $query->createNamedParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%'))
+ )
+ )
+ ->orderBy('u.uid_lower', 'ASC');
}
if ($limit !== -1) {