Skip to content

Commit

Permalink
Rebase and refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
SagarGi committed Apr 15, 2024
1 parent 1cbd552 commit 0b1816f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 48 deletions.
26 changes: 26 additions & 0 deletions tests/TestHelpers/GraphHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1647,6 +1647,32 @@ public static function getPermissionsRoleIdByName(
}
}

/**
* Get the role id by name
*
* @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
Expand Down
17 changes: 8 additions & 9 deletions tests/acceptance/features/apiSharingNg/listPermissions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -568,19 +568,18 @@ Feature: List a sharing permissions
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 from the above response:
| resource | textfile.txt |
| space | Personal |
| sharee | Brian |
| shareType | user |

| resource | textfile.txt |
| space | Personal |
| sharee | Brian |
| shareType | user |

Scenario: user send share invitation for all allowed roles defined in permission lists 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 from the above response:
| resource | folder |
| space | Personal |
| sharee | Brian |
| shareType | user |
| resource | folder |
| space | Personal |
| sharee | Brian |
| shareType | user |
48 changes: 9 additions & 39 deletions tests/acceptance/features/bootstrap/SharingNgContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -668,45 +668,15 @@ public function userShouldHaveSyncEnabledOrDisabledForShare(string $user, string
);
}

/**
* @Then user :user should be able to send share invitation with all allowed permission roles from the above response:
*
* @param string $user
* @param TableNode $table
*
*
* @throws JsonException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function userCanSendShareInvitationToUserWithAllAllowedPermissionRolesForFolder( string $user, TableNode $table)
{
// Get all the permission saved in the above response
// make loop through all the allowed roles
// Make a share invitation request
// Make the assertion status code and also with response was there [one item in the array]
// delete the share response after
$listPermissionResponse = $this->featureContext->getJsonDecodedResponseBodyContent();
if(!isset($listPermissionResponse->{'@libre.graph.permissions.roles.allowedValues'})){
Assert::fail('list permission did not have any permission roles allowed!');
}
Assert::assertNotEmpty($listPermissionResponse->{'@libre.graph.permissions.roles.allowedValues'});
$allowedPermissionRoles = $listPermissionResponse->{'@libre.graph.permissions.roles.allowedValues'};

foreach ($allowedPermissionRoles as $role) {
$response = $this->sendShareInvitation($user, new TableNode(array_merge($table->getTable(), [['permissionRole', $role->displayName]])));
var_dump($response);
}
}
/**
* @Then user :user should be able to send share invitation with all allowed permission roles from the above response:
*
* @param string $user
* @param TableNode $table
*
* @throws JsonException
* @throws \GuzzleHttp\Exception\GuzzleException
*
* @return void
* @throws Exception
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function userCanSendShareInvitationToUserWithAllAllowedPermissionRolesForFolder(string $user, TableNode $table): void {
$listPermissionResponse = $this->featureContext->getJsonDecodedResponseBodyContent();
Expand All @@ -724,20 +694,20 @@ public function userCanSendShareInvitationToUserWithAllAllowedPermissionRolesFor
// 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)
$rows = $table->getRowsHash();
$resource = $rows['resource'];
$shareType = $rows['shareType'];
$space = $rows['space'];
$roleAllowed = $role->displayName;
//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)) {
$shareInvitationRequestResult = $shareInvitationRequestResult . "\tShare invitation for resource '" . $resource . "' with role '" . $roleAllowed . "' was allowed.\n";
// remove the share so that the same user can be share for the next allowed roles
$removePermissionsResponse = $this->removeSharePermission($user, $shareType, $resource, $space);
$removePermissionsResponse = $this->removeSharePermission($user, $shareType, $space, $resource);
Assert::assertEquals(204, $removePermissionsResponse->getStatusCode());
} else {
$areAllSendInvitationSuccessFullForAllowedRoles = false;
Expand Down

0 comments on commit 0b1816f

Please sign in to comment.