PhoenixKitBookings.Policy (PhoenixKitBookings v0.1.1)

Copy Markdown View Source

Authorization + self-service rules for the admin surface, in one server-side module (every admin LiveView routes its reads and mutations through here — buttons are hidden AND actions re-checked).

The permission model

Core's sub-permission semantics (a sub implies its base) force the calendar module's orientation:

  • base "bookings" — access the bookings admin area, scoped to services YOU OWN. This is the key an owner grants to let a user run their own bookable services.
  • sub "bookings.manage_all" — site-wide: every service (owned or site-level), every reservation, and the module settings page. Owner/superadmin roles hold it implicitly.

Self-service settings (owner-controlled, default OFF)

  • bookings_user_services_enabled (boolean, default false) — whether base-permission holders may CREATE services at all. Off = they can still manage services an admin assigned to them.
  • bookings_max_services_per_user (integer, default 1; 0 = unlimited) — per-user creation cap.

Summary

Functions

True when the scope may create a new service: site-wide managers always; base-permission holders only when self-service is enabled and they are under the per-user cap.

True when the scope may manage this specific service.

Booking lifecycle actions authorize against the booking's service.

Creates a service on behalf of scope. Site-wide managers create SITE services (no owner); base-permission holders create services owned by themselves (when allowed).

Site-wide management (sub-permission, Owner/superadmin implicit).

Service UUIDs the scope may see — feeds the reservations filter.

Services this scope may see in the admin (all opts pass through).

Functions

add_rule(scope, service, attrs)

add_unit(scope, service, attrs)

can_create?(scope)

True when the scope may create a new service: site-wide managers always; base-permission holders only when self-service is enabled and they are under the per-user cap.

can_manage?(scope, service)

True when the scope may manage this specific service.

cancel_booking(scope, booking, opts \\ [])

confirm_booking(scope, booking)

Booking lifecycle actions authorize against the booking's service.

create_service(scope, attrs)

Creates a service on behalf of scope. Site-wide managers create SITE services (no owner); base-permission holders create services owned by themselves (when allowed).

delete_rule(scope, service, rule)

delete_service(scope, service)

delete_unit(scope, service, unit)

manage_all?(scope)

Site-wide management (sub-permission, Owner/superadmin implicit).

max_services_per_user()

restore_service(scope, service)

set_status(scope, service, status)

set_unit_active(scope, service, unit, active?)

trash_service(scope, service)

update_service(scope, service, attrs)

user_services_enabled?()

visible_service_uuids(scope)

Service UUIDs the scope may see — feeds the reservations filter.

visible_services(scope, opts \\ [])

Services this scope may see in the admin (all opts pass through).