Skip to content
Open
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 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) {

Check failure on line 213 in lib/Service/NoteUtil.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable29

RiskyTruthyFalsyComparison

lib/Service/NoteUtil.php:213:7: RiskyTruthyFalsyComparison: Operand of type mixed|null contains type mixed, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead. (see https://psalm.dev/356)

Check failure on line 213 in lib/Service/NoteUtil.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

RiskyTruthyFalsyComparison

lib/Service/NoteUtil.php:213:7: RiskyTruthyFalsyComparison: Operand of type mixed|null contains type mixed, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead. (see https://psalm.dev/356)

Check failure on line 213 in lib/Service/NoteUtil.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable30

RiskyTruthyFalsyComparison

lib/Service/NoteUtil.php:213:7: RiskyTruthyFalsyComparison: Operand of type mixed|null contains type mixed, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead. (see https://psalm.dev/356)

Check failure on line 213 in lib/Service/NoteUtil.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable28

RiskyTruthyFalsyComparison

lib/Service/NoteUtil.php:213:7: RiskyTruthyFalsyComparison: Operand of type mixed|null contains type mixed, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead. (see https://psalm.dev/356)

Check failure on line 213 in lib/Service/NoteUtil.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable31

RiskyTruthyFalsyComparison

lib/Service/NoteUtil.php:213:7: RiskyTruthyFalsyComparison: Operand of type mixed|null contains type mixed, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead. (see https://psalm.dev/356)
if (!$allowShared && $folder->isShared()) {
$notesPath = $userFolder->getNonExistingName($notesPath);
$folder = $userFolder->newFolder($notesPath);
Expand Down
48 changes: 41 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 @@
'fileSuffix' => $this->getListAttrs('fileSuffix', [...$this->defaultSuffixes, 'custom']),
'notesPath' => [
'default' => function (string $uid) {
return $this->getDefaultNotesPath($uid);
return $this->getDefaultNotesNode($uid)['path'];
Copy link
Member Author

Choose a reason for hiding this comment

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

not the biggest fan of that, I wonder if it would make sense to keep the old getDefaultNotesPath as it is for this part

},
'validate' => function ($value) {
$value = str_replace([ '/', '\\' ], DIRECTORY_SEPARATOR, $value);
Expand Down Expand Up @@ -86,13 +88,45 @@
];
}

public function getDefaultNotesPath(string $uid) : string {
/**
* Return the default notes node if it exists and the expected path if it exists
* @return array{

Check failure on line 93 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable29

InvalidReturnType

lib/Service/SettingsService.php:93:13: InvalidReturnType: The declared return type 'array{folder: OCP\Files\Folder, path: string}' for OCA\Notes\Service\SettingsService::getDefaultNotesNode is incorrect, got 'array{node: mixed|null, path: string}' which is different due to additional array shape fields (node) (see https://psalm.dev/011)

Check failure on line 93 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

InvalidReturnType

lib/Service/SettingsService.php:93:13: InvalidReturnType: The declared return type 'array{folder: OCP\Files\Folder, path: string}' for OCA\Notes\Service\SettingsService::getDefaultNotesNode is incorrect, got 'array{node: mixed|null, path: string}' which is different due to additional array shape fields (node) (see https://psalm.dev/011)

Check failure on line 93 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable30

InvalidReturnType

lib/Service/SettingsService.php:93:13: InvalidReturnType: The declared return type 'array{folder: OCP\Files\Folder, path: string}' for OCA\Notes\Service\SettingsService::getDefaultNotesNode is incorrect, got 'array{node: mixed|null, path: string}' which is different due to additional array shape fields (node) (see https://psalm.dev/011)

Check failure on line 93 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable28

InvalidReturnType

lib/Service/SettingsService.php:93:13: InvalidReturnType: The declared return type 'array{folder: OCP\Files\Folder, path: string}' for OCA\Notes\Service\SettingsService::getDefaultNotesNode is incorrect, got 'array{node: mixed|null, path: string}' which is different due to additional array shape fields (node) (see https://psalm.dev/011)

Check failure on line 93 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable31

InvalidReturnType

lib/Service/SettingsService.php:93:13: InvalidReturnType: The declared return type 'array{folder: OCP\Files\Folder, path: string}' for OCA\Notes\Service\SettingsService::getDefaultNotesNode is incorrect, got 'array{node: mixed|null, path: string}' which is different due to additional array shape fields (node) (see https://psalm.dev/011)
* 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 {
$node = $userFolder->get($defaultFolder);
return [

Check failure on line 103 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable29

InvalidReturnStatement

lib/Service/SettingsService.php:103:11: InvalidReturnStatement: The inferred type 'array{node: mixed, path: string}' does not match the declared return type 'array{folder: OCP\Files\Folder, path: string}' for OCA\Notes\Service\SettingsService::getDefaultNotesNode due to additional array shape fields (node) (see https://psalm.dev/128)

Check failure on line 103 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

InvalidReturnStatement

lib/Service/SettingsService.php:103:11: InvalidReturnStatement: The inferred type 'array{node: mixed, path: string}' does not match the declared return type 'array{folder: OCP\Files\Folder, path: string}' for OCA\Notes\Service\SettingsService::getDefaultNotesNode due to additional array shape fields (node) (see https://psalm.dev/128)

Check failure on line 103 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable30

InvalidReturnStatement

lib/Service/SettingsService.php:103:11: InvalidReturnStatement: The inferred type 'array{node: mixed, path: string}' does not match the declared return type 'array{folder: OCP\Files\Folder, path: string}' for OCA\Notes\Service\SettingsService::getDefaultNotesNode due to additional array shape fields (node) (see https://psalm.dev/128)

Check failure on line 103 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable28

InvalidReturnStatement

lib/Service/SettingsService.php:103:11: InvalidReturnStatement: The inferred type 'array{node: mixed, path: string}' does not match the declared return type 'array{folder: OCP\Files\Folder, path: string}' for OCA\Notes\Service\SettingsService::getDefaultNotesNode due to additional array shape fields (node) (see https://psalm.dev/128)

Check failure on line 103 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable31

InvalidReturnStatement

lib/Service/SettingsService.php:103:11: InvalidReturnStatement: The inferred type 'array{node: mixed, path: string}' does not match the declared return type 'array{folder: OCP\Files\Folder, path: string}' for OCA\Notes\Service\SettingsService::getDefaultNotesNode due to additional array shape fields (node) (see https://psalm.dev/128)
'path' => $defaultFolder,
'node' => $node,
];
} catch (NotFoundException) {
$path = $this->l10n->t($defaultFolder);

if ($path == $defaultFolder) {
// English locale, still non-existing
return [

Check failure on line 112 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable29

InvalidReturnStatement

lib/Service/SettingsService.php:112:12: InvalidReturnStatement: The inferred type 'array{node: null, path: string}' does not match the declared return type 'array{folder: OCP\Files\Folder, path: string}' for OCA\Notes\Service\SettingsService::getDefaultNotesNode due to additional array shape fields (node) (see https://psalm.dev/128)

Check failure on line 112 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

InvalidReturnStatement

lib/Service/SettingsService.php:112:12: InvalidReturnStatement: The inferred type 'array{node: null, path: string}' does not match the declared return type 'array{folder: OCP\Files\Folder, path: string}' for OCA\Notes\Service\SettingsService::getDefaultNotesNode due to additional array shape fields (node) (see https://psalm.dev/128)

Check failure on line 112 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable30

InvalidReturnStatement

lib/Service/SettingsService.php:112:12: InvalidReturnStatement: The inferred type 'array{node: null, path: string}' does not match the declared return type 'array{folder: OCP\Files\Folder, path: string}' for OCA\Notes\Service\SettingsService::getDefaultNotesNode due to additional array shape fields (node) (see https://psalm.dev/128)

Check failure on line 112 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable28

InvalidReturnStatement

lib/Service/SettingsService.php:112:12: InvalidReturnStatement: The inferred type 'array{node: null, path: string}' does not match the declared return type 'array{folder: OCP\Files\Folder, path: string}' for OCA\Notes\Service\SettingsService::getDefaultNotesNode due to additional array shape fields (node) (see https://psalm.dev/128)

Check failure on line 112 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable31

InvalidReturnStatement

lib/Service/SettingsService.php:112:12: InvalidReturnStatement: The inferred type 'array{node: null, path: string}' does not match the declared return type 'array{folder: OCP\Files\Folder, path: string}' for OCA\Notes\Service\SettingsService::getDefaultNotesNode due to additional array shape fields (node) (see https://psalm.dev/128)
'path' => $path,
'node' => null,
];
}

try {
$node = $userFolder->get($path);
return [

Check failure on line 120 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable29

InvalidReturnStatement

lib/Service/SettingsService.php:120:12: InvalidReturnStatement: The inferred type 'array{node: mixed, path: string}' does not match the declared return type 'array{folder: OCP\Files\Folder, path: string}' for OCA\Notes\Service\SettingsService::getDefaultNotesNode due to additional array shape fields (node) (see https://psalm.dev/128)

Check failure on line 120 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

InvalidReturnStatement

lib/Service/SettingsService.php:120:12: InvalidReturnStatement: The inferred type 'array{node: mixed, path: string}' does not match the declared return type 'array{folder: OCP\Files\Folder, path: string}' for OCA\Notes\Service\SettingsService::getDefaultNotesNode due to additional array shape fields (node) (see https://psalm.dev/128)

Check failure on line 120 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable30

InvalidReturnStatement

lib/Service/SettingsService.php:120:12: InvalidReturnStatement: The inferred type 'array{node: mixed, path: string}' does not match the declared return type 'array{folder: OCP\Files\Folder, path: string}' for OCA\Notes\Service\SettingsService::getDefaultNotesNode due to additional array shape fields (node) (see https://psalm.dev/128)

Check failure on line 120 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable28

InvalidReturnStatement

lib/Service/SettingsService.php:120:12: InvalidReturnStatement: The inferred type 'array{node: mixed, path: string}' does not match the declared return type 'array{folder: OCP\Files\Folder, path: string}' for OCA\Notes\Service\SettingsService::getDefaultNotesNode due to additional array shape fields (node) (see https://psalm.dev/128)

Check failure on line 120 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable31

InvalidReturnStatement

lib/Service/SettingsService.php:120:12: InvalidReturnStatement: The inferred type 'array{node: mixed, path: string}' does not match the declared return type 'array{folder: OCP\Files\Folder, path: string}' for OCA\Notes\Service\SettingsService::getDefaultNotesNode due to additional array shape fields (node) (see https://psalm.dev/128)
'path' => $path,
'node' => $node,
];
} catch (NotFoundException) {
return [

Check failure on line 125 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable29

InvalidReturnStatement

lib/Service/SettingsService.php:125:12: InvalidReturnStatement: The inferred type 'array{node: null, path: string}' does not match the declared return type 'array{folder: OCP\Files\Folder, path: string}' for OCA\Notes\Service\SettingsService::getDefaultNotesNode due to additional array shape fields (node) (see https://psalm.dev/128)

Check failure on line 125 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

InvalidReturnStatement

lib/Service/SettingsService.php:125:12: InvalidReturnStatement: The inferred type 'array{node: null, path: string}' does not match the declared return type 'array{folder: OCP\Files\Folder, path: string}' for OCA\Notes\Service\SettingsService::getDefaultNotesNode due to additional array shape fields (node) (see https://psalm.dev/128)

Check failure on line 125 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable30

InvalidReturnStatement

lib/Service/SettingsService.php:125:12: InvalidReturnStatement: The inferred type 'array{node: null, path: string}' does not match the declared return type 'array{folder: OCP\Files\Folder, path: string}' for OCA\Notes\Service\SettingsService::getDefaultNotesNode due to additional array shape fields (node) (see https://psalm.dev/128)

Check failure on line 125 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable28

InvalidReturnStatement

lib/Service/SettingsService.php:125:12: InvalidReturnStatement: The inferred type 'array{node: null, path: string}' does not match the declared return type 'array{folder: OCP\Files\Folder, path: string}' for OCA\Notes\Service\SettingsService::getDefaultNotesNode due to additional array shape fields (node) (see https://psalm.dev/128)

Check failure on line 125 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable31

InvalidReturnStatement

lib/Service/SettingsService.php:125:12: InvalidReturnStatement: The inferred type 'array{node: null, path: string}' does not match the declared return type 'array{folder: OCP\Files\Folder, path: string}' for OCA\Notes\Service\SettingsService::getDefaultNotesNode due to additional array shape fields (node) (see https://psalm.dev/128)
'path' => $path,
'node' => null,
];
}
}
}

Expand Down
Loading