MishkaCmsCore.Notify (Mishka CMS Core v0.0.1)

Copy Markdown View Source

The notification center domain — one Ash resource, per-user real-time, pluggable through mishka_installer events, and the single public API extensions learn.

Producers call deliver/3 (or react to the existing <app>:<resource>:after_<action> firehose with a tiny hook plugin); the audience is resolved and rows are fanned out (inline for small audiences, an Oban job for large ones). Consumers are the topbar bell (MishkaCmsCore.Notify.LiveHooks), the /admin/dashboard/notifications page, and optional channels (email, …).

Which notification types a site receives is admin-managed: each type is a per-site boolean Setting (setting_key/1), registered via the settings:register hook and checked once per delivery (default on). There is no bespoke type registry — the Settings page is the single control surface.

See MishkaCmsCore.Notify.Notification (data), MishkaCmsCore.Notify.Delivery (who + how), and MishkaCmsCore.Settings (the per-type toggles).

Summary

Functions

Runs authorization checks for MishkaCmsCore.Notify.Notification.read

Runs authorization checks for MishkaCmsCore.Notify.Notification.read, returning a boolean.

Deliver a notification — the one call extensions learn. Producers use the plugin-friendly form (attrs first, audience as named opts)

Calls the read action on MishkaCmsCore.Notify.Notification.

Calls the read action on MishkaCmsCore.Notify.Notification.

Marks every one of user's unread notifications read, in one bulk update. No-op when signed out. Backs both the topbar bell's "Mark all read" and the inbox page's.

page(page, request) deprecated

Returns the query corresponding to the action.

The Settings key that toggles a notification type on/off for a site (site-level, admin-managed).

The per-USER opt-out Setting definition for a notification type — a :user-scoped boolean (default on) under Settings → Preferences → Notifications. An extension registers this ALONGSIDE its own per-site toggle so a recipient can mute the type just for themselves. description defaults to the shared "only your own copy" wording every opt-out shares.

The per-USER preference key for a notification type (a :user-scoped Setting under Settings → Preferences). A recipient can turn their OWN copy of a type off without affecting the site toggle (setting_key/1) or anyone else; delivery honours it per recipient (default on).

Functions

aggregate(query, aggregate_or_aggregates, opts \\ [])

This function is deprecated. Use `Ash.aggregate/3` instead.

aggregate!(query, aggregate_or_aggregates, opts \\ [])

This function is deprecated. Use `Ash.aggregate!/3` instead.

avg(query, field, opts \\ [])

This function is deprecated. Use `Ash.avg/3` instead.

avg!(query, field, opts \\ [])

This function is deprecated. Use `Ash.avg!/3` instead.

bulk_create(inputs, resource, action, opts \\ [])

This function is deprecated. Use `Ash.bulk_create/4` instead.

bulk_create!(inputs, resource, action, opts \\ [])

This function is deprecated. Use `Ash.bulk_create!/4` instead.

bulk_destroy(stream_or_query, action, input, opts \\ [])

This function is deprecated. Use `Ash.bulk_destroy/4` instead.

bulk_destroy!(stream_or_query, action, input, opts \\ [])

This function is deprecated. Use `Ash.bulk_destroy!/4` instead.

bulk_update(stream_or_query, action, input, opts \\ [])

This function is deprecated. Use `Ash.bulk_update/4` instead.

bulk_update!(stream_or_query, action, input, opts \\ [])

This function is deprecated. Use `Ash.bulk_update!/4` instead.

calculate(resource, calculation, opts \\ [])

This function is deprecated. Use `Ash.calculate/3` instead.

calculate!(resource, calculation, opts \\ [])

This function is deprecated. Use `Ash.calculate!/3` instead.

can(action_or_query_or_changeset, actor, opts \\ [])

