Skip to content

fix(collections): reject unknown visibility on admin create and update - #1667

Merged
Quick104 merged 3 commits into
Silo-Server:mainfrom
dannyshafer:fix/1650-collection-visibility-validation
Oct 13, 2026
Merged

Quick104 merged 3 commits into
Silo-Server:mainfrom
dannyshafer:fix/1650-collection-visibility-validation

Conversation

@dannyshafer

@dannyshafer dannyshafer commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #1650
Related issue: N/A
Validation tasks: none

Creating or updating an admin collection with a visibility value other than visible or hidden returned 500 internal_error. The handler passed the string straight to the repository, where it violated library_collections_visibility_check. This change rejects unknown values with a 400 field error before any database access.

Approach

Admin create and update now validate visibility first. Unknown values return a visibility field error that names the allowed values. On create, an empty value still defaults to visible. On update, an omitted field leaves visibility unchanged and an explicit empty value is normalized to visible, since passing an empty string through would hit the same constraint. The v1 bridge routes share these handlers, so they get the same validation.

Validation

  • Unit tests cover rejection of an unknown value on create and update, acceptance of the allowed values, and the update normalization for omitted and empty values. They ran in CI and passed; I could not run go test locally because the package needs libvips (bimg cgo) and it would not build on my machine.
  • gofmt: clean.
  • CI: all required checks pass.

Evidence: none, no user-visible change

Risks

  • Unknown values now return a field error on visibility: 422 validation_failed at body.visibility on /api/v2, which is what the issue asked for, and 400 bad_request on the v1 bridge routes.
  • A client that was sending an explicit empty visibility on update now sets the collection to visible instead of getting a 500.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code (desktop app)
  • Tool(s): Claude Code (sub-agents, Bash, Edit), GitHub CLI
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: Kody reviewed the diff and found that an update with "visibility": "" still passed validation and would hit the constraint. Fixed by normalizing an explicit empty value to visible on update; Kody confirmed the approach. CodeRabbit hit its review limit and did not review this PR.

🤖 Generated with Claude Code

Note

Reject unknown visibility values on admin collection create and update

  • Adds validateCollectionVisibility and a hidden constant; only empty, visible, and hidden are accepted, and other values return a visibility field error in admin_collections_service.go.
  • Update requests now distinguish an omitted visibility (left unchanged) from an explicit empty value (normalized to visible) via normalizeCollectionVisibilityUpdate.
  • Risk: previously accepted unknown visibility values on admin create/update now fail with a bad-request field error; check createAdminCollection and updateAdminCollection for any callers relying on the old passthrough behavior.

Macroscope summarized 792e885.

An unknown visibility value reached the library_collections CHECK
constraint and surfaced as a 500. Validate it in the handler and return a
visibility field error instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5c920ff7-1a92-40ec-840f-8e2a5d1a83da

📥 Commits

Reviewing files that changed from the base of the PR and between 0eddbf9 and 792e885.


📒 Files selected for processing (2)
  • internal/api/handlers/admin_collections_service.go
  • internal/api/handlers/admin_collections_service_test.go

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@kody-ai

kody-ai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Code Review Completed! 🔥

The code review was successfully completed based on your current configurations.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the `@kody start-review` command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Providing Context (Files & MCPs)

Add these hints in your PR description (or a comment) to unlock deeper checks:

  • Ticket / Acceptance Criteria: `Refs: ABC-123` (Linear/Jira/Asana/ClickUp/Trello) or a direct ticket link.
  • Bugfix Validation: a Sentry/Datadog/Bugsnag event link (or paste the stack trace/error message).
  • Endpoint Risk: mention the route (e.g., `POST /api/payments`) or controller/action name.
  • Attach a repo file as context: use an explicit marker like `@file:docs/guide.mdx#L10-L50` (replace with your real path).
  • API Contract Docs: include `@file:openapi.yaml` or `@file:swagger.json` when changing routes/schemas.
  • Definition of Done / Standards: include `@file:DOD.md` or `@file:CONTRIBUTING.md` if your repo has them.
  • Design System Source of Truth: include `@file:ui/index.ts` (replace with your DS entrypoint path).
  • Feature Flags: include the flag key/name and `@file:flags.ts` / `@file:config.json` (and optionally the PostHog flag name).
  • Edge/CDN Rules: link the Cloudflare rule/zone or describe the intended redirect/header behavior.
  • Attach an MCP tool output: use `@mcp<provider|tool>` (replace with an installed MCP provider + tool, e.g., `@mcp<sentry|events.search>`).
Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

