Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 131 additions & 0 deletions src/Drive.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@
use OpenAPI\Client\Model\Drive as ApiDrive;
use OpenAPI\Client\Model\DriveUpdate;
use OpenAPI\Client\Model\DriveItem;
use OpenAPI\Client\Model\DriveItemCreateLink;
use OpenAPI\Client\Model\SharingLinkType;
use OpenAPI\Client\Model\DriveRecipient;
use OpenAPI\Client\Model\DriveItemInvite;
use OpenAPI\Client\Model\DriveRecipient;
use OpenAPI\Client\Model\OdataError;
use OpenAPI\Client\Model\Permission;
use OpenAPI\Client\Model\SharingLink as ApiSharingLink;
use OpenAPI\Client\Model\Permission;
use OpenAPI\Client\Model\Quota;
use Owncloud\OcisPhpSdk\Exception\BadRequestException;
use Owncloud\OcisPhpSdk\Exception\ConflictException;
Expand Down Expand Up @@ -920,6 +925,132 @@ public function setPermissionExpiration(string $permissionId, ?\DateTimeImmutabl
return $this->updatePermission($permissionId, $apiPermission);
}

/**
* @param User $recipient
* @param string $role
* @param string|null $password
* @param string|null $displayName
* @param boolean|null $quickLink
* @param \DateTimeImmutable|null $expiration
* @return ShareLink
*/
public function createLink($recipient, string $role, ?string $password = null, ?string $displayName = null, ?bool $quickLink = false, ?\DateTimeImmutable $expiration = null): ShareLink
{
$driveItemCreateLink = [];
$recipientData = [];

$driveItemCreateLink['type'] = SharingLinkType::from($role); // get from enum
if ($expiration !== null) {
$expirationMutable = \DateTime::createFromImmutable($expiration);
$driveItemCreateLink['expiration_date_time'] = $expirationMutable;
}
if(isset($password)) {
$driveItemCreateLink['password'] = $password;
}
if(isset($displayName)) {
$driveItemCreateLink['display_name'] = $displayName;
}
$driveItemCreateLink['at_libre_graph_quick_link'] = $quickLink;

$recipientData['object_id'] = $recipient->getId();
$driveItemCreateLink['recipients'][] = new DriveRecipient($recipientData);

if (array_key_exists('drivesRootApi', $this->connectionConfig)) {
$apiInstance = $this->connectionConfig['drivesRootApi'];
} else {
$guzzle = new Client(
Ocis::createGuzzleConfig($this->connectionConfig, $this->accessToken)
);
$apiInstance = new DrivesRootApi(
$guzzle,
$this->graphApiConfig
);
}

$inviteData = new DriveItemCreateLink($driveItemCreateLink);
try {
$permissions = $apiInstance->createLinkSpaceRoot($this->getId(), $inviteData);
} catch (ApiException $e) {
throw ExceptionHelper::getHttpErrorException($e);
}
if ($permissions instanceof OdataError) {
throw new InvalidResponseException(
"invite returned an OdataError - " . $permissions->getError()
);
}
if(isset($password)) {
$permissions->setHasPassword(true);
} else {
$permissions->setHasPassword(false);
}

return new ShareLink(
$permissions,
$this->getId(),
$this->getId(),
$this->connectionConfig,
$this->serviceUrl,
$this->accessToken
);
}

/**
* @param ShareLink $recipient
* @param string $role
* @param string|null $password
* @param string|null $displayName
* @param boolean|null $quickLink
* @param \DateTimeImmutable|null $expiration
* @return ShareLink
*/
public function updateLink($share, string $type, ?string $displayName = null, ?bool $quickLink = false, ?\DateTimeImmutable $expiration = null): ShareLink
{
$shareLink=new ApiSharingLink();
$permissions=new Permission();

// $permissions->set;
$shareLink->setType(SharingLinkType::EDIT);

$permissions->setLink($shareLink);

if (array_key_exists('drivesRootApi', $this->connectionConfig)) {
$apiInstance = $this->connectionConfig['drivesRootApi'];
} else {
$guzzle = new Client(
Ocis::createGuzzleConfig($this->connectionConfig, $this->accessToken)
);
$apiInstance = new DrivesRootApi(
$guzzle,
$this->graphApiConfig
);
}

var_dump($this->accessToken);
try {
$permissions = $apiInstance->updatePermissionSpaceRoot($this->getId(), $share->getPermissionId(),$permissions);
} catch (ApiException $e) {
throw ExceptionHelper::getHttpErrorException($e);
}
if ($permissions instanceof OdataError) {
throw new InvalidResponseException(
"invite returned an OdataError - " . $permissions->getError()
);
}
if(isset($password)) {
$permissions->setHasPassword(true);
} else {
$permissions->setHasPassword(false);
}
return new ShareLink(
$permissions,
$this->getId(),
$this->getId(),
$this->connectionConfig,
$this->serviceUrl,
$this->accessToken
);
}

/**
* @param array<string> $tags
* @todo This function is not implemented yet! Place, name and signature of the function might change!
Expand Down
1 change: 1 addition & 0 deletions src/OcisResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use OpenAPI\Client\Api\DrivesApi; // @phan-suppress-current-line PhanUnreferencedUseNormal it's used in a comment
use OpenAPI\Client\Api\DrivesPermissionsApi;
use OpenAPI\Client\Api\TagsApi;
use OpenAPI\Client\Api\DrivesRootApi;
use OpenAPI\Client\ApiException;
use OpenAPI\Client\Configuration;
use OpenAPI\Client\Model\DriveItemCreateLink;
Expand Down
4 changes: 4 additions & 0 deletions src/Share.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,8 @@ public function setExpiration(?\DateTimeImmutable $expiration): bool
$this->apiPermission = $apiPermission;
return true;
}

function getPermission() : ApiPermission {
return $this->apiPermission;
}
}
Loading