diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2016-04-07 13:01:10 +0200 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2016-04-07 13:01:10 +0200 |
commit | 0de15a86f057c8b0e88f353762059d4e0971b780 (patch) | |
tree | 718fc80fb91b2cf032998d49f655b4700cb26570 /lib/private/Share20 | |
parent | 8932ec64a5d61691a506166ebbeeeb37af8b5106 (diff) | |
parent | e0cee43cf0a3899567f50a5fb03d867fc2f0327a (diff) | |
download | nextcloud-server-0de15a86f057c8b0e88f353762059d4e0971b780.tar.gz nextcloud-server-0de15a86f057c8b0e88f353762059d4e0971b780.zip |
Merge pull request #23773 from owncloud/share_move_delete_user_hook
Migrate post_userDelete hook to share manager
Diffstat (limited to 'lib/private/Share20')
-rw-r--r-- | lib/private/Share20/DefaultShareProvider.php | 65 | ||||
-rw-r--r-- | lib/private/Share20/Hooks.php | 27 | ||||
-rw-r--r-- | lib/private/Share20/Manager.php | 12 |
3 files changed, 103 insertions, 1 deletions
diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php index f6171f87992..370655f8315 100644 --- a/lib/private/Share20/DefaultShareProvider.php +++ b/lib/private/Share20/DefaultShareProvider.php @@ -28,7 +28,6 @@ use OC\Share20\Exception\ProviderException; use OCP\Share\Exceptions\ShareNotFound; use OC\Share20\Exception\BackendError; use OCP\DB\QueryBuilder\IQueryBuilder; -use OCP\Files\NotFoundException; use OCP\IGroup; use OCP\IGroupManager; use OCP\IUserManager; @@ -804,4 +803,68 @@ class DefaultShareProvider implements IShareProvider { return $share; } + /** + * A user is deleted from the system + * So clean up the relevant shares. + * + * @param string $uid + * @param int $shareType + */ + public function userDeleted($uid, $shareType) { + $qb = $this->dbConn->getQueryBuilder(); + + $qb->delete('share'); + + if ($shareType === \OCP\Share::SHARE_TYPE_USER) { + /* + * Delete all user shares that are owned by this user + * or that are received by this user + */ + + $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER))); + + $qb->andWhere( + $qb->expr()->orX( + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)), + $qb->expr()->eq('share_with', $qb->createNamedParameter($uid)) + ) + ); + } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { + /* + * Delete all group shares that are owned by this user + * Or special user group shares that are received by this user + */ + $qb->where( + $qb->expr()->andX( + $qb->expr()->orX( + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)), + $qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)) + ), + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)) + ) + ); + + $qb->orWhere( + $qb->expr()->andX( + $qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)), + $qb->expr()->eq('share_with', $qb->createNamedParameter($uid)) + ) + ); + } else if ($shareType === \OCP\Share::SHARE_TYPE_LINK) { + /* + * Delete all link shares owned by this user. + * And all link shares initiated by this user (until #22327 is in) + */ + $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))); + + $qb->andWhere( + $qb->expr()->orX( + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)), + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($uid)) + ) + ); + } + + $qb->execute(); + } } diff --git a/lib/private/Share20/Hooks.php b/lib/private/Share20/Hooks.php new file mode 100644 index 00000000000..93669974b28 --- /dev/null +++ b/lib/private/Share20/Hooks.php @@ -0,0 +1,27 @@ +<?php +/** + * @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\Share20; + +class Hooks { + public static function post_deleteUser($arguments) { + \OC::$server->getShareManager()->userDeleted($arguments['uid']); + } +} diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 1c9d4d82277..6c665f7e133 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -1019,6 +1019,18 @@ class Manager implements IManager { } /** + * @inheritdoc + */ + public function userDeleted($uid) { + $types = [\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_LINK, \OCP\Share::SHARE_TYPE_REMOTE]; + + foreach ($types as $type) { + $provider = $this->factory->getProviderForType($type); + $provider->userDeleted($uid, $type); + } + } + + /** * Get access list to a path. This means * all the users and groups that can access a given path. * |