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
4 changes: 2 additions & 2 deletions .silo-translations
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
platform=web
version=2026.12.05-1ec18ef
sha256=907ce3bb89e3796f0ea73c1330779ef1ace2a63dc018b24bad57d68a7bfcbe5b
version=2026.12.05-3638800
sha256=c5a34cb49a425a2139f5e57a016e618e477345d3ceccd414b332ded21e396963
8 changes: 4 additions & 4 deletions contracts/api/v2/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -173981,7 +173981,7 @@
"bearerAuth": []
}
],
"summary": "For a movie or series, the standing of every other profile on the account: within its limits, allowed, or above its limits and allowable. Household managers only.",
"summary": "For a movie or series, the standing of every other profile on the account: within its limits, allowed, or above its limits and allowable. An episode or season answers 422 validation_failed with field code not_a_title at path.id. Household managers only.",
"tags": [
"profiles"
],
Expand Down Expand Up @@ -229613,7 +229613,7 @@
"bearerAuth": []
}
],
"summary": "Allow a profile every title in a personal collection, including titles added later. Only a manual collection the acting primary profile created can be allowed (422 collection_not_live); copy other collections' titles with allowCollectionTitles. A profile sees at most 10,000 of its allowed titles, from its own allowances and its live collections together, and at most 50,000 entries of its live collections together are read; the rest stay hidden. Household managers only.",
"summary": "Allow a profile every title in a personal collection, including titles added later. The profile must have a limit (422 validation_failed, field code no_maturity_limits at path.id), and only a manual collection the acting primary profile created can be allowed (field code collection_not_live at path.collection_id); copy other collections' titles with allowCollectionTitles. A profile sees at most 10,000 of its allowed titles, from its own allowances and its live collections together, and at most 50,000 entries of its live collections together are read; the rest stay hidden. Household managers only.",
"tags": [
"profiles"
],
Expand Down Expand Up @@ -230098,7 +230098,7 @@
"bearerAuth": []
}
],
"summary": "Allow a profile every movie and series a personal collection holds now, as individual title allowances, up to 10,000 titles per copy; a stored collection's copy reads at most its first 100,000 entries not yet allowed. Only titles the acting profile can see, in libraries the target profile can reach, are copied; for a smart collection, what its query matches for the acting profile. Titles added to the collection later are not allowed. Not retryable: a repeated copy of a stored collection with more titles than one copy takes continues with the next ones, so after an uncertain response read listAllowedTitles before copying again. Household managers only.",
"summary": "Allow a profile every movie and series a personal collection holds now, as individual title allowances, up to 10,000 titles per copy; a stored collection's copy reads at most its first 100,000 entries not yet allowed. Only titles the acting profile can see, in libraries the target profile can reach, are copied; for a smart collection, what its query matches for the acting profile. Titles added to the collection later are not allowed. A profile with no limit answers 422 validation_failed with field code no_maturity_limits at path.id. Not retryable: a repeated copy of a stored collection with more titles than one copy takes continues with the next ones, so after an uncertain response read listAllowedTitles before copying again. Household managers only.",
"tags": [
"profiles"
],
Expand Down Expand Up @@ -230428,7 +230428,7 @@
"bearerAuth": []
}
],
"summary": "Allow a profile a movie or series above its rating or advisory-age limit. A series allowance covers its seasons and episodes. The profile must have a limit (422 no_maturity_limits) and reach the title's library (422 no_library_access); episodes and seasons are refused with 422. A profile sees at most 10,000 of its allowed titles; the rest stay hidden. Allowing an allowed title succeeds and changes nothing. Household managers only.",
"summary": "Allow a profile a movie or series above its rating or advisory-age limit. A series allowance covers its seasons and episodes. The profile must have a limit and reach the title's library, and the item must be a movie or series; otherwise it answers 422 validation_failed with field code no_maturity_limits (at path.id), no_library_access or not_a_title (at path.item_id). A profile sees at most 10,000 of its allowed titles; the rest stay hidden. Allowing an allowed title succeeds and changes nothing. Household managers only.",
"tags": [
"profiles"
],
Expand Down
19 changes: 13 additions & 6 deletions docs/catalog-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -854,19 +854,26 @@ answers `403` otherwise.
- `GET /api/v2/catalog/items/{id}/title-allowances` lists every other profile
on the account with its `state` for the movie or series: `within_limits`,
`allowed`, `allowed_by_collection`, `above_limit` (can be allowed), or
`no_library_access`.
`no_library_access`. An episode or season answers `422` with the field code
`not_a_title`.
- `PUT` and `DELETE /api/v2/profiles/{id}/allowed-titles/{item_id}` add and
remove one allowance; both answer `204` and repeat safely. `PUT` answers `422`
for an episode or season (allow the series), for a profile with no limit
(`no_maturity_limits`), and for a title in a library the profile cannot see
(`no_library_access`). `GET /api/v2/profiles/{id}/allowed-titles` lists the
remove one allowance; both answer `204` and repeat safely. `PUT` refuses with
`422 validation_failed` and one field error whose `code` names the reason:
`not_a_title` at `path.item_id` for an episode or season (allow the series),
`no_maturity_limits` at `path.id` for a profile with no limit, and
`no_library_access` at `path.item_id` for a title in a library the profile
cannot see. `GET /api/v2/profiles/{id}/allowed-titles` lists the
profile's own allowances as catalog cards, newest first, paged with `limit`
and `cursor`. Cards for titles the acting profile cannot see are left out, so
a page can hold fewer cards than its limit while `page.has_more` is true.
- `PUT` and `DELETE /api/v2/profiles/{id}/allowed-collections/{collection_id}`
allow a personal collection as it changes: titles added to it later are
allowed too. Only a manual collection the acting primary profile created can
be allowed this way; any other answers `422` (`collection_not_live`).
be allowed this way: `PUT` answers `422 validation_failed` with the field code
`collection_not_live` at `path.collection_id` for any other, and
`no_maturity_limits` at `path.id` for a profile with no limit, as copying
below does. `DELETE` runs neither check, so it removes an allowance even
after the profile's limits are cleared.
`GET /api/v2/profiles/{id}/allowed-collections` lists them, with `live: false`
for a collection that no longer qualifies and so allows nothing.
- `POST /api/v2/profiles/{id}/allowed-titles/copy-collection` with
Expand Down
9 changes: 9 additions & 0 deletions internal/apiv2/problem.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,15 @@ const (
// codeReorderedSeries refuses a change to one season or episode that
// only the whole series can take, because it uses its own episode order.
codeReorderedSeries = "reordered_series"
// Title-allowance refusals (internal/api/handlers/title_allowances.go):
// the profile has no rating or advisory-age limit to make an exception
// to; the profile cannot reach the title's library; the item is not a
// movie or series; the collection is not a manual one the acting primary
// profile created, so it cannot be allowed as it changes.
codeNoMaturityLimits = "no_maturity_limits"
codeNoLibraryAccess = "no_library_access"
codeNotATitle = "not_a_title"
codeCollectionNotLive = "collection_not_live"

locationBody = "body"
locationBodyFile = "body.file"
Expand Down
40 changes: 32 additions & 8 deletions internal/apiv2/title_allowances.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package apiv2

import (
"context"
"errors"
"net/http"
"strconv"

Expand Down Expand Up @@ -161,7 +162,7 @@ func registerTitleAllowances(reg *Registry) {
return reg.listAllowedTitles(ctx, cursors, in)
})
Register(reg, allowanceMutation(humaOp(http.MethodPut, Prefix+"/profiles/{id}/allowed-titles/{item_id}", "allowTitle", "profiles",
"Allow a profile a movie or series above its rating or advisory-age limit. A series allowance covers its seasons and episodes. The profile must have a limit (422 no_maturity_limits) and reach the title's library (422 no_library_access); episodes and seasons are refused with 422. A profile sees at most 10,000 of its allowed titles; the rest stay hidden. Allowing an allowed title succeeds and changes nothing. Household managers only.")),
"Allow a profile a movie or series above its rating or advisory-age limit. A series allowance covers its seasons and episodes. The profile must have a limit and reach the title's library, and the item must be a movie or series; otherwise it answers 422 validation_failed with field code no_maturity_limits (at path.id), no_library_access or not_a_title (at path.item_id). A profile sees at most 10,000 of its allowed titles; the rest stay hidden. Allowing an allowed title succeeds and changes nothing. Household managers only.")),
func(ctx context.Context, in *AllowedTitleInput) (*struct{}, error) {
return reg.setTitleAllowance(ctx, in, true)
})
Expand All @@ -171,14 +172,14 @@ func registerTitleAllowances(reg *Registry) {
return reg.setTitleAllowance(ctx, in, false)
})
Register(reg, viewerOperation(humaOp(http.MethodGet, Prefix+"/catalog/items/{id}/title-allowances", "listTitleAllowanceProfiles", "profiles",
"For a movie or series, the standing of every other profile on the account: within its limits, allowed, or above its limits and allowable. Household managers only.")),
"For a movie or series, the standing of every other profile on the account: within its limits, allowed, or above its limits and allowable. An episode or season answers 422 validation_failed with field code not_a_title at path.id. Household managers only.")),
reg.listTitleAllowanceProfiles)

