Skip to content

fix(help-center): keep drafts and private content behind help_center.manage, count only openable articles, one vote per signed-out visitor - #1202

Open
mortondev wants to merge 2 commits into
mainfrom
fix/help-center-access
Open

mortondev wants to merge 2 commits into
mainfrom
fix/help-center-access

Conversation

@mortondev

Copy link
Copy Markdown
Member

Fixes three help center access bugs that the product e2e suite found. The owner should review the access decisions listed below.

Fixed quarantined e2e journeys

  • HC-A-76 (HC-B3): a key without help_center.manage could read drafts and private categories over REST.
  • HC-P-04 (HC-B14): the landing card count included articles in private and gated subcategories and gated articles.
  • HC-F-05 (HC-B2): a signed-out visitor who voted Yes and then No left two votes.

These specs are on #1159 and #1174, which are still open. I have not run them locally against this branch. Unit, component and DB tests cover each fix.

Changes

REST reads (HC-B3)

  • New apiKeyHolds(auth, permission) in domains/api/auth.ts. It checks the permission and the scope that permission maps to, using the same rules as the write gates, but returns a boolean.
  • GET /help-center/articles: a key without manage gets listPublicArticles, which returns published articles in public categories that no segment gate hides. status is ignored for these keys.
  • GET /help-center/articles/{id} and GET /help-center/categories/{id}: a draft, a private or gated article, or a private or gated category answers 403 for a key without manage. An id that does not exist still answers 404.
  • GET /help-center/categories: a key without manage gets listPublicCategories, with counts that include only articles everyone can open.
  • The OpenAPI descriptions now explain this, and the two detail reads list 403.

Landing card counts (HC-B14)

  • listPublicCategories has moved to help-center.public-category.query.ts. The category service re-exports it, so callers are unchanged. It counts only articles that pass helpCenterVisibilityConditions('public', viewer), and adds up subcategories the viewer can open. A subcategory the viewer cannot open adds nothing to its parent, and neither does anything below it. This matches what the category page links to.

Signed-out votes (HC-B2)

  • recordArticleFeedback(articleId, helpful, principalId, { replaces }): a signed-out vote can now replace an earlier vote, found by the id the page was given. It only replaces a signed-out vote on the same article, so a vote id cannot reach a signed-in visitor's vote or a vote on another article. The flip is guarded in the UPDATE's WHERE clause, and the counters change only when a row actually flipped.
  • articleFeedbackSchema has a new optional replacesFeedbackId, validated as a kb_article_feedback TypeID. The portal feedback component sends it after the first vote.

Decisions for the owner

  • A scoped key without write:article now gets only the public content, even an admin's read:article key. Its lists shrink quietly instead of answering 403.
  • An id that exists but is not open to the key answers 403, and a missing id answers 404. The e2e spec asserts 403.
  • For a key without manage, the category list leaves out public categories that contain nothing everyone can open.
  • Widget votes are unchanged, because a widget visitor gets a session principal. Signed-out portal votes are deduplicated within the page, using the vote id.

Tests (RED on origin/main, GREEN here)

  • routes/api/v1/help-center/__tests__/read-access.test.ts: on origin/main, all 8 checks of what a contributor key and a read-scoped owner key may read failed. 5 checks confirm that manager keys and public reads still work.
  • domains/help-center/__tests__/help-center-public-access.db.test.ts runs against a real DB using the transactional fixture. On origin/main the card count was 9 where 2 is right, an all-hidden parent was listed, and both vote-flip tests failed. A guard test checks that a signed-in vote and a vote on another article are never rewritten.
  • components/help-center/__tests__/help-center-article-feedback.test.tsx: on origin/main, the second vote did not send the earlier vote id.
  • lib/shared/schemas/__tests__/article-feedback-schema.test.ts checks which vote ids the schema accepts and refuses.
  • Existing tests updated: the route test auth mocks now keep the real apiKeyHolds, and the mocked listPublicCategories tests match the new count query.

oxlint, prettier and the web typecheck are clean. All tests in the help-center domain, the REST routes, the API domain and the help-center components pass.

Notes

  • The MCP quackback://help-center/categories resource (lib/server/mcp/server.ts around line 195) checks only for a team role, so it lists private categories to any teammate. MCP search and get already require help_center.manage. This PR leaves the resource unchanged.
  • This PR and fix/help-center-authoring both edit routes/api/v1/help-center/{articles/$articleId,categories/$categoryId}.ts, lib/shared/schemas/help-center.ts and lib/server/functions/help-center.ts, in different hunks. Whichever merges second needs a rebase. fix/rest-input-errors also edits these routes.

…d count only what visitors can open

- REST GET article/category reads: a key without help_center.manage (or a
  scoped key without its scope) reads only the published public help center.
  A draft, private or gated article or category answers 403; the lists fall
  back to the public slice.
- listPublicCategories counts articles the viewer can open, rolled up only
  through subcategories the viewer can open.
- A signed-out visitor who changes their vote replaces it instead of adding a
  second one: the page sends back the vote id it was handed, and the service
  flips that row only when it is a signed-out vote on the same article.

This branch has not been deployed

No deployments
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.

1 participant