Help us shape the future of Go! Take the 2026 Go Developer Survey

safety

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2026 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package safety persists owner policy and enforces it at Plex request boundaries.

Index

Constants

View Source
const LabelMapNote = "" /* 140-byte string literal not displayed */

LabelMapNote records what a plex.tv label clause can match on Ether. Owner collections and Plex item labels are not stored on the title row; looking them up on a browse path would scale with library size. A title without a TMDB collection name is allowed (the clause is a no-op).

Variables

This section is empty.

Functions

func AllowedWithPolicy added in v0.3.0

func AllowedWithPolicy(u *core.User, t *core.Title, p Policy) bool

AllowedWithPolicy evaluates caller-owned policy facts. The caller must separately enforce the catalog visibility gate and durable policy fence.

func CanPlayWithPolicy added in v0.3.0

func CanPlayWithPolicy(u *core.User, p Policy, remote bool, now time.Time) bool

CanPlayWithPolicy evaluates the same playback rules against an owned policy snapshot. It does not establish freshness or an authorization interval.

func IsRemote

func IsRemote(r *http.Request) bool

func StricterRating added in v0.3.2

func StricterRating(account, policy string) string

StricterRating is the more restrictive of two content rating limits, where "" is unrestricted. It orders labels by contentrating level, as the old account-and-policy merge did.

func StricterStreamLimit added in v0.3.2

func StricterStreamLimit(a, b int) int

StricterStreamLimit is the tighter of two per-viewer stream limits, where 0 adds no limit of its own: the smaller non-zero value.

Types

type PlexShare added in v0.3.0

type PlexShare struct {
	FilterMovies     string
	FilterTelevision string
	AllowSync        *bool
}

PlexShare is the cached plex.tv grant for one viewer. Ether owner policy for that viewer overrides every field here.

type Policy

type Policy struct {
	BlockedGenres   []string `json:"blockedGenres"`
	BlockedKeywords []string `json:"blockedKeywords"`
	RemoteDisabled  bool     `json:"remoteDisabled"`
	MaxBitrateKbps  int      `json:"maxBitrateKbps"`
	// AllowedHours is empty for any time, otherwise hours 0..23 in Timezone.
	AllowedHours []int  `json:"allowedHours"`
	Timezone     string `json:"timezone"`
	// AllowDownloads is an owner override of plex.tv allowSync. Nil means
	// the plex.tv default (and the server AllowFriends setting) still apply.
	AllowDownloads *bool `json:"allowDownloads,omitempty"`
}

Policy is the owner's per-viewer content and playback policy. A viewer's stream limit and content rating limit are not here: they live on the user record (core.User.StreamLimit, core.User.MaxContentRating), which every protocol already reads.

func (Policy) Validate added in v0.2.4

func (p Policy) Validate() error

Validate reports why p cannot be stored, if it cannot.

type Preset added in v0.3.2

type Preset struct {
	MaxContentRating string `json:"maxContentRating"`
	Policy
}

Preset is a parental-controls starting point. MaxContentRating belongs on the viewer's user record; Policy is stored here. JSON flattens both.

func KidsPreset

func KidsPreset(age string) Preset

type Service

type Service struct {
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, db *sql.DB) (*Service, error)

func (*Service) AllowDownloads added in v0.3.0

func (s *Service) AllowDownloads(u *core.User) bool

AllowDownloads implements core.DownloadAccessPolicy. An owner-set Ether flag wins; otherwise plex.tv allowSync=0 refuses the queue. Friends then follow the owner's AllowFriends setting.

func (*Service) Allowed

func (s *Service) Allowed(u *core.User, t *core.Title) bool

func (*Service) BitrateLimit

func (s *Service) BitrateLimit(u *core.User) int

func (*Service) BrowseBlocks added in v0.3.0

func (s *Service) BrowseBlocks(u *core.User) (genres, keywords []string)

BrowseBlocks is the part of a viewer's policy that library SQL can apply before pagination: blocked genres and blocked keywords. The rating limit is on the user record, which browse filters already read.

func (*Service) BrowseShareFilter added in v0.3.0

func (s *Service) BrowseShareFilter(u *core.User, typ core.MediaType) core.Filter

BrowseShareFilter is the parsed plex.tv share predicate for one library type, ready to push into catalog SQL. Owner rating caps drop plex.tv rating clauses and keep label clauses.

func (*Service) CanPlay

func (s *Service) CanPlay(u *core.User, remote bool, now time.Time) bool

func (*Service) Close

func (s *Service) Close()

Close disconnects the cluster bus.

func (*Service) ConfirmPlayback added in v0.3.0

func (s *Service) ConfirmPlayback(ctx context.Context, u *core.User, remote bool, now time.Time) (*core.User, error)

ConfirmPlayback reads membership and safety policy inside one fenced transaction. Restricted viewers fail closed when the store is unavailable. Unrestricted viewers return ErrPolicyUnconfirmed so cached playback can continue. An unrestricted viewer whose epoch has not moved since the last fence is answered from that snapshot, so a play does not take a write lock.

func (*Service) ForUser

func (s *Service) ForUser(u *core.User) Policy

ForUser is u's policy.

func (*Service) FreshPolicy added in v0.3.0

func (s *Service) FreshPolicy(ctx context.Context, viewerID int64) (Policy, error)

FreshPolicy reads the durable policy without consulting the process cache. The caller must fence the corresponding durable viewer-policy epoch across authorization; a standalone result is not itself an authorization. A missing row has the same unrestricted policy value as Service.Get.

func (*Service) Generation added in v0.3.0

func (s *Service) Generation() uint64

Generation changes when a viewer's safety policy is saved.

func (*Service) Get

func (s *Service) Get(id int64) Policy

func (*Service) Handler

func (s *Service) Handler() http.Handler

func (*Service) PolicyInTx added in v0.3.0

func (s *Service) PolicyInTx(ctx context.Context, tx *sql.Tx, viewerID int64) (Policy, error)

PolicyInTx reads the durable policy row. A missing row is unrestricted.

func (*Service) Put

func (s *Service) Put(ctx context.Context, id int64, p Policy) error

func (*Service) Restricted

func (s *Service) Restricted(u *core.User) bool

func (*Service) SetBus

func (s *Service) SetBus(bus clusterbus.Bus)

SetBus connects the cluster bus (nil disconnects): policy changes made on this node reach the others' caches and vice versa.

func (*Service) SetCatalogPolicy added in v0.2.12

func (s *Service) SetCatalogPolicy(fn func(*core.Title) bool)

SetCatalogPolicy installs the global catalogue policy during app construction.

func (*Service) SetFriendsDownloads added in v0.3.0

func (s *Service) SetFriendsDownloads(fn func() bool)

func (*Service) SetPlexShare added in v0.3.0

func (s *Service) SetPlexShare(fn func(*core.User) PlexShare)

func (*Service) UserPolicy

func (s *Service) UserPolicy(u *core.User) *core.User

UserPolicy implements core.UserPolicySource: the viewer as policy-aware code should see them. The stream and rating limits are already on the user record, so this is an independent copy callers may modify.

type ShareFilterPart added in v0.3.0

type ShareFilterPart = sharefilter.Part

ShareFilterPart is one owner-readable clause of a plex.tv share filter.

func FormatShareFilter added in v0.3.0

func FormatShareFilter(spec string) []ShareFilterPart

FormatShareFilter turns a plex.tv filter spec into owner-readable parts.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL