diff --git a/tests/TestHelpers/GraphHelper.php b/tests/TestHelpers/GraphHelper.php index 1f7cd7c69a2..feb522bb634 100644 --- a/tests/TestHelpers/GraphHelper.php +++ b/tests/TestHelpers/GraphHelper.php @@ -1647,6 +1647,32 @@ public static function getPermissionsRoleIdByName( } } + /** + * Get the role name by role id + * + * @param string $permissionsRoleId + * + * @return string + * + * @throws \Exception + */ + public static function getPermissionNameByPermissionRoleId( + string $permissionsRoleId + ): string { + switch ($permissionsRoleId) { + case 'b1e2218d-eef8-4d4c-b82d-0f1a1b48f3b5': + return 'Viewer'; + case 'fb6c3e19-e378-47e5-b277-9732f9de6e21': + return 'Editor'; + case '2d00ce52-1fc2-4dbc-8b95-a73b73395f5a': + return 'File Editor'; + case '1c996275-f1c9-4e71-abdf-a42f6495e960': + return 'Uploader'; + default: + throw new \Exception('Role ' . $permissionsRoleId . ' not found'); + } + } + /** * @param string $baseUrl * @param string $xRequestId diff --git a/tests/acceptance/features/apiSharingNg/listPermissions.feature b/tests/acceptance/features/apiSharingNg/listPermissions.feature index 0e4b7394b31..7ba893df543 100644 --- a/tests/acceptance/features/apiSharingNg/listPermissions.feature +++ b/tests/acceptance/features/apiSharingNg/listPermissions.feature @@ -888,4 +888,28 @@ Feature: List a sharing permissions } } } - """ \ No newline at end of file + """ + + @issues-8331 + Scenario: user sends share invitation with all allowed roles for a file + Given user "Alice" has uploaded file with content "hello text" to "textfile.txt" + And user "Brian" has been created with default attributes and without skeleton files + When user "Alice" gets permissions list for file "textfile.txt" of the space "Personal" using the Graph API + Then the HTTP status code should be "200" + And user "Alice" should be able to send share invitation with all allowed permission roles + | resource | textfile.txt | + | space | Personal | + | sharee | Brian | + | shareType | user | + + @issues-8331 + Scenario: user sends share invitation with all allowed roles for a folder + Given user "Alice" has created folder "folder" + And user "Brian" has been created with default attributes and without skeleton files + When user "Alice" gets permissions list for folder "folder" of the space "Personal" using the Graph API + Then the HTTP status code should be "200" + And user "Alice" should be able to send share invitation with all allowed permission roles + | resource | folder | + | space | Personal | + | sharee | Brian | + | shareType | user | diff --git a/tests/acceptance/features/bootstrap/SharingNgContext.php b/tests/acceptance/features/bootstrap/SharingNgContext.php index e68d86446aa..815ae6d64fa 100644 --- a/tests/acceptance/features/bootstrap/SharingNgContext.php +++ b/tests/acceptance/features/bootstrap/SharingNgContext.php @@ -667,4 +667,51 @@ public function userShouldHaveSyncEnabledOrDisabledForShare(string $user, string "Expected property '@client.synchronize' to be '$expectedValue' but found '$actualValue'" ); } + + /** + * @Then user :user should be able to send share invitation with all allowed permission roles + * + * @param string $user + * @param TableNode $table + * + * @return void + * @throws Exception + * @throws \GuzzleHttp\Exception\GuzzleException + */ + public function userShouldBeAbleToSendShareInvitationWithAllAllowedPermissionRoles(string $user, TableNode $table): void { + $listPermissionResponse = $this->featureContext->getJsonDecodedResponseBodyContent(); + if (!isset($listPermissionResponse->{'@libre.graph.permissions.roles.allowedValues'})) { + Assert::fail( + "The following response does not contain '@libre.graph.permissions.roles.allowedValues' property:\n" . $listPermissionResponse + ); + } + Assert::assertNotEmpty( + $listPermissionResponse->{'@libre.graph.permissions.roles.allowedValues'}, + "'@libre.graph.permissions.roles.allowedValues' should not be empty" + ); + $allowedPermissionRoles = $listPermissionResponse->{'@libre.graph.permissions.roles.allowedValues'}; + // this info is needed for log to see which roles allowed and which were not when tests fail + $shareInvitationRequestResult = "From the given allowed role lists from the permissions:\n"; + $areAllSendInvitationSuccessFullForAllowedRoles = true; + $rows = $table->getRowsHash(); + $resource = $rows['resource']; + $shareType = $rows['shareType']; + $space = $rows['space']; + foreach ($allowedPermissionRoles as $role) { + //we should be able to send share invitation for each of the role allowed for the files/folders which are listed in permissions (allowed) + $roleAllowed = GraphHelper::getPermissionNameByPermissionRoleId($role->id); + $responseSendInvitation = $this->sendShareInvitation($user, new TableNode(array_merge($table->getTable(), [['permissionsRole', $roleAllowed]]))); + $jsonResponseSendInvitation = $this->featureContext->getJsonDecodedResponseBodyContent($responseSendInvitation); + $httpsStatusCode = $responseSendInvitation->getStatusCode(); + if ($httpsStatusCode === 200 && !empty($jsonResponseSendInvitation->value)) { + // remove the share so that the same user can be share for the next allowed roles + $removePermissionsResponse = $this->removeSharePermission($user, $shareType, $space, $resource); + Assert::assertEquals(204, $removePermissionsResponse->getStatusCode()); + } else { + $areAllSendInvitationSuccessFullForAllowedRoles = false; + $shareInvitationRequestResult .= "\tShare invitation for resource '" . $resource . "' with role '" . $roleAllowed . "' failed and was not allowed.\n"; + } + } + Assert::assertTrue($areAllSendInvitationSuccessFullForAllowedRoles, $shareInvitationRequestResult); + } }