Skip to content
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
48 changes: 47 additions & 1 deletion build/integration/features/bootstrap/Provisioning.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ public function assureUserExists($user) {
Assert::assertEquals(200, $this->response->getStatusCode());
}

/**
* @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
Expand All @@ -93,7 +110,7 @@ public function userDoesNotExist($user) {
}
}

public function creatingTheUser($user) {
public function creatingTheUser($user, $displayname = '') {
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users";
$client = new Client();
$options = [];
Expand All @@ -105,6 +122,9 @@ public function creatingTheUser($user) {
'userid' => $user,
'password' => '123456'
];
if ($displayname !== '') {
$options['form_params']['displayName'] = $displayname;
}
$options['headers'] = [
'OCS-APIREQUEST' => 'true',
];
Expand Down Expand Up @@ -540,6 +560,20 @@ public function theUsersShouldBe($usersList) {
}
}

/**
* @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
Expand Down Expand Up @@ -599,6 +633,18 @@ public function getArrayOfUsersResponded($resp) {
return $extractedElementsArray;
}

/**
* 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.
*
Expand Down
14 changes: 14 additions & 0 deletions build/integration/features/provisioning-v2.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
24 changes: 18 additions & 6 deletions lib/private/Group/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,15 +345,27 @@ public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
$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) {
Expand Down