Skip to content

Commit f5adc21

Browse files
committed
address feedback
1 parent e19b79b commit f5adc21

File tree

6 files changed

+39
-19
lines changed

6 files changed

+39
-19
lines changed

lib/AppInfo/BeforeShareCreatedListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ public function overwriteShareTarget(IShare $share): void {
5050
$itemTarget = $share->getTarget();
5151
$uidOwner = $share->getSharedBy();
5252
$ownerPath = $this->noteUtil->getRoot()->getUserFolder($uidOwner)->getPath();
53-
$ownerNotesPath = $ownerPath . '/' . $this->settings->get($uidOwner, 'notesPath');
53+
$ownerNotesPath = $ownerPath . '/' . $this->settings->getValueString($uidOwner, 'notesPath');
5454

5555
$receiver = $share->getSharedWith();
5656
$receiverPath = $this->noteUtil->getRoot()->getUserFolder($receiver)->getPath();
57-
$receiverNotesInternalPath = $this->settings->get($receiver, 'notesPath');
57+
$receiverNotesInternalPath = $this->settings->getValueString($receiver, 'notesPath');
5858
$this->noteUtil->getOrCreateNotesFolder($receiver);
5959

6060
if ($itemType !== 'file' || strpos($fileSourcePath, $ownerNotesPath) !== 0) {

lib/Controller/NotesController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ public function uploadFile(int $noteid): JSONResponse {
359359
}
360360

361361
private function inLockScope(Note $note, callable $callback) {
362-
$isRichText = $this->settingsService->get($this->helper->getUID(), 'noteMode') === 'rich';
362+
$isRichText = $this->settingsService->getValueString($this->helper->getUID(), 'noteMode') === 'rich';
363363
$lockContext = new LockContext(
364364
$note->getFile(),
365365
$isRichText ? ILock::TYPE_APP : ILock::TYPE_USER,

lib/Service/NoteUtil.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public function getNotesFolderUserPath(string $userId): ?string {
197197

198198
public function getOrCreateNotesFolder(string $userId, bool $create = true) : Folder {
199199
$userFolder = $this->getRoot()->getUserFolder($userId);
200-
$notesPath = $this->settingsService->get($userId, 'notesPath');
200+
$notesPath = $this->settingsService->getValueString($userId, 'notesPath');
201201
$allowShared = $notesPath !== $this->settingsService->getDefaultNotesPath($userId);
202202

203203
$folder = null;

lib/Service/NotesService.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function getAll(string $userId, bool $autoCreateNotesFolder = false, ?boo
3535
try {
3636
$notesFolder = $this->getNotesFolder($userId, $autoCreateNotesFolder);
3737
if ($showHidden === null) {
38-
$showHidden = $this->settings->get($userId, 'showHidden');
38+
$showHidden = $this->settings->getValueBool($userId, 'showHidden');
3939
}
4040
$data = self::gatherNoteFiles($customExtension, $notesFolder, $showHidden);
4141
$fileIds = array_keys($data['files']);
@@ -69,7 +69,7 @@ public function countNotes(string $userId) : int {
6969
$customExtension = $this->getCustomExtension($userId);
7070
try {
7171
$notesFolder = $this->getNotesFolder($userId, false);
72-
$showHidden = $this->settings->get($userId, 'showHidden');
72+
$showHidden = $this->settings->getValueBool($userId, 'showHidden');
7373
$data = self::gatherNoteFiles($customExtension, $notesFolder, $showHidden);
7474
return count($data['files']);
7575
} catch (NotesFolderException $e) {
@@ -132,9 +132,9 @@ public function create(string $userId, string $title, string $category) : Note {
132132
$this->noteUtil->ensureSufficientStorage($folder, 1);
133133

134134
// get file name
135-
$fileSuffix = $this->settings->get($userId, 'fileSuffix');
135+
$fileSuffix = $this->settings->getValueString($userId, 'fileSuffix');
136136
if ($fileSuffix === 'custom') {
137-
$fileSuffix = $this->settings->get($userId, 'customSuffix');
137+
$fileSuffix = $this->settings->getValueString($userId, 'customSuffix');
138138
}
139139
$filename = $this->noteUtil->generateFileName($folder, $title, $fileSuffix, -1);
140140
// create file
@@ -211,7 +211,7 @@ private static function isNote(FileInfo $file, string $customExtension) : bool {
211211
* Retrieve the value of user defined files extension
212212
*/
213213
private function getCustomExtension(string $userId) {
214-
$suffix = $this->settings->get($userId, 'customSuffix');
214+
$suffix = $this->settings->getValueString($userId, 'customSuffix');
215215
return ltrim($suffix, '.');
216216
}
217217

lib/Service/SettingsService.php

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ public function __construct(
6969
},
7070
],
7171
'showHidden' => [
72-
'default' => true,
73-
'validate' => function ($value) {
72+
'default' => false,
73+
'validate' => function (mixed $value) : bool {
7474
return (bool)$value;
7575
}
7676
],
@@ -175,13 +175,15 @@ public function getAll(string $uid, $saveInitial = false) : \stdClass {
175175
/**
176176
* @throws \OCP\PreConditionNotMetException
177177
*/
178-
public function get(string $uid, string $name) : string|bool {
179-
$settings = $this->getAll($uid);
180-
if (property_exists($settings, $name)) {
181-
return $settings->{$name};
182-
} else {
183-
throw new \OCP\PreConditionNotMetException('Setting ' . $name . ' not found for user ' . $uid . '.');
184-
}
178+
public function getValueString(string $uid, string $name) : string {
179+
return $this->get($uid, $name, 'string');
180+
}
181+
182+
/**
183+
* @throws \OCP\PreConditionNotMetException
184+
*/
185+
public function getValueBool(string $uid, string $name) : bool {
186+
return $this->get($uid, $name, 'boolean');
185187
}
186188

187189
public function delete(string $uid, string $name): void {
@@ -204,4 +206,22 @@ private function getAvailableEditorModes(): array {
204206
? ['rich', 'edit', 'preview']
205207
: ['edit', 'preview'];
206208
}
209+
210+
/**
211+
* @throws \OCP\PreConditionNotMetException
212+
*/
213+
private function get(string $uid, string $name, string $type) : mixed {
214+
$settings = $this->getAll($uid);
215+
if (property_exists($settings, $name)) {
216+
$value = $settings->{$name};
217+
if (gettype($value) !== $type) {
218+
throw new \TypeError('Invalid type');
219+
}
220+
221+
return $value;
222+
} else {
223+
throw new \OCP\PreConditionNotMetException('Setting ' . $name . ' not found for user ' . $uid . '.');
224+
}
225+
}
226+
207227
}

src/components/AppSettings.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
{{ t('notes', 'Organize your notes in categories.') }}
2323
</div>
2424
</NcAppSettingsSection>
25-
<NcAppSettingsSection id="notes-path-section" :name="t('notes', 'Notes folder')">
25+
<NcAppSettingsSection id="notes-path-section" :name="t('notes', 'Notes path')">
2626
<p class="app-settings-section__desc">
2727
{{ t('notes', 'Folder to store your notes') }}
2828
</p>

0 commit comments

Comments
 (0)