This function is deprecated. Use `Ash.can/3` instead.
@spec can(
  action_or_query_or_changeset ::
    Ash.Query.t()
    | Ash.Changeset.t()
    | {Ash.Resource.t(), atom() | Ash.Resource.Actions.action()},
  actor :: term(),
  opts :: Keyword.t()
) ::
  {:ok, boolean() | :maybe}
  | {:ok, true, Ash.Changeset.t() | Ash.Query.t()}
  | {:ok, true, Ash.Changeset.t(), Ash.Query.t()}
  | {:ok, false, Exception.t()}
  | {:error, term()}

can?(query_or_changeset_or_action, actor, opts \\ [])

This function is deprecated. Use `Ash.can?/3` instead.
@spec can?(
  query_or_changeset_or_action ::
    Ash.Query.t()
    | Ash.Changeset.t()
    | {Ash.Resource.t(), atom() | Ash.Resource.Actions.action()},
  actor :: term(),
  opts :: Keyword.t()
) :: boolean() | no_return()

can_get_notification(actor, id, params_or_opts \\ %{}, opts \\ [])

Runs authorization checks for MishkaCmsCore.Notify.Notification.read

See Ash.can/3 for more information

Options

  • :maybe_is (term/0) - If the actor may be able to perform the action, what value should be returned. The default value is :maybe.

  • :filter_with - If set to :error, the query will raise an error on a match. If set to :filter the query will filter out unauthorized access. Valid values are :filter, :error The default value is :filter.

  • :validate? (boolean/0) - Whether or not to treat an invalid action as a non-allowed action. The default value is false.

  • :reuse_values? (boolean/0) - If true, allow calculations to use attributes and other dependencies already on the struct instead of refetching from the data layer. Default false (prefer persisted data; avoids stale structs acting as an implicit cache).

    Ash.load!(user, :full_name, reuse_values?: true) The default value is `false`.
  • :pre_flight? (boolean/0) - Whether or not this is a pre_flight check (which may perform optimized in-memory checks) or the final proper check. The default value is true.

  • :scope (term/0) - A value that implements the Ash.Scope.ToOpts protocol. Provides a default tenant and deep merges context (explicit opts take precedence). The actor is always taken from the second argument to can/3. See Ash.Scope for more.

  • :context (map/0) - Context to set on the query/changeset/action_input being authorized

  • :run_queries? (boolean/0) - Whether or not to run queries. If set to true, :maybe will not be returned. The default value is true.

  • :data - The record or records specifically attempting to be acted upon.

  • :tenant (value that implements the Ash.ToTenant protocol) - The tenant to use for authorization

  • :as_of - A point in time to authorize "as of" (time travel). See Ash.Query.as_of/2.

  • :alter_source? (boolean/0) - If set to true, the source being authorized is returned so it can be run. The default value is false.

  • :base_query (term/0) - A base query on which to apply an generated filters

  • :no_check? (boolean/0) - Whether or not authorization must pass at the strict/filter step, or if post-checks are allowed to be run The default value is false.

  • :on_must_pass_strict_check (term/0) - Override the value returned when no_check? is true but a check must be run.

  • :atomic_changeset (term/0) - A base query on which to apply an generated filters

  • :return_forbidden_error? (boolean/0) - Whether or not to return a forbidden error in cases of not being authorized. The default value is false.

  • :log? (boolean/0) - Whether or not to log the authorization result. The default value is false.

  • :log_policy_breakdown? (boolean/0) - If set to false, suppresses policy breakdown logs, overriding the global show_policy_breakdowns? configuration.

  • :short_circuit? (boolean/0) - For can_do_all/3 and can_do_all?/3, whether to stop checking after the first failing check. Defaults to false for can_do_all/3 and true for can_do_all?/3. The default value is false.

can_get_notification?(actor, id, params_or_opts \\ %{}, opts \\ [])

Runs authorization checks for MishkaCmsCore.Notify.Notification.read, returning a boolean.

See Ash.can?/3 for more information

