From 81cbd9bd8b56ecdb69de7b8704c10553ea8ff198 Mon Sep 17 00:00:00 2001 From: Anna Larch Date: Thu, 7 May 2026 00:17:26 +0200 Subject: [PATCH] refactor: clarify fileCreate() condition by making the specific case explicit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The original condition used a double-negative (De Morgan) form that made the public-upload branch hard to read as the else. Rewrite as a positive check — empty identifier AND public share token — and make the public-upload path the if-branch. Adds the missing fourth test case (non-empty identifier + isPublicShareToken=true → regular upload). Signed-off-by: Anna Larch AI-Assisted-By: Claude Sonnet 4.6 --- lib/FilesHooks.php | 6 +++--- tests/FilesHooksTest.php | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/FilesHooks.php b/lib/FilesHooks.php index 68390756e..aa1d6ea4e 100644 --- a/lib/FilesHooks.php +++ b/lib/FilesHooks.php @@ -82,10 +82,10 @@ public function fileCreate($path) { return; } - if ($this->currentUser->getUserIdentifier() !== '' || !$this->currentUser->isPublicShareToken()) { - $this->addNotificationsForFileAction($path, Files::TYPE_SHARE_CREATED, 'created_self', 'created_by'); - } else { + if ($this->currentUser->getUserIdentifier() === '' && $this->currentUser->isPublicShareToken()) { $this->addNotificationsForFileAction($path, Files_Sharing::TYPE_PUBLIC_UPLOAD, '', 'created_public'); + } else { + $this->addNotificationsForFileAction($path, Files::TYPE_SHARE_CREATED, 'created_self', 'created_by'); } } diff --git a/tests/FilesHooksTest.php b/tests/FilesHooksTest.php index d31912eee..8457f9818 100644 --- a/tests/FilesHooksTest.php +++ b/tests/FilesHooksTest.php @@ -171,6 +171,8 @@ public static function dataFileCreate(): array { ['user', false, 'created_self', 'created_by', Files::TYPE_SHARE_CREATED], ['', true, '', 'created_public', Files_Sharing::TYPE_PUBLIC_UPLOAD], ['', false, 'created_self', 'created_by', Files::TYPE_SHARE_CREATED], + // logged-in user uploading to a public share link → treated as regular upload + ['user', true, 'created_self', 'created_by', Files::TYPE_SHARE_CREATED], ]; }