feat(cabana): mail templates screen over postcard overrides
- Settings -> Mail -> Mail templates in the internal pseudo-plugin when postcard's Mailer is published; system.manage_mail_templates and system.manage_mail_layouts registered with no role grants - MailTemplate/MailLayout models, catalog-scoped list and form, layout relation over file and custom layouts, no create or delete - save stamps is_custom, base_hash and customized_at and validates the override through postcard.Editor inside the save transaction - serve-start postcard.SyncIndex through lagoon.OnDatabase, retried on the first mail list request - copy en/pl, README and docs; TestMailScreensSmoke/templates Plan 35-02, task 1
This commit is contained in:
@@ -70,6 +70,13 @@ A controller's `pact.AdminPermissioned.RequiredPermissions` are checked before a
|
||||
|
||||
The admin registers three permissions of its own on the System tab of the permission editor: `backend.manage_users` (`cabana.PermissionManageUsers`) opens the Administrators screen, `backend.manage_roles` (`cabana.PermissionManageRoles`) the Roles screen and `backend.view_plugins` (`cabana.PermissionViewPlugins`) the read-only Plugins screen (see [Admin SPA](admin-spa.md#plugins-screen)). None is granted to any role in code, so after an upgrade only superusers reach those screens until an administrator grants a code to a role or to an administrator.
|
||||
|
||||
When the application publishes postcard's Mailer (every application does, through `party.Activate`), the admin also registers two mail codes on the same tab:
|
||||
|
||||
- `system.manage_mail_templates` (`cabana.PermissionManageMailTemplates`) opens Settings → Mail → Mail templates, where an administrator edits the subject, message and layout of every mail template, previews it and sends a test to their own address.
|
||||
- `system.manage_mail_layouts` (`cabana.PermissionManageMailLayouts`) opens the other Mail screens: layouts, partials, branding and the mail image library. These change every message the application sends, so the code is separate.
|
||||
|
||||
Neither is granted to any role in code either. An administrator holding only the templates code sees one Mail tile in Settings and is refused the other mail screens. See [Mail](../services/mail.md#editing-mail-in-the-admin).
|
||||
|
||||
An administrator's grants are the role's `permissions` merged with the administrator's own `backend_users.permissions`, the way WinterCMS merges them: the administrator's value for a code replaces the role's, and only `1` grants. A `-1` (or `0`) on the administrator therefore removes a permission the role grants, so rows copied from a WinterCMS database keep their denies. As in WinterCMS the merge compares codes exactly, so denying `acme.blog.access_posts` does not take it back from a role that grants `acme.blog.*`.
|
||||
|
||||
Actions registered through `pact.HasAdminActions`, bulk actions (`pact.HasAdminBulkActions`) and record actions (`pact.HasAdminRecordActions`) may each name extra permissions, checked on top of the controller's. An administrator who lacks them does not get the action in the list schema or in a record's `meta.actions`, and posting it answers 403 and is written to the authentication log. A bulk, record, toolbar or widget action that ran is logged with the controller, the action and the administrator, plus the affected count for a bulk action, the record id for a record action (and for a widget action posted from a saved record), and the kind `toolbar` or `field` for the other two, without record contents, posted values or payload.
|
||||
|
||||
@@ -165,6 +165,18 @@ An override cannot stop mail from going out:
|
||||
|
||||
The log lines carry the component `postcard`. In a test, pass any `postcard.OverrideSource` in `postcard.Options.Overrides` to supply overrides without a database; `postcard.NewDBSource` is the one `postcard.Activate` installs.
|
||||
|
||||
## Editing mail in the admin
|
||||
|
||||
Every application with an admin gets the mail screens in Settings → Mail, with no setup in the application or its plugins. They are served by the admin itself (cabana) over postcard's tables:
|
||||
|
||||
- **Mail templates** lists every template the application's plugins register, one row per file, so `acme.blog::mail.welcome` and `acme.blog::mail.welcome-en` are separate rows. The list shows the code, the subject, the file's description, the locale (the suffix after the last dash when it is one of the application's locales, otherwise Default) and the layout. The form edits the subject, the Markdown message and the layout, chosen from every file layout and every layout created in the admin. The description stays the file's.
|
||||
|
||||
The screen needs `system.manage_mail_templates` (see [Users and permissions](../backend/users-and-permissions.md#permissions)). Templates come from files, so the list has no create and no delete.
|
||||
|
||||
The rows exist before anyone edits a template: when the admin starts, it writes an index row for every file template, layout and partial (`postcard.SyncIndex`), and keeps a row that is not customized equal to its file. A row whose plugin is no longer installed stays in the table but is not listed. If the tables are not there yet when the admin starts, the first open of a mail list writes the rows.
|
||||
|
||||
Saving a template stores your subject, message and layout in its row and marks it customized, together with the hash of the file the change was based on. From then on your version is sent instead of the file, until the template is reset to the file version. A save is checked the way a send would render it (`postcard.Editor.Validate`): a message that does not parse, does not render with the sample values or fails the safety checks is refused with a line under the field, and nothing is stored.
|
||||
|
||||
## Drivers
|
||||
|
||||
`mail.driver` selects the driver:
|
||||
|
||||
Reference in New Issue
Block a user