Options

  • :maybe_is (term/0) - If the actor may be able to perform the action, what value should be returned. The default value is :maybe.

  • :filter_with - If set to :error, the query will raise an error on a match. If set to :filter the query will filter out unauthorized access. Valid values are :filter, :error The default value is :filter.

  • :validate? (boolean/0) - Whether or not to treat an invalid action as a non-allowed action. The default value is false.

  • :reuse_values? (boolean/0) - If true, allow calculations to use attributes and other dependencies already on the struct instead of refetching from the data layer. Default false (prefer persisted data; avoids stale structs acting as an implicit cache).

    Ash.load!(user, :full_name, reuse_values?: true) The default value is `false`.
  • :pre_flight? (boolean/0) - Whether or not this is a pre_flight check (which may perform optimized in-memory checks) or the final proper check. The default value is true.

  • :scope (term/0) - A value that implements the Ash.Scope.ToOpts protocol. Provides a default tenant and deep merges context (explicit opts take precedence). The actor is always taken from the second argument to can/3. See Ash.Scope for more.

  • :context (map/0) - Context to set on the query/changeset/action_input being authorized

  • :run_queries? (boolean/0) - Whether or not to run queries. If set to true, :maybe will not be returned. The default value is true.

  • :data - The record or records specifically attempting to be acted upon.

  • :tenant (value that implements the Ash.ToTenant protocol) - The tenant to use for authorization

  • :as_of - A point in time to authorize "as of" (time travel). See Ash.Query.as_of/2.

  • :alter_source? (boolean/0) - If set to true, the source being authorized is returned so it can be run. The default value is false.

  • :base_query (term/0) - A base query on which to apply an generated filters

  • :no_check? (boolean/0) - Whether or not authorization must pass at the strict/filter step, or if post-checks are allowed to be run The default value is false.

  • :on_must_pass_strict_check (term/0) - Override the value returned when no_check? is true but a check must be run.

  • :atomic_changeset (term/0) - A base query on which to apply an generated filters

  • :return_forbidden_error? (boolean/0) - Whether or not to return a forbidden error in cases of not being authorized. The default value is false.

  • :log? (boolean/0) - Whether or not to log the authorization result. The default value is false.

  • :log_policy_breakdown? (boolean/0) - If set to false, suppresses policy breakdown logs, overriding the global show_policy_breakdowns? configuration.

  • :short_circuit? (boolean/0) - For can_do_all/3 and can_do_all?/3, whether to stop checking after the first failing check. Defaults to false for can_do_all/3 and true for can_do_all?/3. The default value is false.

count(query, opts \\ [])

This function is deprecated. Use `Ash.count/2` instead.

count!(query, opts \\ [])

This function is deprecated. Use `Ash.count!/2` instead.

create(changeset, opts \\ [])

This function is deprecated. Use `Ash.create/2` instead.

create!(changeset, opts \\ [])

This function is deprecated. Use `Ash.create!/2` instead.

default_short_name()

deliver(attrs_or_audience, opts_or_attrs)

Deliver a notification — the one call extensions learn. Producers use the plugin-friendly form (attrs first, audience as named opts):

Notify.deliver(
  %{
    type: "blog:comment:created",
    title: "New comment awaiting moderation",
    link: "/admin/dashboard/blog/comments",
    source: "mishka_blog",
    metadata: %{"author" => comment.author_name}
  },
  tenant_permissions: "admin:dashboard:blog:comment",
  master_permissions: "admin:dashboard:blog:comment",
  site_id: comment.site_id,
  actor: comment.author
)

Small audiences are written inline; large / unbounded ones are streamed by an Oban job. See MishkaCmsCore.Notify.Delivery for both call forms, all audience opts, and attrs.

deliver(audience, attrs, opts)

See MishkaCmsCore.Notify.Delivery.deliver/3.

destroy(record, opts \\ [])

This function is deprecated. Use `Ash.destroy/2` instead.

destroy!(record, opts \\ [])

This function is deprecated. Use `Ash.destroy!/2` instead.