Register(reg, viewerOperation(humaOp(http.MethodGet, Prefix+"/profiles/{id}/allowed-collections", "listAllowedCollections", "profiles",
"List the personal collections allowed for a profile, newest first. Household managers only.")),
reg.listAllowedCollections)
Register(reg, allowanceMutation(humaOp(http.MethodPut, Prefix+"/profiles/{id}/allowed-collections/{collection_id}", "allowCollection", "profiles",
"Allow a profile every title in a personal collection, including titles added later. Only a manual collection the acting primary profile created can be allowed (422 collection_not_live); copy other collections' titles with allowCollectionTitles. A profile sees at most 10,000 of its allowed titles, from its own allowances and its live collections together, and at most 50,000 entries of its live collections together are read; the rest stay hidden. Household managers only.")),
"Allow a profile every title in a personal collection, including titles added later. The profile must have a limit (422 validation_failed, field code no_maturity_limits at path.id), and only a manual collection the acting primary profile created can be allowed (field code collection_not_live at path.collection_id); copy other collections' titles with allowCollectionTitles. A profile sees at most 10,000 of its allowed titles, from its own allowances and its live collections together, and at most 50,000 entries of its live collections together are read; the rest stay hidden. Household managers only.")),
func(ctx context.Context, in *AllowedCollectionInput) (*struct{}, error) {
return reg.setCollectionAllowance(ctx, in, true)
})
Expand All @@ -188,7 +189,7 @@ func registerTitleAllowances(reg *Registry) {
return reg.setCollectionAllowance(ctx, in, false)
})
copyOp := humaOp(http.MethodPost, Prefix+"/profiles/{id}/allowed-titles/copy-collection", "allowCollectionTitles", "profiles",
"Allow a profile every movie and series a personal collection holds now, as individual title allowances, up to 10,000 titles per copy; a stored collection's copy reads at most its first 100,000 entries not yet allowed. Only titles the acting profile can see, in libraries the target profile can reach, are copied; for a smart collection, what its query matches for the acting profile. Titles added to the collection later are not allowed. Not retryable: a repeated copy of a stored collection with more titles than one copy takes continues with the next ones, so after an uncertain response read listAllowedTitles before copying again. Household managers only.")
"Allow a profile every movie and series a personal collection holds now, as individual title allowances, up to 10,000 titles per copy; a stored collection's copy reads at most its first 100,000 entries not yet allowed. Only titles the acting profile can see, in libraries the target profile can reach, are copied; for a smart collection, what its query matches for the acting profile. Titles added to the collection later are not allowed. A profile with no limit answers 422 validation_failed with field code no_maturity_limits at path.id. Not retryable: a repeated copy of a stored collection with more titles than one copy takes continues with the next ones, so after an uncertain response read listAllowedTitles before copying again. Household managers only.")
Register(reg, Operation{
Operation: copyOp,
Class: ClassProfileScoped,
Expand Down Expand Up @@ -223,6 +224,29 @@ func (reg *Registry) allowanceActor(ctx context.Context, art imagesize.Request)
}, nil
}

