Skip to content

catch missing user for system jobs #4081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2025
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
4 changes: 0 additions & 4 deletions lib/Db/UserMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,6 @@ public function getUserFromShare(Share $share): GenericUser|Email|User|ContactGr
}

public function getUserFromShareToken(string $token): UserBase {
// TODO: This is just a dirty hack. Analyse userId while updating to get correct userId
if ($token === '') {
return new Ghost();
}
$share = $this->getShareByToken($token);

return $this->getUserFromShare($share);
Expand Down
20 changes: 14 additions & 6 deletions lib/UserSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

namespace OCA\Polls;

use Exception;
use OCA\Polls\Db\Share;
use OCA\Polls\Db\ShareMapper;
use OCA\Polls\Db\UserMapper;
use OCA\Polls\Model\User\Cron;
use OCA\Polls\Model\User\Ghost;
use OCA\Polls\Model\UserBase;
use OCP\ISession;
use OCP\IUserSession;
Expand Down Expand Up @@ -56,12 +58,18 @@ public function __construct(
public function getCurrentUser(): UserBase {
if (!$this->currentUser) {

if ($this->getIsLoggedIn()) {
$this->currentUser = $this->userMapper->getUserFromUserBase((string)$this->userSession->getUser()?->getUID());
} elseif ($this->session->get(self::SESSION_KEY_CRON_JOB)) {
$this->currentUser = new Cron();
} else {
$this->currentUser = $this->userMapper->getUserFromShareToken($this->getShareToken());
try {
if ($this->getIsLoggedIn()) {
$this->currentUser = $this->userMapper->getUserFromUserBase((string)$this->userSession->getUser()?->getUID());
} elseif ($this->session->get(self::SESSION_KEY_CRON_JOB)) {
$this->currentUser = new Cron();
} else {
$this->currentUser = $this->userMapper->getUserFromShareToken($this->getShareToken());
}
} catch (Exception $e) {
// In case of system jobs, we do not get a valid user, so we return a Ghost user
// can happen while running cron jobs or during app updates
$this->currentUser = new Ghost();
}
}

Expand Down