AshGrant.Validations.PermissionStrings (AshGrant v0.22.0)

Copy Markdown View Source

An Ash validation for the attribute where an application stores grants.

Runs AshGrant.PermissionValidation.check_all/2 over the value being written and adds one field error per bad string, naming the string — so an admin UI rejects a typo at the form instead of storing a grant that is inert, or that raises on the first request to reach it.

validations do
  validate {AshGrant.Validations.PermissionStrings, attribute: :permissions}
end

The value may be a list of permission strings, a single string, or nil. It is only checked when the action changes it: strings already stored are left alone, so a rename in code does not block unrelated edits to the same record. Scan stored strings with mix ash_grant.check_permissions instead.

Options

  • :attribute — required. The attribute (or action argument) holding the permission strings.
  • :otp_app / :resources — which resources to check against, as in AshGrant.PermissionValidation.check/2. With neither, every AshGrant resource in the started applications' :ash_domains is used.
  • :reject — :errors (default) rejects only issues of severity :error; :warnings rejects warnings too.