summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoeland Douma <rullzer@users.noreply.github.com>2016-02-02 11:34:20 +0100
committerRoeland Douma <rullzer@users.noreply.github.com>2016-02-02 11:34:20 +0100
commit8ebdfd0e05331ed557920dac915653c309424797 (patch)
tree82b716cfbce3e78f6426b4febdca0ea1e8358c4a
parent4777f78187cb758413db1b11f11ccb9304f12482 (diff)
parentdf690cd1f2c3d49d52a0b70fdf04f386718ddb28 (diff)
downloadnextcloud-server-8ebdfd0e05331ed557920dac915653c309424797.tar.gz
nextcloud-server-8ebdfd0e05331ed557920dac915653c309424797.zip
Merge pull request #22005 from owncloud/share2_getshare_byid_as_recipient
[Share 2.0] Allow recipient to be passed in to getShareById
-rw-r--r--lib/private/share20/defaultshareprovider.php36
-rw-r--r--lib/private/share20/manager.php12
-rw-r--r--lib/public/share/imanager.php10
-rw-r--r--lib/public/share/ishareprovider.php3
-rw-r--r--tests/lib/share20/defaultshareprovidertest.php38
5 files changed, 69 insertions, 30 deletions
diff --git a/lib/private/share20/defaultshareprovider.php b/lib/private/share20/defaultshareprovider.php
index 0fa1552a1e7..ed9c03020b6 100644
--- a/lib/private/share20/defaultshareprovider.php
+++ b/lib/private/share20/defaultshareprovider.php
@@ -251,6 +251,7 @@ class DefaultShareProvider implements IShareProvider {
/**
* Get all children of this share
+ * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in
*
* @param \OCP\Share\IShare $parent
* @return IShare[]
@@ -265,12 +266,11 @@ class DefaultShareProvider implements IShareProvider {
->andWhere(
$qb->expr()->in(
'share_type',
- [
- $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER),
- $qb->expr()->literal(\OCP\Share::SHARE_TYPE_GROUP),
- $qb->expr()->literal(\OCP\Share::SHARE_TYPE_LINK),
- $qb->expr()->literal(self::SHARE_TYPE_USERGROUP),
- ]
+ $qb->createNamedParameter([
+ \OCP\Share::SHARE_TYPE_USER,
+ \OCP\Share::SHARE_TYPE_GROUP,
+ \OCP\Share::SHARE_TYPE_LINK,
+ ], IQueryBuilder::PARAM_INT_ARRAY)
)
)
->orderBy('id');
@@ -448,13 +448,9 @@ class DefaultShareProvider implements IShareProvider {
}
/**
- * Get share by id
- *
- * @param int $id
- * @return \OCP\Share\IShare
- * @throws ShareNotFound
+ * @inheritdoc
*/
- public function getShareById($id) {
+ public function getShareById($id, $recipient = null) {
$qb = $this->dbConn->getQueryBuilder();
$qb->select('*')
@@ -463,12 +459,11 @@ class DefaultShareProvider implements IShareProvider {
->andWhere(
$qb->expr()->in(
'share_type',
- [
- $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER),
- $qb->expr()->literal(\OCP\Share::SHARE_TYPE_GROUP),
- $qb->expr()->literal(\OCP\Share::SHARE_TYPE_LINK),
- $qb->expr()->literal(self::SHARE_TYPE_USERGROUP),
- ]
+ $qb->createNamedParameter([
+ \OCP\Share::SHARE_TYPE_USER,
+ \OCP\Share::SHARE_TYPE_GROUP,
+ \OCP\Share::SHARE_TYPE_LINK,
+ ], IQueryBuilder::PARAM_INT_ARRAY)
)
);
@@ -486,6 +481,11 @@ class DefaultShareProvider implements IShareProvider {
throw new ShareNotFound();
}
+ // If the recipient is set for a group share resolve to that user
+ if ($recipient !== null && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
+ $share = $this->resolveGroupShare($share, $recipient);
+ }
+
return $share;
}
diff --git a/lib/private/share20/manager.php b/lib/private/share20/manager.php
index e45fa4b40f9..3c5bd197ae8 100644
--- a/lib/private/share20/manager.php
+++ b/lib/private/share20/manager.php
@@ -612,6 +612,7 @@ class Manager implements IManager {
/**
* Delete all the children of this share
+ * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in
*
* @param \OCP\Share\IShare $share
* @return \OCP\Share\IShare[] List of deleted shares
@@ -746,14 +747,9 @@ class Manager implements IManager {
}
/**
- * Retrieve a share by the share id
- *
- * @param string $id
- * @return Share
- *
- * @throws ShareNotFound
+ * @inheritdoc
*/
- public function getShareById($id) {
+ public function getShareById($id, $recipient = null) {
if ($id === null) {
throw new ShareNotFound();
}
@@ -761,7 +757,7 @@ class Manager implements IManager {
list($providerId, $id) = $this->splitFullId($id);
$provider = $this->factory->getProvider($providerId);
- $share = $provider->getShareById($id);
+ $share = $provider->getShareById($id, $recipient);
return $share;
}
diff --git a/lib/public/share/imanager.php b/lib/public/share/imanager.php
index b2d9953e9ef..6919fea00de 100644
--- a/lib/public/share/imanager.php
+++ b/lib/public/share/imanager.php
@@ -101,14 +101,18 @@ interface IManager {
public function getSharedWith(IUser $user, $shareType, $node = null, $limit = 50, $offset = 0);
/**
- * Retrieve a share by the share id
+ * 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
- * @return Share
+ * @param IUser|null $recipient
+ * @return IShare
* @throws ShareNotFound
* @since 9.0.0
*/
- public function getShareById($id);
+ public function getShareById($id, $recipient = null);
/**
* Get the share by token possible with password
diff --git a/lib/public/share/ishareprovider.php b/lib/public/share/ishareprovider.php
index 8507462cbed..9dc56dc37ad 100644
--- a/lib/public/share/ishareprovider.php
+++ b/lib/public/share/ishareprovider.php
@@ -97,11 +97,12 @@ interface IShareProvider {
* Get share by id
*
* @param int $id
+ * @param IUser|null $recipient
* @return \OCP\Share\IShare
* @throws ShareNotFound
* @since 9.0.0
*/
- public function getShareById($id);
+ public function getShareById($id, $recipient = null);
/**
* Get shares for a given path
diff --git a/tests/lib/share20/defaultshareprovidertest.php b/tests/lib/share20/defaultshareprovidertest.php
index 28b57435e1d..4145e9e5ec6 100644
--- a/tests/lib/share20/defaultshareprovidertest.php
+++ b/tests/lib/share20/defaultshareprovidertest.php
@@ -247,6 +247,44 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals('myTarget', $share->getTarget());
}
+ public function testGetShareByIdUserGroupShare() {
+ $id = $this->addShareToDB(\OCP\Share::SHARE_TYPE_GROUP, 'group0', 'user0', 'user0', 'file', 42, 'myTarget', 31, null, null);
+ $this->addShareToDB(2, 'user1', 'user0', 'user0', 'file', 42, 'userTarget', 0, null, null, $id);
+
+ $user0 = $this->getMock('OCP\IUser');
+ $user0->method('getUID')->willReturn('user0');
+ $user1 = $this->getMock('OCP\IUser');
+ $user1->method('getUID')->willReturn('user1');
+
+ $group0 = $this->getMock('OCP\IGroup');
+ $group0->method('inGroup')->with($user1)->willReturn(true);
+
+ $node = $this->getMock('\OCP\Files\Folder');
+ $node->method('getId')->willReturn(42);
+
+ $this->rootFolder->method('getUserFolder')->with('user0')->will($this->returnSelf());
+ $this->rootFolder->method('getById')->willReturn([$node]);
+
+ $this->userManager->method('get')->will($this->returnValueMap([
+ ['user0', $user0],
+ ['user1', $user1],
+ ]));
+ $this->groupManager->method('get')->with('group0')->willReturn($group0);
+
+ $share = $this->provider->getShareById($id, $user1);
+
+ $this->assertEquals($id, $share->getId());
+ $this->assertEquals(\OCP\Share::SHARE_TYPE_GROUP, $share->getShareType());
+ $this->assertSame($group0, $share->getSharedWith());
+ $this->assertSame($user0, $share->getSharedBy());
+ $this->assertSame($user0, $share->getShareOwner());
+ $this->assertSame($node, $share->getNode());
+ $this->assertEquals(0, $share->getPermissions());
+ $this->assertEquals(null, $share->getToken());
+ $this->assertEquals(null, $share->getExpirationDate());
+ $this->assertEquals('userTarget', $share->getTarget());
+ }
+
public function testGetShareByIdLinkShare() {
$qb = $this->dbConn->getQueryBuilder();