Access your configuration settings here.

@macroscopeapp

macroscopeapp Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

The PR body is missing the required Validation tasks: line. I found no recorded Collections case this patch invalidates or unblocks: related reports concern personal-collection counts, sharing, ordering, or generated posters, not admin visibility validation.

Please add:
Validation tasks: none

Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed.

Posted via Macroscope — v1 validation impact

@kody-ai

kody-ai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Code Review Completed! 🔥

The code review was successfully completed based on your current configurations.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the `@kody start-review` command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Providing Context (Files & MCPs)

Add these hints in your PR description (or a comment) to unlock deeper checks:

  • Ticket / Acceptance Criteria: `Refs: ABC-123` (Linear/Jira/Asana/ClickUp/Trello) or a direct ticket link.
  • Bugfix Validation: a Sentry/Datadog/Bugsnag event link (or paste the stack trace/error message).
  • Endpoint Risk: mention the route (e.g., `POST /api/payments`) or controller/action name.
  • Attach a repo file as context: use an explicit marker like `@file:docs/guide.mdx#L10-L50` (replace with your real path).
  • API Contract Docs: include `@file:openapi.yaml` or `@file:swagger.json` when changing routes/schemas.
  • Definition of Done / Standards: include `@file:DOD.md` or `@file:CONTRIBUTING.md` if your repo has them.
  • Design System Source of Truth: include `@file:ui/index.ts` (replace with your DS entrypoint path).
  • Feature Flags: include the flag key/name and `@file:flags.ts` / `@file:config.json` (and optionally the PostHog flag name).
  • Edge/CDN Rules: link the Cloudflare rule/zone or describe the intended redirect/header behavior.
  • Attach an MCP tool output: use `@mcp<provider|tool>` (replace with an installed MCP provider + tool, e.g., `@mcp<sentry|events.search>`).
Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

Access your configuration settings here.

@kody-ai

kody-ai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Code Review Completed! 🔥

The code review was successfully completed based on your current configurations.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the `@kody start-review` command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Providing Context (Files & MCPs)

Add these hints in your PR description (or a comment) to unlock deeper checks:

  • Ticket / Acceptance Criteria: `Refs: ABC-123` (Linear/Jira/Asana/ClickUp/Trello) or a direct ticket link.
  • Bugfix Validation: a Sentry/Datadog/Bugsnag event link (or paste the stack trace/error message).
  • Endpoint Risk: mention the route (e.g., `POST /api/payments`) or controller/action name.
  • Attach a repo file as context: use an explicit marker like `@file:docs/guide.mdx#L10-L50` (replace with your real path).
  • API Contract Docs: include `@file:openapi.yaml` or `@file:swagger.json` when changing routes/schemas.
  • Definition of Done / Standards: include `@file:DOD.md` or `@file:CONTRIBUTING.md` if your repo has them.
  • Design System Source of Truth: include `@file:ui/index.ts` (replace with your DS entrypoint path).
  • Feature Flags: include the flag key/name and `@file:flags.ts` / `@file:config.json` (and optionally the PostHog flag name).
  • Edge/CDN Rules: link the Cloudflare rule/zone or describe the intended redirect/header behavior.
  • Attach an MCP tool output: use `@mcp<provider|tool>` (replace with an installed MCP provider + tool, e.g., `@mcp<sentry|events.search>`).
Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

Access your configuration settings here.

@Quick104
Quick104 marked this pull request as draft October 6, 2026 19:20

Quick104 commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Silo's pull request guidance changed today (#2016). A PR that changes what a user sees now needs before-and-after evidence in its Evidence section, and a PR with no visible change says Evidence: none, no user-visible change. This PR was opened before the rule existed, so it hasn't had a chance to meet it yet.