exists(query, opts \\ [])

This function is deprecated. Use `Ash.exists/2` instead.

exists?(query, opts \\ [])

This function is deprecated. Use `Ash.exists?/2` instead.

first(query, field, opts \\ [])

This function is deprecated. Use `Ash.first/3` instead.

first!(query, field, opts \\ [])

This function is deprecated. Use `Ash.first!/3` instead.

get(resource, id_or_filter, opts \\ [])

This function is deprecated. Use `Ash.get/3` instead.

get!(resource, id_or_filter, opts \\ [])

This function is deprecated. Use `Ash.get!/3` instead.

get_notification(id, params \\ nil, opts \\ nil)

Calls the read action on MishkaCmsCore.Notify.Notification.

Options

  • :as_of - A point in time to read "as of" (time travel). See Ash.Query.as_of/2.

  • :page - Pagination options, see Ash.read/2 for more.

  • :load (term/0) - A load statement to add onto the query

  • :max_concurrency (non_neg_integer/0) - The maximum number of processes allowed to be started for parallel loading of relationships and calculations. Defaults to System.schedulers_online() * 2

  • :lock (term/0) - A lock statement to add onto the query

  • :return_query? (boolean/0) - If true, the query that was ultimately used is returned as a third tuple element.
    The query goes through many potential changes during a request, potentially adding authorization filters, or replacing relationships for other data layers with their corresponding ids. This option can be used to get the true query that was sent to the data layer. The default value is false.

  • :skip_unknown_inputs - A list of inputs that, if provided, will be ignored if they are not recognized by the action. Use :* to indicate all unknown keys.

  • :reuse_values? (boolean/0) - If true, allow calculations to use attributes and other dependencies already on the struct instead of refetching from the data layer. Default false (prefer persisted data; avoids stale structs acting as an implicit cache).

    Ash.load!(user, :full_name, reuse_values?: true) The default value is `false`.
  • :strict? (boolean/0) - If set to true, only specified attributes will be loaded when passing a list of fields to fetch on a relationship, which allows for more optimized data-fetching.
    See Ash.Query.load/2. The default value is false.

  • :authorize_with - If set to :error, instead of applying authorization filters as a filter, any records not matching the authorization filter will cause an error to be returned. Valid values are :filter, :error The default value is :filter.

  • :timeout (timeout/0) - A positive integer, or :infinity. If none is provided, the timeout configured on the domain is used.

  • :tracer (one or a list of module that adopts Ash.Tracer) - A tracer that implements the Ash.Tracer behaviour. See that module for more.

  • :action (term/0) - The action to use, either an Action struct or the name of the action

  • :authorize? - If an actor option is provided (even if it is nil), authorization happens automatically. If not, this flag can be used to authorize with no user.

  • :context (map/0) - Context to set on the query, changeset, or input

  • :tenant (value that implements the Ash.ToTenant protocol) - A tenant to set on the query or changeset

  • :actor (term/0) - If an actor is provided, it will be used in conjunction with the authorizers of a resource to authorize access

  • :scope (term/0) - A value that implements the Ash.Scope.ToOpts protocol, for passing around actor/tenant/context in a single value. See Ash.Scope.ToOpts for more.

  • :query - A query to seed the action with.

  • :not_found_error? (boolean/0) - Whether or not to return or raise a NotFound error or to return nil when a get? action/interface is called.

  • :stream? (boolean/0) - If true, a stream of the results will be returned The default value is false.

  • :stream_options (keyword/0) - Options passed to Ash.stream!, if stream?: true is given

    • :batch_size (integer/0) - How many records to request in each query run. Defaults to the pagination limits on the resource, or 250.

    • :allow_stream_with - The 'worst' strategy allowed to be used to fetch records. See Ash.stream!/2 docs for more. The default value is :keyset.

    • :stream_with - The specific strategy to use to fetch records. See Ash.stream!/2 docs for more.

