Skip to content

refactor: clarify fileCreate() condition by making the specific case explicit#2568

Merged
miaulalala merged 1 commit intomasterfrom
refactor/file-create-condition
May 7, 2026
Merged

refactor: clarify fileCreate() condition by making the specific case explicit#2568
miaulalala merged 1 commit intomasterfrom
refactor/file-create-condition

Conversation

@miaulalala
Copy link
Copy Markdown
Collaborator

Summary

The original condition in FilesHooks::fileCreate() used a double-negative (De Morgan) form:

// Before — hard to parse: "unless identifier is empty AND it's a public token"
if ($this->currentUser->getUserIdentifier() !== '' || !$this->currentUser->isPublicShareToken()) {
    // regular upload
} else {
    // public upload
}

Rewritten as a direct positive check, with the specific case (public upload) as the if-branch:

// After — reads naturally
if ($this->currentUser->getUserIdentifier() === '' && $this->currentUser->isPublicShareToken()) {
    // public upload
} else {
    // regular upload
}

Also adds the missing fourth test case: a non-empty identifier combined with isPublicShareToken=true (a logged-in user uploading to a public share link) → treated as a regular upload.

No behaviour change.

Test plan

  • All testFileCreate cases (4 data rows × 2 root tests = 6 assertions) — green

🤖 Generated with Claude Code

…explicit

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 <anna@nextcloud.com>
AI-Assisted-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@cypress
Copy link
Copy Markdown

cypress Bot commented May 6, 2026

Activity    Run #3707

Run Properties:  status check passed Passed #3707  •  git commit 4744d6ecde: refactor: clarify fileCreate() condition by making the specific case explicit
Project Activity
Branch Review refactor/file-create-condition
Run status status check passed Passed #3707
Run duration 02m 17s
Commit git commit 4744d6ecde: refactor: clarify fileCreate() condition by making the specific case explicit
Committer Anna
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 1
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 9
View all changes introduced in this branch ↗︎

Copy link
Copy Markdown
Contributor

@Antreesy Antreesy left a comment

Choose a reason for hiding this comment

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

This I can comprehend 🦭

@miaulalala miaulalala merged commit 1d4a9a8 into master May 7, 2026
56 of 58 checks passed
@miaulalala miaulalala deleted the refactor/file-create-condition branch May 7, 2026 11:10
@miaulalala
Copy link
Copy Markdown
Collaborator Author

/backport to stable33

@miaulalala
Copy link
Copy Markdown
Collaborator Author

/backport to stable32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants