diff options
author | Roeland Jago Douma <rullzer@owncloud.com> | 2016-04-04 12:28:19 +0200 |
---|---|---|
committer | Roeland Jago Douma <rullzer@owncloud.com> | 2016-04-04 14:15:38 +0200 |
commit | e0cee43cf0a3899567f50a5fb03d867fc2f0327a (patch) | |
tree | 5f0d5503b3d971e0b813bc14fd7956cf114abbfe /apps | |
parent | f6cea3c9c436142110504ba76320d57ca7899b27 (diff) | |
download | nextcloud-server-e0cee43cf0a3899567f50a5fb03d867fc2f0327a.tar.gz nextcloud-server-e0cee43cf0a3899567f50a5fb03d867fc2f0327a.zip |
Migrate post_userDelete hook to share manager
This makes the post_userDelete hook call the sharemanager. This will
cleanup to and from this user.
* All shares owned by this user
* All shares with this user (user)
* All custom group shares
* All link share initiated by this user (to avoid invisible link shares)
Unit tests are added for the defaultshare provider as well as the
federated share provider
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); + } } |