diff --git a/.drone.star b/.drone.star index ad17abf0..d9e30b4c 100644 --- a/.drone.star +++ b/.drone.star @@ -142,6 +142,7 @@ def phpIntegrationTest(ctx, phpVersions, coverage): "OCIS_URL": "https://ocis:9200", "OCISWRAPPER_URL": "http://ocis:5200", "COMPOSER_HOME": "%s/.cache/composer" % dir["base"], + "OCIS_VERSION": branch, }, "commands": [ installPhpXdebugCommand(phpVersion), diff --git a/src/Drive.php b/src/Drive.php index 00276806..59ff3e17 100644 --- a/src/Drive.php +++ b/src/Drive.php @@ -5,6 +5,7 @@ use DateTime; use GuzzleHttp\Client; use OpenAPI\Client\Api\DrivesApi; +use OpenAPI\Client\Api\DrivesRootApi; use OpenAPI\Client\ApiException; use OpenAPI\Client\Configuration; use OpenAPI\Client\Model\Drive as ApiDrive; @@ -572,6 +573,49 @@ public function emptyTrashbin(): bool return true; } + /** + * Gets all possible roles for the drive + * @return array + * @throws BadRequestException + * @throws ForbiddenException + * @throws HttpException + * @throws NotFoundException + * @throws UnauthorizedException + * @throws InvalidResponseException + * @throws InternalServerErrorException + */ + public function getRoles(): array + { + $guzzle = new Client( + Ocis::createGuzzleConfig($this->connectionConfig, $this->accessToken) + ); + + if (array_key_exists('drivesRootApi', $this->connectionConfig)) { + $apiInstance = $this->connectionConfig['drivesRootApi']; + } else { + $apiInstance = new DrivesRootApi( + $guzzle, + $this->graphApiConfig + ); + } + try { + $collectionOfPermissions = $apiInstance->listPermissionsSpaceRoot($this->getId()); + } catch (ApiException $e) { + throw ExceptionHelper::getHttpErrorException($e); + } + if ($collectionOfPermissions instanceof OdataError) { + throw new InvalidResponseException( + "listPermissions returned an OdataError - " . $collectionOfPermissions->getError() + ); + } + $apiRoles = $collectionOfPermissions->getAtLibreGraphPermissionsRolesAllowedValues() ?? []; + $roles = []; + foreach ($apiRoles as $role) { + $roles[] = new SharingRole($role); + } + return $roles; + } + /** * @param array $tags * @todo This function is not implemented yet! Place, name and signature of the function might change! diff --git a/src/Ocis.php b/src/Ocis.php index 791e5088..202cb29a 100644 --- a/src/Ocis.php +++ b/src/Ocis.php @@ -8,6 +8,7 @@ use OpenAPI\Client\Api\DrivesApi; use OpenAPI\Client\Api\DrivesGetDrivesApi; use OpenAPI\Client\Api\DrivesPermissionsApi; +use OpenAPI\Client\Api\DrivesRootApi; use OpenAPI\Client\Api\GroupApi; use OpenAPI\Client\Api\MeDriveApi; use OpenAPI\Client\Api\MeDrivesApi; @@ -43,7 +44,8 @@ * 'guzzle'?:Client, * 'drivesApi'?:DrivesApi, * 'drivesGetDrivesApi'?:DrivesGetDrivesApi, - * 'drivesPermissionsApi'?:DrivesPermissionsApi + * 'drivesPermissionsApi'?:DrivesPermissionsApi, + * 'drivesRootApi'?:DrivesRootApi * } */ class Ocis @@ -155,6 +157,11 @@ public static function isDrivesGetDrivesApi(mixed $api): bool return $api instanceof DrivesGetDrivesApi; } + public static function isDrivesRootApi(mixed $api): bool + { + return $api instanceof DrivesRootApi; + } + /** * @param array $connectionConfig * @ignore This function is used for internal purposes only and should not be shown in the documentation. @@ -170,6 +177,7 @@ public static function isConnectionConfigValid(array $connectionConfig): bool 'drivesPermissionsApi' => self::class . '::isDrivesPermissionsApi', 'drivesApi' => self::class . '::isDrivesApi', 'drivesGetDrivesApi' => self::class . '::isDrivesGetDrivesApi', + 'drivesRootApi' => self::class . '::isDrivesRootApi', 'proxy' => 'is_array', ]; foreach ($connectionConfig as $key => $check) { diff --git a/tests/integration/Owncloud/OcisPhpSdk/DriveTest.php b/tests/integration/Owncloud/OcisPhpSdk/DriveTest.php index 83d022fb..97d2f52f 100644 --- a/tests/integration/Owncloud/OcisPhpSdk/DriveTest.php +++ b/tests/integration/Owncloud/OcisPhpSdk/DriveTest.php @@ -6,6 +6,7 @@ use Owncloud\OcisPhpSdk\Exception\BadRequestException; use Owncloud\OcisPhpSdk\Exception\NotFoundException; use Owncloud\OcisPhpSdk\Ocis; +use Owncloud\OcisPhpSdk\SharingRole; require_once __DIR__ . '/OcisPhpSdkTestCase.php'; @@ -68,4 +69,22 @@ public function testDeleteEnabledDrive(): void $this->expectExceptionMessage('invalidRequest - error: bad request: can\'t purge enabled space'); $this->drive->delete(); } + + public function testGetDriveRole(): void + { + // At the time of writing, "stable" is major version 5 of ocis. + // This functionality works with major version 6. + // When ocis major version 6 has been released as "stable" then remove this test skip. + if (getenv('OCIS_VERSION') === "stable") { + $this->markTestSkipped( + 'This test is skipped because root endpoint for drive share is not applicable for version 5 of OCIS.' + ); + }; + $role = $this->drive->getRoles(); + $this->assertContainsOnlyInstancesOf( + SharingRole::class, + $role, + "Array contains not only 'SharingRole' items" + ); + } }