diff options
author | Roeland Jago Douma <rullzer@owncloud.com> | 2016-03-23 14:20:02 +0100 |
---|---|---|
committer | Roeland Jago Douma <rullzer@owncloud.com> | 2016-03-30 22:55:03 +0200 |
commit | d883b877d134813781094c885c9f076524022184 (patch) | |
tree | d45204f1da905354a5a329c766b820f7ec5adc8f /lib/public/Share | |
parent | 2f4294e7819c5cb298407b7e6101fd4f076969f9 (diff) | |
download | nextcloud-server-d883b877d134813781094c885c9f076524022184.tar.gz nextcloud-server-d883b877d134813781094c885c9f076524022184.zip |
Move OCP\Share over to PSR-4
Touching the code so moving it over to PSR-4
Diffstat (limited to 'lib/public/Share')
-rw-r--r-- | lib/public/Share/Exceptions/GenericShareException.php | 47 | ||||
-rw-r--r-- | lib/public/Share/Exceptions/IllegalIDChangeException.php | 27 | ||||
-rw-r--r-- | lib/public/Share/Exceptions/ShareNotFound.php | 32 | ||||
-rw-r--r-- | lib/public/Share/IManager.php | 247 | ||||
-rw-r--r-- | lib/public/Share/IProviderFactory.php | 57 | ||||
-rw-r--r-- | lib/public/Share/IShare.php | 326 | ||||
-rw-r--r-- | lib/public/Share/IShareProvider.php | 149 |
7 files changed, 885 insertions, 0 deletions
diff --git a/lib/public/Share/Exceptions/GenericShareException.php b/lib/public/Share/Exceptions/GenericShareException.php new file mode 100644 index 00000000000..b32c2f26574 --- /dev/null +++ b/lib/public/Share/Exceptions/GenericShareException.php @@ -0,0 +1,47 @@ +<?php +/** + * @author Lukas Reschke <lukas@owncloud.com> + * @author Roeland Jago Douma <rullzer@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ +namespace OCP\Share\Exceptions; +use OC\HintException; + +/** + * Class GenericEncryptionException + * + * @package OCP\Share\Exceptions + * @since 9.0.0 + */ +class GenericShareException extends HintException { + + /** + * @param string $message + * @param string $hint + * @param int $code + * @param \Exception $previous + * @since 9.0.0 + */ + public function __construct($message = '', $hint = '', $code = 0, \Exception $previous = null) { + if (empty($message)) { + $message = 'Unspecified share exception'; + } + parent::__construct($message, $hint, $code, $previous); + } + +} diff --git a/lib/public/Share/Exceptions/IllegalIDChangeException.php b/lib/public/Share/Exceptions/IllegalIDChangeException.php new file mode 100644 index 00000000000..6cd887c386b --- /dev/null +++ b/lib/public/Share/Exceptions/IllegalIDChangeException.php @@ -0,0 +1,27 @@ +<?php +/** + * @author Roeland Jago Douma <rullzer@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ +namespace OCP\Share\Exceptions; + +/** + * Exception for illegal attempts to modify an id of a share + * @since 9.1.0 + */ +class IllegalIDChangeException extends GenericShareException {} diff --git a/lib/public/Share/Exceptions/ShareNotFound.php b/lib/public/Share/Exceptions/ShareNotFound.php new file mode 100644 index 00000000000..96e7c096492 --- /dev/null +++ b/lib/public/Share/Exceptions/ShareNotFound.php @@ -0,0 +1,32 @@ +<?php +/** + * @author Roeland Jago Douma <rullzer@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace OCP\Share\Exceptions; + +/** + * Class ShareNotFound + * + * @package OCP\Share\Exceptions + * @since 9.0.0 + */ +class ShareNotFound extends GenericShareException { + +} diff --git a/lib/public/Share/IManager.php b/lib/public/Share/IManager.php new file mode 100644 index 00000000000..64e5b554de9 --- /dev/null +++ b/lib/public/Share/IManager.php @@ -0,0 +1,247 @@ +<?php +/** + * @author Roeland Jago Douma <rullzer@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace OCP\Share; + +use OCP\Files\Node; +use OCP\IUser; + +use OCP\Share\Exceptions\ShareNotFound; + +/** + * Interface IManager + * + * @package OCP\Share + * @since 9.0.0 + */ +interface IManager { + + /** + * Create a Share + * + * @param IShare $share + * @return IShare The share object + * @since 9.0.0 + */ + public function createShare(IShare $share); + + /** + * Update a share. + * The target of the share can't be changed this way: use moveShare + * The share can't be removed this way (permission 0): use deleteShare + * + * @param IShare $share + * @return IShare The share object + * @since 9.0.0 + */ + public function updateShare(IShare $share); + + /** + * Delete a share + * + * @param IShare $share + * @throws ShareNotFound + * @since 9.0.0 + */ + public function deleteShare(IShare $share); + + /** + * Unshare a file as the recipient. + * This can be different from a regular delete for example when one of + * the users in a groups deletes that share. But the provider should + * handle this. + * + * @param IShare $share + * @param string $recipientId + * @since 9.0.0 + */ + public function deleteFromSelf(IShare $share, $recipientId); + + /** + * Move the share as a recipient of the share. + * This is updating the share target. So where the recipient has the share mounted. + * + * @param IShare $share + * @param string $recipientId + * @return IShare + * @throws \InvalidArgumentException If $share is a link share or the $recipient does not match + * @since 9.0.0 + */ + public function moveShare(IShare $share, $recipientId); + + /** + * Get shares shared by (initiated) by the provided user. + * + * @param string $userId + * @param int $shareType + * @param Node|null $path + * @param bool $reshares + * @param int $limit The maximum number of returned results, -1 for all results + * @param int $offset + * @return IShare[] + * @since 9.0.0 + */ + public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0); + + /** + * Get shares shared with $user. + * Filter by $node if provided + * + * @param string $userId + * @param int $shareType + * @param Node|null $node + * @param int $limit The maximum number of shares returned, -1 for all + * @param int $offset + * @return IShare[] + * @since 9.0.0 + */ + public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0); + + /** + * Retrieve a share by the share id. + * If the recipient is set make sure to retrieve the file for that user. + * This makes sure that if a user has moved/deleted a group share this + * is reflected. + * + * @param string $id + * @param IUser|null $recipient + * @return IShare + * @throws ShareNotFound + * @since 9.0.0 + */ + public function getShareById($id, $recipient = null); + + /** + * Get the share by token possible with password + * + * @param string $token + * @return IShare + * @throws ShareNotFound + * @since 9.0.0 + */ + public function getShareByToken($token); + + /** + * Verify the password of a public share + * + * @param IShare $share + * @param string $password + * @return bool + * @since 9.0.0 + */ + public function checkPassword(IShare $share, $password); + + /** + * Instantiates a new share object. This is to be passed to + * createShare. + * + * @return IShare + * @since 9.0.0 + */ + public function newShare(); + + /** + * Is the share API enabled + * + * @return bool + * @since 9.0.0 + */ + public function shareApiEnabled(); + + /** + * Is public link sharing enabled + * + * @return bool + * @since 9.0.0 + */ + public function shareApiAllowLinks(); + + /** + * Is password on public link requires + * + * @return bool + * @since 9.0.0 + */ + public function shareApiLinkEnforcePassword(); + + /** + * Is default expire date enabled + * + * @return bool + * @since 9.0.0 + */ + public function shareApiLinkDefaultExpireDate(); + + /** + * Is default expire date enforced + *` + * @return bool + * @since 9.0.0 + */ + public function shareApiLinkDefaultExpireDateEnforced(); + + /** + * Number of default expire days + * + * @return int + * @since 9.0.0 + */ + public function shareApiLinkDefaultExpireDays(); + + /** + * Allow public upload on link shares + * + * @return bool + * @since 9.0.0 + */ + public function shareApiLinkAllowPublicUpload(); + + /** + * check if user can only share with group members + * @return bool + * @since 9.0.0 + */ + public function shareWithGroupMembersOnly(); + + /** + * Check if users can share with groups + * @return bool + * @since 9.0.1 + */ + public function allowGroupSharing(); + + /** + * Check if sharing is disabled for the given user + * + * @param string $userId + * @return bool + * @since 9.0.0 + */ + public function sharingDisabledForUser($userId); + + /** + * Check if outgoing server2server shares are allowed + * @return bool + * @since 9.0.0 + */ + public function outgoingServer2ServerSharesAllowed(); + +} diff --git a/lib/public/Share/IProviderFactory.php b/lib/public/Share/IProviderFactory.php new file mode 100644 index 00000000000..3a8baccf33b --- /dev/null +++ b/lib/public/Share/IProviderFactory.php @@ -0,0 +1,57 @@ +<?php +/** + * @author Roeland Jago Douma <rullzer@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace OCP\Share; + +use OC\Share20\Exception\ProviderException; +use OCP\IServerContainer; + +/** + * Interface IProviderFactory + * + * @package OC\Share20 + * @since 9.0.0 + */ +interface IProviderFactory { + + /** + * IProviderFactory constructor. + * @param IServerContainer $serverContainer + * @since 9.0.0 + */ + public function __construct(IServerContainer $serverContainer); + + /** + * @param string $id + * @return IShareProvider + * @throws ProviderException + * @since 9.0.0 + */ + public function getProvider($id); + + /** + * @param int $shareType + * @return IShareProvider + * @throws ProviderException + * @since 9.0.0 + */ + public function getProviderForType($shareType); +} diff --git a/lib/public/Share/IShare.php b/lib/public/Share/IShare.php new file mode 100644 index 00000000000..ee71715f436 --- /dev/null +++ b/lib/public/Share/IShare.php @@ -0,0 +1,326 @@ +<?php +/** + * @author Roeland Jago Douma <rullzer@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace OCP\Share; + +use OCP\Files\File; +use OCP\Files\Folder; +use OCP\Files\Node; +use OCP\Files\NotFoundException; +use OCP\Share\Exceptions\IllegalIDChangeException; + +/** + * Interface IShare + * + * @package OCP\Share + * @since 9.0.0 + */ +interface IShare { + + /** + * Set the internal id of the share + * It is only allowed to set the internal id of a share once. + * Attempts to override the internal id will result in an IllegalIDChangeException + * + * @param string $id + * @return \OCP\Share\IShare + * @throws IllegalIDChangeException + * @throws \InvalidArgumentException + * @since 9.1.0 + */ + public function setId($id); + + /** + * Get the internal id of the share. + * + * @return string + * @since 9.0.0 + */ + public function getId(); + + /** + * Get the full share id. This is the <providerid>:<internalid>. + * The full id is unique in the system. + * + * @return string + * @since 9.0.0 + * @throws \UnexpectedValueException If the fullId could not be constructed + */ + public function getFullId(); + + /** + * Set the provider id of the share + * It is only allowed to set the provider id of a share once. + * Attempts to override the provider id will result in an IllegalIDChangeException + * + * @param string $id + * @return \OCP\Share\IShare + * @throws IllegalIDChangeException + * @throws \InvalidArgumentException + * @since 9.1.0 + */ + public function setProviderId($id); + + /** + * Set the node of the file/folder that is shared + * + * @param Node $node + * @return \OCP\Share\IShare The modified object + * @since 9.0.0 + */ + public function setNode(Node $node); + + /** + * Get the node of the file/folder that is shared + * + * @return File|Folder + * @since 9.0.0 + * @throws NotFoundException + */ + public function getNode(); + + /** + * Set file id for lazy evaluation of the node + * @param int $fileId + * @return \OCP\Share\IShare The modified object + * @since 9.0.0 + */ + public function setNodeId($fileId); + + /** + * Get the fileid of the node of this share + * @return int + * @since 9.0.0 + * @throws NotFoundException + */ + public function getNodeId(); + + /** + * Set the type of node (file/folder) + * + * @param string $type + * @return \OCP\Share\IShare The modified object + * @since 9.0.0 + */ + public function setNodeType($type); + + /** + * Get the type of node (file/folder) + * + * @return string + * @since 9.0.0 + * @throws NotFoundException + */ + public function getNodeType(); + + /** + * Set the shareType + * + * @param int $shareType + * @return \OCP\Share\IShare The modified object + * @since 9.0.0 + */ + public function setShareType($shareType); + + /** + * Get the shareType + * + * @return int + * @since 9.0.0 + */ + public function getShareType(); + + /** + * Set the receiver of this share. + * + * @param string $sharedWith + * @return \OCP\Share\IShare The modified object + * @since 9.0.0 + */ + public function setSharedWith($sharedWith); + + /** + * Get the receiver of this share. + * + * @return string + * @since 9.0.0 + */ + public function getSharedWith(); + + /** + * Set the permissions. + * See \OCP\Constants::PERMISSION_* + * + * @param int $permissions + * @return \OCP\Share\IShare The modified object + * @since 9.0.0 + */ + public function setPermissions($permissions); + + /** + * Get the share permissions + * See \OCP\Constants::PERMISSION_* + * + * @return int + * @since 9.0.0 + */ + public function getPermissions(); + + /** + * Set the expiration date + * + * @param \DateTime $expireDate + * @return \OCP\Share\IShare The modified object + * @since 9.0.0 + */ + public function setExpirationDate($expireDate); + + /** + * Get the expiration date + * + * @return \DateTime + * @since 9.0.0 + */ + public function getExpirationDate(); + + /** + * Set the sharer of the path. + * + * @param string $sharedBy + * @return \OCP\Share\IShare The modified object + * @since 9.0.0 + */ + public function setSharedBy($sharedBy); + + /** + * Get share sharer + * + * @return string + * @since 9.0.0 + */ + public function getSharedBy(); + + /** + * Set the original share owner (who owns the path that is shared) + * + * @param string $shareOwner + * @return \OCP\Share\IShare The modified object + * @since 9.0.0 + */ + public function setShareOwner($shareOwner); + + /** + * Get the original share owner (who owns the path that is shared) + * + * @return string + * @since 9.0.0 + */ + public function getShareOwner(); + + /** + * Set the password for this share. + * When the share is passed to the share manager to be created + * or updated the password will be hashed. + * + * @param string $password + * @return \OCP\Share\IShare The modified object + * @since 9.0.0 + */ + public function setPassword($password); + + /** + * Get the password of this share. + * If this share is obtained via a shareprovider the password is + * hashed. + * + * @return string + * @since 9.0.0 + */ + public function getPassword(); + + /** + * Set the public link token. + * + * @param string $token + * @return \OCP\Share\IShare The modified object + * @since 9.0.0 + */ + public function setToken($token); + + /** + * Get the public link token. + * + * @return string + * @since 9.0.0 + */ + public function getToken(); + + /** + * Set the target path of this share relative to the recipients user folder. + * + * @param string $target + * @return \OCP\Share\IShare The modified object + * @since 9.0.0 + */ + public function setTarget($target); + + /** + * Get the target path of this share relative to the recipients user folder. + * + * @return string + * @since 9.0.0 + */ + public function getTarget(); + + /** + * Set the time this share was created + * + * @param \DateTime $shareTime + * @return \OCP\Share\IShare The modified object + * @since 9.0.0 + */ + public function setShareTime(\DateTime $shareTime); + + /** + * Get the timestamp this share was created + * + * @return \DateTime + * @since 9.0.0 + */ + public function getShareTime(); + + /** + * Set if the recipient is informed by mail about the share. + * + * @param bool $mailSend + * @return \OCP\Share\IShare The modified object + * @since 9.0.0 + */ + public function setMailSend($mailSend); + + /** + * Get if the recipient informed by mail about the share. + * + * @return bool + * @since 9.0.0 + */ + public function getMailSend(); +} diff --git a/lib/public/Share/IShareProvider.php b/lib/public/Share/IShareProvider.php new file mode 100644 index 00000000000..d00b9da7b59 --- /dev/null +++ b/lib/public/Share/IShareProvider.php @@ -0,0 +1,149 @@ +<?php +/** + * @author Roeland Jago Douma <rullzer@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace OCP\Share; + +use OCP\Share\Exceptions\ShareNotFound; +use OCP\Files\Node; + +/** + * Interface IShareProvider + * + * @package OCP\Share + * @since 9.0.0 + */ +interface IShareProvider { + + /** + * Return the identifier of this provider. + * + * @return string Containing only [a-zA-Z0-9] + * @since 9.0.0 + */ + public function identifier(); + + /** + * Create a share + * + * @param \OCP\Share\IShare $share + * @return \OCP\Share\IShare The share object + * @since 9.0.0 + */ + public function create(\OCP\Share\IShare $share); + + /** + * Update a share + * + * @param \OCP\Share\IShare $share + * @return \OCP\Share\IShare The share object + * @since 9.0.0 + */ + public function update(\OCP\Share\IShare $share); + + /** + * Delete a share + * + * @param \OCP\Share\IShare $share + * @since 9.0.0 + */ + public function delete(\OCP\Share\IShare $share); + + /** + * Unshare a file from self as recipient. + * This may require special handling. If a user unshares a group + * share from their self then the original group share should still exist. + * + * @param \OCP\Share\IShare $share + * @param string $recipient UserId of the recipient + * @since 9.0.0 + */ + public function deleteFromSelf(\OCP\Share\IShare $share, $recipient); + + /** + * Move a share as a recipient. + * This is updating the share target. Thus the mount point of the recipient. + * This may require special handling. If a user moves a group share + * the target should only be changed for them. + * + * @param \OCP\Share\IShare $share + * @param string $recipient userId of recipient + * @return \OCP\Share\IShare + * @since 9.0.0 + */ + public function move(\OCP\Share\IShare $share, $recipient); + + /** + * Get all shares by the given user + * + * @param string $userId + * @param int $shareType + * @param Node|null $node + * @param bool $reshares Also get the shares where $user is the owner instead of just the shares where $user is the initiator + * @param int $limit The maximum number of shares to be returned, -1 for all shares + * @param int $offset + * @return \OCP\Share\IShare[] + * @since 9.0.0 + */ + public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset); + + /** + * Get share by id + * + * @param int $id + * @param string|null $recipientId + * @return \OCP\Share\IShare + * @throws ShareNotFound + * @since 9.0.0 + */ + public function getShareById($id, $recipientId = null); + + /** + * Get shares for a given path + * + * @param Node $path + * @return \OCP\Share\IShare[] + * @since 9.0.0 + */ + public function getSharesByPath(Node $path); + + /** + * Get shared with the given user + * + * @param string $userId get shares where this user is the recipient + * @param int $shareType + * @param Node|null $node + * @param int $limit The max number of entries returned, -1 for all + * @param int $offset + * @return \OCP\Share\IShare[] + * @since 9.0.0 + */ + public function getSharedWith($userId, $shareType, $node, $limit, $offset); + + /** + * Get a share by token + * + * @param string $token + * @return \OCP\Share\IShare + * @throws ShareNotFound + * @since 9.0.0 + */ + public function getShareByToken($token); +} |