MishkaCmsCore.Runtime.Resources.Validations.SiteScopedDocument (Mishka CMS Core v0.0.1)

Copy Markdown View Source

Refuses a global row about a document that cannot itself be global.

What it is for

MishkaCmsCore.Runtime.PageComment is global? true, because the builder edits documents that are global — components and layouts — as well as documents that are not. But the two global? false documents, pages and error pages, always belong to exactly one site, so a note about one has no honest reading as "belongs to no site". Left unguarded, such a row is visible to every tenant on every site, which is the opposite of what a page note means.

It was true in practice already, by accident: the builder happens to hand a master the record's own site_id. That is a LiveView doing the right thing, not a rule — and a JSON:API caller, a seed, or a future screen would not know to. This makes it a rule.

Options

  • :sections — the section values that require a site. Required.
  • :attribute — where the section is stored. Defaults to :section.

Usage

create :master_create do
  validate {SiteScopedDocument, sections: [:page, :error_page]}
end

A section not in the list is left alone: a note on a component may be global, and a tenant's note on that same component is stamped with their own site by the tenant action, not by this.