added test to send share invitation to multiple groups at once

This commit is contained in:
prajwol
2024-01-15 12:45:46 +05:45
parent 9224b46c05
commit 3b48dfd8bd
3 changed files with 90 additions and 13 deletions
+11 -8
View File
@@ -1581,8 +1581,8 @@ class GraphHelper {
* @param string $password * @param string $password
* @param string $spaceId * @param string $spaceId
* @param string $itemId * @param string $itemId
* @param string $shareeId * @param array $shareeIds
* @param string $shareType * @param array $shareTypes
* @param string|null $permissionsRole * @param string|null $permissionsRole
* @param string|null $permissionsAction * @param string|null $permissionsAction
* @param string|null $expireDate * @param string|null $expireDate
@@ -1598,8 +1598,8 @@ class GraphHelper {
string $password, string $password,
string $spaceId, string $spaceId,
string $itemId, string $itemId,
string $shareeId, array $shareeIds,
string $shareType, array $shareTypes,
?string $permissionsRole, ?string $permissionsRole,
?string $permissionsAction, ?string $permissionsAction,
?string $expireDate ?string $expireDate
@@ -1607,10 +1607,13 @@ class GraphHelper {
$url = self::getBetaFullUrl($baseUrl, "drives/$spaceId/items/$itemId/invite"); $url = self::getBetaFullUrl($baseUrl, "drives/$spaceId/items/$itemId/invite");
$body = []; $body = [];
$recipients['objectId'] = $shareeId; foreach ($shareeIds as $index => $shareeId) {
$recipients['@libre.graph.recipient.type'] = $shareType; $shareType = $shareTypes[$index];
$body['recipients'][] = [
$body['recipients'] = [$recipients]; "@libre.graph.recipient.type" => $shareType,
"objectId" => $shareeId
];
}
if ($permissionsRole !== null) { if ($permissionsRole !== null) {
$roleId = self::getPermissionsRoleIdByName($permissionsRole); $roleId = self::getPermissionsRoleIdByName($permissionsRole);
@@ -979,3 +979,70 @@ Feature: Send a sharing invitations
| Co Owner | folder | FolderToShare | | Co Owner | folder | FolderToShare |
| Uploader | folder | FolderToShare | | Uploader | folder | FolderToShare |
| Manager | folder | FolderToShare | | Manager | folder | FolderToShare |
Scenario Outline: try to send sharing invitation to multiple groups
Given these users have been created with default attributes and without skeleton files:
| username |
| Carol |
| Bob |
And group "grp1" has been created
And group "grp2" has been created
And the following users have been added to the following groups
| username | groupname |
| Brian | grp1 |
| Carol | grp2 |
| Bob | grp2 |
And user "Alice" has uploaded file with content "to share" to "/textfile1.txt"
And user "Alice" has created folder "FolderToShare"
When user "Alice" sends the following share invitation using the Graph API:
| resourceType | <resource-type> |
| resource | <path> |
| space | Personal |
| sharee | grp1, grp2 |
| shareType | group, group |
| permissionsRole | <permissions-role> |
Then the HTTP status code should be "400"
And the JSON data of the response should match
"""
{
"type": "object",
"required": [
"error"
],
"properties": {
"error": {
"type": "object",
"required": [
"code",
"message"
],
"properties": {
"code": {
"type": "string",
"enum": [
"invalidRequest"
]
},
"message": {
"type": "string",
"enum": [
"Key: 'DriveItemInvite.Recipients' Error:Field validation for 'Recipients' failed on the 'len' tag"
]
}
}
}
}
}
"""
Examples:
| permissions-role | resource-type | path |
| Viewer | file | /textfile1.txt |
| File Editor | file | /textfile1.txt |
| Co Owner | file | /textfile1.txt |
| Manager | file | /textfile1.txt |
| Viewer | folder | FolderToShare |
| Editor | folder | FolderToShare |
| Co Owner | folder | FolderToShare |
| Uploader | folder | FolderToShare |
| Manager | folder | FolderToShare |
@@ -143,9 +143,16 @@ class SharingNgContext implements Context {
? $this->spacesContext->getResourceId($user, $rows['space'], $rows['resource']) ? $this->spacesContext->getResourceId($user, $rows['space'], $rows['resource'])
: $this->spacesContext->getFileId($user, $rows['space'], $rows['resource']); : $this->spacesContext->getFileId($user, $rows['space'], $rows['resource']);
$shareeId = ($rows['shareType'] === 'user') $sharees = array_map('trim', explode(',', $rows['sharee']));
? $this->featureContext->getAttributeOfCreatedUser($rows['sharee'], 'id') $shareTypes = array_map('trim', explode(',', $rows['shareType']));
: $this->featureContext->getAttributeOfCreatedGroup($rows['sharee'], 'id');
$shareeIds = [];
foreach ($sharees as $index => $sharee) {
$shareType = $shareTypes[$index];
$shareeIds[] = ($shareType === 'user')
? $this->featureContext->getAttributeOfCreatedUser($sharee, 'id')
: $this->featureContext->getAttributeOfCreatedGroup($sharee, 'id');
}
$permissionsRole = $rows['permissionsRole'] ?? null; $permissionsRole = $rows['permissionsRole'] ?? null;
$permissionsAction = $rows['permissionsAction'] ?? null; $permissionsAction = $rows['permissionsAction'] ?? null;
@@ -158,8 +165,8 @@ class SharingNgContext implements Context {
$this->featureContext->getPasswordForUser($user), $this->featureContext->getPasswordForUser($user),
$spaceId, $spaceId,
$itemId, $itemId,
$shareeId, $shareeIds,
$rows['shareType'], $shareTypes,
$permissionsRole, $permissionsRole,
$permissionsAction, $permissionsAction,
$expireDate $expireDate