Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
{
"id": "s-continue",
"section_type": "continue_watching",
"title": "Continue Watching",
"title": "Keep watching",
"default_title": "Continue Watching",
"featured": false,
"item_limit": 20,
"hidden": true,
Expand All @@ -15,6 +16,7 @@
"id": "u-gems",
"section_type": "hidden_gems",
"title": "Hidden gems",
"default_title": "",
"featured": false,
"item_limit": 12,
"hidden": false,
Expand Down
2 changes: 1 addition & 1 deletion contracts/api/v2/fixtures/get_system_info_ok.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"server_version": "unavailable",
"api_major": 2,
"contract_digest": "4fce9b5b77258ce6fcd6dc1fe537ce18f89a70ad73e6507f4df3fe353c517fa8",
"contract_digest": "3e64af6df30f3adacdf1d9bae6ea7c75f18aac3a9b673547bcf810c63cb9f8a6",
"links": {
"openapi": "/api/v2/openapi.json",
"capabilities": "/api/v2/capabilities",
Expand Down
2 changes: 1 addition & 1 deletion contracts/api/v2/migration.json
Original file line number Diff line number Diff line change
Expand Up @@ -35150,7 +35150,7 @@
"path": "/api/v2/profile/sections/settings",
"operation_id": "getProfileSectionSettings"
},
"notes": "Conditionally registered: authMiddleware != nil; sectionHandler != nil. v2 registers the operation unconditionally and reports capability state instead. Path keeps the v1 shape. Collection envelope (items) instead of {sections}; config is an extension bag."
"notes": "Conditionally registered: authMiddleware != nil; sectionHandler != nil. v2 registers the operation unconditionally and reports capability state instead. Path keeps the v1 shape. Collection envelope (items) instead of {sections}; config is an extension bag. Adds default_title, the administrator's title for the row, which v1 does not return."
},
{
"listener": "api",
Expand Down
9 changes: 9 additions & 0 deletions contracts/api/v2/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -37719,6 +37719,13 @@
],
"type": "boolean"
},
"default_title": {
"description": "The administrator's title for this row; title shows it unless the profile saved a title override. Empty for a section the profile built",
"examples": [
"Continue Watching"
],
"type": "string"
},
"featured": {
"examples": [
false
Expand Down Expand Up @@ -37767,6 +37774,7 @@
"type": "string"
},
"title": {
"description": "The title this profile sees: its own title override, or the administrator's title",
"examples": [
"Continue Watching"
],
Expand All @@ -37777,6 +37785,7 @@
"id",
"section_type",
"title",
"default_title",
"featured",
"item_limit",
"hidden",
Expand Down
5 changes: 4 additions & 1 deletion docs/architecture/api-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -1318,7 +1318,10 @@ types or an undecodable image is `422` at `body.avatar`, an oversized avatar is
server without an upload store answers `503`; section overrides drop the `/reset` suffix
(`DELETE` on the same resource), take `scope` and `library_id` as query parameters on every
method, and read back in `snake_case` like the write (the Phase 1 catalogs flagged v1's GET/PUT
casing mismatch). Every profile mutation in the section is demo-restricted on v2 (v1's demo guard lists none of them), and `createProfile`'s `Location` names the `PATCH`/`DELETE` resource; the created profile is read back through `listProfiles`.
casing mismatch). `getProfileSectionSettings` also returns `default_title`, the administrator's
own title for each admin row next to the profile's effective `title`, so a client can show that a
profile renamed a row and offer the original name back (saving an empty `title` override restores
it); it is empty for a profile-built row, and v1 does not return it. Every profile mutation in the section is demo-restricted on v2 (v1's demo guard lists none of them), and `createProfile`'s `Location` names the `PATCH`/`DELETE` resource; the created profile is read back through `listProfiles`.

**Settings section (Phase 4).** Operations: `getSettingsContract` (serves both v1
`/settings/contract` and `/settings/manifest`), `getSettingsContractCapabilities` (also v1
Expand Down
101 changes: 101 additions & 0 deletions internal/api/handlers/sections_settings_default_title_db_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package handlers

import (
"context"
"encoding/json"
"strconv"
"testing"

"github.com/Silo-Server/silo-server/internal/catalog"
"github.com/Silo-Server/silo-server/internal/sections"
"github.com/Silo-Server/silo-server/internal/userstore"
"github.com/Silo-Server/silo-server/internal/userstore/pgstore"
)

// TestProfileSectionSettingsKeepAdminTitleDB: the settings read over the
// real section repository and profile store returns the profile's rename as
// the title and the admin row's own title beside it, and follows a later
// admin rename for the default while the profile's rename stays.
func TestProfileSectionSettingsKeepAdminTitleDB(t *testing.T) {
f := newPagingIntegrationFixture(t)
ctx := t.Context()
provider := pgstore.NewPostgresProvider(f.pool)
store, err := provider.ForUser(ctx, f.account)
if err != nil {
t.Fatal(err)
}
if err := store.CreateProfile(ctx, userstore.Profile{ID: "p1", Name: "p1"}); err != nil {
t.Fatal(err)
}

repo := sections.NewRepository(f.pool)
library := f.library
create := func(title string, position int) *sections.PageSection {
t.Helper()
s, err := repo.Create(ctx, &sections.PageSection{
Scope: "library", LibraryID: &library, Position: position, SectionType: sections.SectionRecentlyAdded,
Title: title, ItemLimit: 20, Config: json.RawMessage(`{}`), Enabled: true,
})
if err != nil {
t.Fatal(err)
}
return s
}
renamed := create("Recently Added", 0)
untouched := create("Favorites", 1)
t.Cleanup(func() {
_, _ = f.pool.Exec(context.Background(), `DELETE FROM page_sections WHERE id = ANY($1)`, []string{renamed.ID, untouched.ID})
})

libraryKey := strconv.Itoa(library)
position := 2
if err := store.SaveSectionOverrides(ctx, "p1", "library", libraryKey, []userstore.SectionOverride{
{ID: "o-renamed", SectionID: renamed.ID, Title: "Weekend picks"},
{ID: "o-gems", IsUserAdded: true, UserSectionType: string(sections.SectionHiddenGems), UserTitle: "Hidden gems", Position: &position},
}); err != nil {
t.Fatal(err)
}

h := NewSectionHandler(repo, nil)
h.StoreProvider = provider
titles := func() map[string][2]string {
t.Helper()
resolved, err := h.ResolveProfileSectionSettings(ctx, f.account, "p1", "library", &library, catalog.AccessFilter{})
if err != nil {
t.Fatal(err)
}
out := map[string][2]string{}
for _, s := range resolved {
out[s.ID] = [2]string{s.Title, s.DefaultTitle}
}
return out
}
assert := func(want map[string][2]string) {
t.Helper()
got := titles()
if len(got) != len(want) {
t.Fatalf("settings = %q, want %q", got, want)
}
for id, w := range want {
if got[id] != w {
t.Errorf("section %s (title, default title) = %q, want %q", id, got[id], w)
}
}
}

assert(map[string][2]string{
renamed.ID: {"Weekend picks", "Recently Added"},
untouched.ID: {"Favorites", "Favorites"},
"o-gems": {"Hidden gems", ""},
})

renamed.Title = "New this week"
if err := repo.Update(ctx, renamed); err != nil {
t.Fatal(err)
}
assert(map[string][2]string{
renamed.ID: {"Weekend picks", "New this week"},
untouched.ID: {"Favorites", "Favorites"},
"o-gems": {"Hidden gems", ""},
})
}
2 changes: 1 addition & 1 deletion internal/apiv2/pilot_fakes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ func (f *fakeProfileSections) ResolveProfileSectionSettings(_ context.Context, u
return nil, f.err
}
return []sections.ResolvedSection{
{ID: "s-continue", SectionType: "continue_watching", Title: "Continue Watching", ItemLimit: 20, Position: 0, Customized: true, Hidden: true},
{ID: "s-continue", SectionType: "continue_watching", Title: "Keep watching", DefaultTitle: "Continue Watching", ItemLimit: 20, Position: 0, Customized: true, Hidden: true},
{ID: "u-gems", SectionType: "hidden_gems", Title: "Hidden gems", ItemLimit: 12, Position: 1, IsCustom: true, Config: json.RawMessage(`{"library_ids":[3]}`)},
}, nil
}
Expand Down
42 changes: 22 additions & 20 deletions internal/apiv2/profile_sections.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,17 @@ type SectionOverridesReplaceInput struct {
// the customization screen: the admin definition with the profile's
// overrides applied.
type ProfileSectionSetting struct {
ID string `json:"id" example:"s-continue-watching"`
SectionType string `json:"section_type" doc:"The recipe; the set is extensible" example:"continue_watching"`
Title string `json:"title" example:"Continue Watching"`
Featured bool `json:"featured" example:"false"`
ItemLimit int `json:"item_limit" example:"20"`
Hidden bool `json:"hidden" doc:"Hidden by the profile" example:"false"`
IsCustom bool `json:"is_custom" doc:"Built by the profile rather than defined by an administrator" example:"false"`
Customized bool `json:"customized" doc:"An admin section the profile has changed" example:"true"`
Position int `json:"position" example:"0"`
Config SectionConfig `json:"config,omitzero" doc:"The recipe's effective config; absent when none, {} when explicitly empty"`
ID string `json:"id" example:"s-continue-watching"`
SectionType string `json:"section_type" doc:"The recipe; the set is extensible" example:"continue_watching"`
Title string `json:"title" doc:"The title this profile sees: its own title override, or the administrator's title" example:"Continue Watching"`
DefaultTitle string `json:"default_title" doc:"The administrator's title for this row; title shows it unless the profile saved a title override. Empty for a section the profile built" example:"Continue Watching"`

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Advertise default-title support through a capability

Adding default_title without extending a profile-sections capability leaves newer clients without the required support signal when they connect to an older server or a mixed-version cluster. Such clients must infer support from field presence or the server version/digest before enabling rename/reset behavior, even though repository policy requires new client-visible features to expose a capability endpoint; add an explicit capability field and keep it false or absent on implementations that cannot return the title.

AGENTS.md reference: AGENTS.md:L146-L150

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not adding a capability for this. default_title is an extra read-only field on an existing response, not optional behavior a client sends. It is serialized on every row (no omitempty), so its presence is the support signal: an older server omits it, and a client then just doesn't show "Renamed from" or offer the original name. Restoring the name saves an empty title override, which older servers already accept, so nothing new is sent to a server that lacks the field. The contract's capability-document rule covers optional domains and optional request behavior, and the v2 contract is not locked yet. Dismissed on #1913 (follow-up for late findings).

Featured bool `json:"featured" example:"false"`
ItemLimit int `json:"item_limit" example:"20"`
Hidden bool `json:"hidden" doc:"Hidden by the profile" example:"false"`
IsCustom bool `json:"is_custom" doc:"Built by the profile rather than defined by an administrator" example:"false"`
Customized bool `json:"customized" doc:"An admin section the profile has changed" example:"true"`
Position int `json:"position" example:"0"`
Config SectionConfig `json:"config,omitzero" doc:"The recipe's effective config; absent when none, {} when explicitly empty"`
}

// ProfileSectionSettingCollection is the getProfileSectionSettings envelope.
Expand Down Expand Up @@ -332,16 +333,17 @@ func (reg *Registry) getProfileSectionSettings(ctx context.Context, in *SectionO
return nil, p
}
items = append(items, ProfileSectionSetting{
ID: s.ID,
SectionType: string(s.SectionType),
Title: s.Title,
Featured: s.Featured,
ItemLimit: s.ItemLimit,
Hidden: s.Hidden,
IsCustom: s.IsCustom,
Customized: s.Customized,
Position: s.Position,
Config: config,
ID: s.ID,
SectionType: string(s.SectionType),
Title: s.Title,
DefaultTitle: s.DefaultTitle,
Featured: s.Featured,
ItemLimit: s.ItemLimit,
Hidden: s.Hidden,
IsCustom: s.IsCustom,
Customized: s.Customized,
Position: s.Position,
Config: config,
})
}
return &ProfileSectionSettingCollectionOutput{Body: ProfileSectionSettingCollection{Collection: NewCollection(items)}}, nil
Expand Down
7 changes: 5 additions & 2 deletions internal/apiv2/profile_sections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ func TestResetProfileSectionOverrides(t *testing.T) {
}
}

// TestGetProfileSectionSettings: title is what the profile sees and
// default_title the administrator's own title for that row, so a renamed row
// carries both; a profile-built row has no administrator title.
func TestGetProfileSectionSettings(t *testing.T) {
svc := &fakeProfileSections{}
h := newTestHandler(t, sectionDeps(svc))
Expand All @@ -234,8 +237,8 @@ func TestGetProfileSectionSettings(t *testing.T) {
t.Fatal(rec.Body.String())
}
want := `{"items":[` +
`{"id":"s-continue","section_type":"continue_watching","title":"Continue Watching","featured":false,"item_limit":20,"hidden":true,"is_custom":false,"customized":true,"position":0},` +
`{"id":"u-gems","section_type":"hidden_gems","title":"Hidden gems","featured":false,"item_limit":12,"hidden":false,"is_custom":true,"customized":false,"position":1,"config":{"library_ids":[3]}}` +
`{"id":"s-continue","section_type":"continue_watching","title":"Keep watching","default_title":"Continue Watching","featured":false,"item_limit":20,"hidden":true,"is_custom":false,"customized":true,"position":0},` +
`{"id":"u-gems","section_type":"hidden_gems","title":"Hidden gems","default_title":"","featured":false,"item_limit":12,"hidden":false,"is_custom":true,"customized":false,"position":1,"config":{"library_ids":[3]}}` +
`]}` + "\n"
if rec.Body.String() != want {
t.Fatalf("body = %s", rec.Body.String())
Expand Down
20 changes: 11 additions & 9 deletions internal/sections/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ func Resolve(admin []*PageSection, overrides []ProfileSectionOverride) []Resolve
return result
}

// ResolveForSettings is like Resolve but includes hidden sections with Hidden=true.
// Used by the settings UI so users can toggle visibility.
// ResolveForSettings is like Resolve but includes hidden sections with Hidden=true
// and keeps each admin section's own title in DefaultTitle. Used by the
// settings UI so users can toggle visibility and undo a rename.
func ResolveForSettings(admin []*PageSection, overrides []ProfileSectionOverride) []ResolvedSection {
overrideBySection := make(map[string]*ProfileSectionOverride)
var userAdded []ProfileSectionOverride
Expand All @@ -101,13 +102,14 @@ func ResolveForSettings(admin []*PageSection, overrides []ProfileSectionOverride
continue
}
rs := ResolvedSection{
ID: s.ID,
SectionType: s.SectionType,
Title: s.Title,
Featured: s.Featured,
ItemLimit: s.ItemLimit,
Config: s.Config,
Position: s.Position,
ID: s.ID,
SectionType: s.SectionType,
Title: s.Title,
DefaultTitle: s.Title,
Featured: s.Featured,
ItemLimit: s.ItemLimit,
Config: s.Config,
Position: s.Position,
}

if hasOverride {
Expand Down
44 changes: 44 additions & 0 deletions internal/sections/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sections

import (
"encoding/json"
"strings"
"testing"
)

Expand Down Expand Up @@ -155,6 +156,49 @@ func TestResolveForSettings_IncludesHidden(t *testing.T) {
}
}

// TestResolveForSettings_KeepsAdminTitleAsDefault: the settings view keeps
// the admin row's own title beside the profile's rename, so the profile can
// see what it renamed and go back to it; a profile-built row has no admin
// title.
func TestResolveForSettings_KeepsAdminTitleAsDefault(t *testing.T) {
admin := []*PageSection{
{ID: "1", Position: 0, SectionType: SectionRecentlyAdded, Title: "Recently Added", ItemLimit: 20, Config: json.RawMessage(`{}`)},
{ID: "2", Position: 1, SectionType: SectionFavorites, Title: "Favorites", ItemLimit: 10, Config: json.RawMessage(`{}`)},
}
pos := 2
overrides := []ProfileSectionOverride{
{SectionID: "1", Title: "New this week"},
{ID: "custom-1", IsUserAdded: true, UserSectionType: SectionHiddenGems, UserTitle: "Hidden gems", Position: &pos},
}

result := ResolveForSettings(admin, overrides)
if len(result) != 3 {
t.Fatalf("expected 3 sections, got %d", len(result))
}
got := map[string][2]string{}
for _, r := range result {
got[r.ID] = [2]string{r.Title, r.DefaultTitle}
}
want := map[string][2]string{
"1": {"New this week", "Recently Added"},
"2": {"Favorites", "Favorites"},
"custom-1": {"Hidden gems", ""},
}
for id, w := range want {
if got[id] != w {
t.Errorf("section %s (title, default title) = %q, want %q", id, got[id], w)
}
}
// v1 bodies embed ResolvedSection; the field must never reach them.
raw, err := json.Marshal(result[0])
if err != nil {
t.Fatal(err)
}
if strings.Contains(string(raw), "Recently Added") {
t.Errorf("ResolvedSection JSON carries the default title: %s", raw)
}
}

func TestResolveForSettings_SkipsRemovedSection(t *testing.T) {
admin := []*PageSection{
{ID: "1", Position: 0, SectionType: SectionRecentlyAdded, Title: "Recently Added", ItemLimit: 20, Config: json.RawMessage(`{}`)},
Expand Down
5 changes: 5 additions & 0 deletions internal/sections/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ type ResolvedSection struct {
Customized bool `json:"customized"`
Hidden bool `json:"hidden,omitempty"`

// DefaultTitle is the admin section's own title, before the profile's
// title override. Only ResolveForSettings fills it, and it is empty for a
// profile-built section. Not serialized: v1 bodies embed this struct.
DefaultTitle string `json:"-"`

// SuppressNextUp, when true on a continue-watching section, skips the
// next-up injection (and the combined series collapse/sort that pairs with
// it) so the section returns in-progress resume points only. Callers that
Expand Down
2 changes: 2 additions & 0 deletions web/src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4606,6 +4606,8 @@ export interface SettingsSectionEntry {
id: string;
section_type: string;
title: string;
/** The admin row's own title; empty for a profile-built row. Absent on entries built locally. */
default_title?: string;
featured: boolean;
item_limit: number;
hidden: boolean;
Expand Down
Loading
Loading