Skip to content

Commit

Permalink
Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
SagarGi committed Feb 20, 2024
1 parent 9e77413 commit 081d3af
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 34 deletions.
23 changes: 18 additions & 5 deletions tests/acceptance/features/apiSharingNg/listPermissions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,25 @@ Feature: List a sharing permissions
"""


Scenario: user send share invitation for all allowed roles defined in permission lists
Scenario: user send share invitation for all allowed roles defined in permission lists 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 from the above response:
| 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 |
86 changes: 57 additions & 29 deletions tests/acceptance/features/bootstrap/SharingNgContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -531,33 +531,61 @@ public function forUserTheSpaceSharesShouldContainTheseEntries(string $user, str
Assert::assertSame($should, $fileFound, $assertMessage);
}

/**
* @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
*/
public function userCanSendShareInvitationToUserWithAllAllowedPermissionRolesForFolder(string $user, TableNode $table): void {
$listPermissionResponse = $this->featureContext->getJsonDecodedResponseBodyContent();
if (!isset($listPermissionResponse->{'@libre.graph.permissions.roles.allowedValues'})) {
Assert::fail(
'The response' . $listPermissionResponse .
'does not contain any @libre.graph.permissions.roles.allowedValues'
);
}
Assert::assertNotEmpty(
$listPermissionResponse->{'@libre.graph.permissions.roles.allowedValues'},
'@libre.graph.permissions.roles.allowedValues in the response 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";
$areAllowedRolesAllowsShareInvitation = true;
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)
// the allowed roles in the response have 2 editor role but of different role id
// we have distinguished it from or test code as 'Editor' and 'File Editor'
if ($role->id === 'fb6c3e19-e378-47e5-b277-9732f9de6e21') {
$roleAllowed = 'Editor';
} elseif ($role->id === '2d00ce52-1fc2-4dbc-8b95-a73b73395f5a') {
$roleAllowed = 'File Editor';
} else {
$roleAllowed = $role->displayName;
}
$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
$rows = $table->getRowsHash();
$resource = $rows['resource'];
$shareType = $rows['shareType'];
$space = $rows['space'];
$removePermissionsResponse = $this->removeSharePermission($user, $shareType, $resource, $space);
Assert::assertEquals(204, $removePermissionsResponse->getStatusCode());
$shareInvitationRequestResult = $shareInvitationRequestResult . "\tShare invitation for resource with role '" . $roleAllowed . "' was allowed.\n";
} else {
$areAllowedRolesAllowsShareInvitation = false;
$shareInvitationRequestResult = $shareInvitationRequestResult . "\tShare invitation for resource with role '" . $roleAllowed . "' failed and was not allowed.\n";
}
}
Assert::assertTrue($areAllowedRolesAllowsShareInvitation, $shareInvitationRequestResult);
}
}

0 comments on commit 081d3af

Please sign in to comment.