From 4a3b3abe6f7e13cd71361bc7252393127d6a9257 Mon Sep 17 00:00:00 2001 From: Dries Mys Date: Mon, 24 May 2021 18:53:25 +0200 Subject: [PATCH 1/4] [ProvisioningAPI] Allow specifying group display name during creation Signed-off-by: Dries Mys --- apps/provisioning_api/lib/Controller/GroupsController.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/provisioning_api/lib/Controller/GroupsController.php b/apps/provisioning_api/lib/Controller/GroupsController.php index 05c738bdbd..bcab9f89d0 100644 --- a/apps/provisioning_api/lib/Controller/GroupsController.php +++ b/apps/provisioning_api/lib/Controller/GroupsController.php @@ -234,10 +234,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']); @@ -247,7 +248,10 @@ 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 ($displayname !== '') { + $group->setDisplayName($displayname); + } return new DataResponse(); } From 4a518827938a8ddb5817f63379abbc5c3e717467 Mon Sep 17 00:00:00 2001 From: Dries Mys Date: Mon, 24 May 2021 22:22:22 +0200 Subject: [PATCH 2/4] Fixed indentation Signed-off-by: Dries Mys --- apps/provisioning_api/lib/Controller/GroupsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/provisioning_api/lib/Controller/GroupsController.php b/apps/provisioning_api/lib/Controller/GroupsController.php index bcab9f89d0..665d08cd2a 100644 --- a/apps/provisioning_api/lib/Controller/GroupsController.php +++ b/apps/provisioning_api/lib/Controller/GroupsController.php @@ -250,7 +250,7 @@ class GroupsController extends AUserData { } $group = $this->groupManager->createGroup($groupid); if ($displayname !== '') { - $group->setDisplayName($displayname); + $group->setDisplayName($displayname); } return new DataResponse(); } From 7a8e4c504bcedd1f5e56e3537764dc2661536ecf Mon Sep 17 00:00:00 2001 From: Dries Mys Date: Tue, 1 Jun 2021 01:11:21 +0200 Subject: [PATCH 3/4] Group may be null if backend doesn't support creating groups Signed-off-by: Dries Mys --- apps/provisioning_api/lib/Controller/GroupsController.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/provisioning_api/lib/Controller/GroupsController.php b/apps/provisioning_api/lib/Controller/GroupsController.php index 665d08cd2a..b5219fa0c0 100644 --- a/apps/provisioning_api/lib/Controller/GroupsController.php +++ b/apps/provisioning_api/lib/Controller/GroupsController.php @@ -249,6 +249,9 @@ class GroupsController extends AUserData { throw new OCSException('group exists', 102); } $group = $this->groupManager->createGroup($groupid); + if ($group === null) { + throw new OCSException('Not supported by backend', 103); + } if ($displayname !== '') { $group->setDisplayName($displayname); } From 899a15270870c4299c4a35dbe29215366d56be72 Mon Sep 17 00:00:00 2001 From: Dries Mys Date: Tue, 1 Jun 2021 01:13:40 +0200 Subject: [PATCH 4/4] Added tests for specifying custom display name during group creation. Signed-off-by: Dries Mys --- .../features/bootstrap/Provisioning.php | 32 +++++++++++++++++++ .../features/provisioning-v1.feature | 17 ++++++++++ 2 files changed, 49 insertions(+) diff --git a/build/integration/features/bootstrap/Provisioning.php b/build/integration/features/bootstrap/Provisioning.php index cbe11403ba..d30943a23f 100644 --- a/build/integration/features/bootstrap/Provisioning.php +++ b/build/integration/features/bootstrap/Provisioning.php @@ -176,6 +176,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 /^search users by phone for region "([^"]*)" with$/ diff --git a/build/integration/features/provisioning-v1.feature b/build/integration/features/provisioning-v1.feature index 307440b4e4..b58899f91e 100644 --- a/build/integration/features/provisioning-v1.feature +++ b/build/integration/features/provisioning-v1.feature @@ -205,6 +205,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" @@ -215,6 +230,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"