// allowanceProblem renders a title-allowance failure. A refusal the service
// explains by code becomes a validation failure with that code at the
// request location it is about: the profile at path.id, the collection at
// path.collection_id, and the title at item (empty when the operation names
// none). Anything else is a serviceProblem.
func allowanceProblem(err error, item string) *Problem {
if apiErr, ok := errors.AsType[*handlers.APIError](err); ok && apiErr.Status == http.StatusUnprocessableEntity {
location := ""
switch apiErr.Code {
case codeNoMaturityLimits:
location = locationPathID
case codeCollectionNotLive:
location = "path.collection_id"
case codeNoLibraryAccess, codeNotATitle:
location = item
}
if location != "" {
return validationProblem(location, apiErr.Code, apiErr.Message)
}
}
return serviceProblem(err)
}

func (reg *Registry) getTitleAllowanceCapability(ctx context.Context, _ *CapabilityInput) (*TitleAllowanceCapabilityOutput, error) {
state := StateUnsupported
if reg.deps.TitleAllowances != nil {
Expand Down Expand Up @@ -277,7 +301,7 @@ func (reg *Registry) setTitleAllowance(ctx context.Context, in *AllowedTitleInpu
return nil, p
}
if err := reg.deps.TitleAllowances.SetTitleAllowance(ctx, actor, string(in.ProfileID), string(in.ItemID), allowed); err != nil {
return nil, serviceProblem(err)
return nil, allowanceProblem(err, "path.item_id")
}
return nil, nil
}
Expand All @@ -292,7 +316,7 @@ func (reg *Registry) listTitleAllowanceProfiles(ctx context.Context, in *TitleAl
}
states, err := reg.deps.TitleAllowances.TitleAllowanceStates(ctx, actor, string(in.ItemID))
if err != nil {
return nil, serviceProblem(err)
return nil, allowanceProblem(err, locationPathID)
}
out := make([]TitleAllowanceProfile, 0, len(states))
for _, s := range states {
Expand Down Expand Up @@ -341,7 +365,7 @@ func (reg *Registry) setCollectionAllowance(ctx context.Context, in *AllowedColl
return nil, p
}
if err := reg.deps.TitleAllowances.SetCollectionAllowance(ctx, actor, string(in.ProfileID), string(in.CollectionID), allowed); err != nil {
return nil, serviceProblem(err)
return nil, allowanceProblem(err, "")
}
return nil, nil
}
Expand All @@ -356,7 +380,7 @@ func (reg *Registry) allowCollectionTitles(ctx context.Context, in *AllowCollect
}
added, err := reg.deps.TitleAllowances.AllowCollectionTitles(ctx, actor, string(in.ProfileID), string(in.Body.CollectionID))
if err != nil {
return nil, serviceProblem(err)
return nil, allowanceProblem(err, "")
}
return &AllowCollectionTitlesOutput{Body: AllowCollectionTitlesResult{Added: added}}, nil
}
35 changes: 35 additions & 0 deletions internal/apiv2/title_allowances_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package apiv2

