diff --git a/appinfo/info.xml b/appinfo/info.xml index 5374929be..b4275b396 100755 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -14,7 +14,7 @@ Guests accounts can be created from the share menu by entering either the recipients email or name and choosing "create guest account", once the share is created the guest user will receive an email notification about the mail with a link to set their password. Guests users can only access files shared to them and cannot create any files outside of shares, additionally, the apps accessible to guest accounts are whitelisted.]]> - 4.5.1 + 4.5.2 agpl Nextcloud diff --git a/lib/Listener/UserChangedListener.php b/lib/Listener/UserChangedListener.php index f3b7ef1f7..28b689127 100644 --- a/lib/Listener/UserChangedListener.php +++ b/lib/Listener/UserChangedListener.php @@ -8,10 +8,12 @@ namespace OCA\Guests\Listener; +use OCA\Guests\AppInfo\Application; use OCA\Guests\GuestManager; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; use OCP\IAppConfig; +use OCP\IConfig; use OCP\IUserSession; use OCP\User\Events\UserChangedEvent; @@ -25,6 +27,7 @@ public function __construct( private readonly IUserSession $userSession, private readonly GuestManager $guestManager, private readonly IAppConfig $appConfig, + private readonly IConfig $config, ) { } @@ -36,20 +39,29 @@ public function handle(Event $event): void { return; } $user = $event->getUser(); - if ($this->userSession->getUser() !== $user) { - return; - } if (!$this->guestManager->isGuest($user)) { return; } - if (strtolower($event->getValue()) === strtolower($user->getUID())) { + + $guestEmail = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'email', strtolower($user->getUID())); + if ($event->getValue() === $guestEmail) { return; } - if ($this->appConfig->getValueBool('guests', 'allow_email_change', false, true)) { - return; + + $allowChange = false; + if (strtolower($event->getValue()) === strtolower($user->getUID())) { + $allowChange = true; + } elseif ($this->userSession->getUser() !== $user) { + $allowChange = true; + } elseif ($this->appConfig->getValueBool(Application::APP_ID, 'allow_email_change', false, true) && $event->getValue() !== '') { + $allowChange = true; } - $user->setSystemEMailAddress(strtolower($user->getUID())); - $event->stopPropagation(); + if ($allowChange) { + $this->config->setUserValue($user->getUID(), Application::APP_ID, 'email', $event->getValue()); + } else { + $user->setSystemEMailAddress($guestEmail); + $event->stopPropagation(); + } } } diff --git a/lib/Repair/ResetEmails.php b/lib/Repair/ResetEmails.php index 7f1521f2b..616b41ad1 100644 --- a/lib/Repair/ResetEmails.php +++ b/lib/Repair/ResetEmails.php @@ -8,6 +8,7 @@ namespace OCA\Guests\Repair; +use OCA\Guests\AppInfo\Application; use OCA\Guests\GuestManager; use OCP\IAppConfig; use OCP\IConfig; @@ -38,9 +39,10 @@ public function run(IOutput $output) { foreach ($this->guestManager->listGuests() as $guestId) { $guest = $this->userManager->get($guestId); - if (strtolower($guest?->getSystemEMailAddress() ?? '') !== strtolower($guestId)) { + $expectedEmail = $this->config->getUserValue($guestId, Application::APP_ID, 'email', strtolower($guestId)); + if (strtolower($guest?->getSystemEMailAddress() ?? '') !== $expectedEmail) { $this->config->setUserValue($guestId, 'guests', 'old_email', $guest?->getSystemEMailAddress() ?? ''); - $guest->setSystemEMailAddress(strtolower($guestId)); + $guest->setSystemEMailAddress($expectedEmail); } } }