summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/base.php2
-rw-r--r--lib/private/Share20/DefaultShareProvider.php38
-rw-r--r--lib/private/Share20/Hooks.php4
-rw-r--r--lib/private/Share20/Manager.php8
-rw-r--r--lib/private/share/hooks.php46
-rw-r--r--lib/public/Share/IManager.php12
-rw-r--r--lib/public/Share/IShareProvider.php11
7 files changed, 73 insertions, 48 deletions
diff --git a/lib/base.php b/lib/base.php
index 5a1d15913ba..79f5c673438 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -778,7 +778,7 @@ class OC {
public static function registerShareHooks() {
if (\OC::$server->getSystemConfig()->getValue('installed')) {
OC_Hook::connect('OC_User', 'post_deleteUser', 'OC\Share20\Hooks', 'post_deleteUser');
- OC_Hook::connect('OC_User', 'post_removeFromGroup', 'OC\Share\Hooks', 'post_removeFromGroup');
+ OC_Hook::connect('OC_User', 'post_removeFromGroup', 'OC\Share20\Hooks', 'post_removeFromGroup');
OC_Hook::connect('OC_User', 'post_deleteGroup', 'OC\Share20\Hooks', 'post_deleteGroup');
}
}
diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php
index b1f3b4dab83..f0de39fdad3 100644
--- a/lib/private/Share20/DefaultShareProvider.php
+++ b/lib/private/Share20/DefaultShareProvider.php
@@ -910,4 +910,42 @@ class DefaultShareProvider implements IShareProvider {
->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid)));
$qb->execute();
}
+
+ /**
+ * Delete custom group shares to this group for this user
+ *
+ * @param string $uid
+ * @param string $gid
+ */
+ public function userDeletedFromGroup($uid, $gid) {
+ /*
+ * Get all group shares
+ */
+ $qb = $this->dbConn->getQueryBuilder();
+ $qb->select('id')
+ ->from('share')
+ ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)))
+ ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid)));
+
+ $cursor = $qb->execute();
+ $ids = [];
+ while($row = $cursor->fetch()) {
+ $ids[] = (int)$row['id'];
+ }
+ $cursor->closeCursor();
+
+ if (!empty($ids)) {
+ $chunks = array_chunk($ids, 100);
+ foreach ($chunks as $chunk) {
+ /*
+ * Delete all special shares wit this users for the found group shares
+ */
+ $qb->delete('share')
+ ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
+ ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($uid)))
+ ->andWhere($qb->expr()->in('parent', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY)));
+ $qb->execute();
+ }
+ }
+ }
}
diff --git a/lib/private/Share20/Hooks.php b/lib/private/Share20/Hooks.php
index b391ffce8d5..f29114a1b5d 100644
--- a/lib/private/Share20/Hooks.php
+++ b/lib/private/Share20/Hooks.php
@@ -28,4 +28,8 @@ class Hooks {
public static function post_deleteGroup($arguments) {
\OC::$server->getShareManager()->groupDeleted($arguments['gid']);
}
+
+ public static function post_removeFromGroup($arguments) {
+ \OC::$server->getShareManager()->userDeletedFromGroup($arguments['uid'], $arguments['gid']);
+ }
}
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php
index 6f2efe167d4..1ec25750cfe 100644
--- a/lib/private/Share20/Manager.php
+++ b/lib/private/Share20/Manager.php
@@ -1057,6 +1057,14 @@ class Manager implements IManager {
}
/**
+ * @inheritdoc
+ */
+ public function userDeletedFromGroup($uid, $gid) {
+ $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP);
+ $provider->userDeletedFromGroup($uid, $gid);
+ }
+
+ /**
* Get access list to a path. This means
* all the users and groups that can access a given path.
*
diff --git a/lib/private/share/hooks.php b/lib/private/share/hooks.php
deleted file mode 100644
index 5faf81c5e9b..00000000000
--- a/lib/private/share/hooks.php
+++ /dev/null
@@ -1,46 +0,0 @@
-<?php
-/**
- * @author Björn Schießle <schiessle@owncloud.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin McCorkell <robin@mccorkell.me.uk>
- * @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 OC\Share;
-
-class Hooks extends \OC\Share\Constants {
- /**
- * Function that is called after a user is removed from a group. Shares are cleaned up.
- * @param array $arguments
- */
- public static function post_removeFromGroup($arguments) {
- $sql = 'SELECT `id`, `share_type` FROM `*PREFIX*share`'
- .' WHERE (`share_type` = ? AND `share_with` = ?) OR (`share_type` = ? AND `share_with` = ?)';
- $result = \OC_DB::executeAudited($sql, array(self::SHARE_TYPE_GROUP, $arguments['gid'],
- self::$shareTypeGroupUserUnique, $arguments['uid']));
- while ($item = $result->fetchRow()) {
- if ($item['share_type'] == self::SHARE_TYPE_GROUP) {
- // Delete all reshares by this user of the group share
- Helper::delete($item['id'], true, $arguments['uid']);
- } else {
- Helper::delete($item['id']);
- }
- }
- }
-}
diff --git a/lib/public/Share/IManager.php b/lib/public/Share/IManager.php
index c43011d3177..392c0471768 100644
--- a/lib/public/Share/IManager.php
+++ b/lib/public/Share/IManager.php
@@ -164,12 +164,22 @@ interface IManager {
* The group with $gid is deleted
* We need to clear up all shares to this group
*
- * @param $gid
+ * @param string $gid
* @since 9.1.0
*/
public function groupDeleted($gid);
/**
+ * The user $uid is deleted from the group $gid
+ * All user specific group shares have to be removed
+ *
+ * @param string $uid
+ * @param string $gid
+ * @since 9.1.0
+ */
+ public function userDeletedFromGroup($uid, $gid);
+
+ /**
* Instantiates a new share object. This is to be passed to
* createShare.
*
diff --git a/lib/public/Share/IShareProvider.php b/lib/public/Share/IShareProvider.php
index 24af36e0757..ac75a6f20b0 100644
--- a/lib/public/Share/IShareProvider.php
+++ b/lib/public/Share/IShareProvider.php
@@ -166,4 +166,15 @@ interface IShareProvider {
* @since 9.1.0
*/
public function groupDeleted($gid);
+
+ /**
+ * A user is deleted from a group
+ * We have to clean up all the related user specific group shares
+ * Providers not handling group shares should just return
+ *
+ * @param string $uid
+ * @param string $gid
+ * @since 9.1.0
+ */
+ public function userDeletedFromGroup($uid, $gid);
}