import (
"context"
"net/http"
"testing"

"github.com/Silo-Server/silo-server/internal/api/handlers"
)

// refusingTitleAllowances refuses every allowance write with the given error.
type refusingTitleAllowances struct {
TitleAllowanceService
err error
}

func (f refusingTitleAllowances) SetTitleAllowance(context.Context, handlers.AllowanceActor, string, string, bool) error {
return f.err
}

// An allowance refusal names its reason as a field code at the request
// location it is about, so clients can tell the refusals apart without
// reading the English detail.
func TestAllowTitleRefusalCarriesFieldCode(t *testing.T) {
refusal := &handlers.APIError{Status: http.StatusUnprocessableEntity, Code: "no_library_access", Message: "The profile cannot see the library this title is in"}
deps := fixtureDeps()
deps.TitleAllowances = refusingTitleAllowances{err: refusal}
h := newTestHandler(t, deps)
rec := do(t, h, http.MethodPut, Prefix+"/profiles/p-kid/allowed-titles/movie-1", "", with(bearer(memberToken), "X-Profile-Id", "p-owner"))
p := requireProblem(t, rec, TypeValidationFailed)
requireProblemAt(t, p, "path.item_id", "no_library_access")
if p.Detail != refusal.Message {
t.Fatalf("detail = %q, want %q", p.Detail, refusal.Message)
}
}
Loading
Loading