summaryrefslogtreecommitdiffstats
path: root/apps/federatedfilesharing
diff options
context:
space:
mode:
Diffstat (limited to 'apps/federatedfilesharing')
-rw-r--r--apps/federatedfilesharing/lib/federatedshareprovider.php17
-rw-r--r--apps/federatedfilesharing/tests/federatedshareprovidertest.php48
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);
+ }
}