]> source.dussan.org Git - nextcloud-server.git/commitdiff
Tags.php and the old sharing mechanism
authorMorris Jobke <hey@morrisjobke.de>
Wed, 29 Apr 2020 18:40:45 +0000 (20:40 +0200)
committerMorris Jobke <hey@morrisjobke.de>
Mon, 6 Jul 2020 12:12:12 +0000 (14:12 +0200)
The old sharing mechanism isn't working anymore, because it was replaced by Share 2.0. Also it was nowhere used so this removes the code paths and reduces complexity.

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
lib/private/Share/Share.php
lib/private/TagManager.php
lib/private/Tags.php
lib/public/ITagManager.php
tests/lib/TagsTest.php

index c624f24312377f3165a9961d416ac04de5219b27..b37d167d8967f35ebda206d5a271f28cf4ce559c 100644 (file)
@@ -520,60 +520,6 @@ class Share extends Constants {
                return false;
        }
 
-       /**
-        * Get the owners of items shared with a user.
-        *
-        * @param string $user The user the items are shared with.
-        * @param string $type The type of the items shared with the user.
-        * @param boolean $includeCollections Include collection item types (optional)
-        * @param boolean $includeOwner include owner in the list of users the item is shared with (optional)
-        * @return array
-        * @deprecated TESTS ONLY - this methods is only used by tests
-        * called like this:
-        * \OC\Share\Share::getSharedItemsOwners($this->user, $this->type, true)
-        */
-       public static function getSharedItemsOwners($user, $type, $includeCollections = false, $includeOwner = false) {
-               // First, we find out if $type is part of a collection (and if that collection is part of
-               // another one and so on).
-               $collectionTypes = [];
-               if (!$includeCollections || !$collectionTypes = self::getCollectionItemTypes($type)) {
-                       $collectionTypes[] = $type;
-               }
-
-               // Of these collection types, along with our original $type, we make a
-               // list of the ones for which a sharing backend has been registered.
-               // FIXME: Ideally, we wouldn't need to nest getItemsSharedWith in this loop but just call it
-               // with its $includeCollections parameter set to true. Unfortunately, this fails currently.
-               $allMaybeSharedItems = [];
-               foreach ($collectionTypes as $collectionType) {
-                       if (isset(self::$backends[$collectionType])) {
-                               $allMaybeSharedItems[$collectionType] = self::getItemsSharedWithUser(
-                                       $collectionType,
-                                       $user,
-                                       self::FORMAT_NONE
-                               );
-                       }
-               }
-
-               $owners = [];
-               if ($includeOwner) {
-                       $owners[] = $user;
-               }
-
-               // We take a look at all shared items of the given $type (or of the collections it is part of)
-               // and find out their owners. Then, we gather the tags for the original $type from all owners,
-               // and return them as elements of a list that look like "Tag (owner)".
-               foreach ($allMaybeSharedItems as $collectionType => $maybeSharedItems) {
-                       foreach ($maybeSharedItems as $sharedItem) {
-                               if (isset($sharedItem['id'])) { //workaround for https://github.com/owncloud/core/issues/2814
-                                       $owners[] = $sharedItem['uid_owner'];
-                               }
-                       }
-               }
-
-               return $owners;
-       }
-
        /**
         * Get shared items from the database
         * @param string $itemType
index ecc80b271fa5620016c62706fd30497ce9c151f2..96786c58a1a9ac9cc2acffb4c8839ccb5ab04552 100644 (file)
@@ -76,6 +76,8 @@ class TagManager implements \OCP\ITagManager {
         * @param string $userId user for which to retrieve the tags, defaults to the currently
         * logged in user
         * @return \OCP\ITags
+        *
+        * since 20.0.0 $includeShared isn't used anymore
         */
        public function load($type, $defaultTags = [], $includeShared = false, $userId = null) {
                if (is_null($userId)) {
@@ -86,6 +88,6 @@ class TagManager implements \OCP\ITagManager {
                        }
                        $userId = $this->userSession->getUser()->getUId();
                }
-               return new Tags($this->mapper, $userId, $type, $defaultTags, $includeShared);
+               return new Tags($this->mapper, $userId, $type, $defaultTags);
        }
 }
