Skip to content

Commit d15ea3c

Browse files
juliusknorrbackportbot[bot]
authored andcommitted
fix: Allow shared notes folder if manually set
Signed-off-by: Julius Härtl <jus@bitgrid.net>
1 parent b8d9004 commit d15ea3c

4 files changed

Lines changed: 37 additions & 20 deletions

File tree

lib/AppInfo/BeforeShareCreatedListener.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ public function overwriteShareTarget(IShare $share): void {
4949
$receiver = $share->getSharedWith();
5050
$receiverPath = $this->noteUtil->getRoot()->getUserFolder($receiver)->getPath();
5151
$receiverNotesInternalPath = $this->settings->get($receiver, 'notesPath');
52-
$receiverNotesPath = $receiverPath . '/' . $receiverNotesInternalPath;
53-
$this->noteUtil->getOrCreateFolder($receiverNotesPath);
52+
$this->noteUtil->getOrCreateNotesFolder($receiver);
5453

5554
if ($itemType !== 'file' || strpos($fileSourcePath, $ownerNotesPath) !== 0) {
5655
return;

lib/Service/NoteUtil.php

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,24 @@ class NoteUtil {
2121
private TagService $tagService;
2222
private IManager $shareManager;
2323
private IUserSession $userSession;
24+
private SettingsService $settingsService;
2425

2526
public function __construct(
2627
Util $util,
2728
IRootFolder $root,
2829
IDBConnection $db,
2930
TagService $tagService,
3031
IManager $shareManager,
31-
IUserSession $userSession
32+
IUserSession $userSession,
33+
SettingsService $settingsService
3234
) {
3335
$this->util = $util;
3436
$this->root = $root;
3537
$this->db = $db;
3638
$this->tagService = $tagService;
3739
$this->shareManager = $shareManager;
3840
$this->userSession = $userSession;
41+
$this->settingsService = $settingsService;
3942
}
4043

4144
public function getRoot() : IRootFolder {
@@ -172,9 +175,36 @@ public function getOrCreateFolder(string $path, bool $create = true) : Folder {
172175
throw new NotesFolderException($path.' is not a folder');
173176
}
174177

175-
if ($folder->isShared()) {
176-
$folderName = $this->root->getNonExistingName($path);
177-
$folder = $this->root->newFolder($folderName);
178+
return $folder;
179+
}
180+
181+
public function getOrCreateNotesFolder(string $userId, bool $create = true) : Folder {
182+
$userFolder = $this->getRoot()->getUserFolder($userId);
183+
$notesPath = $this->settingsService->get($userId, 'notesPath');
184+
$allowShared = $notesPath !== $this->settingsService->getDefaultNotesPath($userId);
185+
186+
$folder = null;
187+
$updateNotesPath = false;
188+
if ($userFolder->nodeExists($notesPath)) {
189+
$folder = $userFolder->get($notesPath);
190+
if (!$allowShared && $folder->isShared()) {
191+
$notesPath = $userFolder->getNonExistingName($notesPath);
192+
$folder = $userFolder->newFolder($notesPath);
193+
$updateNotesPath = true;
194+
}
195+
} elseif ($create) {
196+
$folder = $userFolder->newFolder($notesPath);
197+
$updateNotesPath = true;
198+
}
199+
200+
if (!($folder instanceof Folder)) {
201+
throw new NotesFolderException($notesPath . ' is not a folder');
202+
}
203+
204+
if ($updateNotesPath) {
205+
$this->settingsService->set($userId, [
206+
'notesPath' => $notesPath,
207+
]);
178208
}
179209

180210
return $folder;

lib/Service/NotesService.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -149,20 +149,8 @@ public function getTitleFromContent(string $content) : string {
149149
return $this->noteUtil->getSafeTitle($content);
150150
}
151151

152-
153-
154-
155-
156-
157-
/**
158-
* @param string $userId the user id
159-
* @return Folder
160-
*/
161152
private function getNotesFolder(string $userId, bool $create = true) : Folder {
162-
$userPath = $this->noteUtil->getRoot()->getUserFolder($userId)->getPath();
163-
$path = $userPath . '/' . $this->settings->get($userId, 'notesPath');
164-
$folder = $this->noteUtil->getOrCreateFolder($path, $create);
165-
return $folder;
153+
return $this->noteUtil->getOrCreateNotesFolder($userId, $create);
166154
}
167155

168156
/**

lib/Service/SettingsService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private function getListAttrs(string $attributeName, array $values) : array {
8181
];
8282
}
8383

84-
private function getDefaultNotesPath(string $uid) : string {
84+
public function getDefaultNotesPath(string $uid) : string {
8585
$defaultFolder = $this->config->getAppValue(Application::APP_ID, 'defaultFolder', 'Notes');
8686
$defaultExists = $this->root->getUserFolder($uid)->nodeExists($defaultFolder);
8787
if ($defaultExists) {

0 commit comments

Comments
 (0)