Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable27] fix(settings): Delete settings when a user is deleted #1584

Merged
merged 3 commits into from
Jun 21, 2023
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
5 changes: 3 additions & 2 deletions .github/workflows/phpunit-mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ jobs:

- name: Enable ONLY_FULL_GROUP_BY MySQL option
run: |
echo "SET GLOBAL sql_mode=(SELECT CONCAT(@@sql_mode,',ONLY_FULL_GROUP_BY'));" | mysql -h 127.0.0.1 -P 4444 -u root -prootpassword
echo "SELECT @@sql_mode;" | mysql -h 127.0.0.1 -P 4444 -u root -prootpassword
sleep 5
echo "SET GLOBAL sql_mode=(SELECT CONCAT(@@sql_mode,',ONLY_FULL_GROUP_BY'));" | mysql -h 127.0.0.1 -P 4444 -w -u root -prootpassword
echo "SELECT @@sql_mode;" | mysql -h 127.0.0.1 -P 4444 -w -u root -prootpassword

- name: Checkout server
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
Expand Down
10 changes: 9 additions & 1 deletion lib/Listener/UserDeletedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/**
* @copyright Copyright (c) 2020, Daniel Kesselberg <[email protected]>
*
* @author Joas Schilling <[email protected]>
* @author Daniel Kesselberg <[email protected]>
*
* @license AGPL-3.0-or-later
Expand All @@ -27,6 +28,7 @@
namespace OCA\Notifications\Listener;

use OCA\Notifications\Handler;
use OCA\Notifications\Model\SettingsMapper;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\User\Events\UserDeletedEvent;
Expand All @@ -36,9 +38,14 @@
*/
class UserDeletedListener implements IEventListener {
private Handler $handler;
private SettingsMapper $settingsMapper;

public function __construct(Handler $handler) {
public function __construct(
Handler $handler,
SettingsMapper $settingsMapper,
) {
$this->handler = $handler;
$this->settingsMapper = $settingsMapper;
}

public function handle(Event $event): void {
Expand All @@ -49,5 +56,6 @@ public function handle(Event $event): void {

$user = $event->getUser();
$this->handler->deleteByUser($user->getUID());
$this->settingsMapper->deleteSettingsByUser($user->getUID());
}
}
13 changes: 13 additions & 0 deletions lib/Model/SettingsMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ public function getSettingsByUser(string $userId): Settings {
return $this->findEntity($query);
}

/**
* @param string $userId
* @throws DBException
*/
public function deleteSettingsByUser(string $userId): void {
$query = $this->db->getQueryBuilder();

$query->delete($this->getTableName())
->where($query->expr()->eq('user_id', $query->createNamedParameter($userId)));

$query->executeStatement();
}

public function setBatchSettingForUser(string $userId, int $batchSetting): void {
try {
$settings = $this->getSettingsByUser($userId);
Expand Down