summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2016-02-02 13:34:50 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2016-02-02 13:34:50 +0100
commitce053b980860070957bedb13e6fcd9d45fe50b9b (patch)
tree4d31c74f75d43629b815d4184e3f93be46f1cee1 /lib
parent2d1d89ee29e49412192b051412755610e0538198 (diff)
parent2316cb1f8b9704621b47e6eb1c2cbf30c06c552d (diff)
downloadnextcloud-server-ce053b980860070957bedb13e6fcd9d45fe50b9b.tar.gz
nextcloud-server-ce053b980860070957bedb13e6fcd9d45fe50b9b.zip
Merge pull request #22013 from owncloud/share2_moveshare
[Share 2.0] Allow moving of shares
Diffstat (limited to 'lib')
-rw-r--r--lib/private/share20/defaultshareprovider.php58
-rw-r--r--lib/private/share20/manager.php19
-rw-r--r--lib/public/share/imanager.php20
-rw-r--r--lib/public/share/ishareprovider.php13
4 files changed, 107 insertions, 3 deletions
diff --git a/lib/private/share20/defaultshareprovider.php b/lib/private/share20/defaultshareprovider.php
index ed9c03020b6..224dddf4019 100644
--- a/lib/private/share20/defaultshareprovider.php
+++ b/lib/private/share20/defaultshareprovider.php
@@ -20,6 +20,7 @@
*/
namespace OC\Share20;
+use OCP\Files\File;
use OCP\Share\IShareProvider;
use OC\Share20\Exception\InvalidShare;
use OC\Share20\Exception\ProviderException;
@@ -384,6 +385,63 @@ class DefaultShareProvider implements IShareProvider {
}
/**
+ * @inheritdoc
+ */
+ public function move(\OCP\Share\IShare $share, IUser $recipient) {
+ if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
+ // Just update the target
+ $qb = $this->dbConn->getQueryBuilder();
+ $qb->update('share')
+ ->set('file_target', $qb->createNamedParameter($share->getTarget()))
+ ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
+ ->execute();
+
+ } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
+
+ // Check if there is a usergroup share
+ $qb = $this->dbConn->getQueryBuilder();
+ $stmt = $qb->select('id')
+ ->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())))
+ ->setMaxResults(1)
+ ->execute();
+
+ $data = $stmt->fetch();
+ $stmt->closeCursor();
+
+ if ($data === false) {
+ // No usergroup share yet. Create one.
+ $qb = $this->dbConn->getQueryBuilder();
+ $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($share->getNode() instanceof File ? 'file' : 'folder'),
+ 'item_source' => $qb->createNamedParameter($share->getNode()->getId()),
+ 'file_source' => $qb->createNamedParameter($share->getNode()->getId()),
+ 'file_target' => $qb->createNamedParameter($share->getTarget()),
+ 'permissions' => $qb->createNamedParameter($share->getPermissions()),
+ 'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()),
+ ])->execute();
+ } else {
+ // Already a usergroup share. Update it.
+ $qb = $this->dbConn->getQueryBuilder();
+ $qb->update('share')
+ ->set('file_target', $qb->createNamedParameter($share->getTarget()))
+ ->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id'])))
+ ->execute();
+ }
+ }
+
+ return $share;
+ }
+
+ /**
* Get all shares by the given user. Sharetype and path can be used to filter.
*
* @param IUser $user
diff --git a/lib/private/share20/manager.php b/lib/private/share20/manager.php
index ac82fe05df4..b22b81bb404 100644
--- a/lib/private/share20/manager.php
+++ b/lib/private/share20/manager.php
@@ -715,6 +715,25 @@ class Manager implements IManager {
}
/**
+ * @inheritdoc
+ */
+ public function moveShare(\OCP\Share\IShare $share, IUser $recipient) {
+ if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
+ throw new \InvalidArgumentException('Can\'t change target of link share');
+ }
+
+ if (($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && $share->getSharedWith() !== $recipient) ||
+ ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP && !$share->getSharedWith()->inGroup($recipient))) {
+ throw new \InvalidArgumentException('Invalid recipient');
+ }
+
+ list($providerId, ) = $this->splitFullId($share->getId());
+ $provider = $this->factory->getProvider($providerId);
+
+ $provider->move($share, $recipient);
+ }
+
+ /**
* Get shares shared by (initiated) by the provided user.
*
* @param IUser $user
diff --git a/lib/public/share/imanager.php b/lib/public/share/imanager.php
index 6919fea00de..15b9f34764e 100644
--- a/lib/public/share/imanager.php
+++ b/lib/public/share/imanager.php
@@ -37,13 +37,15 @@ interface IManager {
* Create a Share
*
* @param IShare $share
- * @return Share The share object
+ * @return IShare The share object
* @since 9.0.0
*/
public function createShare(IShare $share);
/**
- * Update a 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
@@ -73,6 +75,18 @@ interface IManager {
public function deleteFromSelf(IShare $share, IUser $recipient);
/**
+ * 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 IUser $recipient
+ * @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, IUser $recipient);
+
+ /**
* Get shares shared by (initiated) by the provided user.
*
* @param IUser $user
@@ -118,7 +132,7 @@ interface IManager {
* Get the share by token possible with password
*
* @param string $token
- * @return Share
+ * @return IShare
* @throws ShareNotFound
* @since 9.0.0
*/
diff --git a/lib/public/share/ishareprovider.php b/lib/public/share/ishareprovider.php
index 9dc56dc37ad..42a2881718e 100644
--- a/lib/public/share/ishareprovider.php
+++ b/lib/public/share/ishareprovider.php
@@ -80,6 +80,19 @@ interface IShareProvider {
public function deleteFromSelf(\OCP\Share\IShare $share, IUser $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 IUser $recipient
+ * @return \OCP\Share\IShare
+ * @since 9.0.0
+ */
+ public function move(\OCP\Share\IShare $share, IUser $recipient);
+
+ /**
* Get all shares by the given user
*
* @param IUser $user