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
11 changes: 9 additions & 2 deletions apps/provisioning_api/lib/Controller/GroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,11 @@ public function getGroupUsersDetails(string $groupId, string $search = '', int $
* @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']);
Expand All @@ -245,7 +246,13 @@ public function addGroup(string $groupid): DataResponse {
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 !== '') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also check if not null

Copy link
Member

@blizzz blizzz May 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for null, the parameter list needs to be adjusted. but it might be that null is passed when displayname was not provided by the client - at least i believe to remember, but didn't doublecheck. Integration tests pass, should be ok

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just repeating what psalm is saying 😉 🦜

Copy link
Contributor Author

@m7913d m7913d Jun 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@skjnldsv I added a null check and I throw an exception if it is the case. However, this results in a failure of the nodb test (see continuous integration). Shouldn't I throw an exception in this case or is the failing nodb test wrong? It seems to me appropriate that an error message is returned in case the group creation failed.

$group->setDisplayName($displayname);
}
return new DataResponse();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,12 @@ public function testAddGroup() {
->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');
}
Expand All @@ -419,10 +421,12 @@ public function testAddGroupWithSpecialChar() {
->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');
}
Expand Down
32 changes: 32 additions & 0 deletions build/integration/features/bootstrap/Provisioning.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,38 @@ public function userHasSetting($user, $settings) {
}
}
}

/**
* @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$/
Expand Down
17 changes: 17 additions & 0 deletions build/integration/features/provisioning-v1.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down