feat: allow admins to preview draft articles #224

Merged
erik merged 1 commit from feat/task-551421c7-admin-article-previews into main 2026-06-28 07:05:15 -05:00
Owner

Summary

  • Allow /posts/:slug to resolve unpublished article drafts only for authenticated admin users.
  • Keep anonymous users, non-admin authenticated users, unpublished notes, and unpublished links on the not-found path.
  • Add a visible unpublished draft indicator and admin-only preview notice on draft article detail pages.
  • Preserve existing published post detail behavior.

Verification

  • npm exec --workspace @slugkit/template-site -- vitest run --config ./vitest.config.ts src/routes/tests/public.test.ts
  • npm run typecheck --workspace @slugkit/template-site
  • npm run lint
  • ./scripts/pre-pr.sh

Task: #task-551421c7

## Summary - Allow `/posts/:slug` to resolve unpublished article drafts only for authenticated admin users. - Keep anonymous users, non-admin authenticated users, unpublished notes, and unpublished links on the not-found path. - Add a visible unpublished draft indicator and admin-only preview notice on draft article detail pages. - Preserve existing published post detail behavior. ## Verification - npm exec --workspace @slugkit/template-site -- vitest run --config ./vitest.config.ts src/routes/__tests__/public.test.ts - npm run typecheck --workspace @slugkit/template-site - npm run lint - ./scripts/pre-pr.sh Task: #task-551421c7
feat: allow admins to preview draft articles
All checks were successful
CI / build-lint-test (pull_request) Successful in 48s
66b06d82a5
Task: #task-551421c7
Author
Owner

Review summary

Approved.

Acceptance criteria

  • Anonymous users cannot view unpublished articles. Evidence: route test requests /posts/draft-article without a session and asserts 404.
  • Non-admin authenticated users cannot view unpublished articles. Evidence: viewer-session test asserts 404 for /posts/draft-article.
  • Authenticated admins can view unpublished article detail pages. Evidence: admin-session test asserts 200 and draft article body/title are present.
  • Draft/unpublished state is clearly indicated in the UI. Evidence: admin preview test asserts Unpublished draft and Previewing an unpublished article; published post test asserts those strings are absent for normal published details.
  • Access control is enforced server-side. Evidence: /posts/:slug now resolves drafts through server-side getVisiblePost() and canPreviewUnpublishedArticles() checks using the session cookie and admin role.
  • Published article behavior remains unchanged. Evidence: existing published detail test remains passing and explicitly asserts no draft indicator.
  • Tests cover the new access-control and UI behavior. Evidence: public route tests cover anonymous, viewer, admin, draft note/link denial, and UI indicators.

Blocking issues

  • None.

Warnings

  • None.

Verification reviewed

  • ./scripts/pre-pr.sh passed locally.
  • Forgejo CI run #310 passed.
  • Diff reviewed with git diff --check main...HEAD.

Final verdict

Approved. Ready for human merge approval.

### Review summary Approved. ### Acceptance criteria - [x] Anonymous users cannot view unpublished articles. Evidence: route test requests `/posts/draft-article` without a session and asserts `404`. - [x] Non-admin authenticated users cannot view unpublished articles. Evidence: viewer-session test asserts `404` for `/posts/draft-article`. - [x] Authenticated admins can view unpublished article detail pages. Evidence: admin-session test asserts `200` and draft article body/title are present. - [x] Draft/unpublished state is clearly indicated in the UI. Evidence: admin preview test asserts `Unpublished draft` and `Previewing an unpublished article`; published post test asserts those strings are absent for normal published details. - [x] Access control is enforced server-side. Evidence: `/posts/:slug` now resolves drafts through server-side `getVisiblePost()` and `canPreviewUnpublishedArticles()` checks using the session cookie and admin role. - [x] Published article behavior remains unchanged. Evidence: existing published detail test remains passing and explicitly asserts no draft indicator. - [x] Tests cover the new access-control and UI behavior. Evidence: public route tests cover anonymous, viewer, admin, draft note/link denial, and UI indicators. ### Blocking issues - None. ### Warnings - None. ### Verification reviewed - `./scripts/pre-pr.sh` passed locally. - Forgejo CI run #310 passed. - Diff reviewed with `git diff --check main...HEAD`. ### Final verdict Approved. Ready for human merge approval.
erik merged commit f0298dc770 into main 2026-06-28 07:05:15 -05:00
erik deleted branch feat/task-551421c7-admin-article-previews 2026-06-28 07:05:15 -05:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
erik/slugkit!224
No description provided.