diff --git a/lib/Listener/UserChangedListener.php b/lib/Listener/UserChangedListener.php index 48c432ca..f3b7ef1f 100644 --- a/lib/Listener/UserChangedListener.php +++ b/lib/Listener/UserChangedListener.php @@ -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; @@ -23,6 +24,7 @@ class UserChangedListener implements IEventListener { public function __construct( private readonly IUserSession $userSession, private readonly GuestManager $guestManager, + private readonly IAppConfig $appConfig, ) { } @@ -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(); } diff --git a/lib/Repair/ResetEmails.php b/lib/Repair/ResetEmails.php index 5c5b9e93..7f1521f2 100644 --- a/lib/Repair/ResetEmails.php +++ b/lib/Repair/ResetEmails.php @@ -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; @@ -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, ) { } @@ -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)) {