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
11 changes: 7 additions & 4 deletions lib/AppInfo/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,24 @@

namespace OCA\Notes\AppInfo;

use OCA\Notes\Service\NoteUtil;
use OCP\App\IAppManager;
use OCP\Capabilities\ICapability;

class Capabilities implements ICapability {
private IAppManager $appManager;

public function __construct(IAppManager $appManager) {
$this->appManager = $appManager;
public function __construct(
private IAppManager $appManager,
private NoteUtil $noteUtil,
private ?string $userId,
) {
}

public function getCapabilities(): array {
return [
Application::APP_ID => [
'api_version' => Application::$API_VERSIONS,
'version' => $this->appManager->getAppVersion(Application::APP_ID),
'notes_path' => $this->userId !== null && $this->userId !== ' ' ? $this->noteUtil->getNotesFolderUserPath($this->userId) : null,
],
];
}
Expand Down
7 changes: 7 additions & 0 deletions lib/Service/NoteUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,13 @@ public function getOrCreateFolder(string $path, bool $create = true) : Folder {
return $folder;
}

public function getNotesFolderUserPath(string $userId): ?string {
/** @psalm-suppress MissingDependency */
$userFolder = $this->getRoot()->getUserFolder($userId);
$nodesFolder = $this->getOrCreateNotesFolder($userId, false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably on users where the folder does not exists yet (e.g. new users on first login).
Possible solutions: either the create parameter has to be true, or the NotesFolderException has to be caught.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An integration test would have caught this btw.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even a frontend test would have caught this too, since this error crashes the entire server 🤦

return $userFolder->getRelativePath($nodesFolder->getPath());
}

public function getOrCreateNotesFolder(string $userId, bool $create = true) : Folder {
$userFolder = $this->getRoot()->getUserFolder($userId);
$notesPath = $this->settingsService->get($userId, 'notesPath');
Expand Down