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
17 changes: 13 additions & 4 deletions lib/Service/NoteUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\IDBConnection;
use OCP\IUserSession;
use OCP\Share\IManager;
Expand Down Expand Up @@ -196,12 +197,20 @@ public function getNotesFolderUserPath(string $userId, bool $saveInitial = false
public function getOrCreateNotesFolder(string $userId, bool $create = true) : Folder {
$userFolder = $this->getRoot()->getUserFolder($userId);
$notesPath = $this->settingsService->get($userId, 'notesPath');
$allowShared = $notesPath !== $this->settingsService->getDefaultNotesPath($userId);

$folder = null;
['path' => $defaultPath, 'node' => $folder] = $this->settingsService->getDefaultNotesNode($userId);
$allowShared = $notesPath !== $defaultPath;

if ($allowShared) {
try {
$folder = $userFolder->get($notesPath);
} catch (NotFoundException) {
$folder = null;
}
}

$updateNotesPath = false;
if ($userFolder->nodeExists($notesPath)) {
$folder = $userFolder->get($notesPath);
if ($folder instanceof Folder) {
if (!$allowShared && $folder->isShared()) {
$notesPath = $userFolder->getNonExistingName($notesPath);
$folder = $userFolder->newFolder($notesPath);
Expand Down
49 changes: 42 additions & 7 deletions lib/Service/SettingsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
use OCA\Notes\AppInfo\Application;

use OCP\App\IAppManager;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\IConfig;
use OCP\IL10N;

Expand Down Expand Up @@ -41,7 +43,7 @@ public function __construct(
'fileSuffix' => $this->getListAttrs('fileSuffix', [...$this->defaultSuffixes, 'custom']),
'notesPath' => [
'default' => function (string $uid) {
return $this->getDefaultNotesPath($uid);
return $this->getDefaultNotesNode($uid)['path'];
},
'validate' => function ($value) {
$value = str_replace([ '/', '\\' ], DIRECTORY_SEPARATOR, $value);
Expand Down Expand Up @@ -86,13 +88,46 @@ private function getListAttrs(string $attributeName, array $values) : array {
];
}

public function getDefaultNotesPath(string $uid) : string {
/**
* Return the default notes node if it exists and the expected path if it exists
* @return array{
* path: string,
* folder: ?Folder
* }
*/
public function getDefaultNotesNode(string $uid): array {
$defaultFolder = $this->config->getAppValue(Application::APP_ID, 'defaultFolder', 'Notes');
$defaultExists = $this->root->getUserFolder($uid)->nodeExists($defaultFolder);
if ($defaultExists) {
return $defaultFolder;
} else {
return $this->l10n->t($defaultFolder);
$userFolder = $this->root->getUserFolder($uid);
try {
/** @var Folder $node */
$node = $userFolder->get($defaultFolder);
return [
'path' => $defaultFolder,
'folder' => $node,
];
} catch (NotFoundException) {
$path = $this->l10n->t($defaultFolder);

if ($path == $defaultFolder) {
// English locale, still non-existing
return [
'path' => $path,
'folder' => null,
];
}

try {
$node = $userFolder->get($path);
return [
'path' => $path,
'folder' => $node,
];
} catch (NotFoundException) {
return [
'path' => $path,
'folder' => null,
];
}
}
}

Expand Down
Loading