Skip to content

Commit

Permalink
fix(FederatedShareProvider): Delete external shares when groups are d…
Browse files Browse the repository at this point in the history
…eleted or users removed from a group

Signed-off-by: provokateurin <[email protected]>

[skip ci]
  • Loading branch information
provokateurin authored and backportbot[bot] committed Mar 3, 2025
1 parent 4aa3662 commit ec4ded5
Showing 1 changed file with 44 additions and 14 deletions.
58 changes: 44 additions & 14 deletions apps/federatedfilesharing/lib/FederatedShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -882,30 +882,60 @@ public function userDeleted($uid, $shareType) {
//TODO: probably 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(IShare::TYPE_REMOTE)))
->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)))
->executeStatement();

$qb = $this->dbConnection->getQueryBuilder();
$qb->delete('share_external')
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_GROUP)))
->andWhere($qb->expr()->eq('user', $qb->createNamedParameter($uid)))
->executeStatement();
}

/**
* This provider does not handle groups
*
* @param string $gid
*/
public function groupDeleted($gid) {
// We don't handle groups here
$qb = $this->dbConnection->getQueryBuilder();
$qb->select('id')
->from('share_external')
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_GROUP)))
// This is not a typo, the group ID is really stored in the 'user' column
->andWhere($qb->expr()->eq('user', $qb->createNamedParameter($gid)));
$cursor = $qb->executeQuery();
$parentShareIds = $cursor->fetchAll(\PDO::FETCH_COLUMN);
$cursor->closeCursor();
if ($parentShareIds === []) {
return;
}

$qb = $this->dbConnection->getQueryBuilder();
$parentShareIdsParam = $qb->createNamedParameter($parentShareIds, IQueryBuilder::PARAM_INT_ARRAY);
$qb->delete('share_external')
->where($qb->expr()->in('id', $parentShareIdsParam))
->orWhere($qb->expr()->in('parent', $parentShareIdsParam))
->executeStatement();
}

/**
* This provider does not handle groups
*
* @param string $uid
* @param string $gid
*/
public function userDeletedFromGroup($uid, $gid) {
// We don't handle groups here
$qb = $this->dbConnection->getQueryBuilder();
$qb->select('id')
->from('share_external')
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_GROUP)))
// This is not a typo, the group ID is really stored in the 'user' column
->andWhere($qb->expr()->eq('user', $qb->createNamedParameter($gid)));
$cursor = $qb->executeQuery();
$parentShareIds = $cursor->fetchAll(\PDO::FETCH_COLUMN);
$cursor->closeCursor();
if ($parentShareIds === []) {
return;
}

$qb = $this->dbConnection->getQueryBuilder();
$parentShareIdsParam = $qb->createNamedParameter($parentShareIds, IQueryBuilder::PARAM_INT_ARRAY);
$qb->delete('share_external')
->where($qb->expr()->in('parent', $parentShareIdsParam))
->andWhere($qb->expr()->eq('user', $qb->createNamedParameter($uid)))
->executeStatement();
}

/**
Expand Down

0 comments on commit ec4ded5

Please sign in to comment.