summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@owncloud.com>2016-01-21 14:31:09 +0100
committerRoeland Jago Douma <rullzer@owncloud.com>2016-01-22 15:06:50 +0100
commita6600e95dc73010822793f6c4aebad9e6c13e07b (patch)
tree43bb139bec8d804c51b5c3d6a27d90ff8cbdcbbf /lib/private
parent2d569d92eb081b0272872307ac36368e07370d9c (diff)
downloadnextcloud-server-a6600e95dc73010822793f6c4aebad9e6c13e07b.tar.gz
nextcloud-server-a6600e95dc73010822793f6c4aebad9e6c13e07b.zip
[Share 2.0] Add deleteFromSelf method
This allows recipient to delete a share. For user shares this is the same as deleting (at least for now). But for group shares this means creating a new share with type 2. With permissions set to 0.
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/share20/defaultshareprovider.php79
-rw-r--r--lib/private/share20/ishareprovider.php9
-rw-r--r--lib/private/share20/manager.php16
3 files changed, 104 insertions, 0 deletions
diff --git a/lib/private/share20/defaultshareprovider.php b/lib/private/share20/defaultshareprovider.php
index 5d768a4bc4b..8c193c437d3 100644
--- a/lib/private/share20/defaultshareprovider.php
+++ b/lib/private/share20/defaultshareprovider.php
@@ -21,6 +21,7 @@
namespace OC\Share20;
use OC\Share20\Exception\InvalidShare;
+use OC\Share20\Exception\ProviderException;
use OC\Share20\Exception\ShareNotFound;
use OC\Share20\Exception\BackendError;
use OCP\Files\NotFoundException;
@@ -242,6 +243,84 @@ class DefaultShareProvider implements IShareProvider {
}
/**
+ * Unshare a share from the recipient. If this is a group share
+ * this means we need a special entry in the share db.
+ *
+ * @param IShare $share
+ * @param IUser $recipient
+ * @throws BackendError
+ * @throws ProviderException
+ */
+ public function deleteFromSelf(IShare $share, IUser $recipient) {
+ if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
+
+ /** @var IGroup $group */
+ $group = $share->getSharedWith();
+
+ if (!$group->inGroup($recipient)) {
+ throw new ProviderException('Recipient not in receiving group');
+ }
+
+ // Try to fetch user specific share
+ $qb = $this->dbConn->getQueryBuilder();
+ $stmt = $qb->select('*')
+ ->from('share')
+ ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
+ ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient->getUID())))
+ ->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
+ ->execute();
+
+ $data = $stmt->fetch();
+
+ /*
+ * Check if there already is a user specific group share.
+ * If there is update it (if required).
+ */
+ if ($data === false) {
+ $qb = $this->dbConn->getQueryBuilder();
+
+ $type = $share->getPath() instanceof \OCP\Files\File ? 'file' : 'folder';
+
+ //Insert new share
+ $qb->insert('share')
+ ->values([
+ 'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP),
+ 'share_with' => $qb->createNamedParameter($recipient->getUID()),
+ 'uid_owner' => $qb->createNamedParameter($share->getShareOwner()->getUID()),
+ 'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()->getUID()),
+ 'parent' => $qb->createNamedParameter($share->getId()),
+ 'item_type' => $qb->createNamedParameter($type),
+ 'item_source' => $qb->createNamedParameter($share->getPath()->getId()),
+ 'file_source' => $qb->createNamedParameter($share->getPath()->getId()),
+ 'file_target' => $qb->createNamedParameter($share->getTarget()),
+ 'permissions' => $qb->createNamedParameter(0),
+ 'stime' => $qb->createNamedParameter($share->getSharetime()),
+ ])->execute();
+
+ } else if ($data['permissions'] !== 0) {
+
+ // Update existing usergroup share
+ $qb = $this->dbConn->getQueryBuilder();
+ $qb->update('share')
+ ->set('permissions', $qb->createNamedParameter(0))
+ ->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id'])))
+ ->execute();
+ }
+
+ } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
+
+ if ($share->getSharedWith() !== $recipient) {
+ throw new ProviderException('Recipient does not match');
+ }
+
+ // We can just delete user and link shares
+ $this->delete($share);
+ } else {
+ throw new ProviderException('Invalid shareType');
+ }
+ }
+
+ /**
* Get all shares by the given user. Sharetype and path can be used to filter.
*
* @param IUser $user
diff --git a/lib/private/share20/ishareprovider.php b/lib/private/share20/ishareprovider.php
index 36d0f10c7f1..17ee4abb9a8 100644
--- a/lib/private/share20/ishareprovider.php
+++ b/lib/private/share20/ishareprovider.php
@@ -58,6 +58,15 @@ interface IShareProvider {
public function delete(IShare $share);
/**
+ * Unshare a file from self as recipient.
+ * This may require special handling.
+ *
+ * @param IShare $share
+ * @param IUser $recipient
+ */
+ public function deleteFromSelf(IShare $share, IUser $recipient);
+
+ /**
* Get all shares by the given user
*
* @param IUser $user
diff --git a/lib/private/share20/manager.php b/lib/private/share20/manager.php
index 3935307b977..ea6463c745c 100644
--- a/lib/private/share20/manager.php
+++ b/lib/private/share20/manager.php
@@ -607,6 +607,22 @@ class Manager {
/**
+ * 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 IUser $recipient
+ */
+ public function deleteFromSelf(IShare $share, IUser $recipient) {
+ list($providerId, $id) = $this->splitFullId($share->getId());
+ $provider = $this->factory->getProvider($providerId);
+
+ $provider->deleteFromSelf($share, $recipient);
+ }
+
+ /**
* Get shares shared by (initiated) by the provided user.
*
* @param IUser $user