mirror of
https://github.com/nextcloud/server.git
synced 2026-02-15 16:59:47 -05:00
Merge pull request #27089 from m7913d/feature/addGroupDisplayNames
[ProvisioningAPI] Allow specifying group display name during creation
This commit is contained in:
commit
a416d508de
4 changed files with 64 additions and 4 deletions
|
|
@ -232,10 +232,11 @@ class GroupsController extends AUserData {
|
|||
* @PasswordConfirmationRequired
|
||||
*
|
||||
* @param string $groupid
|
||||
* @param string $displayname
|
||||
* @return DataResponse
|
||||
* @throws OCSException
|
||||
*/
|
||||
public function addGroup(string $groupid): DataResponse {
|
||||
public function addGroup(string $groupid, string $displayname = ''): DataResponse {
|
||||
// Validate name
|
||||
if (empty($groupid)) {
|
||||
$this->logger->error('Group name not supplied', ['app' => 'provisioning_api']);
|
||||
|
|
@ -245,7 +246,13 @@ class GroupsController extends AUserData {
|
|||
if ($this->groupManager->groupExists($groupid)) {
|
||||
throw new OCSException('group exists', 102);
|
||||
}
|
||||
$this->groupManager->createGroup($groupid);
|
||||
$group = $this->groupManager->createGroup($groupid);
|
||||
if ($group === null) {
|
||||
throw new OCSException('Not supported by backend', 103);
|
||||
}
|
||||
if ($displayname !== '') {
|
||||
$group->setDisplayName($displayname);
|
||||
}
|
||||
return new DataResponse();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -405,10 +405,12 @@ class GroupsControllerTest extends \Test\TestCase {
|
|||
->with('NewGroup')
|
||||
->willReturn(false);
|
||||
|
||||
$group = $this->createGroup('NewGroup');
|
||||
$this->groupManager
|
||||
->expects($this->once())
|
||||
->method('createGroup')
|
||||
->with('NewGroup');
|
||||
->with('NewGroup')
|
||||
->willReturn($group);
|
||||
|
||||
$this->api->addGroup('NewGroup');
|
||||
}
|
||||
|
|
@ -419,10 +421,12 @@ class GroupsControllerTest extends \Test\TestCase {
|
|||
->with('Iñtërnâtiônàlizætiøn')
|
||||
->willReturn(false);
|
||||
|
||||
$group = $this->createGroup('Iñtërnâtiônàlizætiøn');
|
||||
$this->groupManager
|
||||
->expects($this->once())
|
||||
->method('createGroup')
|
||||
->with('Iñtërnâtiônàlizætiøn');
|
||||
->with('Iñtërnâtiônàlizætiøn')
|
||||
->willReturn($group);
|
||||
|
||||
$this->api->addGroup('Iñtërnâtiônàlizætiøn');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -175,6 +175,38 @@ trait Provisioning {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^group "([^"]*)" has$/
|
||||
*
|
||||
* @param string $user
|
||||
* @param \Behat\Gherkin\Node\TableNode|null $settings
|
||||
*/
|
||||
public function groupHasSetting($group, $settings) {
|
||||
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/groups/details?search=$group";
|
||||
$client = new Client();
|
||||
$options = [];
|
||||
if ($this->currentUser === 'admin') {
|
||||
$options['auth'] = $this->adminUser;
|
||||
} else {
|
||||
$options['auth'] = [$this->currentUser, $this->regularUser];
|
||||
}
|
||||
$options['headers'] = [
|
||||
'OCS-APIREQUEST' => 'true',
|
||||
];
|
||||
|
||||
$response = $client->get($fullUrl, $options);
|
||||
$groupDetails = simplexml_load_string($response->getBody())->data[0]->groups[0]->element;
|
||||
foreach ($settings->getRows() as $setting) {
|
||||
$value = json_decode(json_encode($groupDetails->{$setting[0]}), 1);
|
||||
if (isset($value[0])) {
|
||||
Assert::assertEquals($setting[1], $value[0], "", 0.0, 10, true);
|
||||
} else {
|
||||
Assert::assertEquals('', $setting[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Then /^user "([^"]*)" has editable fields$/
|
||||
|
|
|
|||
|
|
@ -231,6 +231,21 @@ Feature: provisioning
|
|||
Then the OCS status code should be "100"
|
||||
And the HTTP status code should be "200"
|
||||
And group "new-group" exists
|
||||
And group "new-group" has
|
||||
| displayname | new-group |
|
||||
|
||||
Scenario: Create a group with custom display name
|
||||
Given As an "admin"
|
||||
And group "new-group" does not exist
|
||||
When sending "POST" to "/cloud/groups" with
|
||||
| groupid | new-group |
|
||||
| password | 123456 |
|
||||
| displayname | new-group-displayname |
|
||||
Then the OCS status code should be "100"
|
||||
And the HTTP status code should be "200"
|
||||
And group "new-group" exists
|
||||
And group "new-group" has
|
||||
| displayname | new-group-displayname |
|
||||
|
||||
Scenario: Create a group with special characters
|
||||
Given As an "admin"
|
||||
|
|
@ -241,6 +256,8 @@ Feature: provisioning
|
|||
Then the OCS status code should be "100"
|
||||
And the HTTP status code should be "200"
|
||||
And group "España" exists
|
||||
And group "España" has
|
||||
| displayname | España |
|
||||
|
||||
Scenario: adding user to a group without sending the group
|
||||
Given As an "admin"
|
||||
|
|
|
|||
Loading…
Reference in a new issue