Skip to content

Commit 0a99fe1

Browse files
committed
feat: add repair step to ensure guests haven't changed their email
Signed-off-by: Robin Appelman <[email protected]>
1 parent f822233 commit 0a99fe1

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

appinfo/info.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Guests users can only access files shared to them and cannot create any files ou
3636
<repair-steps>
3737
<post-migration>
3838
<step>OCA\Guests\Migration\OwncloudGuestsMigration</step>
39+
<step>OCA\Guests\Repair\ResetEmails</step>
3940
</post-migration>
4041
</repair-steps>
4142
<commands>

lib/Repair/ResetEmails.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* SPDX-FileCopyrightText: 2025 Robin Appelman <[email protected]>
6+
* SPDX-License-Identifier: AGPL-3.0-or-later
7+
*/
8+
9+
namespace OCA\Guests\Repair;
10+
11+
use OCA\Guests\GuestManager;
12+
use OCP\IUserManager;
13+
use OCP\Migration\IOutput;
14+
use OCP\Migration\IRepairStep;
15+
16+
class ResetEmails implements IRepairStep {
17+
public function __construct(
18+
private readonly GuestManager $guestManager,
19+
private readonly IUserManager $userManager,
20+
) {
21+
}
22+
23+
public function getName(): string {
24+
return "Reset the email of all guest accounts";
25+
}
26+
27+
public function run(IOutput $output) {
28+
foreach ($this->guestManager->listGuests() as $guestId) {
29+
$guest = $this->userManager->get($guestId);
30+
if (strtolower($guest->getSystemEMailAddress()) !== strtolower($guestId)) {
31+
$guest->setSystemEMailAddress(strtolower($guestId));
32+
}
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)