Missing here: Needs the line 'Evidence: none, no user-visible change'.

The rules are in Show visible changes, and the PR template shows the Evidence section layout. I've converted this PR to draft for now. Mark it ready for review once the Evidence section is filled in.


Generated by Claude Code

@dannyshafer

Copy link
Copy Markdown
Contributor Author

Thanks for the pointer to the updated guidance. Evidence for this one:

Evidence: none, no user-visible change

The change only affects how the admin collections create/update endpoints answer an unknown visibility value (400 field error instead of a 500). No client renders a new or different field, and valid requests behave exactly as before.

@dannyshafer
dannyshafer marked this pull request as ready for review October 10, 2026 16:18
@silo-kody

silo-kody Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-10T16:22:26.010256Z 792e885 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@dannyshafer

Copy link
Copy Markdown
Contributor Author

@Quick104 the Evidence: none, no user-visible change line is now in the Validation section of the description, and Kody's empty-visibility finding was fixed in 792e885. Ready for another look when you have time.

@Quick104

Copy link
Copy Markdown
Contributor

Review summary

Reviewed head: 792e885. It merges cleanly with current main, and main still has no visibility validation, so this PR is still needed.

Fit: 9/10 · Readiness: 9/10 — ready

I found no defects in the code. It closes #1650 as filed.

  • Unknown visibility values stop at validateCollectionVisibility before any database write, on create and on update. On /api/v2 both requests now return 422 validation_failed with an error at body.visibility, which is what [bug] Admin collection create and update return 500 for an unknown visibility value #1650 asked for. I checked this by passing the service error through adminCollectionError. The v1 bridge routes return a 400 field error.
  • No other path writes caller-supplied visibility. Imports and template bundles hard-code visible, and sync and artwork writes leave visibility alone.
  • The v2 PATCH still checks existence and If-Match before the service runs. On v1, an invalid visibility sent to a missing collection now gets 400 instead of 404. That request failed before too, so nothing that worked has changed.
  • Kody's empty-string finding is fixed in 792e885: an explicit "" on update becomes visible, and an omitted field leaves visibility unchanged.

PR body change

I corrected the first line under Risks. It said the change returns 400 where the issue wanted 422, but on /api/v2 it returns 422 validation_failed. Only the v1 bridge routes return 400.

A note for maintainers, not a blocker

On update, an explicit "visibility": "" now makes a hidden collection visible. The description already mentions this. Before this change that request returned 500, so no working client depends on it, and the web UI only sends visible or hidden. If you'd rather reject an explicit empty value on update, that's a two-line change in normalizeCollectionVisibilityUpdate.

Pre-existing defect, filed separately

collection_type fails in the same way: an unknown value passes every handler check and the library_collections_collection_type_check constraint turns it into a 500 on create and update. That bug is older than this PR, so I filed it as #2418. Its fix belongs next to the validation this PR adds, so it should land after this one merges. #2418 also suggests declaring the allowed values for both fields as enums in the v2 request schema before /api/v2 locks.

Validated features

Nothing changes. On the Collections server task (#193), the passed cases S1–S3, S5, and the passed parts of S4 and S6 cover admin authorization, reads, and personal collections. Requests with visible or hidden behave exactly as before, and the admin check that S5 exercises runs before this code. The Web admin task (#194) has no recorded results. Validation tasks: none is correct. I read the task issues directly; I couldn't read the project board.

Other checks

  • CI: all required checks pass on 792e885. I also ran the focused handler tests locally, and they pass.
  • User manual: no change needed. siloserver.org doesn't describe collection visibility values.
  • Apple, Android, and Jellyfin compatibility: no follow-up. Neither app sends admin collection mutations, and jellycompat only reads the stored visibility.
  • A Codex review (gpt-6.1-sol) of this head found no defects. It also caught the incorrect status code in the description.
  • No live deployment run; the evidence above comes from source, unit tests, and the error-mapping check.

Review by Claude Code (claude-opus-5-5) with a Codex (gpt-6.1-sol) cross-check.

@Quick104
Quick104 merged commit 626d29f into Silo-Server:main Oct 13, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Admin collection create and update return 500 for an unknown visibility value

2 participants