Skip to content

Commit f5b5aec

Browse files
committed
fix(FederatedShareProvider): Delete external shares when groups are deleted or users removed from a group
Signed-off-by: provokateurin <[email protected]>
1 parent 0df4817 commit f5b5aec

File tree

1 file changed

+44
-14
lines changed

1 file changed

+44
-14
lines changed

apps/federatedfilesharing/lib/FederatedShareProvider.php

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -882,30 +882,60 @@ public function userDeleted($uid, $shareType) {
882882
//TODO: probably a good idea to send unshare info to remote servers
883883

884884
$qb = $this->dbConnection->getQueryBuilder();
885-
886885
$qb->delete('share')
887886
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_REMOTE)))
888887
->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)))
889888
->executeStatement();
889+
890+
$qb = $this->dbConnection->getQueryBuilder();
891+
$qb->delete('share_external')
892+
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_GROUP)))
893+
->andWhere($qb->expr()->eq('user', $qb->createNamedParameter($uid)))
894+
->executeStatement();
890895
}
891896

892-
/**
893-
* This provider does not handle groups
894-
*
895-
* @param string $gid
896-
*/
897897
public function groupDeleted($gid) {
898-
// We don't handle groups here
898+
$qb = $this->dbConnection->getQueryBuilder();
899+
$qb->select('id')
900+
->from('share_external')
901+
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_GROUP)))
902+
// This is not a typo, the group ID is really stored in the 'user' column
903+
->andWhere($qb->expr()->eq('user', $qb->createNamedParameter($gid)));
904+
$cursor = $qb->executeQuery();
905+
$parentShareIds = $cursor->fetchAll(\PDO::FETCH_COLUMN);
906+
$cursor->closeCursor();
907+
if ($parentShareIds === []) {
908+
return;
909+
}
910+
911+
$qb = $this->dbConnection->getQueryBuilder();
912+
$parentShareIdsParam = $qb->createNamedParameter($parentShareIds, IQueryBuilder::PARAM_INT_ARRAY);
913+
$qb->delete('share_external')
914+
->where($qb->expr()->in('id', $parentShareIdsParam))
915+
->orWhere($qb->expr()->in('parent', $parentShareIdsParam))
916+
->executeStatement();
899917
}
900918

901-
/**
902-
* This provider does not handle groups
903-
*
904-
* @param string $uid
905-
* @param string $gid
906-
*/
907919
public function userDeletedFromGroup($uid, $gid) {
908-
// We don't handle groups here
920+
$qb = $this->dbConnection->getQueryBuilder();
921+
$qb->select('id')
922+
->from('share_external')
923+
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_GROUP)))
924+
// This is not a typo, the group ID is really stored in the 'user' column
925+
->andWhere($qb->expr()->eq('user', $qb->createNamedParameter($gid)));
926+
$cursor = $qb->executeQuery();
927+
$parentShareIds = $cursor->fetchAll(\PDO::FETCH_COLUMN);
928+
$cursor->closeCursor();
929+
if ($parentShareIds === []) {
930+
return;
931+
}
932+
933+
$qb = $this->dbConnection->getQueryBuilder();
934+
$parentShareIdsParam = $qb->createNamedParameter($parentShareIds, IQueryBuilder::PARAM_INT_ARRAY);
935+
$qb->delete('share_external')
936+
->where($qb->expr()->in('parent', $parentShareIdsParam))
937+
->andWhere($qb->expr()->eq('user', $qb->createNamedParameter($uid)))
938+
->executeStatement();
909939
}
910940

911941
/**

0 commit comments

Comments
 (0)