PhoenixKit.Modules.Legal (phoenix_kit v1.7.43)

Copy Markdown View Source

Legal module for PhoenixKit - GDPR/CCPA compliant legal pages and consent management.

  • Compliance framework selection (GDPR, CCPA, etc.)
  • Company information management
  • Legal page generation (Privacy Policy, Terms, Cookie Policy)
  • Integration with Publishing module for page storage
  • Cookie consent banner
  • Consent logging to phoenix_kit_consent_logs table
  • Google Consent Mode v2 integration

Dependencies

  • Publishing module must be enabled before Legal module

Usage

# Enable the module (requires Publishing to be enabled)
PhoenixKit.Modules.Legal.enable_system()

# Check if enabled
PhoenixKit.Modules.Legal.enabled?()

# Get configuration
PhoenixKit.Modules.Legal.get_config()

# Generate legal pages
PhoenixKit.Modules.Legal.generate_all_pages()

Summary

Functions

Check if all required legal pages are published.

Get available compliance frameworks.

Get available page types.

Check if consent widget is enabled (Phase 2 feature).

Disable consent widget.

Disable Google Consent Mode v2.

Disable the Legal module.

Enable consent widget.

Enable Google Consent Mode v2.

Enable the Legal module.

Check if Legal module is enabled.

Generate all required pages for selected frameworks.

Generate a legal page from template.

Get all pages (required + optional) for given frameworks.

Get auto-calculated policy version based on legal page updates.

Get company information.

Get the full configuration of the Legal module.

Get consent mode.

Get full consent widget configuration for the component.

Get cookie banner/icon position. Options: "bottom-left", "bottom-right", "top-left", "top-right"

Get Data Protection Officer contact.

Alias for get_cookie_banner_position/0.

Get policy version for consent tracking. Changing this version will prompt users to re-consent.

Get pages required for given frameworks.

Get selected compliance frameworks.

Check if there are unpublished legal pages that are required.

Check if Google Consent Mode v2 is enabled.

Check if any opt-in framework is selected.

Check if consent widget should be hidden for authenticated users. Only applies in "notice" mode.

List generated legal pages.

Publish a legal page by slug.

Set compliance frameworks.

Check if consent icon should be shown.

Update company information.

Update consent mode.

Update DPO contact information.

Update hide for authenticated setting.

Update cookie banner/icon position.

Update policy version.

Functions

all_required_pages_published?()

@spec all_required_pages_published?() :: boolean()

Check if all required legal pages are published.

available_frameworks()

@spec available_frameworks() :: %{
  required(String.t()) => PhoenixKit.Modules.Legal.LegalFramework.t()
}

Get available compliance frameworks.

available_page_types()

@spec available_page_types() :: %{
  required(String.t()) => PhoenixKit.Modules.Legal.PageType.t()
}

Get available page types.

disable_system()

@spec disable_system() :: {:ok, term()} | {:error, term()}

Disable the Legal module.

enable_system()

@spec enable_system() :: {:ok, :enabled} | {:error, :publishing_required | term()}

Enable the Legal module.

Requires Publishing module to be enabled first. Creates the "legal" publishing group if it doesn't exist.

Returns

  • {:ok, :enabled} - Successfully enabled
  • {:error, :publishing_required} - Publishing module must be enabled first

enabled?()

@spec enabled?() :: boolean()

Check if Legal module is enabled.

generate_all_pages(opts \\ [])

@spec generate_all_pages(keyword()) :: {:ok, map()}

Generate all required pages for selected frameworks.

Parameters

  • opts: Keyword options
    • :language - Language code (default: "en")
    • :scope - User scope for audit trail
    • :include_optional - Include optional pages (default: false)

Returns

  • {:ok, results} - Map of page_type => result

generate_page(page_type, opts \\ [])

@spec generate_page(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, term()}

Generate a legal page from template.

Parameters

  • page_type: Page type slug (e.g., "privacy-policy")
  • opts: Keyword options
    • :language - Language code (default: "en")
    • :scope - User scope for audit trail

Returns

  • {:ok, post} on success
  • {:error, reason} on failure

get_all_pages_for_frameworks(framework_ids)

@spec get_all_pages_for_frameworks([String.t()]) :: [String.t()]

Get all pages (required + optional) for given frameworks.

get_auto_policy_version()

@spec get_auto_policy_version() :: String.t()

Get auto-calculated policy version based on legal page updates.

Uses the latest updated_at from cookie-policy or privacy-policy pages. Falls back to manual version if no pages exist.

get_company_info()

@spec get_company_info() :: map()

Get company information.

Reads from consolidated company_info key with fallback to legacy legal_company_info.

get_config()

@spec get_config() :: map()

Get the full configuration of the Legal module.

Returns a map with:

  • enabled: boolean
  • frameworks: list of selected framework IDs
  • company_info: map with company details
  • dpo_contact: map with DPO contact info
  • generated_pages: list of generated page slugs
  • consent_widget_enabled: boolean (Phase 2)

get_dpo_contact()

@spec get_dpo_contact() :: map()

Get Data Protection Officer contact.

get_icon_position()

@spec get_icon_position() :: String.t()

Alias for get_cookie_banner_position/0.

get_policy_version()

@spec get_policy_version() :: String.t()

Get policy version for consent tracking. Changing this version will prompt users to re-consent.

get_required_pages_for_frameworks(framework_ids)

@spec get_required_pages_for_frameworks([String.t()]) :: [String.t()]

Get pages required for given frameworks.

get_selected_frameworks()

@spec get_selected_frameworks() :: [String.t()]

Get selected compliance frameworks.

get_unpublished_required_pages()

@spec get_unpublished_required_pages() :: [String.t()]

Check if there are unpublished legal pages that are required.

Returns a list of unpublished page slugs (e.g., ["cookie-policy", "privacy-policy"]).

has_opt_in_framework?()

@spec has_opt_in_framework?() :: boolean()

Check if any opt-in framework is selected.

hide_for_authenticated?()

@spec hide_for_authenticated?() :: boolean()

Check if consent widget should be hidden for authenticated users. Only applies in "notice" mode.

list_generated_pages()

@spec list_generated_pages() :: [map()]

List generated legal pages.

publish_page(page_slug, opts \\ [])

@spec publish_page(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, term()}

Publish a legal page by slug.

Parameters

  • page_slug: The slug of the page to publish (e.g., "cookie-policy")
  • opts: Keyword options
    • :scope - User scope for audit trail

Returns

  • {:ok, post} on success
  • {:error, reason} on failure

set_frameworks(framework_ids)

@spec set_frameworks([String.t()]) :: {:ok, term()} | {:error, term()}

Set compliance frameworks.

Parameters

  • framework_ids: List of framework IDs to enable

Returns

  • {:ok, setting} on success
  • {:error, reason} on failure

update_company_info(params)

@spec update_company_info(map()) :: {:ok, term()} | {:error, term()}

Update company information.

update_dpo_contact(params)

@spec update_dpo_contact(map()) :: {:ok, term()} | {:error, term()}

Update DPO contact information.

update_hide_for_authenticated(value)

@spec update_hide_for_authenticated(boolean()) :: {:ok, term()} | {:error, term()}

Update hide for authenticated setting.

update_icon_position(position)

@spec update_icon_position(String.t()) :: {:ok, term()} | {:error, term()}

Update cookie banner/icon position.

update_policy_version(version)

@spec update_policy_version(String.t()) :: {:ok, term()} | {:error, term()}

Update policy version.