PlotDirector/docs/subscription-entitlements.md

4.7 KiB

Subscription entitlements

PlotDirector calculates access at request time. It does not persist a second "effective plan" field.

Plans and limits

SubscriptionLevel remains the authoritative plan catalogue. The existing levels are Draft Desk, Writing Room, Story Forge, and Author Studio. Their book, chapter, scene, character, storage, and collaborator limits are database data and must not be duplicated in controllers or views.

Active books in active projects owned by the user count toward MaxBooks. Archived books and archived projects do not. A downgrade never deletes or hides existing data; an account at or above its new limit may read its existing books but cannot create another.

Effective access precedence

SubscriptionService.GetEffectiveEntitlementAsync is the application authority. Precedence is:

  1. An active, non-revoked administrative override whose start has arrived and whose optional expiry has not arrived.
  2. An active application-managed trial whose expiry is strictly later than the current UTC time.
  3. An active paid subscription, including a cancellation that has not yet reached its paid-through period end.
  4. Read-only access for an expired trial, ended subscription, or missing subscription.

The expiry boundary is exclusive: at the exact expiry instant, temporary access has ended. Expired overrides need no background job; they simply stop participating in evaluation and the underlying billing/trial state applies again.

Stripe state remains commercial state. SubscriptionOverride never updates Stripe identifiers, price IDs, status, or billing periods.

Enforcement

All authenticated unsafe MVC/API requests pass through SubscriptionEnforcementFilter. Inactive accounts retain GET/read/export/account/billing access, while writes are redirected to subscription information or receive an API 403 problem response. Account management, billing, export, webhook, and authorised administration endpoints are intentionally exempt.

Resource creation also remains guarded at its service boundary. Normal MVC, onboarding, Word Companion, legacy JSON imports, and project-backup imports all use the same subscription service. Book creation obtains a short database reservation through SubscriptionEntitlement_TryReserveBookSlots; sp_getapplock serializes the final-slot decision per owner, so concurrent requests cannot both consume one remaining place. Reservations are released after the operation and expire defensively after 15 minutes.

Insert triggers on books, chapters, scenes, and characters are the final backstop for alternate and future bulk paths. They evaluate the same underlying subscription/override precedence and reject creation above the configured plan limit without affecting updates, reads, archives, or existing over-limit data. Bulk imports and Word Companion sync also perform projected-limit checks first so users receive a useful message rather than a database error.

Story Intelligence queue and worker execution both call the central feature decision. This prevents already-queued paid AI work from running after access expires. Export remains available because no existing plan defines it as restricted and authors must be able to retrieve their work.

When adding a future plan-specific feature, add its decision to SubscriptionFeature and SubscriptionService; do not inspect subscription rows or plan names in a controller.

Trials

New registration rows are explicit Draft Desk trials with IsTrial = 1 and TrialExpiryDateUTC = StartDateUTC + 30 days. Historical Draft Desk/no-Stripe rows are materialized the same way by migration 201. Missing legacy expiry remains defensively interpreted as start plus 30 days in the evaluator.

Expired trials can authenticate, read existing projects and books, export, manage their account, and reach pricing. They cannot edit, import, create resources, or queue/execute Story Intelligence.

Administration and audit

Subscription administration is under /admin/subscriptions and the existing AdminOnly policy. It shows underlying billing state separately from effective access and current book usage.

Administrators can:

  • set an application-managed trial expiry;
  • grant an existing level from a UTC start until an optional UTC expiry;
  • revoke an override.

Every change requires a reason and writes previous/new state, affected user, administrator, action, and timestamp to SubscriptionAdministrationAudit. Internal reasons are not shown on user-facing subscription pages.

Schema

Migration PlotLine/Sql/201_SubscriptionEntitlementEnforcement.sql adds SubscriptionOverride, SubscriptionAdministrationAudit, SubscriptionBookSlotReservation, their stored procedures and insert guards, explicit trial creation, and the safe historical trial-expiry materialization.