Repository navigation
refactor(viewer-rules): rename LectureTags, unify audience across collections - #296
Merged
Merged
Conversation
Unifies viewer-targeting under a single reusable `viewer-rules` collection that AppCards, Lectures, and LectureClips reference via a common `audience` field. Removes the inline rulesField from AppCards and the hasMany `tags` from Lectures/LectureClips. - Collection: `lecture-tags` → `viewer-rules` (admin group: Metadata). Dropped `hasRealization` boolean rule — redundant with `pathProgress >= 1`. - Fields: AppCards.rules removed; AppCards/Lectures/LectureClips each gain a single `audience` relationship (nullable, hasMany: false). `audience: null` now hides the item from /api/*/for-viewer (behavior change for AppCards). - Endpoints: appCardsForViewer reads the virtual `isEligibleForViewer` off the populated audience; lecturesForViewer filters by `where[audience][in]` against the eligible viewer-rule set. - ContentIndexBlock lectureFilters/lectureClipFilters switched from `lecture-tags` to `viewer-rules` with `where[audience][in]` query. - Migration rebuilds payload_locked_documents_rels; worked around the known Drizzle polymorphic-FK rename bug (CLAUDE.md) by dropping the renamed column from both sides of the INSERT/SELECT. No data preservation — per issue #293 decisions, editors recreate audiences after the cutover. Closes #293 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…points Apply PR #296 review follow-ups. - Extract VIEWER_RULE_DEFINITIONS from ViewerRules as the single source of truth for targeting dimensions; both for-viewer endpoints now derive their query schemas from it via the new buildViewerDataShape helper, which pulls in meditationsPerWeek on the lectures endpoint (previously missing) automatically. - Add withViewerContext helper in rulesField.ts for the req.context threading both endpoints duplicated. - Drop the redundant JS isAudienceEligible post-filter in lecturesForViewer (the DB query already filters by audience now that it's a single relationship, no longer hasMany tags), and replace the local idOf helper with extractID from payload/shared. - Add filterOptions: () => true and align admin description wording on the audience relationship fields in AppCards, Lectures, and LectureClips. - Tighten join-field docs type casts in viewer-rules tests to { id: number } (tests always populate at depth:1) and extend the "passes viewerData" lectures-for-viewer case to cover all four rule dimensions. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
3 tasks
Ardnived
added a commit
that referenced
this pull request
Nov 5, 2026
…points Apply PR #296 review follow-ups. - Extract VIEWER_RULE_DEFINITIONS from ViewerRules as the single source of truth for targeting dimensions; both for-viewer endpoints now derive their query schemas from it via the new buildViewerDataShape helper, which pulls in meditationsPerWeek on the lectures endpoint (previously missing) automatically. - Add withViewerContext helper in rulesField.ts for the req.context threading both endpoints duplicated. - Drop the redundant JS isAudienceEligible post-filter in lecturesForViewer (the DB query already filters by audience now that it's a single relationship, no longer hasMany tags), and replace the local idOf helper with extractID from payload/shared. - Add filterOptions: () => true and align admin description wording on the audience relationship fields in AppCards, Lectures, and LectureClips. - Tighten join-field docs type casts in viewer-rules tests to { id: number } (tests always populate at depth:1) and extend the "passes viewerData" lectures-for-viewer case to cover all four rule dimensions. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
lecture-tagscollection toviewer-rules(admin group: Metadata). Drops the redundanthasRealizationboolean rule —pathProgress >= 1expresses the same condition.audiencerelationship toviewer-rules(nullable,hasMany: false), replacing the inlinerulesFieldon AppCards and thetagshasMany on Lectures/LectureClips.audience: nullnow hides the item from/api/app-cards/for-viewerand/api/lectures/for-vieweron all three consumers. For AppCards this is new — previously no-rules meant always-visible. Editors will recreate a catch-all ViewerRule with no conditions to restore that semantic.appCardsForViewerreadsisEligibleForVieweroff the populatedaudience;lecturesForViewerfilters bywhere[audience][in]against the eligible viewer-rule set.lecture-tagstoviewer-ruleswithwhere[audience][in].Migration
Standard generated migration, plus a manual fix for the known Drizzle polymorphic-FK rename bug documented in CLAUDE.md —
viewer_rules_idwas dropped from both sides of thepayload_locked_documents_relsINSERT/SELECT since the old table only hadlecture_tags_id. No data preservation per issue decisions; editors recreate audiences after the cutover.Test Results
Test plan
pnpm payload migrate) and confirmviewer_rulestable exists andlecture_tags/lectures_rels/lecture_clips_relsare droppedpathProgress { min: 1 }, attach to an AppCard + Lecture; confirm/api/app-cards/for-viewer?pathProgress=0&targetSection=hero&limit=10excludes it and?pathProgress=3&...includes it/api/lectures/for-viewer?pathProgress=3&limit=10returns the lecture when its audience is eligibleaudience: nullis excluded from the viewer endpoint responseswemeditate-appproject is selected (under Metadata)Closes #293
🤖 Generated with Claude Code