index 92263ca4fbea763e8bd1db43b88ff711524f0569..3fc66c69d6cc236fd82a6e566c8cb9f4b10893c0 100644 (file)
@@ -119,18 +119,14 @@ class Tags implements ITags {
         * @param string $user The user whose data the object will operate on.
         * @param string $type The type of items for which tags will be loaded.
         * @param array $defaultTags Tags that should be created at construction.
-        * @param boolean $includeShared Whether to include tags for items shared with this user by others.
+        *
+        * since 20.0.0 $includeShared isn't used anymore
         */
-       public function __construct(TagMapper $mapper, $user, $type, $defaultTags = [], $includeShared = false) {
+       public function __construct(TagMapper $mapper, $user, $type, $defaultTags = []) {
                $this->mapper = $mapper;
                $this->user = $user;
                $this->type = $type;
-               $this->includeShared = $includeShared;
                $this->owners = [$this->user];
-               if ($this->includeShared) {
-                       $this->owners = array_merge($this->owners, \OC\Share\Share::getSharedItemsOwners($this->user, $this->type, true));
-                       $this->backend = \OC\Share\Share::getBackend($this->type);
-               }
                $this->tags = $this->mapper->loadTags($this->owners, $this->type);
 
                if (count($defaultTags) > 0 && count($this->tags) === 0) {
@@ -303,22 +299,7 @@ class Tags implements ITags {
 
                if (!is_null($result)) {
                        while ($row = $result->fetchRow()) {
-                               $id = (int)$row['objid'];
-
-                               if ($this->includeShared) {
-                                       // We have to check if we are really allowed to access the
-                                       // items that are tagged with $tag. To that end, we ask the
-                                       // corresponding sharing backend if the item identified by $id
-                                       // is owned by any of $this->owners.
-                                       foreach ($this->owners as $owner) {
-                                               if ($this->backend->isValidSource($id, $owner)) {
-                                                       $ids[] = $id;
-                                                       break;
-                                               }
-                                       }
-                               } else {
-                                       $ids[] = $id;
-                               }
+                               $ids[] = (int)$row['objid'];
                        }
                }
 
index 46e1ba06297e21f37d1c6f45ed2f60d4b1da96e7..9003beb8a2a3aa378a6ebcb5970218d44b2243ad 100644 (file)
@@ -54,11 +54,11 @@ interface ITagManager {
         * @see \OCP\ITags
         * @param string $type The type identifier e.g. 'contact' or 'event'.
         * @param array $defaultTags An array of default tags to be used if none are stored.
-        * @param boolean $includeShared Whether to include tags for items shared with this user by others.
+        * @param boolean $includeShared Whether to include tags for items shared with this user by others. - always false since 20.0.0
         * @param string $userId user for which to retrieve the tags, defaults to the currently
         * logged in user
         * @return \OCP\ITags
-        * @since 6.0.0 - parameter $includeShared and $userId were added in 8.0.0
+        * @since 6.0.0 - parameter $includeShared and $userId were added in 8.0.0 - $includeShared is always false since 20.0.0
         */
        public function load($type, $defaultTags = [], $includeShared = false, $userId = null);
 }
index 38d3d611bb83e03ff811e5b002b3c4ebc0f45d14..69c2833433d9ceb2591535c7a8bbd2b85e95effd 100644 (file)
@@ -24,7 +24,6 @@ namespace Test;
 
 use OCP\IUser;
 use OCP\IUserSession;
-use OCP\Share\IShare;
 
 /**
  * Class TagsTest
@@ -287,39 +286,4 @@ class TagsTest extends \Test\TestCase {
                $this->assertTrue($tagger->removeFromFavorites(1));
                $this->assertEquals([], $tagger->getFavorites());
        }
-
-       public function testShareTags() {
-               $testTag = 'TestTag';
-               \OC\Share\Share::registerBackend('test', 'Test\Share\Backend');
-
-               $tagger = $this->tagMgr->load('test');
-               $tagger->tagAs(1, $testTag);
-
-
-               $otherUserId = $this->getUniqueID('user2_');
-               $otherUser = $this->createMock(IUser::class);
-               $otherUser->method('getUID')
-                       ->willReturn($otherUserId);
-
-               \OC::$server->getUserManager()->createUser($otherUserId, 'pass');
-               \OC_User::setUserId($otherUserId);
-               $otherUserSession = $this->createMock(IUserSession::class);
-               $otherUserSession
-                       ->expects($this->any())
-                       ->method('getUser')
-                       ->willReturn($otherUser);
-
-               $otherTagMgr = new \OC\TagManager($this->tagMapper, $otherUserSession);
-               $otherTagger = $otherTagMgr->load('test');
-               $this->assertFalse($otherTagger->hasTag($testTag));
-
-               \OC_User::setUserId($this->user->getUID());
-               // TODO new sharing
-               \OC\Share\Share::shareItem('test', 1, IShare::TYPE_USER, $otherUserId, \OCP\Constants::PERMISSION_READ);
-
-               \OC_User::setUserId($otherUserId);
-               $otherTagger = $otherTagMgr->load('test', [], true); // Update tags, load shared ones.
-               $this->assertTrue($otherTagger->hasTag($testTag));
-               $this->assertContains(1, $otherTagger->getIdsForTag($testTag));
-       }
 }