Skip to content

Commit

Permalink
Added test for sending share invitation to user with role
Browse files Browse the repository at this point in the history
  • Loading branch information
grgprarup committed Dec 15, 2023
1 parent 1e94245 commit 84b6bd5
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 1 deletion.
83 changes: 83 additions & 0 deletions tests/TestHelpers/GraphHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1532,4 +1532,87 @@ public static function getPermissionsList(
self::getRequestHeaders()
);
}

/**
* Get the role id by name
* @param string $baseUrl
* @param string $xRequestId
* @param string $user
* @param string $password
* @param string $role
*
* @return string
*
*/
public static function getRoleIdByName(string $baseUrl,
string $xRequestId,
string $user,
string $password,
string $role) : string {
$url = self::getBetaFullUrl($baseUrl, "roleManagement/permissions/roleDefinitions");

$response = HttpRequestHelper::get(
$url,
$xRequestId,
$user,
$password,
self::getRequestHeaders(),
);

$roles = \json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR);

if (isset($roles)) {
foreach ($roles as $item) {
if ($item["displayName"] === $role) {
return $item["id"];
}
}
}
}

/**
* @param string $baseUrl
* @param string $xRequestId
* @param string $user
* @param string $password
* @param string $spaceId
* @param string $itemId
* @param string $shareeId
* @param string|null $role
*
* @return ResponseInterface
* @throws \JsonException
*/
public static function sendSharingInvitation(
string $baseUrl,
string $xRequestId,
string $user,
string $password,
string $spaceId,
string $itemId,
string $shareeId,
?string $role
): ResponseInterface {
$url = self::getBetaFullUrl($baseUrl, "drives/$spaceId/items/$itemId/invite");
$body = [];

if ($shareeId !== null) {
$recipients['objectId'] = $shareeId;
$body['recipients'] = [$recipients];
}

if ($role !== null) {
$roleId = self::getRoleIdByName($baseUrl, $xRequestId, $user, $password, $role);
$body['roles'] = [$roleId];
}

return HttpRequestHelper::post(
$url,
$xRequestId,
$user,
$password,
self::getRequestHeaders(),
\json_encode($body)
);
}
}
23 changes: 23 additions & 0 deletions tests/acceptance/features/apiSharingNg/shareInvitations.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Feature: Send a sharing invitations
As the owner of a resource
I want to be able to send invitation to a resource
So that other users can have access to it

https://owncloud.dev/libre-graph-api/#/drives.permissions/Invite

Background:
Given these users have been created with default attributes and without skeleton files:
| username |
| Alice |
| Brian |


Scenario Outline: send sharing invitation for file to user with different permissions via the Graph API
Given user "Alice" has uploaded file with content "to share" to "/textfile1.txt"
When user "Alice" sends sharing invitation for a file "textfile1.txt" of the space "Personal" to user "Brian" with role "Viewer" using the Graph API
Then the HTTP status code should be "200"
Examples:
| role |
| Viewer |
| Editor |
| Uploader |
31 changes: 30 additions & 1 deletion tests/acceptance/features/bootstrap/SharingNgContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function before(BeforeScenarioScope $scope): void {
*/
public function theUserPermissionsListOfResource(string $user, string $fileOrFolder, string $resource, string $space):void {
$spaceId = ($this->spacesContext->getSpaceByName($user, $space))["id"];

if ($fileOrFolder === 'folder') {
$itemId = $this->spacesContext->getResourceId($user, $space, $resource);
} else {
Expand All @@ -80,4 +80,33 @@ public function theUserPermissionsListOfResource(string $user, string $fileOrFol
)
);
}

/**
* @When /^user "([^"]*)" sends sharing invitation for a (folder|file) "([^"]*)" of the space "([^"]*)" to user "([^"]*)" with role "([^"]*)" using the Graph API$/
*/
public function userSendsSharingInvitationForAFileOfTheSpaceToUserWithRoleUsingTheGraphApi(string $user, string $fileOrFolder, string $resource, string $space, string $sharee, string $role)
{
$spaceId = ($this->spacesContext->getSpaceByName($user, $space))["id"];

if ($fileOrFolder === 'folder') {
$itemId = $this->spacesContext->getResourceId($user, $space, $resource);
} else {
$itemId = $this->spacesContext->getFileId($user, $space, $resource);
}

$shareeId = $this->featureContext->getAttributeOfCreatedUser($sharee, 'id');

$this->featureContext->setResponse(
GraphHelper::sendSharingInvitation(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$user,
$this->featureContext->getPasswordForUser($user),
$spaceId,
$itemId,
$shareeId,
$role
)
);
}
}

0 comments on commit 84b6bd5

Please sign in to comment.