A shared account previously inherited its members' library access but none of their content restrictions, so a child could log into "alice+kid" with their own password and get around their own rating cap. The shared account now gets the strictest member's parental rating, unrated-item block, blocked tags and allowed tags, recomputed at creation, on membership change and at startup. An admin can raise the rating cap on a slider between the strictest and the loosest member; unrated and tag rules stay strictest-wins. What makes raising the cap safe is the unlock rule: after a member's password matches, both users' live policies are compared and the login is refused if the account is looser than the member on any field. So raising the cap above the child's rating means the child's password no longer opens the account, while the parent's still does. The same rule bounds the slider - past the loosest member nobody could unlock the account - so a chosen cap is clamped back into range whenever applied. Allowed tags need care: Jellyfin reads an empty list as "no whitelist", so an empty intersection of members' whitelists is written as a sentinel tag no item carries. Access schedules and channels are not inherited yet. The shared account is never an administrator. Groups created at the login screen always inherit and are restricted before the first session exists. The dashboard shows each member's cap, who a chosen cap shuts out, and the restrictions in effect, and gains a per-group edit form for the sync options. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
69 lines
2.9 KiB
C#
69 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Jellyfin.Database.Implementations.Entities;
|
|
using Jellyfin.Plugin.WatchedTogether.Configuration;
|
|
|
|
namespace Jellyfin.Plugin.WatchedTogether.Services;
|
|
|
|
/// <summary>
|
|
/// Computes, applies and checks the content restrictions a shared account should have.
|
|
/// </summary>
|
|
public interface IRestrictionService
|
|
{
|
|
/// <summary>
|
|
/// Computes the strictest combination of the given members' restrictions.
|
|
/// </summary>
|
|
/// <param name="memberIds">The members to combine.</param>
|
|
/// <returns>Restrictions at least as strict as every member's.</returns>
|
|
ContentRestrictions ComputeStrictest(IReadOnlyList<Guid> memberIds);
|
|
|
|
/// <summary>
|
|
/// Finds the range the members' parental rating caps span.
|
|
/// </summary>
|
|
/// <param name="memberIds">The members to inspect.</param>
|
|
/// <returns>The strictest and loosest caps among them.</returns>
|
|
RatingRange GetRatingRange(IReadOnlyList<Guid> memberIds);
|
|
|
|
/// <summary>
|
|
/// Writes the restrictions a group's shared account should have: the strictest member's,
|
|
/// except for the rating cap when the group has chosen its own.
|
|
/// </summary>
|
|
/// <param name="group">The group whose shared account to update.</param>
|
|
/// <returns>
|
|
/// The restrictions written, and whether the group's chosen cap had to be adjusted to stay
|
|
/// within its members' range - in which case <paramref name="group"/> has been updated in
|
|
/// place and the caller should persist it.
|
|
/// </returns>
|
|
Task<RestrictionApplyResult> ApplyAsync(SharedGroup group);
|
|
|
|
/// <summary>
|
|
/// Determines whether <paramref name="candidate"/> hides at least everything
|
|
/// <paramref name="member"/> cannot see, reading both users live.
|
|
/// </summary>
|
|
/// <param name="candidate">The shared account being unlocked.</param>
|
|
/// <param name="member">The member whose password matched.</param>
|
|
/// <returns><c>true</c> if the member may unlock the account.</returns>
|
|
bool IsAtLeastAsStrict(User candidate, User member);
|
|
}
|
|
|
|
/// <summary>
|
|
/// The range spanned by a set of members' parental rating caps.
|
|
/// </summary>
|
|
/// <param name="Strictest">The lowest cap, or <c>null</c> if no member has one.</param>
|
|
/// <param name="Loosest">The highest cap, or <c>null</c> if any member has none.</param>
|
|
public readonly record struct RatingRange(int? Strictest, int? Loosest)
|
|
{
|
|
/// <summary>
|
|
/// Gets a value indicating whether there is anything to choose: at least one member is capped.
|
|
/// </summary>
|
|
public bool HasChoice => Strictest is not null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// The outcome of applying a group's restrictions to its shared account.
|
|
/// </summary>
|
|
/// <param name="Restrictions">What was written.</param>
|
|
/// <param name="CapAdjusted">Whether the group's chosen cap was changed to fit its members' range.</param>
|
|
public sealed record RestrictionApplyResult(ContentRestrictions Restrictions, bool CapAdjusted);
|