diff --git a/tests/TestHelpers/GraphHelper.php b/tests/TestHelpers/GraphHelper.php index 684ad2c93..71aead1b1 100644 --- a/tests/TestHelpers/GraphHelper.php +++ b/tests/TestHelpers/GraphHelper.php @@ -1547,6 +1547,7 @@ class GraphHelper { * * @return string * + * @throws \Exception */ public static function getRoleIdByName( string $role @@ -1568,6 +1569,8 @@ class GraphHelper { return '1c996275-f1c9-4e71-abdf-a42f6495e960'; case 'Manager': return '312c0871-5ef7-4b3a-85b6-0e4074c64049'; + default: + throw new \Exception('Role ' . $role . ' not found'); } } @@ -1581,9 +1584,11 @@ class GraphHelper { * @param string $shareeId * @param string $shareType * @param string|null $role + * @param string|null $permission * * @return ResponseInterface * @throws \JsonException + * @throws \Exception */ public static function sendSharingInvitation( string $baseUrl, @@ -1594,7 +1599,8 @@ class GraphHelper { string $itemId, string $shareeId, string $shareType, - ?string $role + ?string $role, + ?string $permission ): ResponseInterface { $url = self::getBetaFullUrl($baseUrl, "drives/$spaceId/items/$itemId/invite"); $body = []; @@ -1609,6 +1615,10 @@ class GraphHelper { $body['roles'] = [$roleId]; } + if ($permission !== null) { + $body['@libre.graph.permissions.actions'] = ['libre.graph/driveItem/' . $permission]; + } + return HttpRequestHelper::post( $url, $xRequestId, diff --git a/tests/acceptance/features/apiSharingNg/shareInvitations.feature b/tests/acceptance/features/apiSharingNg/shareInvitations.feature index abc74273e..35888e533 100644 --- a/tests/acceptance/features/apiSharingNg/shareInvitations.feature +++ b/tests/acceptance/features/apiSharingNg/shareInvitations.feature @@ -188,3 +188,395 @@ Feature: Send a sharing invitations | Co Owner | folder | FolderToShare | | Uploader | folder | FolderToShare | | Manager | folder | FolderToShare | + + + Scenario Outline: send share invitation for a file to user with different permissions + Given user "Alice" has uploaded file with content "to share" to "textfile1.txt" + When user "Alice" sends the following share invitation using the Graph API: + | resourceType | file | + | resource | textfile1.txt | + | space | Personal | + | sharee | Brian | + | shareType | user | + | permission | | + Then the HTTP status code should be "200" + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "value" + ], + "properties": { + "value": { + "type": "array", + "items": { + "type": "object", + "required": [ + "id", + "@libre.graph.permissions.actions", + "grantedToV2" + ], + "properties": { + "id": { + "type": "string", + "pattern": "^%share_id_pattern%$" + }, + "@libre.graph.permissions.actions": { + "type": "array", + "items": { + "type": "string", + "pattern": "^libre\\.graph\\/driveItem\\/$" + } + }, + "grantedToV2": { + "type": "object", + "required": [ + "user" + ], + "properties": { + "user": { + "type": "object", + "required": [ + "id", + "displayName" + ], + "properties": { + "id": { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "displayName": { + "type": "string", + "enum": [ + "Brian Murphy" + ] + } + } + } + } + } + } + } + } + } + } + """ + Examples: + | permission | + | permissions/create | + | children/create | + | upload/create | + | path/read | + | quota/read | + | content/read | + | permissions/read | + | children/read | + | versions/read | + | deleted/read | + | basic/read | + | path/update | + | versions/update | + | deleted/update | + | permissions/update | + | standard/delete | + | permissions/delete | + | deleted/delete | + | permissions/deny | + + + Scenario Outline: send share invitation for a folder to user with different permissions + Given user "Alice" has created folder "FolderToShare" + When user "Alice" sends the following share invitation using the Graph API: + | resourceType | folder | + | resource | FolderToShare | + | space | Personal | + | sharee | Brian | + | shareType | user | + | permission | | + Then the HTTP status code should be "200" + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "value" + ], + "properties": { + "value": { + "type": "array", + "items": { + "type": "object", + "required": [ + "id", + "@libre.graph.permissions.actions", + "grantedToV2" + ], + "properties": { + "id": { + "type": "string", + "pattern": "^%share_id_pattern%$" + }, + "@libre.graph.permissions.actions": { + "type": "array", + "items": { + "type": "string", + "pattern": "^libre\\.graph\\/driveItem\\/$" + } + }, + "grantedToV2": { + "type": "object", + "required": [ + "user" + ], + "properties": { + "user": { + "type": "object", + "required": [ + "id", + "displayName" + ], + "properties": { + "id": { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "displayName": { + "type": "string", + "enum": [ + "Brian Murphy" + ] + } + } + } + } + } + } + } + } + } + } + """ + Examples: + | permission | + | permissions/create | + | children/create | + | upload/create | + | path/read | + | quota/read | + | content/read | + | permissions/read | + | children/read | + | versions/read | + | deleted/read | + | basic/read | + | path/update | + | versions/update | + | deleted/update | + | permissions/update | + | standard/delete | + | permissions/delete | + | deleted/delete | + | permissions/deny | + + + Scenario Outline: send share invitation for a file to group with different permissions + Given user "Carol" has been created with default attributes and without skeleton files + And group "grp1" has been created + And the following users have been added to the following groups + | username | groupname | + | Brian | grp1 | + | Carol | grp1 | + And user "Alice" has uploaded file with content "to share" to "textfile1.txt" + When user "Alice" sends the following share invitation using the Graph API: + | resourceType | file | + | resource | textfile1.txt | + | space | Personal | + | sharee | grp1 | + | shareType | group | + | permission | | + Then the HTTP status code should be "200" + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "value" + ], + "properties": { + "value": { + "type": "array", + "items": { + "type": "object", + "required": [ + "id", + "@libre.graph.permissions.actions", + "grantedToV2" + ], + "properties": { + "id": { + "type": "string", + "pattern": "^%share_id_pattern%$" + }, + "@libre.graph.permissions.actions": { + "type": "array", + "items": { + "type": "string", + "pattern": "^libre\\.graph\\/driveItem\\/$" + } + }, + "grantedToV2": { + "type": "object", + "required": [ + "group" + ], + "properties": { + "group": { + "type": "object", + "required": [ + "id", + "displayName" + ], + "properties": { + "id": { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "displayName": { + "type": "string", + "enum": [ + "grp1" + ] + } + } + } + } + } + } + } + } + } + } + """ + Examples: + | permission | + | permissions/create | + | children/create | + | upload/create | + | path/read | + | quota/read | + | content/read | + | permissions/read | + | children/read | + | versions/read | + | deleted/read | + | basic/read | + | path/update | + | versions/update | + | deleted/update | + | permissions/update | + | standard/delete | + | permissions/delete | + | deleted/delete | + | permissions/deny | + + + Scenario Outline: send share invitation for a folder to group with different permissions + Given user "Carol" has been created with default attributes and without skeleton files + And group "grp1" has been created + And the following users have been added to the following groups + | username | groupname | + | Brian | grp1 | + | Carol | grp1 | + And user "Alice" has created folder "FolderToShare" + When user "Alice" sends the following share invitation using the Graph API: + | resourceType | folder | + | resource | FolderToShare | + | space | Personal | + | sharee | grp1 | + | shareType | group | + | permission | | + Then the HTTP status code should be "200" + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "value" + ], + "properties": { + "value": { + "type": "array", + "items": { + "type": "object", + "required": [ + "id", + "@libre.graph.permissions.actions", + "grantedToV2" + ], + "properties": { + "id": { + "type": "string", + "pattern": "^%share_id_pattern%$" + }, + "@libre.graph.permissions.actions": { + "type": "array", + "items": { + "type": "string", + "pattern": "^libre\\.graph\\/driveItem\\/$" + } + }, + "grantedToV2": { + "type": "object", + "required": [ + "group" + ], + "properties": { + "group": { + "type": "object", + "required": [ + "id", + "displayName" + ], + "properties": { + "id": { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "displayName": { + "type": "string", + "enum": [ + "grp1" + ] + } + } + } + } + } + } + } + } + } + } + """ + Examples: + | permission | + | permissions/create | + | children/create | + | upload/create | + | path/read | + | quota/read | + | content/read | + | permissions/read | + | children/read | + | versions/read | + | deleted/read | + | basic/read | + | path/update | + | versions/update | + | deleted/update | + | permissions/update | + | standard/delete | + | permissions/delete | + | deleted/delete | + | permissions/deny | diff --git a/tests/acceptance/features/bootstrap/SharingNgContext.php b/tests/acceptance/features/bootstrap/SharingNgContext.php index 7ec8b9a99..9828ffbb6 100644 --- a/tests/acceptance/features/bootstrap/SharingNgContext.php +++ b/tests/acceptance/features/bootstrap/SharingNgContext.php @@ -104,6 +104,9 @@ class SharingNgContext implements Context { ? $this->featureContext->getAttributeOfCreatedUser($rows['sharee'], 'id') : $this->featureContext->getAttributeOfCreatedGroup($rows['sharee'], 'id'); + $role = $rows['role'] ?? null; + $permission = $rows['permission'] ?? null; + $this->featureContext->setResponse( GraphHelper::sendSharingInvitation( $this->featureContext->getBaseUrl(), @@ -114,7 +117,8 @@ class SharingNgContext implements Context { $itemId, $shareeId, $rows['shareType'], - $rows['role'] + $role, + $permission ) ); }