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
6 changes: 6 additions & 0 deletions lib/Listener/UserChangedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use OCA\Guests\GuestManager;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\IAppConfig;
use OCP\IUserSession;
use OCP\User\Events\UserChangedEvent;

Expand All @@ -23,6 +24,7 @@ class UserChangedListener implements IEventListener {
public function __construct(
private readonly IUserSession $userSession,
private readonly GuestManager $guestManager,
private readonly IAppConfig $appConfig,
) {
}

Expand All @@ -43,6 +45,10 @@ public function handle(Event $event): void {
if (strtolower($event->getValue()) === strtolower($user->getUID())) {
return;
}
if ($this->appConfig->getValueBool('guests', 'allow_email_change', false, true)) {
return;
}

$user->setSystemEMailAddress(strtolower($user->getUID()));
$event->stopPropagation();
}
Expand Down
6 changes: 6 additions & 0 deletions lib/Repair/ResetEmails.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace OCA\Guests\Repair;

use OCA\Guests\GuestManager;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IUserManager;
use OCP\Migration\IOutput;
Expand All @@ -18,6 +19,7 @@ class ResetEmails implements IRepairStep {
public function __construct(
private readonly GuestManager $guestManager,
private readonly IUserManager $userManager,
private readonly IAppConfig $appConfig,
private readonly IConfig $config,
) {
}
Expand All @@ -30,6 +32,10 @@ public function getName(): string {
* @return void
*/
public function run(IOutput $output) {
if ($this->appConfig->getValueBool('guests', 'allow_email_change', false, true)) {
return;
}

foreach ($this->guestManager->listGuests() as $guestId) {
$guest = $this->userManager->get($guestId);
if (strtolower($guest?->getSystemEMailAddress() ?? '') !== strtolower($guestId)) {
Expand Down
Loading