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 /apps | |
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 'apps')
-rw-r--r-- | apps/federatedfilesharing/lib/federatedshareprovider.php | 17 | ||||
-rw-r--r-- | apps/federatedfilesharing/tests/federatedshareprovidertest.php | 48 |
2 files changed, 65 insertions, 0 deletions
diff --git a/apps/federatedfilesharing/lib/federatedshareprovider.php b/apps/federatedfilesharing/lib/federatedshareprovider.php index e54ce08fb04..a450b420cf4 100644 --- a/apps/federatedfilesharing/lib/federatedshareprovider.php +++ b/apps/federatedfilesharing/lib/federatedshareprovider.php @@ -563,4 +563,21 @@ class FederatedShareProvider implements IShareProvider { return $nodes[0]; } + /** + * A user is deleted from the system + * So clean up the relevant shares. + * + * @param string $uid + * @param int $shareType + */ + public function userDeleted($uid, $shareType) { + //TODO: probabaly a good idea to send unshare info to remote servers + + $qb = $this->dbConnection->getQueryBuilder(); + + $qb->delete('share') + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE))) + ->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid))) + ->execute(); + } } diff --git a/apps/federatedfilesharing/tests/federatedshareprovidertest.php b/apps/federatedfilesharing/tests/federatedshareprovidertest.php index dedd6767b49..92e9f10c3cd 100644 --- a/apps/federatedfilesharing/tests/federatedshareprovidertest.php +++ b/apps/federatedfilesharing/tests/federatedshareprovidertest.php @@ -462,4 +462,52 @@ class FederatedShareProviderTest extends TestCase { $this->assertCount(1, $shares); $this->assertEquals('user2@server.com', $shares[0]->getSharedWith()); } + + public function dataDeleteUser() { + return [ + ['a', 'b', 'c', 'a', true], + ['a', 'b', 'c', 'b', false], + // The recipient is non local. + ['a', 'b', 'c', 'c', false], + ['a', 'b', 'c', 'd', false], + ]; + } + + /** + * @dataProvider dataDeleteUser + * + * @param string $owner The owner of the share (uid) + * @param string $initiator The initiator of the share (uid) + * @param string $recipient The recipient of the share (uid/gid/pass) + * @param string $deletedUser The user that is deleted + * @param bool $rowDeleted Is the row deleted in this setup + */ + public function testDeleteUser($owner, $initiator, $recipient, $deletedUser, $rowDeleted) { + $qb = $this->connection->getQueryBuilder(); + $qb->insert('share') + ->setValue('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE)) + ->setValue('uid_owner', $qb->createNamedParameter($owner)) + ->setValue('uid_initiator', $qb->createNamedParameter($initiator)) + ->setValue('share_with', $qb->createNamedParameter($recipient)) + ->setValue('item_type', $qb->createNamedParameter('file')) + ->setValue('item_source', $qb->createNamedParameter(42)) + ->setValue('file_source', $qb->createNamedParameter(42)) + ->execute(); + + $id = $qb->getLastInsertId(); + + $this->provider->userDeleted($deletedUser, \OCP\Share::SHARE_TYPE_REMOTE); + + $qb = $this->connection->getQueryBuilder(); + $qb->select('*') + ->from('share') + ->where( + $qb->expr()->eq('id', $qb->createNamedParameter($id)) + ); + $cursor = $qb->execute(); + $data = $cursor->fetchAll(); + $cursor->closeCursor(); + + $this->assertCount($rowDeleted ? 0 : 1, $data); + } } |