get_notification!(id, params \\ nil, opts \\ nil)

Calls the read action on MishkaCmsCore.Notify.Notification.

Raises any errors instead of returning them

Options

  • :as_of - A point in time to read "as of" (time travel). See Ash.Query.as_of/2.

  • :page - Pagination options, see Ash.read/2 for more.

  • :load (term/0) - A load statement to add onto the query

  • :max_concurrency (non_neg_integer/0) - The maximum number of processes allowed to be started for parallel loading of relationships and calculations. Defaults to System.schedulers_online() * 2

  • :lock (term/0) - A lock statement to add onto the query

  • :return_query? (boolean/0) - If true, the query that was ultimately used is returned as a third tuple element.
    The query goes through many potential changes during a request, potentially adding authorization filters, or replacing relationships for other data layers with their corresponding ids. This option can be used to get the true query that was sent to the data layer. The default value is false.

  • :skip_unknown_inputs - A list of inputs that, if provided, will be ignored if they are not recognized by the action. Use :* to indicate all unknown keys.

  • :reuse_values? (boolean/0) - If true, allow calculations to use attributes and other dependencies already on the struct instead of refetching from the data layer. Default false (prefer persisted data; avoids stale structs acting as an implicit cache).

    Ash.load!(user, :full_name, reuse_values?: true) The default value is `false`.
  • :strict? (boolean/0) - If set to true, only specified attributes will be loaded when passing a list of fields to fetch on a relationship, which allows for more optimized data-fetching.
    See Ash.Query.load/2. The default value is false.

  • :authorize_with - If set to :error, instead of applying authorization filters as a filter, any records not matching the authorization filter will cause an error to be returned. Valid values are :filter, :error The default value is :filter.

  • :timeout (timeout/0) - A positive integer, or :infinity. If none is provided, the timeout configured on the domain is used.

  • :tracer (one or a list of module that adopts Ash.Tracer) - A tracer that implements the Ash.Tracer behaviour. See that module for more.

  • :action (term/0) - The action to use, either an Action struct or the name of the action

  • :authorize? - If an actor option is provided (even if it is nil), authorization happens automatically. If not, this flag can be used to authorize with no user.

  • :context (map/0) - Context to set on the query, changeset, or input

  • :tenant (value that implements the Ash.ToTenant protocol) - A tenant to set on the query or changeset

  • :actor (term/0) - If an actor is provided, it will be used in conjunction with the authorizers of a resource to authorize access

  • :scope (term/0) - A value that implements the Ash.Scope.ToOpts protocol, for passing around actor/tenant/context in a single value. See Ash.Scope.ToOpts for more.

  • :query - A query to seed the action with.

  • :not_found_error? (boolean/0) - Whether or not to return or raise a NotFound error or to return nil when a get? action/interface is called.

  • :stream? (boolean/0) - If true, a stream of the results will be returned The default value is false.

  • :stream_options (keyword/0) - Options passed to Ash.stream!, if stream?: true is given

    • :batch_size (integer/0) - How many records to request in each query run. Defaults to the pagination limits on the resource, or 250.

    • :allow_stream_with - The 'worst' strategy allowed to be used to fetch records. See Ash.stream!/2 docs for more. The default value is :keyset.

    • :stream_with - The specific strategy to use to fetch records. See Ash.stream!/2 docs for more.

list(query, field, opts \\ [])

This function is deprecated. Use `Ash.list/3` instead.

list!(query, field, opts \\ [])

This function is deprecated. Use `Ash.list!/3` instead.

load(data, query, opts \\ [])

This function is deprecated. Use `Ash.load/3` instead.

load!(data, query, opts \\ [])

This function is deprecated. Use `Ash.load!/3` instead.

mark_all_read(user)

@spec mark_all_read(map() | nil) :: :ok

Marks every one of user's unread notifications read, in one bulk update. No-op when signed out. Backs both the topbar bell's "Mark all read" and the inbox page's.

