[tests-only][full-ci]Add tests for share invite on drives root (#8850)
* add tests for root share invite * add more tests scenarios
This commit is contained in:
@@ -1673,6 +1673,48 @@ class GraphHelper {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $shareeIds
|
||||
* @param array $shareTypes
|
||||
* @param string|null $permissionsRole
|
||||
* @param string|null $permissionsAction
|
||||
* @param string|null $expireDate
|
||||
*
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function createShareInviteBody(
|
||||
array $shareeIds,
|
||||
array $shareTypes,
|
||||
?string $permissionsRole,
|
||||
?string $permissionsAction,
|
||||
?string $expireDate
|
||||
): array {
|
||||
$body = [];
|
||||
|
||||
foreach ($shareeIds as $index => $shareeId) {
|
||||
$shareType = $shareTypes[$index];
|
||||
$body['recipients'][] = [
|
||||
"@libre.graph.recipient.type" => $shareType,
|
||||
"objectId" => $shareeId
|
||||
];
|
||||
}
|
||||
|
||||
if ($permissionsRole !== null) {
|
||||
$roleId = self::getPermissionsRoleIdByName($permissionsRole);
|
||||
$body['roles'] = [$roleId];
|
||||
}
|
||||
|
||||
if ($permissionsAction !== null) {
|
||||
$body['@libre.graph.permissions.actions'] = ['libre.graph/driveItem/' . $permissionsAction];
|
||||
}
|
||||
|
||||
if ($expireDate !== null) {
|
||||
$body['expirationDateTime'] = $expireDate;
|
||||
}
|
||||
return $body;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $baseUrl
|
||||
* @param string $xRequestId
|
||||
@@ -1704,28 +1746,7 @@ class GraphHelper {
|
||||
?string $expireDate
|
||||
): ResponseInterface {
|
||||
$url = self::getBetaFullUrl($baseUrl, "drives/$spaceId/items/$itemId/invite");
|
||||
$body = [];
|
||||
|
||||
foreach ($shareeIds as $index => $shareeId) {
|
||||
$shareType = $shareTypes[$index];
|
||||
$body['recipients'][] = [
|
||||
"@libre.graph.recipient.type" => $shareType,
|
||||
"objectId" => $shareeId
|
||||
];
|
||||
}
|
||||
|
||||
if ($permissionsRole !== null) {
|
||||
$roleId = self::getPermissionsRoleIdByName($permissionsRole);
|
||||
$body['roles'] = [$roleId];
|
||||
}
|
||||
|
||||
if ($permissionsAction !== null) {
|
||||
$body['@libre.graph.permissions.actions'] = ['libre.graph/driveItem/' . $permissionsAction];
|
||||
}
|
||||
|
||||
if ($expireDate !== null) {
|
||||
$body['expirationDateTime'] = $expireDate;
|
||||
}
|
||||
$body = self::createShareInviteBody($shareeIds, $shareTypes, $permissionsRole, $permissionsAction, $expireDate);
|
||||
|
||||
return HttpRequestHelper::post(
|
||||
$url,
|
||||
@@ -2040,4 +2061,44 @@ class GraphHelper {
|
||||
self::getRequestHeaders()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $baseUrl
|
||||
* @param string $xRequestId
|
||||
* @param string $user
|
||||
* @param string $password
|
||||
* @param string $spaceId
|
||||
* @param array $shareeIds
|
||||
* @param array $shareTypes
|
||||
* @param string|null $permissionsRole
|
||||
* @param string|null $permissionsAction
|
||||
* @param string|null $expireDate
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws \Exception|GuzzleException
|
||||
*/
|
||||
public static function sendSharingInvitationForDrive(
|
||||
string $baseUrl,
|
||||
string $xRequestId,
|
||||
string $user,
|
||||
string $password,
|
||||
string $spaceId,
|
||||
array $shareeIds,
|
||||
array $shareTypes,
|
||||
?string $permissionsRole,
|
||||
?string $permissionsAction,
|
||||
?string $expireDate
|
||||
): ResponseInterface {
|
||||
$url = self::getBetaFullUrl($baseUrl, "drives/$spaceId/root/invite");
|
||||
$body = self::createShareInviteBody($shareeIds, $shareTypes, $permissionsRole, $permissionsAction, $expireDate);
|
||||
|
||||
return HttpRequestHelper::post(
|
||||
$url,
|
||||
$xRequestId,
|
||||
$user,
|
||||
$password,
|
||||
self::getRequestHeaders(),
|
||||
\json_encode($body)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user