A game sold in the EU cannot ship what a licence excluding the EU made. On the profile page a person leaves out licences one by one, or by rule: every licence forbidding commercial use, every licence granting nothing in a region. The rules cover models added later. The choice reaches every principal through the resolved limits, so permits() leaves such models out of /v1/models, requests, jobs, fallbacks and the portal's pickers, and a request for one is refused 403 licence_excluded saying which choice did. Kept in user_excluded_licences (migration 0046), copied with the store and gone with the person. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package store
|
|
|
|
import (
|
|
"context"
|
|
"slices"
|
|
"strings"
|
|
)
|
|
|
|
// UserExcludedLicences is what a person has said not to use, sorted: a
|
|
// licence by its id, or a rule over licences ("rule:non-commercial",
|
|
// "rule:region:EU"). What each means is the router's to match; the store
|
|
// keeps the words.
|
|
func (s *DB) UserExcludedLicences(ctx context.Context, userID string) ([]string, error) {
|
|
rows, err := s.db.QueryContext(ctx,
|
|
`SELECT licence FROM user_excluded_licences WHERE user_id = ? ORDER BY licence`, userID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer func() { _ = rows.Close() }()
|
|
var out []string
|
|
for rows.Next() {
|
|
var l string
|
|
if err := rows.Scan(&l); err != nil {
|
|
return nil, err
|
|
}
|
|
out = append(out, l)
|
|
}
|
|
return out, rows.Err()
|
|
}
|
|
|
|
// SetUserExcludedLicences replaces what a person has said not to use; an
|
|
// empty list excludes nothing.
|
|
func (s *DB) SetUserExcludedLicences(ctx context.Context, userID string, licences []string) error {
|
|
keys := make([]string, 0, len(licences))
|
|
for _, l := range licences {
|
|
if l = strings.TrimSpace(l); l != "" {
|
|
keys = append(keys, l)
|
|
}
|
|
}
|
|
slices.Sort(keys)
|
|
keys = slices.Compact(keys)
|
|
return s.inTx(ctx, func(c conn) error {
|
|
if _, err := c.ExecContext(ctx, `DELETE FROM user_excluded_licences WHERE user_id = ?`, userID); err != nil {
|
|
return err
|
|
}
|
|
for _, k := range keys {
|
|
if _, err := c.ExecContext(ctx,
|
|
`INSERT INTO user_excluded_licences (user_id, licence) VALUES (?, ?)`, userID, k); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
})
|
|
}
|