Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
extend with group deletion handling
Signed-off-by: Arthur Schiwon <[email protected]>
  • Loading branch information
blizzz committed Nov 28, 2019
commit 4baab51f4ccdf44399f656e5a5acf89d1f6b779b
11 changes: 11 additions & 0 deletions apps/files_external/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
use OCP\AppFramework\App;
use OCP\AppFramework\IAppContainer;
use OCP\Files\Config\IUserMountCache;
use OCP\IGroup;
use OCP\IUser;
use Symfony\Component\EventDispatcher\GenericEvent;

Expand Down Expand Up @@ -111,6 +112,16 @@ function (GenericEvent $event) {
$config->modifyMountsOnUserDelete($user->getUID());
}
);
$dispatcher->addListener(
IGroup::class . '::postDelete',
function (GenericEvent $event) {
/** @var IGroup $group */
$group = $event->getSubject();
/** @var DBConfigService $config */
$config = $this->getContainer()->query(DBConfigService::class);
$config->modifyMountsOnGroupDelete($group->getGID());
}
);
}

/**
Expand Down
20 changes: 14 additions & 6 deletions apps/files_external/lib/Service/DBConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,23 @@ public function getMountsForUser($userId, $groupIds) {
return $this->getMountsFromQuery($query);
}

public function modifyMountsOnUserDelete(string $uid) {
public function modifyMountsOnUserDelete(string $uid): void {
$this->modifyMountsOnDelete($uid, self::APPLICABLE_TYPE_USER);
}

public function modifyMountsOnGroupDelete(string $gid): void {
$this->modifyMountsOnDelete($gid, self::APPLICABLE_TYPE_GROUP);
}

protected function modifyMountsOnDelete(string $applicableId, int $applicableType): void {
$builder = $this->connection->getQueryBuilder();
$query = $builder->select(['a.mount_id', $builder->func()->count('a.mount_id', 'count')])
->from('external_applicable', 'a')
->rightJoin('a', 'external_applicable', 'b', $builder->expr()->eq('a.mount_id', 'b.mount_id'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right join was not supported on sqlite iirc

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

turning it around seems to work, same table after all. PR incoming,

->where($builder->expr()->andX( // mounts for user
$builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_USER, IQueryBuilder::PARAM_INT)),
$builder->expr()->eq('a.value', $builder->createNamedParameter($uid))
)
->where($builder->expr()->andX(
$builder->expr()->eq('a.type', $builder->createNamedParameter($applicableType, IQueryBuilder::PARAM_INT)),
$builder->expr()->eq('a.value', $builder->createNamedParameter($applicableId))
)
)
->groupBy(['a.mount_id']);
$stmt = $query->execute();
Expand All @@ -131,7 +139,7 @@ public function modifyMountsOnUserDelete(string $uid) {

foreach ($result as $row) {
if((int)$row['count'] > 1) {
$this->removeApplicable($row['mount_id'], self::APPLICABLE_TYPE_USER, $uid);
$this->removeApplicable($row['mount_id'], $applicableType, $applicableId);
} else {
$this->removeMount($row['mount_id']);
}
Expand Down