Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions apps/files_external/appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

// register Application object singleton
\OC_Mount_Config::$app = \OC::$server->query(\OCA\Files_External\AppInfo\Application::class);
\OC_Mount_Config::$app->registerListeners();

$appContainer = \OC_Mount_Config::$app->getContainer();

\OCA\Files\App::getNavigationManager()->add(function () {
Expand Down
28 changes: 28 additions & 0 deletions apps/files_external/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
namespace OCA\Files_External\AppInfo;

use OCA\Files_External\Config\UserPlaceholderHandler;
use OCA\Files_External\Service\DBConfigService;
use OCA\Files_External\Lib\Auth\AmazonS3\AccessKey;
use OCA\Files_External\Lib\Auth\Builtin;
use OCA\Files_External\Lib\Auth\NullMechanism;
Expand Down Expand Up @@ -63,6 +64,9 @@
use OCP\AppFramework\App;
use OCP\AppFramework\IAppContainer;
use OCP\Files\Config\IUserMountCache;
use OCP\IGroup;
use OCP\IUser;
use Symfony\Component\EventDispatcher\GenericEvent;

/**
* @package OCA\Files_External\AppInfo
Expand Down Expand Up @@ -96,6 +100,30 @@ public function __construct(array $urlParams = []) {
$this->getAuthMechanisms();
}

public function registerListeners() {
$dispatcher = $this->getContainer()->getServer()->getEventDispatcher();
$dispatcher->addListener(
IUser::class . '::postDelete',
function (GenericEvent $event) {
/** @var IUser $user */
$user = $event->getSubject();
/** @var DBConfigService $config */
$config = $this->getContainer()->query(DBConfigService::class);
$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());
}
);
}

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

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(
$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();
$result = $stmt->fetchAll();
$stmt->closeCursor();

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

/**
* Get admin defined mounts
*
Expand Down