max(query, field, opts \\ [])

This function is deprecated. Use `Ash.max/3` instead.

max!(query, field, opts \\ [])

This function is deprecated. Use `Ash.max!/3` instead.

min(query, field, opts \\ [])

This function is deprecated. Use `Ash.min/3` instead.

min!(query, field, opts \\ [])

This function is deprecated. Use `Ash.min!/3` instead.

page(page, request)

This function is deprecated. Use `Ash.page/2` instead.

page!(page, request)

This function is deprecated. Use `Ash.page!/2` instead.

query_to_get_notification(id, params_or_opts \\ %{}, opts \\ [])

Returns the query corresponding to the action.

Options

  • :as_of - A point in time to read "as of" (time travel). See Ash.Query.as_of/2.

  • :tracer (one or a list of module that adopts Ash.Tracer) - A tracer that implements the Ash.Tracer behaviour. See that module for more.

  • :authorize? - If an actor option is provided (even if it is nil), authorization happens automatically. If not, this flag can be used to authorize with no user.

  • :tenant (value that implements the Ash.ToTenant protocol) - A tenant to set on the query or changeset

  • :actor (term/0) - If an actor is provided, it will be used in conjunction with the authorizers of a resource to authorize access

  • :scope (term/0) - A value that implements the Ash.Scope.ToOpts protocol, for passing around actor/tenant/context in a single value. See Ash.Scope.ToOpts for more.

  • :query - A query to seed the action with.

read(query, opts \\ [])

This function is deprecated. Use `Ash.read/2` instead.

read!(query, opts \\ [])

This function is deprecated. Use `Ash.read!/2` instead.

read_one(query, opts \\ [])

This function is deprecated. Use `Ash.read_one/2` instead.

read_one!(query, opts \\ [])

This function is deprecated. Use `Ash.read_one!/2` instead.

reload(record, opts \\ [])

This function is deprecated. Use `Ash.reload/2` instead.

reload!(record, opts \\ [])

This function is deprecated. Use `Ash.reload!/2` instead.

run_action(input, opts \\ [])

This function is deprecated. Use `Ash.run_action/2` instead.

run_action!(input, opts \\ [])

This function is deprecated. Use `Ash.run_action/2` instead.

setting_key(type)

The Settings key that toggles a notification type on/off for a site (site-level, admin-managed).

Extensions register a boolean Setting under this key via settings:register — it then appears as a normal toggle in the Settings page, and delivery checks it (default on). Colons become dots so the key is a clean settings/DOM id:

Notify.setting_key("blog:post:published")  #=> "notify.blog.post.published"

stream!(query, opts \\ [])

This function is deprecated. Use `Ash.stream!/2` instead.

sum(query, field, opts \\ [])

This function is deprecated. Use `Ash.sum/3` instead.

sum!(query, field, opts \\ [])

This function is deprecated. Use `Ash.sum!/3` instead.

update(changeset, opts \\ [])

This function is deprecated. Use `Ash.update/2` instead.

update!(changeset, opts \\ [])

This function is deprecated. Use `Ash.update!/2` instead.

user_pref_definition(type, label, description \\ "Turns this off for you only — everyone else still gets theirs.")

The per-USER opt-out Setting definition for a notification type — a :user-scoped boolean (default on) under Settings → Preferences → Notifications. An extension registers this ALONGSIDE its own per-site toggle so a recipient can mute the type just for themselves. description defaults to the shared "only your own copy" wording every opt-out shares.

Settings.define(...) # the site toggle (its own category)
Notify.user_pref_definition("blog:post:published", "New posts published")

user_setting_key(type)

The per-USER preference key for a notification type (a :user-scoped Setting under Settings → Preferences). A recipient can turn their OWN copy of a type off without affecting the site toggle (setting_key/1) or anyone else; delivery honours it per recipient (default on).

Notify.user_setting_key("blog:post:published")  #=> "notify.pref.blog.post.published"