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
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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.]]></description>
<version>4.5.1</version>
<version>4.5.2</version>
<licence>agpl</licence>
<author>Nextcloud</author>
<types>
Expand Down
28 changes: 20 additions & 8 deletions lib/Listener/UserChangedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -25,6 +27,7 @@ public function __construct(
private readonly IUserSession $userSession,
private readonly GuestManager $guestManager,
private readonly IAppConfig $appConfig,
private readonly IConfig $config,
) {
}

Expand All @@ -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();
}
}
}
6 changes: 4 additions & 2 deletions lib/Repair/ResetEmails.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace OCA\Guests\Repair;

use OCA\Guests\AppInfo\Application;
use OCA\Guests\GuestManager;
use OCP\IAppConfig;
use OCP\IConfig;
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
Loading