commit 860182098c184b4cd759c2650371c1fa3e2dc8db Author: deploy-bot Date: Fri Dec 4 15:10:03 2026 +0000 v0.9.0 diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..988762b --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,161 @@ +# Changelog + +Every release has a section here, named after its version (for example `v0.1.0 - 2026-12-04`, as a second-level +heading). The release pull request to `production` is stopped by PR CI when its section is missing, and the text of +the section is the text of the release in Gitea. + +## v0.9.0 - 2026-12-04 + +- The page builder, first layer: a page can hold blocks (`pages.blocks`, an ordered list of `{id, type, data, style, hidden}`). A page with a definition says `'blocks' => true` (or a list of block types); `manager.blocks.free_pages` does the same for pages without one. `Support\Blocks` knows the block types that ship (hero, page title, text, text with picture, picture, box with points, gallery, before and after, quote, numbers, tags, questions and answers, cards from a list, call to action, request form, line, space), the ones a site adds in `manager.blocks.types` or with `Blocks::register()`, and the choices of the style options (`manager.blocks.tokens`). Saving cleans every block with the fields of its type; `Blocks::for('home')` gives the public site the visible blocks in order, with the records of a list for a block that shows one (a block of a feature that is off is left out); the pages API gives the screen the blocks and the types. Design and decision: `docs/design/page-builder.md` and ADR-0012 (in the repository, not in the package). +- The page builder, editor: a page that holds blocks shows a block editor under its fixed fields: add from a catalogue grouped by kind, reorder (buttons, dragging, Alt and the arrow keys), duplicate, hide, delete, and fill in the fields and style options of a block. The simple face uses the plain names of the block types. +- The page builder, renderers: the blocks of a page are drawn by the site in one of three ways. **Inertia and Vue:** `resources/blocks/vue/` has a component per shipped block type, a `BlockRenderer` (with `components` to replace one per type), a component map and a neutral stylesheet; a site imports it with a Vite alias. **Blade:** `` with views in `resources/views/blocks/` that a site overrides by publishing (`manager-blocks`, `manager-blocks-assets`), and the `faq` block prints `FAQPage` data. **Headless:** `GET /api/manager/pages/{slug}` and `GET /api/manager/blocks/schema` under `manager.blocks.api` (off by default). `Blocks::for()` adds a safe `_html` for every Markdown field; output is escaped and addresses are checked. +- The page builder, live preview: with `manager.blocks.preview.enabled` the page editor shows the real public page next to the form, at phone, tablet or desktop width, updated as you edit and without saving. The editor posts the blocks, gets a signed address with a short-lived token (`?mb-preview=`), and `Blocks::for()` swaps in the unsaved blocks only for a person who is logged in with `pages.edit`; it works the same for Inertia, Blade and the page API. The address of a page is `manager.blocks.preview.url` (a pattern with `{slug}` or an invokable class). New right `pages.layout`: who may change the blocks of a page. A page also gets a "View the page" link. ADR-0013. +- The page builder, record context: a list can have a **page layout** (`template` in its definition, ADR-0014 in the repository): the blocks of the page of one record, edited in the manager under "Page layout" on the list (needs `.manage`) and kept in the new table `block_templates`. A text, address or list field of a block can say `{record.title}` (or any field of the list, or `{record.id}`) and is filled in with the record; a `cards` block can show only the records that belong to this one (`match_list` / `match_record`) and leaves the record itself out. `Blocks::forRecord($resource, $record)` gives the blocks, and `GET /api/manager/templates/{resource}/{id}` serves them (blocks only) to a frontend of its own. An inactive record has no page. +- The frontend is a setting: "Who shows the website" on the settings screen (`manager.frontend.mode`): the site itself (default), this manager (it draws every page with blocks at `/{slug}` as a fallback route, in `manager::public.layout`) or headless (the page API). The live preview and the page API are switches on the same screen (ADR-0015 in the repository). +- The page editor for the simple face: plainer words for every block type, a part is taken off the site and put back instead of deleted, how it looks is folded away, and a photo is chosen with the phone's own picker (several at once for a gallery, made smaller and upright in the browser) with a hint per field of the picture it needs. The tour has a step for building a page and one for photos. `docs/guide/building-pages.md` explains it for owners and for whoever sets a site up. +- A table of pages that a site already has (`manager.tables`) gets the text and the published flag it lacks, `manager:doctor` warns about rights stored in a group that no module knows (`stored_permissions`: they grant nothing), and the README explains how block style choices become the classes of the site's own CSS. + +## v0.8.0 - 2026-12-04 + +- A site that had its own manager before the package keeps its own middleware aliases (`manager.auth`, `manager.shell`, `manager.locale`): the routes of the package + use the middleware classes themselves, so the alias of the site is never taken over, and the alias is only offered when the site has none. +- The settings screen has a "Try it" button per group that makes a connection (the IriksIT API: logs in; Turnstile: asks Cloudflare whether it knows the secret key). It tries what is saved, needs `settings.secrets`, and a site adds its own with `manager.settings.checks`. +- Features of the site: `manager.features` declares switches (services, projects, reviews, requests, a contact form) that show up as toggles in a group of their own on the settings screen. One switch is followed by the manager (a `resources` entry with `'feature' => 'services'` disappears completely: menu, permissions, screens, routes) and by the public site (`Features::on()`, `Features::flags()`, the route middleware `manager.feature:services`, and `@feature('services') … @endfeature` in Blade). Off hides; the data stays and comes back when the switch goes on. +- The requests module (`leads`, off by default; with a feature `leads` in `manager.features` that one switch turns it on and off): requests of visitors (callback requests, questions, quotes, a contact form) are screened into the folders inbox, other and spam (links, words of selling to a business, text in another language, a form that was open too short, a throwaway address, the same text twice, blocked senders; nothing is ever refused, every call is kept with its reasons), stored, mailed to an address of the settings screen, and handled on a screen of their own (waiting, handled, notes, outcome, call/WhatsApp/mail buttons; whoever manages also sees the folders and the reasons, moves requests and blocks senders). The forms stay the site's own and call `Support\Leads\Intake::take()`. `manager:leads-prune` removes old requests, old spam and expired blocks. New migration: `leads` and `lead_blocks`. +- The public forms of the requests module: `POST /requests/{form}` (path and forms in `manager.leads.form`) takes a callback request, a question or a quote in with the fields each form requires (`contact` is one box for a phone number or a mail address), only the questions and moments the site offers, a honeypot, the signed moment of the form, Turnstile when its keys are set and a limit per address and for everyone together. A visitor always gets the normal thank-you, whatever the screening thinks. `GET /requests/token` gives the signed moment to a form built by script. Where a visit came from comes from the statistics module by itself. +- The requests module gets a report for whoever manages it (the last 90 days: requests, ways in, pages, sources, subjects, how many became a job, how much the screening kept away), counting of taps on the phone number and the WhatsApp button (`POST /requests/tap`, a counter per day and page, nothing else; new migration `lead_taps`), and `manager:import leads|taps` for a site that had its own. +- Richer fields for pages and `manager.resources`: `slug` (an address part, made of the field named in `from` when left empty), `list` (a list of short texts, one per line), `media_list` (a gallery from the media library), `repeater` (a list of items with fields of their own, for example questions and answers), and a `select` that takes its choices from the rows of a table of the site (`source` => model, label, value). With these a site can describe services, projects and reviews without code, on its own models and tables. +- A site that already has tables for the same job (groups, pages, leads…) can keep them: point `manager.tables` at them and the migrations of the package skip a table that exists and only add a column it lacks (`groups.start`, `group_user.is_primary`, `pages.meta_description`, `pages.content`). The rows stay where they are. +- `manager:doctor` checks the columns of the tables of every active module, so a table of the site that the package adopted and that lacks a column the package writes is reported (`columns`) instead of failing at the first save. `Support\Tables::COLUMNS` lists them, and a test keeps that list equal to what the migrations make. +- The rights a site stored for its groups keep working after the package takes over: the names follow `.` and `.view`/`.manage`, and a stored `.manage` also lets the account see the list. Written down in the README ("A site with data and names of its own") and kept by a test. +- Ready-made lists for `manager.resources`: `Support\Presets::services()`, `projects()`, `testimonials()`, `menu()` and `socials()` (a service with a page, photos, points and questions; a project with a town, year and photos; a review; a menu; social links). A site points `model` at its own table or keeps the records in the package, sets a `feature`, and overrides single fields. +- A table of requests that a site already has can be adopted: a migration adds `subject` and `subject_id` to it and, when it has `service_id`, gives that id to `subject_id`. The revisions table of a site is not adopted (the package makes its own; the history of the site stays in its old table). +- `Support\Presets::business()`: the page of business details (name, owner, phone, WhatsApp, address, registration numbers, opening hours, towns) for `manager.pages.definitions`, so every site enters them once and reads them with `Page::contentFor('business')`. +- The updates module (`updates`, off by default, right `updates.view`): a screen with the releases of the CHANGELOG.md of the site, newest first, with or without a heading per kind of change. `manager.updates.changelog` points at another file and `limit` says how many releases show. No tables. +- A contact message with a subject is a request too: the form `contact` (kind `message`, `POST /requests/contact`) requires name, mail address, subject and message, and a form may now list `subject` in `require`. `Support\Presets::experience()` is the list of work and projects for a CV (title, role, period, story, points, links, technology). +- The sharing module (`sharing`, off by default, needs `posts`): connect the owner's LinkedIn account (OAuth with a session state and PKCE, tokens stored encrypted) and share a published post with the button "Share now" on its screen. Until the setting "Post for real" is on, a share is a dry run and nothing is sent. A site adds other networks with a class that implements `Contracts\Sharer`. Rights `sharing.view`, `sharing.publish` and `sharing.manage`; new migration: `social_connections` and `post_shares`. The two steps of a connection (route names `*.connect` and `*.callback`) are left alone by the screens, like downloads. +- The simple face has words of its own: a field, a resource and a defined page take `'simple' => [...]` (`label` and `help` for a field, `label` and `singular` for a resource and its menu item, `title` for a page), shown to accounts in the simple face while the full face keeps the usual words. The presets (services, projects, reviews, menu, social links, business details) bring plain-language words for it. +- Screens for the owner of a business: the module `numbers` (off by default, needs `statistics`, right `numbers.view`) shows how the site is doing in plain words: visitors against the period before, requests and what became of them, taps on the call and WhatsApp buttons, pages, how people found the site and the most read articles, over 7 days, 30 days or a year. +- The module `costs` (off by default, right `costs.view`, new migration `work_costs`) shows what the work on the site cost, from the table of its `TOKENS.md`: tokens in euros per piece of work and per release, hours at an hourly rate, hosting and a discount. A row is priced once and kept: by an invokable class of the site (`manager.costs.pricer`), else by the IriksIT API (`Support\IriksStorage\Client::tokenCosts()`, the account of `manager.media.iriksit`, permission `ai.pricing`), else by the fixed `manager.costs.rates`. `manager:costs-price` prices what is new. +- The simple start screen says what waits: a line under the button of the requests, the posts and the numbers (`Support\Tiles`), a badge with the new requests, a "Need help?" button (`manager.simple.help`) and a "View the site" button (`manager.simple.site_link`). + +## v0.7.0 - 2026-12-04 + +- Per account a primary group (and any number of secondary ones): the primary group is the label of the account and sets its start screen; what the + account may do stays the sum of all its groups. A group can name a start screen. New migration: `is_primary` on the group-user table and `start` on groups. +- The settings screen (module `settings`, whole face only): switch parts of the manager and features of the site on or off and set the keys and addresses of + integrations (the IriksIT API, Turnstile) from the manager, with the rights `settings.manage` and `settings.secrets`. Works at once (database plus one compiled + file laid over the config, also with `config:cache`), optionally written into `.env` too (`manager.settings.write_env`). Sites add their own with + `manager.settings.definitions`. New migration: `settings`. +- More commands: `manager:settings` (list, get, set, reset, refresh; secrets are typed hidden), `manager:users`, `manager:user-password`, `manager:media-prune` + (unused media, or files no row knows; nothing is deleted without `--delete`) and `manager:import media` (the rows of a site's own media table, with `--set` for a value every row gets). +- `php artisan manager:media-move `: moves the files of the media library to another disk (for example to `iriksit`), keeping their addresses, with `--dry-run`, `--from`, `--limit`, `--verify` and `--delete-source`. Safe to run again. +- The disk `iriksit`: media files at the IriksIT API (`MANAGER_MEDIA_DISK=iriksit`, `manager.media.iriksit`), with a table that remembers which + path is which id (new migration `storage_files`) and `php artisan manager:storage-check` to try it. New requirement: `league/flysystem`. + +## v0.6.0 - 2026-12-04 + +- Per account: the face of the manager (the whole one or the simple one) is stored on the account and wins over what its rights give; an administrator sets it + on the accounts screen, an account with `manager.switch` (or `manager.full`) sets it itself. The language (Dutch or English) is a choice in the profile + and applies on the server too, inside the manager only. New migration: `locale` and `tutorial` on the user settings. +- The tour: an administrator switches it on for an account (accounts screen); the account gets it at its next load, and finishing or skipping it is stored + (`PUT /manager/profile/tutorial`), so it does not come back until it is switched on again. +- The simple face, made usable: posts, pages, media and the lists of `manager.resources` are marked `simple` by default (so with `simple_view` on, a simple + account has something to work with), menu items and lists take a `hint` (a line of explanation), a field takes `advanced` (left out of the simple face) + and `help` (shown under the field). The simple face has a start page of big buttons with a line of explanation, and bigger type and calmer spacing everywhere. +- The tour: a playful walk through the manager with a mascot (a card beside what it points at, steps for exactly what this account sees, Back/Next, dots). + It can be stopped at any moment (the cross, Escape or the link) and that is remembered per account, whether it was finished or not; it comes back only when + an administrator switches it on again, and an account that has had it can start it again ("Show the tour", in the menu and the profile). The pictures are + `resources/mascot/.webp|png` (or a folder of the site: `manager.mascot.path`); a picture that is missing is a paw. A module adds steps with `tutorial()`. + +## v0.5.2 - 2026-12-04 + +- The mirror for Packagist gets a clean tree per release (no tests, `ui/`, `dev/`, `TOKENS.md`, `.gitea/` or agent files), with no history and no + branch, so `composer require` installs less and this repository can be private. `mirror_tags.sh`, with tests; `out/` is export-ignored too. + +## v0.5.1 - 2026-12-04 + +- Packagist shows only the releases: the Release workflow pushes the tags to a mirror (`iriks-it/laravel-manager-packagist`) that has only a `production` branch with a note (no `composer.json`, so no version), + and Packagist reads that, so the `dev-…` versions of every branch are gone. + +## v0.5.0 - 2026-12-04 + +- Names that can move: `route_name` for the route-name prefix, `tables` for a table of its own per short name (on top of `table_prefix`), + `IriksIT\Manager\Support\Names` to ask for either. The defaults are the names of every earlier version. +- `manager:import posts|pages|reviews` copies the rows of a table of the site into the package (read-only on the source, repeatable, + `--dry-run`, column mapping). +- Server texts are translatable: menu, permission labels and sections, theme names, audit summaries and the main messages go through `__()`, + and the package ships `resources/lang/nl.json`. A site's own `lang/.json` wins. +- Fix: the audit log and the bot counter strip the configured route-name prefix, not a fixed `manager.`. +- Menu: sections, icons and order, changeable from `manager.menu` (items and links of the site's own). The old item shape stays valid. +- Simple view (`simple_view`, off by default): permissions `manager.full` and `manager.switch`, a remembered choice per account (new migration + adds `view` to the user settings) and a switch in the menu. +- Pages with fields: definitions in `manager.pages.definitions` (types text, textarea, markdown, lines, media, url, number, date, toggle, + select), `Page::contentFor($slug)` for the public site, and screens to edit them and to make free pages (new migration: `meta_description` + and `content` on the pages table). The field definitions (`Support\Fields`) and the form component are shared with what comes next. +- Lists without code: `manager.resources` makes a menu item, list, form, validation and permissions (`.view`, `.manage`) from field + definitions, kept in a model of the site or in the new `manager_records` table (new module `resources`, on by default, nothing registered + without definitions). +- Screens of the site's own: `manager.extensions` loads JavaScript modules next to the manager; `window.IriksManager` offers `register`, `api`, + `Vue` and the shared components, and `resources/dist/vue.js` maps `import 'vue'` to the Vue of the screens. A browser that opens a manager + address without a route of the package gets the screens (an HTML request only). +- History: a new module `revisions` (on by default, `MANAGER_REVISIONS`) keeps the state of every saved post and page with who and what changed, + shows it on the screens and puts an earlier state back (`revisions.view`, `revisions.restore`; new table `manager_revisions`). More models can + join with `manager.revisions.types`. +- Editor: Markdown fields get a toolbar, photos from the media library and a server-rendered preview (`POST /manager/markdown`); the media + library gets a click-to-set focus point with a square preview. (No cropping or rotating: the file stays as uploaded.) +- Statistics: `` puts the counting script (`/pulse/pulse.js`, no cookies, honours Do Not Track) in the public pages of a site. +- Login checks: `manager.login.checks` (contract `LoginCheck`, base class `BaseLoginCheck`) adds fields and checks before and after the password; + Cloudflare Turnstile is built in (two env keys). No two-factor login in the package itself. +- Roles of the host: `manager.permissions` (`mode` groups/host/merge, `roles` map or a `resolver` implementing `PermissionResolver`) lets a site + with its own roles say what an account may do; groups stay the default. +- CI: nothing runs weekly any more, and Trivy no longer runs in the jobs (the runner disk filled up with its database). `composer audit` stays in every + pull request and every release; Trivy scans production from the homelab, every night and after every release. The nightly dependency round of the + homelab replaces the weekly *Dependency updates* workflow (and `update_dependencies.py`); its `renovate/*` pull requests may go to `production` and + become a patch release of their own (one a night at most, none while a release branch is open). +- `manager:doctor` has a `names` check: it warns when the site uses a route name or an address of the manager and says to set `route_name` or `path`. + +## v0.4.0 - 2026-12-04 + +- Screens in the package: a small Vue app on the JSON routes, built and served by the package (a site needs no Node). Login, logout and + profile for an app that has none, a dashboard and menu, and screens for accounts, groups, media (with a picker for covers), posts, + categories and tags, the audit log with bans, and statistics. Pages and reviews show a read-only list. `MANAGER_UI=none` keeps only the + JSON routes. The default middleware is now `['web', 'manager.auth']` (a published config that still says `auth` keeps working). +- Themes: `dark` and `light`, your own as a JSON file (`php artisan manager:make-theme`) or in the config, chosen per account in the + profile (new table `manager_user_settings`; `MANAGER_THEME`, `MANAGER_USER_THEMES`). Every value is checked before it reaches a page. +- For AI agents: `php artisan manager:install` (no questions), `php artisan manager:doctor --json` (checks the setup, says how to fix + it, non-zero exit on failure), a step-by-step guide (`resources/ai/INTEGRATION.md`) and a Laravel Boost guideline. Modules report + their tables with `tables()`. +- PR CI: a job that type-checks and builds the screens and fails when the committed `resources/dist` is out of date. + +## v0.3.0 - 2026-12-04 + +- The Packagist step submits the package itself when Packagist does not know it yet (the update call answered 404), instead + of failing until someone submits it by hand. + +## v0.2.0 - 2026-12-04 + +- CI: the composer cache and three tries for the install in every job, so a hiccup of a download no longer breaks a run. +- Audit log (module `audit`, off by default): logins and failed logins, changes, opened pages and refusals, with the + address and the browser. Modules name their routes with the new `actions()` and `views()`. +- Address bans: by hand, for a group of addresses, or by itself after too many failed logins; optionally for the + whole app. `manager:unban` and `manager:audit-prune`. +- Statistics (module `statistics`, off by default): page views and time on a page without cookies or stored addresses, sources, + devices, programs, comparisons and CSV export. Which pages count is up to the site. +- Breaking for a module that implements `Contract\Module` without extending `BaseModule`: the contract gained + `actions()`, `views()` and `middleware()`. +- Weekly workflow *Dependency updates*: widens the version constraints in `composer.json` for a new release of a dependency, as a pull request to the open release branch. +- `dev/token-usage-hermes.py`: the same rows per model for work done by a Hermes agent; the token script also counts the advisor. +- `CLAUDE.md` and the rules shared with the other IriksIT repos in `AGENTS.md`. + +## v0.1.0 - 2026-12-04 + +First version. + +- The module registry, with a switch per part of the manager. A part that is off has no routes, tables, menu + item or permissions. +- Users: accounts, groups and permissions (a permission can need another), and `manager:create-user`. +- Media: the library on a Laravel disk and the public file route `/media-files/{id}/{name}/view`. +- Posts: drafts, scheduling, Markdown, categories and tags. +- MIT license; the development cycle with release branches, tags and Packagist, and CI with tests, `composer audit` + and Trivy. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3dbecaf --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Iriks IT + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..f6be78b --- /dev/null +++ b/README.md @@ -0,0 +1,441 @@ +# iriks-it/laravel-manager + +A modular backend for Laravel sites. Install it, switch on the parts the site needs, done. + +```bash +composer require iriks-it/laravel-manager +php artisan vendor:publish --tag=manager-config +php artisan migrate +``` + +Put `IriksIT\Manager\Concerns\HasManagerAccess` on the `User` model. The manager lives at `/manager` +(`MANAGER_PATH`) behind the `web` and `auth` middleware (`config/manager.php`). + +## Set up with an AI agent + +```bash +php artisan manager:install --modules=users,media,posts --user-model="App\Models\User" +php artisan manager:doctor --json # non-zero exit when something is wrong; each problem has a `fix` +``` + +`resources/ai/INTEGRATION.md` is a step-by-step guide for an agent; `resources/boost/guidelines/core.blade.php` +is picked up by Laravel Boost. + +## Screens and themes + +The package brings its own screens (a small Vue app on the JSON routes, already built: your app needs no Node). They also +give an app without a login a login and a profile. `MANAGER_UI=none` turns them off, for an app that builds its own screens +on the JSON routes. A browser that opens a manager address gets the page; anything that asks for JSON gets the data. + +- **Looks.** Built in are `dark` and `light`. `MANAGER_THEME` is what everyone sees until they choose; with + `MANAGER_USER_THEMES=true` (default) each account picks its own in its profile. +- **The house style of the site.** `php artisan manager:make-theme acme --brand=#e4002b --name="Acme" --logo=/img/logo.svg --font="Inter, sans-serif"` + writes `resources/manager-themes/acme.json`; set `MANAGER_THEME=acme`. A theme is colours, a radius, fonts, a name and a logo, and every + value is checked, so a theme file can never put CSS or markup in the page. Themes can also be listed in `manager.themes`. +- **Not built yet:** a theme editor in the manager (themes are files for now), and screens for modules your own site adds (they show a notice). +- **Working on the screens:** the sources are in `ui/`; `npm ci && npm run build` there writes `resources/dist`, which is committed + (PR CI fails when it is out of date). + +## Modules + +| Key | What | Default | +|---|---|---| +| `users` | Accounts, groups and permissions | on | +| `media` | Media library | on | +| `pages` | Page texts | on | +| `posts` | Posts | on | +| `reviews` | Reviews | off | +| `audit` | Audit log and address bans | off | +| `statistics` | Visitor statistics | off | +| `resources` | Lists defined in config (`manager.resources`) | on (nothing without definitions) | +| `revisions` | History of posts and pages, with restore | on | +| `sharing` | Share a published post on LinkedIn with one button (`manager.sharing`); a site adds other networks with a `Sharer` class. Rights `sharing.view`, `sharing.publish`, `sharing.manage` | off | +| `updates` | What changed on the site: the releases of its `CHANGELOG.md` (`manager.updates`), right `updates.view` | off | + +Switch a part in `config/manager.php` (`modules`) or with `MANAGER_PAGES`, `MANAGER_POSTS`, +`MANAGER_REVIEWS`, `MANAGER_AUDIT`, `MANAGER_STATISTICS`, `MANAGER_REVISIONS`, `MANAGER_UPDATES`, `MANAGER_SHARING`. A module that is off has **no routes, no tables, no menu item and no permissions**: +| `costs` | What the work on the site cost, from its `TOKENS.md`, priced once and kept (`manager.costs`), right `costs.view` | off | +| `numbers` | How the site is doing in plain words for an owner (needs `statistics`; uses `leads` when on), right `numbers.view` | off | +| `updates` | What changed on the site: the releases of its `CHANGELOG.md` (`manager.updates`), right `updates.view` | off | + +Switch a part in `config/manager.php` (`modules`) or with `MANAGER_PAGES`, `MANAGER_POSTS`, +`MANAGER_REVIEWS`, `MANAGER_AUDIT`, `MANAGER_STATISTICS`, `MANAGER_REVISIONS`, `MANAGER_UPDATES`, `MANAGER_COSTS`, `MANAGER_NUMBERS`. A module that is off has **no routes, no tables, no menu item and no permissions**: +its migrations are not loaded at all. A module that needs another one (`requires()`) fails at boot when +that one is off. + +## Language + +The texts the server makes (menu, permission and section labels, theme names, audit summaries and the messages of the JSON routes) go through Laravel's `__()` with the English text as the key. The package ships `resources/lang/nl.json`; the screens follow `app()->getLocale()`. A site translates more, or words things differently, with its own `lang/.json`: that file wins over the package. Audit lines are written in the language of the request that made them. + +## The menu and the simple view + +A module's menu item is `['label' =>, 'route' =>, 'permission' =>]` and may add `section` (a heading), `icon` (`home`, `file`, `image`, `users`, `group`, `chart`, `shield`, `star`, `tag`, `link`, `cog`), `order` (lower first, default 100), `simple` and `new_tab`. A site changes the menu without code in `config/manager.php`: `menu.items` by route name without the prefix (`'posts.index' => ['order' => 10, 'section' => 'Content', 'hidden' => false]`) and `menu.links` for items of its own (`['label' => 'Leads', 'url' => '/manager/leads', 'permission' => null]`). + +`simple_view` (`MANAGER_SIMPLE_VIEW=true`) adds a simple face next to the full one, for an owner who only needs a few screens. Two permissions appear in the group form: `manager.full` (everything; super admins have it) and `manager.switch` (starts simple and may switch; the choice is remembered per account and the menu has a button for it). Every other account always gets the simple face: only the items marked `simple`. It limits the menu, not the access: the routes still check their own permissions. Turning it on makes accounts without `manager.full` or `manager.switch` see only the simple items, so give the groups what they need first. + +## Your own lists and screens + +**Lists without code.** `manager.resources` turns a definition into a menu item, a list, a form, validation and the permissions `.view` and `.manage`, for things like a menu, socials, services, testimonials or leads: + +```php +'resources' => [ + 'services' => [ + 'label' => 'Services', 'singular' => 'Service', + 'model' => App\Models\Service::class, // the records live in a model of the site; leave it out to use the package's own table + 'columns' => ['name', 'price'], 'order' => ['position', 'asc'], + 'fields' => ['name' => ['type' => 'text', 'required' => true], 'price' => ['type' => 'number'], 'photo' => ['type' => 'media']], + ], +], +``` + +**Ready-made lists.** `IriksIT\Manager\Support\Presets` has definitions for what a business site nearly always has: `services()`, `projects()`, `testimonials()`, `menu()` and `socials()`. Their field keys are the usual column names (`title`, `summary`, `is_active`, `sort_order`), so a site points `model` at its own table, or leaves it out to keep the records in the package's table. What the site passes wins, field by field: `'services' => Presets::services(['model' => Service::class, 'feature' => 'services', 'fields' => ['title' => ['label' => 'Name']]])`. `Presets::projects($override, serviceModel: Service::class)` adds the choice of a kind of work. `Presets::experience()` is work and projects for a CV (title, role, period, story, points, links, technology; `type` is `work` or `project` and the site may add kinds). `Presets::business()` is the page of business details (name, phone, address, registration numbers, opening hours, work area) for `manager.pages.definitions['business']`; read it with `Page::contentFor('business')`. + +The field keys are the attributes of the model (the definition is the whitelist: nothing else is written); without a model the values are kept as JSON in `manager_records`. Field types are the ones of the pages. Names that belong to a module (`posts`, `pages`, `media`, ...) are refused. + +**Screens of your own.** List a JavaScript module in `manager.extensions` (a path of your site, or https). The manager loads it before it shows anything and puts `window.IriksManager` in reach: `Vue`, `boot`, `api`, `t`, `flash`, `navigate`, `register` and the components `Link`, `FormFields`, `Icon` and `MediaPicker`. `register('^/leads$', Component, { data: true })` shows `Component` at `/manager/leads`, with the JSON of that same address (or of `source`) as props; an address of yours needs a route for the data, and a menu item through `manager.menu.links`. Build your bundle with `vue` left external (`build.rollupOptions.external: ['vue']`): the manager points `import 'vue'` at its own Vue, so your components share its reactivity. A browser that opens a manager address without a route of the package gets the screens (which show yours, or "no screen yet"); a request for data gets a plain 404. + +## A site with data and names of its own + +The package never maps its queries onto other columns: every screen assumes its own columns. What it does give you is room to coexist, a way to take over the tables of a site that had a manager before, and a way to move data in. + +- `route_name` (default `manager`): the prefix of the route names. A site that already has `manager.*` routes sets, for example, `'route_name' => 'cms'`; the menu and the screens follow. Use `IriksIT\Manager\Support\Names::route('posts.index')` in code of your own. +- `table_prefix` (default `manager_`) and `tables` (`['media' => 'site_files']`): the names of the tables. Set them before the first `migrate`; the package does not rename a table that exists. +- Taking over the manager of a site: point `tables` at the tables the site already has (`['groups' => 'groups', 'group_user' => 'group_user', 'pages' => 'pages']`). A migration of the package skips a table that exists and adds only a column it lacks, so rows stay where they are; `php artisan manager:doctor` lists columns that are still missing (`columns`). The names of the rights stay as they were when they follow `.` (`posts.write`, `pages.edit`, `leads.handle`) and, for a list of your own (`manager.resources`), `.view` and `.manage`: a group stored with only `services.manage` may also see the list, because the package adds what a right needs when it checks. +- `php artisan manager:import posts --table=articles --map=title=headline --map=body=content [--dry-run] [--connection=...] [--limit=...]` copies the rows of a table of the site into `posts`, `pages` or `reviews`. The source is only read, and running it again updates the rows it made (found by slug, or by author and text for reviews). `--map` is `package_column=source_column`. Put the settings in `manager.import.` (`table`, `connection`, `map`) to run it without options. Tags may be JSON or a comma separated list; a row without the required text is skipped and reported. + +## Your own module + +Implement `IriksIT\Manager\Contracts\Module` (or extend `Modules\BaseModule`), keep `routes.php` and a +`migrations/` folder next to the class, and add the class to `available` in the config. + +## Users module + +Accounts and groups. `HasManagerAccess` on the host `User` model gives it `managerGroups()`, +`managerPermissions()`, `hasManagerPermission()`, `managerOutranks()` and `managerMayGive()`. +Keep `is_super_admin` out of `$fillable`: nobody becomes a super admin through a form. + +```bash +php artisan manager:create-user # the only way to make a super admin +``` + +- A group is a name plus permissions; a permission that needs another one (`posts.publish` needs + `posts.write`) brings it along. Permissions of a module that is off are ignored. +- Whoever manages accounts only touches accounts that need nothing more than their own rights, and + only hands out groups that give nothing they lack themselves. +- `groups.manage` is a gate for super admins only, not a permission of a group. +- The package defines one gate per permission and **no `Gate::before`**: it never answers for the + abilities of your own app. +- **A site with roles of its own** (decided in 0.5.0: groups stay the default, the site's roles are added next to them). + `manager.permissions.mode` is `groups` (default), `host` (the groups are ignored) or `merge` (both). The site says what a role may do + with `roles` (`['editor' => ['posts.view', 'posts.write'], 'owner' => ['*']]`, read from the attribute `role_attribute`: a string, a + list or a relation with a `name`) or with a `resolver` class that implements `IriksIT\Manager\Contracts\PermissionResolver`. Values + that are no permission of an active module are ignored and what a permission needs is added. A super admin may always do everything. + The group screens still work in `host` mode but give nothing. +- The migration adds `is_super_admin` to your users table (the table of `manager.user_model`). It + promotes nobody. + +## Checks on the login + +The login of the screens can ask for more. Write a class that extends `IriksIT\Manager\Support\Login\BaseLoginCheck` (the contract is `IriksIT\Manager\Contracts\LoginCheck`) and list it in `manager.login.checks`: + +- `fields()`: extra inputs on the form (`['name' => 'code', 'type' => 'text', 'label' => 'Code', 'autocomplete' => 'one-time-code']`); +- `before($request)`: runs before the password is looked at: a captcha; +- `after($request, $user)`: runs when the email and password are right and before anyone is logged in: a second factor. Refuse by throwing a `ValidationException`; the attempt then counts as a failed login, so the audit log and the bans see it. + +**Cloudflare Turnstile** is built in: set `MANAGER_TURNSTILE_SITE_KEY` and `MANAGER_TURNSTILE_SECRET` and the widget appears and is checked (a token that cannot be checked refuses the login). The widget loads a script from `challenges.cloudflare.com`; a strict Content-Security-Policy has to allow it. **There is no two-factor login in the package itself**: `after()` is the place for it, the code to make and keep the secrets is the site's. These checks belong to the login of the screens (`MANAGER_UI=package`); an app with its own login keeps its own. + +## Media module + +Files live on a Laravel filesystem disk (`manager.media.disk`); each row remembers its own disk. + +- Manager (behind `manager.middleware`): `GET /manager/media`, `/manager/media/items`, `POST`, + `PUT /{id}`, `DELETE /{id}`. Limits (total room, file size, extensions) are in `manager.media.*`. +- Visitors: `GET /media-files/{id}/{filename}/view`, outside the manager, no session. ETag, byte + ranges, `nosniff`, and only images, video and PDF are shown inline. Rate limiter `media-files`. +- Where a file is used: other modules or your app register a source with + `app(IriksIT\Manager\Support\MediaUsage::class)->register(fn () => $texts)`. Posts and Pages do. +- No SVG: it can carry scripts. +- **Files at the IriksIT API** (the disk `iriksit`): set `MANAGER_MEDIA_DISK=iriksit` and `MANAGER_IRIKSIT_URL` (the address of the + API with its version, for example `https://api.iriks-it.nl/v1`), `MANAGER_IRIKSIT_EMAIL` and `MANAGER_IRIKSIT_PASSWORD`. The account needs + the permissions `storage.read` and `storage.write`. Run the migrations (table `storage_files`), then `php artisan manager:storage-check` + writes, reads and deletes a test file and says what fails. The API keeps a file under an id of its own; the table remembers + which path of the disk is which id, and a location without a slash that is not in the table is taken for an id (a row of a site's older code + keeps working). Tokens are kept encrypted in the cache of the app. There are no folders and no listing on this disk. + +## Commands + +| Command | What it does | +|---|---| +| `manager:install`, `manager:doctor [--json]` | Set the manager up, and check that it is wired in (for people and agents). | +| `manager:create-user` | A super admin. | +| `manager:users [--json]` | The accounts with their groups. | +| `manager:user-password [--generate]` | A new password for an account (typed hidden, never an argument). | +| `manager:settings list|get|set|reset|refresh` | The settings screen in the terminal; a secret is typed hidden or read from `--stdin`. | +| `manager:import posts|pages|reviews|media` | Copy the rows of a site's own table (`--map`, `--set=disk=iriksit`, `--dry-run`). | +| `manager:storage-check [--disk]` | Write, read and delete a test file on the disk of the media library. | +| `manager:media-move ` | Move the library to another disk, keeping every address (`--dry-run`, `--verify`, `--delete-source`). | +| `manager:media-prune` | List media nothing uses any more (`--older-than`), or files no row knows (`--orphans`); `--delete` removes. | +| `manager:audit-prune`, `manager:unban`, `manager:make-theme` | Housekeeping of the audit log, bans and themes. | + +## Field types + +`text`, `textarea`, `markdown`, `lines`, `media`, `url`, `number`, `date`, `toggle`, `select`, and for richer records: `slug` (`'from' => 'title'` fills it when empty), `list` (an array of short texts), +`media_list` (a gallery), `repeater` (`'items' => ['question' => ['type' => 'text'], 'answer' => ['type' => 'textarea']]`, an array of items) and a `select` with `'source' => ['model' => Service::class, 'label' => 'title', 'value' => 'id']`. +**Words for the simple face.** A field, a resource and a defined page can have words of their own for the simple face of the manager, for someone who is not a webmaster: `'phone' => ['label' => 'Phone number', 'help' => 'Shown on every page.', 'simple' => ['label' => 'Your phone number', 'help' => 'As you want people to read it.']]`; on a resource `'simple' => ['label' => 'What customers say', 'singular' => 'Customer review']` (also the menu item), on a page `'simple' => ['title' => 'About your business']`. A part left out falls back to the usual one, and the full face always shows the usual words. The presets (`Support\Presets`) bring plain-language words, which a site overrides like any other field. + +Used by pages and by `manager.resources`; a resource with a `model` writes straight into the site's own table (give JSON columns an `array` cast). + +## Features of the site + +A site that lists parts of itself that its owner may want to switch off (services, projects, reviews, requests, a contact form) declares them once: + +```php +'features' => ['services' => ['label' => 'Services', 'hint' => 'What you offer', 'enabled' => true, 'env' => 'SITE_SERVICES']], +'resources' => ['services' => ['feature' => 'services', 'label' => 'Services', 'fields' => [...]]], +``` + +Each feature is a toggle on the settings screen (group "Features of the site"). While it is off, the manager has no menu item, permission, screen or route for a resource with that +`feature`, and the public site follows the same switch: `Features::on('services')`, `Route::get(...)->middleware('manager.feature:services')` (a 404 while off), +`@feature('services') ... @endfeature` in Blade and `Features::flags()` to hand all of them to a page (links, sitemap, structured data). Off hides and never deletes: the data stays and comes back when the switch goes on. + +## Screens for the owner (`numbers`, `costs`, the simple start screen) + +For someone who owns the business and does not build sites. They show up as big buttons on the simple start screen (`manager.simple_view`). + +- **`numbers`** (needs `statistics`): visitors, the contact buttons, requests (when `leads` is on and the account has `leads.view`), pages, how people found the site, in plain words, with three periods to choose from. Right `numbers.view`. +- **`costs`**: the table of the site's `TOKENS.md` with the tokens of each piece of work in euros, per release, next to hours at an hourly rate, hosting and a discount (`manager.costs`). Right `costs.view`. A row is priced once and the price is kept in `work_costs`, by a pricer of the site (`manager.costs.pricer`, an invokable class), else by the IriksIT API with the account of `manager.media.iriksit` (needs `ai.pricing`), else by the fixed `manager.costs.rates`. `php artisan manager:costs-price` prices what is new, for example after a deploy. A site with no `TOKENS.md` shows an empty screen. +- **The start screen** says more than a fixed line under a button: how many requests wait (and how many are new, as a badge on the button), how many posts wait, how many visitors came this week. `manager.simple.help` (`name`, `link`) adds a "Need help?" button, and `manager.simple.site_link` a "View the site" button. + +## Requests module (`leads`) + +A request of a visitor (a callback request, a question, a quote, a contact form) is stored, screened and shown on the screen **Requests**. The forms are the site's own (their +fields, words and thank-you page); a form validates what it got and then calls the package: + +```php +use IriksIT\Manager\Support\Leads\Intake; + +// in the form: , and a honeypot field the visitor never sees +$lead = app(Intake::class)->take( + ['kind' => 'question', 'name' => $name, 'phone' => $phone, 'email' => $email, 'message' => $message, 'about' => 'job', 'subject' => 'Roofing', 'page' => $path], + Intake::secondsOpen($request->string('form_token')->toString()), // how long the form was open, null when the token says nothing + (string) $request->ip(), + (string) $request->userAgent(), +); +// always show the normal thank-you, whatever folder it landed in +``` + +- **Screening** puts a request in the inbox, "other" (acquisition, or the visitor ticked "something else") or spam, with the reasons kept next to it. Nothing is refused; one signal alone + is rarely enough. The rules and thresholds are `manager.leads` (`acquisition_words`, `throwaway_domains`, `spam_from`, `other_from`, `min_seconds`, `language`). +- **Forms without code:** `POST /requests/{form}` (`manager.leads.form`) takes the request in: a form is a name with the kind it makes and the fields it requires (`name`, `phone`, `email`, `contact` for one + box that takes either, `message`, `location`); `questions` and `moments` are what a visitor may tap. A honeypot field (`website`), the signed `form_token` (`Intake::formToken()`, or `GET /requests/token`), + Turnstile (when its keys are set; send its token as `turnstile`) and a limit per address and for all addresses (`per_hour`, `per_hour_all`) keep programs out. JSON gets `201 {ok: true}`, a form in a page is + redirected to `thanks` (or back). Name your own: `'terugbellen' => ['kind' => 'callback', 'require' => ['name', 'phone']]`. +- **Told:** a real request is mailed to `manager.leads.notify` (a setting) with call, WhatsApp and mail buttons; the visitor is the Reply-To. A confirmation to the visitor is `manager.leads.confirm`. + Replace the mail views by putting your own in `resources/views/vendor/manager/mail/`. +- **Report and taps:** whoever has `leads.manage` sees what it brought in on the screen. A page counts a press on the number or the WhatsApp button with `POST /requests/tap` (`kind` call or whatsapp, `path`). + A site with its own table moves it over with `php artisan manager:import leads --table=...` and `manager:import taps --table=...`. A contact form with a subject is the form `contact` (`kind` `message`; name, mail address, subject and message are required): `POST /requests/contact`. Contact messages a site stored in a table of its own come over with `manager:import leads --table=contact_messages --set=kind=message --map=opened_at=read_at`. +- **Permissions:** `leads.view`, `leads.handle`, `leads.manage` (folders, reasons, blocking), `leads.delete`. +- **Kept:** `php artisan manager:leads-prune` (schedule it daily) removes requests after `keep_days`, spam after `keep_spam_days` and expired blocks, and never a request with the outcome "won". +- With a feature `leads` in `manager.features` the module follows that one switch instead of `manager.modules.leads`. + +## Sharing module (`sharing`) + +Connects the owner's account of a social network (OAuth) and posts a published post there with the button **Share now** on the screen of the post. Off by default; it needs the posts module. + +- **LinkedIn** comes with the package. Create an app at LinkedIn with the products "Share on LinkedIn" and "Sign In with LinkedIn using OpenID Connect", put the address shown on the Sharing screen ("Return address for the app") in the app's redirect addresses, and fill in the client id and client secret on the settings screen (group "Sharing"; the secret is never shown again). Then press **Connect** under Sharing. +- `manager.sharing.post_url` says where a post lives (`https://example.test/blog/{slug}`); the shared address gets `?via=linkedin`, so the statistics know where a reader came from. +- **Dry run**: until the setting "Post for real" (`manager.sharing.live`) is on, a share is only written down (marked "dry run") and nothing is sent. Keep it off on a test site. +- A site adds a network by writing a class that implements `IriksIT\Manager\Contracts\Sharer` and listing it: `'platforms' => ['linkedin' => LinkedInSharer::class, 'mastodon' => App\Sharing\MastodonSharer::class]`. +- Tokens are stored encrypted and never leave the server; the connect step checks a session state and uses a PKCE verifier; what a platform says in an error is shown, a token never. +- Not in the package: planning a share for later, X, Facebook and Instagram, and fetching recommendations from LinkedIn (see ADR-0010 in the repository). + +## Pages of blocks + +A page can be built from blocks (hero, text with a picture, cards from a list, questions and answers, …): give a page definition +`'blocks' => true` (or a list of block types) and read the blocks with `Blocks::for('home')`. Add your own types in `manager.blocks.types`. How they are drawn is your choice: + +- **Inertia + Vue:** pass `Blocks::for('home')` to the page and draw it with `BlockRenderer` from `resources/blocks/vue/` (import it with a Vite alias to `vendor/iriks-it/laravel-manager/resources/blocks`; pass your own components with `:components`). A component of your own must declare a `style` prop. +- **Blade:** ``; change a view by putting the same file in `resources/views/blocks/` or publish them all with `php artisan vendor:publish --tag=manager-blocks`. +- **Another frontend:** `MANAGER_BLOCKS_API=true` serves `GET /api/manager/pages/{slug}` and `GET /api/manager/blocks/schema` as JSON. + +**Live preview:** `MANAGER_BLOCKS_PREVIEW=true` shows the real public page next to the editor (phone, tablet, desktop), with the blocks that are not saved yet. The page address is `manager.blocks.preview.url` (`/{slug}` by default, the home page is `/`, or an invokable class). The preview address carries a signed, short-lived `?mb-preview=` token; only a person logged in with `pages.edit` sees the draft, and your site must not cache that response. Changing blocks needs the right `pages.layout`. +A service or a project can have a page of its own: give its list `'template' => true`, and the list gets a "Page layout" button. In it, a text says `{record.title}` and the page fills it in; a `cards` block can show the projects of this service (`match_list` = `service_id`, `match_record` = `id`). Your route loads the record and passes `Blocks::forRecord('services', $service)` to the same renderer as a page; a frontend of its own reads `GET /api/manager/templates/services/{id}`. + +**Who draws the site:** `manager.frontend.mode` (`MANAGER_FRONTEND`, also on the settings screen as "Who shows the website"): `site` (default, the site draws its pages), `package` (the manager draws every page with blocks at `/{slug}`, the home page at `/`, as a fallback route that a route of the site always beats; the Blade view is `manager.frontend.layout`) or `headless` (the page API on, nothing drawn). A person in the simple face gets plainer words, a phone photo picker and no delete; see `docs/guide/building-pages.md`, which also says which photos a block needs. + +`php artisan vendor:publish --tag=manager-blocks-assets` copies a plain stylesheet (`blocks.css`, CSS variables) to `public/vendor/manager/`. A markdown field comes with its safe HTML as `_html`; print only that as HTML. + +**Style options and your own CSS (for example Tailwind).** A block type names style options (`background`, `width`, `spacing`, `columns`, …). The package only decides which *choices* exist, in `manager.blocks.tokens`: `'background' => ['none' => 'None', 'sand' => 'Sand', 'dark' => 'Dark']`. A block arrives with the chosen key (`style.background === 'sand'`), and your component or view turns it into the classes of your design system, so nothing of the design sits in the package: + +```js +const background = { none: '', sand: 'bg-sand-100', dark: 'bg-stone-900 text-white' } // in your component: :class="background[style.background]" +``` + +Write each class in full (Tailwind only finds classes that are spelled out in a file it scans), and a component of your own declares `style` in `defineProps`, or Vue puts it on the element as inline style. + +## Settings module + +A screen (`/manager/settings`, only in the whole face of the manager) where an account with `settings.manage` switches parts of the manager on and off and +changes settings, and an account with `settings.secrets` also changes keys, passwords and addresses (the IriksIT API, Turnstile, the disk of the media). + +- A change is kept in the table `settings` (secrets encrypted) and in one compiled file, `bootstrap/cache/manager-settings.php`, that is laid over the config while + the app starts. So it works at once, on every server that shares the database, with or without `config:cache`, and a request reads one file from opcache, not the + database. "Refresh now" writes that file again and empties the caches. Without the file the table is read. +- `manager.settings.write_env` (`MANAGER_SETTINGS_WRITE_ENV`, off by default): also write the changed value into `.env`, when that file may be written. The old + one is kept as `.env.manager-backup`. Only variables that a definition names are ever written. +- Only what is defined can be set: the parts of the manager, the integrations of the package, and the site's own in `manager.settings.definitions` + (`'site.contact_form' => ['label' => 'Contact form', 'type' => 'toggle', 'group' => 'Site']`; the key is the config path it overrides, so + `config('site.contact_form')` has the answer). A module of your own can add some with a `settings()` method. +- What can send a password or a file elsewhere (secrets, addresses, accounts, disks) needs `settings.secrets` and the password of whoever saves it. A secret is + never sent to a browser; it is only said to be set. Clearing one is "back to what the config says". +- A part that is switched on and misses its tables is named: run `php artisan migrate`. + +## Pages module + +Pages are texts with keys, so the public site reads them and the owner edits them without code. Define a page in `config/manager.php`: + +```php +'pages' => ['definitions' => ['home' => ['title' => 'Home', 'fields' => [ + 'hero_title' => ['label' => 'Title on the photo', 'type' => 'text', 'default' => 'Welcome', 'max' => 120], + 'intro' => ['label' => 'Story', 'type' => 'markdown'], + 'photo' => ['label' => 'Photo', 'type' => 'media'], +]]]], +``` + +and read it with `IriksIT\Manager\Models\Page::contentFor('home')`: the stored values over the defaults, so a page that was never saved still has all its keys. Field types: `text`, `textarea`, `markdown`, `lines`, `media`, `url`, `number`, `date`, `toggle` and `select` (with `options`); `required`, `default`, `max`, `help` and `rules` work on all. The screens make the form, and the server validates and cleans every value by its type (a media or url value must be an address of the site or http(s)). A page without a definition is a free page with one Markdown text, a description for search engines and a publish switch; it can be made and removed in the screens. Permission: `pages.edit`. The definitions are shared code (`IriksIT\Manager\Support\Fields`), so other records can use them. + +## Posts module + +Posts written in Markdown, with drafts, scheduling, categories and tags. + +- Routes under `/manager`: `posts` (list, `create`, `{id}/edit`, `{id}/preview`, update, `{id}/online`, + delete) and `labels` (categories and tags: make, rename, merge, remove). Rights: `posts.view`, `write`, + `publish`, `delete`, `labels`. +- Who may not publish only saves drafts, and cannot change or delete a post that is live or scheduled. +- A post is a draft (`published_at` null), scheduled (in the future) or published. For your public pages: + `IriksIT\Manager\Models\Post::published()`, `toCard()` and `IriksIT\Manager\Support\Markdown::toHtml()` + (raw HTML is escaped, external links open in a new window). The package has no public post routes: the + host decides what a visitor sees. +- Categories offered in the form: `manager.posts.categories`, the ones in use, the ones made by hand and + whatever your site adds with + `app(IriksIT\Manager\Modules\Posts\PostLabels::class)->suggestCategories(fn () => $titles)`. +- Covers and bodies count as use of a media file. + +## The editor + +Texts in Markdown (posts, free pages and `markdown` fields) have a toolbar (bold, italic, heading, list, quote, link), a **Photo** button that puts a picture from the media library into the text, and a **Preview** that is rendered by the server the way the site renders it (raw HTML is escaped; `POST /manager/markdown`, not written in the audit log). In the media library a click on a picture sets its **focus point** (`focus_x`, `focus_y`, 0 to 1): the part that must stay in view when the site crops it, shown in a square preview. There is no cropping or rotating in the manager: the file is kept as it was uploaded, and the site crops with the focus point. + +## History module + +Every save of a post or a page keeps its state (`manager_revisions`, the newest 50 per record, `manager.revisions.keep`), with who saved it and which fields changed; saving the same state again keeps nothing. The post and page screens show the history, and `revisions.restore` puts an earlier state back, which is a save like any other (so what was there is in the history too). Whether a post is on the site (`published_at`) and whether a page is published is not part of the history: going back in time never publishes or hides anything. A live post can only be put back by someone who may publish. Permissions: `revisions.view` (and the permission to see that kind of text) and `revisions.restore` (and the permission to write it). A site adds its own models with `manager.revisions.types`, e.g. `'services' => ['model' => App\\Models\\Service::class, 'view' => 'services.view', 'restore' => 'services.manage']`. `MANAGER_REVISIONS=false` turns the module off. + +## Audit module + +Off by default: it stores IP addresses and browser lines, so a site switches it on knowingly and says so in its +privacy policy (`MANAGER_AUDIT=true`). + +- **The log**: logins, logouts and failed logins (from Laravel's own `Login`, `Logout` and `Failed` events, so it + works with any login the host has), every change in the manager, every page that is opened (not twice within + five minutes) and every refusal. Only the account, the address and the browser line are kept, and for an action + the fields its module listed, never what was typed into a form. The log is read with `audit.view`. +- **Names**: a module says what its routes are called in the log with `actions()` and `views()`; a test fails on a + manager route without a name. +- **Bans** (`audit.manage`): ban an address by hand, for a time or until lifted, or a whole group of addresses + (notes put addresses in a group). After too many failed logins an address is banned by itself (the rules are set + in the manager). A banned address gets a 403 (429 for an automatic ban) on every manager route. Put the + `manager.not-banned` middleware on the login routes of your app too. A site that is locked out lifts the ban + with `php artisan manager:unban {ip}`. +- **Behind a proxy**: set up trusted proxies (or `MANAGER_NEVER_BAN`) before switching the module on. Without + them every visitor shares one address, and one bad actor can lock the whole manager out. Failed logins on any + guard count towards the automatic ban. +- **Whole-site bans**: with `MANAGER_AUDIT_WHOLE_SITE_BANS=true` a ban can also keep an address off the whole app. + That adds a global middleware that is answered from the cache. +- **Config** (`manager.audit`): `never_ban` (`MANAGER_NEVER_BAN`, comma-separated: your own addresses), and + `max_keep_days` (`MANAGER_AUDIT_MAX_KEEP_DAYS`, 90): the longest the log may be kept, which your privacy policy + has to agree with. `manager:audit-prune` runs daily and deletes old lines and ended bans; notes stay until removed. + +## Statistics module + +Off by default (`MANAGER_STATISTICS=true`). The site's own visitor statistics, with no cookie and no stored IP address: +a visitor is a code made of the address, the browser and a random key that is deleted after a day (`manager:forget-visitor-keys`, +scheduled daily), so a code cannot be traced back afterwards. A browser that sends `DNT` or `Sec-GPC` is not counted. + +- **The script**: put `` once in the layout of the public site (`:spa="true"` for a site with a client-side router). It loads `/pulse/pulse.js` (about 2 kB, plain JavaScript, no cookies or storage), reports the page and the time it was in view, and does nothing for a browser with Do Not Track or Global Privacy Control. With the module off the component prints nothing. Behind a Content-Security-Policy allow that one script address. +- **Reporting** (what the script does, for a site that wants to do it itself): the pages of your site `POST` to `/pulse/view` (`{path, referrer, via, campaign}`, answers `{token}`) and, when the + visitor leaves, `/pulse/leave` (`{token, seconds}`). No session, rate limited (`manager.statistics.per_minute`). +- **Which pages count**: only addresses you name, so nobody can fill the statistics with made-up ones: + `manager.statistics.pages`, the posts under `manager.statistics.posts_path` (published ones only), and anything else through + `app(IriksIT\Manager\Modules\Statistics\CountedPages::class)->register(fn (string $path) => ...)`. +- **Programs**: the pages served to search engines, crawlers and previews are counted per day, program and page (no address, no browser + line), by a middleware the module adds to the `web` group (`manager.statistics.count_bots`). +- **The report** (`statistics.view`): visitors, visits, page views, time, bounce rate, a comparison with another period, pages, posts, + sources and channels, devices, heatmap, programs; `GET /manager/statistics?range=30d` and a CSV per sheet + (`/manager/statistics/export?sheet=days|pages|sources|bots`). +- **Country** only when `manager.statistics.country_header` names a header (Cloudflare: `CF-IPCountry`). + +## State of this version + +Done: module registry and switches, permissions per module, users (accounts, groups, command, roles of the host), media (library and +public file route, focus point), posts (with categories and tags), pages with fields, lists defined in config, the history with restore, +the audit log with bans, the statistics (with the counting script), the built-in screens for all of these (with a login, checks on the +login, a profile and the simple view), an editor, themes, translations, a site's own bundle of screens, the import of existing data, and +the install and doctor commands for AI agents. `composer test` runs the tests. + +Reviews are still a read-only list. The answers of every action are JSON in the shape the screens use, so an app can build its own screens +with `MANAGER_UI=none`. Not in the package: two-factor login (the login checks are the place for it), cropping or rotating pictures, a theme editor. + +## Development cycle + +``` +develop ── feature/*, fix/* ──► release/vX.Y.Z ──► production ──► tag vX.Y.Z ──► Packagist + ▲ (pull request, (collects the (pull request, │ + │ merges by itself) features) merged by hand) │ + └──────────────────────── sync: production into develop ◄─────────────────────────┘ +``` + +1. **Start a release:** Actions → *Start release* → version (`0.2.0`). That makes `release/v0.2.0` from `develop`. +2. **Features:** branch `feature/…` or `fix/…` from `develop`, open a pull request to the release branch. It + merges by itself when *PR CI* is green. Every pull request adds its row to `TOKENS.md`. +3. **Ready:** add a section `## v0.2.0 - date` to `CHANGELOG.md` and open a pull request from the release branch + to `production`. A person merges it. +4. **Release (automatic, on the merge):** tests and audit once more, the tag `v0.2.0` and a Gitea release with the + changelog text, Packagist is told, and `production` is merged into `develop`. + +Nobody opens a pull request to `develop`, and `production` and the release branches take no direct pushes. + +| When | What runs | +|---|---| +| Pull request to a release branch or to production | *flow* (right branches, version above the latest tag, changelog section, tests of these scripts), *ledger* (`TOKENS.md`), *test* (Pint, Pest with the newest and the oldest dependencies, `composer validate`), *security* (`composer audit`: the job fails on any advisory). The check `PR CI / pr-ci` is green when all are. | +| Push to production | verify (Pest, `composer audit`), tag and release, the tags to the mirror `laravel-manager-packagist`, Packagist, sync develop; then the homelab scans production with Trivy | +| Every night | the homelab scans every repository with Trivy (03:00) and updates its dependencies (04:00): nothing runs weekly in this repository | +| Every night | *Prune branches*: removes `feature/*` and `fix/*` branches whose last commit is over 30 days old and that have no open pull request (a branch of a pull request can be restored from it in Gitea) | + +### Security and updates + +Nothing here runs on a weekly schedule; the checks hang on the moments that matter, and the homelab does the rest every night. + +- **Every pull request:** `composer audit` (it fails on any advisory). +- **Every release:** `composer audit` again on the merge to `production`. +- **After every release to production:** Trivy scans `production` from the homelab (LXC 120, no database to download in a job). +- **Every night:** Trivy scans every repository of the organisation (03:00), and the dependency round (04:00) opens a pull request + `renovate/deps-DATE` straight to `production` for updates that have been public for 48 hours. PR CI tests it, and when it is + merged the Release workflow makes a patch release of it (v0.5.0 → v0.5.1, text from the pull request), tells Packagist and syncs `develop`: + one a night at most. While a release branch is open there is no patch release; the update goes out with that release. A critical advisory on the installed version skips the 48 hours. + +Packagist reads the mirror `iriks-it/laravel-manager-packagist`, not this repository, because it shows every branch of the +repository it reads as a `dev-…` version. For every release the Release workflow (`.gitea/scripts/mirror_tags.sh`) puts a clean +tree on the mirror: what `git archive` of the tag gives, so without what `.gitattributes` marks `export-ignore` (tests, `ui/`, +`dev/`, `TOKENS.md`, `.gitea/`, the agent files), as a commit with no history and no branch, and pushes only its tag. The mirror +has one branch, `production`, that only holds a note (no `composer.json`, so no version); nothing else is ever pushed there. Packagist +and `composer require` only see the mirror, so this repository can be private. (Versions up to v0.5.1 on the mirror are the full tree.) + +Secrets of the repository for this: `DEPLOY_TOKEN` (the organisation has it), and `PACKAGIST_USERNAME` and +`PACKAGIST_TOKEN` (until they are set that step only says so). When Packagist does not know the package yet, that step +submits it through the create-package API; after that it only tells Packagist about each new tag. + +## What Composer installs + +`.gitattributes` leaves what only belongs to the repository out of the package (`export-ignore`): `.gitea/`, +`dev/`, `scripts/`, `tests/`, `TOKENS.md`, `AGENTS.md`, `phpunit.xml` and the dotfiles. They stay in the repository. +Packagist builds the archive from `git archive`, so what a site installs is `src/`, `config/`, `routes/`, +`resources/`, `composer.json`, `README.md` and `CHANGELOG.md`. Check it with `git archive HEAD | tar -t`. diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..41dec73 --- /dev/null +++ b/composer.json @@ -0,0 +1,59 @@ +{ + "name": "iriks-it/laravel-manager", + "description": "A modular backend (manager) for Laravel sites: users, media, pages, posts, reviews. Every part can be switched on or off.", + "type": "library", + "license": "MIT", + "keywords": ["laravel", "manager", "cms", "admin", "modules"], + "require": { + "php": "^8.4", + "illuminate/auth": "^13.0", + "illuminate/cache": "^13.0", + "illuminate/console": "^13.0", + "illuminate/contracts": "^13.0", + "illuminate/database": "^13.0", + "illuminate/filesystem": "^13.0", + "illuminate/http": "^13.0", + "illuminate/routing": "^13.0", + "illuminate/support": "^13.0", + "illuminate/validation": "^13.0", + "league/commonmark": "^2.6", + "league/flysystem": "^3.0" + }, + "require-dev": { + "orchestra/testbench": "^11.0", + "pestphp/pest": "^5.0", + "laravel/pint": "^1.15" + }, + "autoload": { + "psr-4": { + "IriksIT\\Manager\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "IriksIT\\Manager\\Tests\\": "tests/" + } + }, + "extra": { + "laravel": { + "providers": [ + "IriksIT\\Manager\\ManagerServiceProvider" + ], + "aliases": { + "Manager": "IriksIT\\Manager\\Facades\\Manager" + } + } + }, + "scripts": { + "test": "pest", + "lint": "pint --test" + }, + "config": { + "sort-packages": true, + "allow-plugins": { + "pestphp/pest-plugin": true + } + }, + "minimum-stability": "stable", + "prefer-stable": true +} diff --git a/config/manager.php b/config/manager.php new file mode 100644 index 0000000..0b6d874 --- /dev/null +++ b/config/manager.php @@ -0,0 +1,420 @@ + env('MANAGER_PATH', 'manager'), + + /* + | Middleware around every manager route. Authentication of the manager itself + | is left to the host app: use the guard it already has. + */ + 'middleware' => ['web', 'manager.auth'], + + /* + | The screens. `package`: the manager brings its own (a Vue app, built, served by the package; it also gives a login and + | a profile when the app has none). `none`: only the JSON API, for an app that builds its own screens. + */ + 'ui' => env('MANAGER_UI', 'package'), + + /* + | The name in the menu and on the login screen. + */ + 'name' => env('MANAGER_NAME'), + + /* + | Looks. `theme` is what everyone gets until they choose; `user_themes` lets each account pick its own (profile). + | A theme is a set of colours, a radius and fonts: built in are `dark` and `light`; the site's own live as JSON files in + | `themes_path` (make one with `php artisan manager:make-theme`) or here in `themes`, by key. + */ + 'theme' => env('MANAGER_THEME', 'dark'), + 'user_themes' => (bool) env('MANAGER_USER_THEMES', true), + 'themes_path' => null, // default: resources/manager-themes of the app + 'themes' => [], + + /* + | The Eloquent model of the people who log in. Must use IriksIT\Manager\Concerns\HasManagerAccess. + */ + 'user_model' => env('MANAGER_USER_MODEL', 'App\\Models\\User'), + + /* + | The modules this manager knows. Add your own class here to give a site its own part. + */ + 'available' => [ + Modules\Users\UsersModule::class, + Modules\Media\MediaModule::class, + Modules\Pages\PagesModule::class, + Modules\Posts\PostsModule::class, + Modules\Reviews\ReviewsModule::class, + Modules\Audit\AuditModule::class, + Modules\Statistics\StatisticsModule::class, + Modules\Resources\ResourcesModule::class, + Modules\Revisions\RevisionsModule::class, + Modules\Settings\SettingsModule::class, + Modules\Leads\LeadsModule::class, + Modules\Updates\UpdatesModule::class, + Modules\Sharing\SharingModule::class, + Modules\Costs\CostsModule::class, + Modules\Numbers\NumbersModule::class, + ], + + /* + | Switch a part on or off per site. A key left out falls back to the default of the + | module: users and media are on, everything else is off. A module that is off has no + | routes, no tables (its migrations are not loaded), no menu item and no permissions. + */ + 'modules' => [ + 'users' => true, + 'media' => true, + 'pages' => env('MANAGER_PAGES', true), + 'posts' => env('MANAGER_POSTS', true), + 'reviews' => env('MANAGER_REVIEWS', false), + 'audit' => env('MANAGER_AUDIT', false), + 'statistics' => env('MANAGER_STATISTICS', false), + 'resources' => true, + 'revisions' => env('MANAGER_REVISIONS', true), + 'updates' => env('MANAGER_UPDATES', false), + 'sharing' => env('MANAGER_SHARING', false), + 'costs' => env('MANAGER_COSTS', false), + 'numbers' => env('MANAGER_NUMBERS', false), + 'settings' => true, + 'leads' => env('MANAGER_LEADS', false), + ], + + /* + | Features of the site that the settings screen switches on and off: one switch that the manager and the public site both follow. + | 'services' => ['label' => 'Services', 'hint' => 'The page with what you offer', 'enabled' => true, 'env' => 'SITE_SERVICES'] + | In the manager: a `resources` entry with `'feature' => 'services'` is left out while the feature is off. In the site: `Features::on('services')`, + | the route middleware `manager.feature:services` (404 while off) and `@feature('services') … @endfeature`. Off hides, it never deletes data. + */ + 'features' => [], + + /* + | The media library. Files live on a Laravel filesystem disk; each media row remembers + | its own disk, so a file stays where it was uploaded when `disk` changes later. + */ + 'media' => [ + 'disk' => env('MANAGER_MEDIA_DISK', 'public'), + + // How much room the library has in total, in GB. An upload that would go over it is refused. + 'max_total_gb' => (float) env('MANAGER_MEDIA_MAX_TOTAL_GB', 15), + + // Largest single upload in MB. PHP and the web server must allow it too + // (upload_max_filesize, post_max_size, client_max_body_size). + 'max_file_mb' => (int) env('MANAGER_MEDIA_MAX_FILE_MB', 40), + + // File extensions the library accepts. SVG is deliberately missing: it can carry scripts. + 'extensions' => ['jpg', 'jpeg', 'png', 'webp', 'gif', 'pdf', 'mp4', 'webm'], + + // The disk `iriksit` keeps files at the IriksIT API (set `disk` to `iriksit`). The account needs the permissions + // `storage.read` and `storage.write`. Leave this empty for any other disk. + 'iriksit' => [ + 'url' => env('MANAGER_IRIKSIT_URL'), + 'email' => env('MANAGER_IRIKSIT_EMAIL'), + 'password' => env('MANAGER_IRIKSIT_PASSWORD'), + 'timeout' => 300, + ], + + // Visitors loading files per minute per address (the `media-files` rate limiter). + 'per_minute' => 600, + ], + + /* + | Posts. `categories` are always offered in the post form, next to the ones in use and the + | ones made by hand; a site can offer more through PostLabels::suggestCategories(). + */ + 'posts' => [ + 'categories' => ['General'], + ], + + /* + | Markdown in posts: hosts besides APP_URL whose links do not open in a new window. + */ + 'markdown' => [ + 'internal_hosts' => [], + ], + + /* + | The audit log and the bans (module `audit`). + */ + 'audit' => [ + // Addresses that are never banned, by hand or by themselves: your own, so a slip or a rule + // that is too strict never locks you out. Comma-separated in MANAGER_NEVER_BAN. + 'never_ban' => array_values(array_filter(array_map('trim', explode(',', (string) env('MANAGER_NEVER_BAN', ''))))), + + // The longest the log may be kept, in days. Set it to what your privacy policy promises. + 'max_keep_days' => (int) env('MANAGER_AUDIT_MAX_KEEP_DAYS', 90), + + // Let a ban "for the whole site" work: the middleware then runs on every request of the app. + 'whole_site_bans' => (bool) env('MANAGER_AUDIT_WHOLE_SITE_BANS', false), + ], + + /* + | The visitor statistics (module `statistics`). + */ + 'statistics' => [ + // The addresses of the public site that count as a page. Anything else is ignored, so + // nobody can fill the statistics with made-up addresses. Posts and other kinds of pages + // come from `posts_path` or a resolver: app(CountedPages::class)->register(fn ($path) => ...). + 'pages' => ['/'], + + // The address under which the posts live (`/blog` for `/blog/my-post`); null: posts are not counted. + 'posts_path' => null, + + // Where the public pages report a view (POST {pulse_path}/view and {pulse_path}/leave). + 'pulse_path' => 'pulse', + + // Reports per minute per address. + 'per_minute' => 120, + + // The request header with the country code of the visitor, e.g. CF-IPCountry behind Cloudflare. Null: no country. + 'country_header' => env('MANAGER_STATISTICS_COUNTRY_HEADER'), + + // Count the pages served to programs (search engines, crawlers) by adding a middleware to the `web` group. + 'count_bots' => (bool) env('MANAGER_STATISTICS_COUNT_BOTS', true), + ], + + /* + | Pages with fields (module `pages`): per slug a title and the fields the screens make a form of, and the + | public site reads with `IriksIT\Manager\Models\Page::contentFor('home')`: + | 'definitions' => ['home' => ['title' => 'Home', 'fields' => [ + | 'hero_title' => ['label' => 'Title on the photo', 'type' => 'text'], + | 'intro' => ['label' => 'Story', 'type' => 'markdown'], + | 'photo' => ['label' => 'Photo', 'type' => 'media'], + | ]]]. + | Types: text, textarea, markdown, lines, media, url, number, date, toggle, select (with `options`). + */ + 'pages' => ['definitions' => [], 'checks' => []], + + /* + | Lists the site manages without code of its own: a form, a list, permissions (`.view`, `.manage`) + | and a menu item for each. `model` keeps the records in a model of the site (the field keys are its + | attributes); without it they go into the package's own table. Fields: see `pages`. + | A `hint` is the line under the item on the simple start page. + | 'services' => ['label' => 'Services', 'hint' => 'What you offer', 'singular' => 'Service', 'model' => App\Models\Service::class, + | 'columns' => ['name', 'price'], 'order' => ['position', 'asc'], 'fields' => ['name' => ['type' => 'text', 'required' => true], ...]] + */ + 'resources' => [], + + /* + | A bundle of the site's own screens: JavaScript modules (a path of the site, or https) the manager loads next to its own, + | after it has started. They add screens with `IriksManager.register('^/leads$', Component, { data: true })`, and may + | `import { ref } from 'vue'` when the build leaves `vue` external. See README, "Your own screens". + */ + 'extensions' => [], + + /* + | The history of posts and pages (module `revisions`): `keep` states per record, more `types` of the site's own + | (['services' => ['model' => App\Models\Service::class, 'view' => 'services.view', 'restore' => 'services.manage']]), + | and `skip` for model classes that should not have one. + */ + 'revisions' => ['keep' => 50, 'types' => [], 'skip' => []], + + /* + | More a login asks for. `checks`: classes that implement IriksIT\Manager\Contracts\LoginCheck (extend + | IriksIT\Manager\Support\Login\BaseLoginCheck): a field of the form, something to check before the password is + | tried (a captcha) or after it was right (a second factor). Cloudflare Turnstile is built in and turns itself on + | when both of its keys are set. These apply to the login of the manager's own screens. + */ + 'login' => [ + 'checks' => [], + 'turnstile' => ['site_key' => env('MANAGER_TURNSTILE_SITE_KEY'), 'secret' => env('MANAGER_TURNSTILE_SECRET')], + ], + + /* + | Who may do what. `groups` (default): the groups of the package. A site that has roles of its own can say it itself: + | `host` takes the permissions only from the site, `merge` adds them to what the groups give. The site's side is a + | `resolver` class (IriksIT\Manager\Contracts\PermissionResolver), or, simpler, `roles` per role name (`*` is + | everything) read from the attribute `role_attribute` of the account (a string, a list or a relation with a `name`). + | 'roles' => ['editor' => ['posts.view', 'posts.write'], 'owner' => ['*']]. A super admin may always do everything. + */ + 'permissions' => ['mode' => env('MANAGER_PERMISSIONS', 'groups'), 'resolver' => null, 'roles' => [], 'role_attribute' => 'role'], + + /* + | The menu. `items` changes what a module gives, by the route name without the prefix: + | 'posts.index' => ['order' => 10, 'section' => 'Content', 'icon' => 'file', 'simple' => true, 'hidden' => false]. + | `links` adds items of the site's own: ['label' => 'Leads', 'url' => '/manager/leads', 'permission' => null, + | 'section' => ..., 'icon' => ..., 'order' => ..., 'simple' => ..., 'new_tab' => ...]. + | Icons: home, file, image, users, group, chart, shield, star, tag, link, cog. + */ + 'menu' => ['items' => [], 'links' => []], + + /* + | A simple face of the manager next to the full one. With this on, the permissions `manager.full` and + | `manager.switch` exist: an account with the first (or a super admin) gets everything; one with the + | second starts simple and may switch; all others always get the simple face, which shows only the + | menu items marked `simple`. Off: everyone sees the whole menu. + */ + 'simple_view' => (bool) env('MANAGER_SIMPLE_VIEW', false), + + /* + | What the simple start screen shows under its big buttons: `help` is a way to ask for help, a name and a link (for example a WhatsApp + | link), and `site_link` the address of the site ("View the site"; null leaves it out). + */ + 'simple' => ['help' => ['name' => env('MANAGER_HELP_NAME'), 'link' => env('MANAGER_HELP_LINK')], 'site_link' => '/'], + + /* + | The pictures of the tour: a folder with `welcome`, `point`, `calm`, `write`, `photos`, `pages`, `undo`, `oops`, `party`, `profile` and + | `peek` (`.webp` or `.png`). Null: the set of the package. A picture that is missing is replaced by a paw. + */ + 'mascot' => ['path' => null], + + /* + | The settings screen (module `settings`, whole face of the manager only). Changes are kept in the database and in one compiled file + | and work at once. `write_env` also writes the changed value into .env, when that file may be written (it is left alone otherwise). + | `definitions` adds settings of the site's own, by the config path they override: + | 'site.contact_form' => ['label' => 'Contact form', 'type' => 'toggle', 'group' => 'Site', 'env' => 'CONTACT_FORM']. + | Types: toggle, text, url, number, select (with `options`), secret (never shown again). A definition with `sensitive` => true needs the + | right `settings.secrets` and the password of whoever saves it. `checks` adds a "try it" button to a group of settings: + | `'Group name' => SomeClass::class`, invokable, returns what worked and throws when it did not. + */ + 'settings' => ['write_env' => (bool) env('MANAGER_SETTINGS_WRITE_ENV', false), 'definitions' => [], 'checks' => []], + + /* + | Sharing posts on social networks (module `sharing`). `platforms` is name => class of a `Contracts\Sharer`; LinkedIn comes with the + | package, a site adds its own. `post_url` says where a post lives on the site (`{slug}` is its address), `live` is whether a + | share is sent for real (off: a dry run, nothing leaves the site). The keys of the app of a platform are settings (secrets). + */ + 'sharing' => [ + 'platforms' => ['linkedin' => Modules\Sharing\LinkedInSharer::class], + 'post_url' => env('MANAGER_SHARING_POST_URL'), + 'live' => (bool) env('MANAGER_SHARING_LIVE', false), + 'linkedin' => [ + 'client_id' => env('MANAGER_LINKEDIN_CLIENT_ID'), + 'client_secret' => env('MANAGER_LINKEDIN_CLIENT_SECRET'), + 'auth_url' => 'https://www.linkedin.com/oauth/v2', + 'userinfo_url' => 'https://api.linkedin.com/v2/userinfo', + 'base_url' => 'https://api.linkedin.com/rest', + 'version' => '202511', + ], + ], + + /* + | Who draws the pages of the site (switchable on the settings screen, "Who shows the website"): + | 'site' the site draws them itself with the blocks (Inertia + Vue or Blade). No public route is added. The default. + | 'package' the package draws every page that has blocks at `/{slug}` (the home page at `/`), in the Blade view `layout`, as a + | fallback route: a route of the site always wins and what is not a page stays a 404. `middleware` is the group it runs in. + | 'headless' nothing is drawn; the pages are JSON for a frontend elsewhere (the same as `blocks.api.enabled`). + */ + 'frontend' => ['mode' => env('MANAGER_FRONTEND', 'site'), 'layout' => 'manager::public.layout', 'middleware' => ['web']], + + /* + | The blocks a page is built from (see docs/design/page-builder.md). `types` adds block types of the site (or replaces a shipped + | one by its key): 'map' => ['label' => 'Map', 'fields' => [...], 'style' => ['width']]. `tokens` sets the choices of a style + | option: 'background' => ['none' => 'None', 'sand' => 'Sand']. `max` is the most blocks on a page. A page with a definition holds + | blocks when its definition says `'blocks' => true` (or a list of types); `free_pages` does the same for pages without one. + */ + 'blocks' => [ + 'types' => [], 'tokens' => [], 'max' => 100, 'free_pages' => false, + // The same blocks as JSON for a frontend on another server: GET {path}/pages/{slug} and, when `schema` is on, GET {path}/blocks/schema. + // The live preview in the editor: the public page of the site shown in a frame, with the blocks that are not saved yet. `url` is the + // address of a page (`/{slug}`, with the home page as `/`; or an invokable class that gets the slug), `ttl` how long a preview is kept (seconds). + 'preview' => ['enabled' => env('MANAGER_BLOCKS_PREVIEW', false), 'url' => null, 'home' => 'home', 'ttl' => 600, 'max_kb' => 512], + 'api' => ['enabled' => env('MANAGER_BLOCKS_API', false), 'path' => 'api/manager', 'middleware' => ['throttle:60,1'], 'schema' => true], + ], + + /* + | What changed on the site (module `updates`): the releases of a CHANGELOG.md, newest first. `changelog` is the file (default: the + | CHANGELOG.md in the root of the site) and `limit` how many releases the screen shows. + */ + 'updates' => ['changelog' => env('MANAGER_UPDATES_CHANGELOG'), 'limit' => 20], + + /* + | What the work on the site has cost (module `costs`): the table of the site's TOKENS.md (`ledger`, default the TOKENS.md in the root of the + | site) with the tokens of each piece of work in euros. A row is priced once and the price is kept. Who prices it: `pricer` (an invokable + | class of the site that gets the rows to price and returns ['row-0' => ['usd' => ..., 'eur' => ..., 'usd_per_eur' => ...]]), else the IriksIT + | API when `media.iriksit` is set (switch it off with `use_api`; the account needs `ai.pricing`), else the fixed `rates` (US dollars per + | million tokens per model: ['model' => ['input' => ..., 'cache_write' => ..., 'cache_read' => ..., 'output' => ...]]) with `usd_to_eur`. + | `hourly_rate` turns the hours of a row into euros, `hosting` is a yearly amount from a day on, `discount` a share of the work and the AI + | costs before a day. `assign_open_to_newest` puts a row without a release in the newest release (right on a site where everything that + | is deployed is released). + */ + 'costs' => [ + 'ledger' => env('MANAGER_COSTS_LEDGER'), + 'hourly_rate' => (float) env('MANAGER_COSTS_HOURLY_RATE', 0), + 'hosting' => ['per_year' => 0, 'from' => null], + 'discount' => ['percent' => 0, 'until' => null], + 'pricer' => null, + 'use_api' => true, + 'rates' => [], + 'usd_to_eur' => null, + 'assign_open_to_newest' => false, + ], + + /* + | The requests of visitors (module `leads`): how they are screened and kept. Every rule is a setting; nothing is ever refused on score, + | the worst that happens to a real request is the folder "other". `kinds` names the forms of the site (kind => label), `notify` is where a + | real request is mailed to (a setting on the settings screen), `confirm` mails the visitor a short confirmation, `source` is an invokable + | class that tells where a visit came from (returns ['channel' => ..., 'source' => ...]), `language` (nl, en or null) marks text in another + | language as spam, `country_code` is the home country for phone numbers. + */ + 'leads' => [ + 'kinds' => ['callback' => 'Callback request', 'question' => 'Question', 'quote' => 'Quote request', 'message' => 'Message'], + 'notify' => env('MANAGER_LEADS_NOTIFY'), + 'confirm' => false, + 'source' => null, + 'language' => null, + 'country_code' => '31', + // The public forms (`POST /{path}/{form}`, see Modules\Leads\LeadFormController): a form is a name with the kind it makes and the fields it + // requires (name, phone, email, contact = one box for either, message, location). `questions` and `moments` are what a visitor may tap. + // `thanks` is where a visitor lands after sending (null: back to the page). A honeypot field and Turnstile (when its keys are set) keep programs out. + 'form' => [ + 'path' => 'requests', + 'honeypot' => 'website', + 'turnstile' => true, + 'thanks' => null, + 'per_hour' => 6, + 'per_hour_all' => 120, + 'forms' => [ + 'callback' => ['kind' => 'callback', 'require' => ['name', 'phone']], + 'question' => ['kind' => 'question', 'require' => ['name', 'contact', 'message']], + 'quote' => ['kind' => 'quote', 'require' => ['name', 'phone', 'location']], + 'contact' => ['kind' => 'message', 'require' => ['name', 'email', 'subject', 'message']], + ], + 'questions' => [], + 'moments' => [], + ], + 'min_seconds' => 3, + 'max_hours' => 24, + 'spam_from' => 5, + 'other_from' => 3, + 'keep_days' => 365, + 'keep_spam_days' => 30, + 'acquisition_words' => [ + 'seo', 'backlinks', 'backlink', 'linkbuilding', 'lead generation', 'more leads', 'more customers', 'web design', 'webdesign', 'web development', + 'digital marketing', 'online marketing', 'marketing agency', 'social media management', 'free analysis', 'our offer', 'we offer', 'partnership', + 'guest post', 'sponsored', 'crypto', 'investment', 'loan', 'traffic', 'ranking', + ], + 'throwaway_domains' => [ + 'mailinator.com', 'guerrillamail.com', 'guerrillamail.net', 'sharklasers.com', '10minutemail.com', 'tempmail.com', 'temp-mail.org', 'yopmail.com', + 'trashmail.com', 'getnada.com', 'dispostable.com', 'maildrop.cc', 'mailnesia.com', 'throwawaymail.com', 'fakeinbox.com', 'mohmal.com', 'emailondeck.com', + ], + ], + + /* + | Prefix for the tables of the package. + */ + 'table_prefix' => 'manager_', + + /* + | A table with a name of its own, by short name (`posts`, `pages`, `media`, ...): wins over the prefix. + | Set it before the first migrate; the package never renames a table that exists. + */ + 'tables' => [], + + /* + | Prefix of the route names (`manager.posts.index`). Change it when the site already has `manager.*` + | routes; menu items and screens follow by themselves. + */ + 'route_name' => 'manager', + + /* + | Where `php artisan manager:import ` reads from, so it needs no options: + | 'posts' => ['table' => 'articles', 'connection' => null, 'map' => ['title' => 'headline']]. + */ + 'import' => [], +]; diff --git a/database/migrations/2026_12_05_000001_create_manager_user_settings.php b/database/migrations/2026_12_05_000001_create_manager_user_settings.php new file mode 100644 index 0000000..614d985 --- /dev/null +++ b/database/migrations/2026_12_05_000001_create_manager_user_settings.php @@ -0,0 +1,27 @@ +getTable(); + + Tables::create(Names::table('user_settings'), function (Blueprint $table) use ($users) { + $table->id(); + $table->foreignId('user_id')->unique()->constrained($users)->cascadeOnDelete(); + $table->string('theme', 60)->nullable(); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists(Names::table('user_settings')); + } +}; diff --git a/database/migrations/2026_12_06_000001_add_view_to_manager_user_settings.php b/database/migrations/2026_12_06_000001_add_view_to_manager_user_settings.php new file mode 100644 index 0000000..df4cecb --- /dev/null +++ b/database/migrations/2026_12_06_000001_add_view_to_manager_user_settings.php @@ -0,0 +1,24 @@ +string('view', 10)->nullable()->after('theme'); + }); + } + + public function down(): void + { + Schema::table(Names::table('user_settings'), function (Blueprint $table) { + $table->dropColumn('view'); + }); + } +}; diff --git a/database/migrations/2026_12_07_000001_add_locale_and_tutorial_to_manager_user_settings.php b/database/migrations/2026_12_07_000001_add_locale_and_tutorial_to_manager_user_settings.php new file mode 100644 index 0000000..9ca6724 --- /dev/null +++ b/database/migrations/2026_12_07_000001_add_locale_and_tutorial_to_manager_user_settings.php @@ -0,0 +1,25 @@ +string('locale', 5)->nullable()->after('view'); + $table->string('tutorial', 10)->nullable()->after('locale'); + }); + } + + public function down(): void + { + Schema::table(Names::table('user_settings'), function (Blueprint $table) { + $table->dropColumn(['locale', 'tutorial']); + }); + } +}; diff --git a/docs/guide/building-pages.md b/docs/guide/building-pages.md new file mode 100644 index 0000000..5e2f4cd --- /dev/null +++ b/docs/guide/building-pages.md @@ -0,0 +1,48 @@ +# Building pages and choosing photos + +For the people who look after a site with this manager, and for whoever sets it up. The same words are in the tour that a new account sees +(the cross closes it; "Show the tour" in the menu opens it again). + +## Who shows the website + +On the settings screen (only in the whole manager, with the right `settings.manage`), group **The website**: + +| Setting | What it does | +| --- | --- | +| **Who shows the website** | *The website itself*: the site has its own code and draws the pages (the usual choice). *This manager*: the manager draws every page made of blocks at its own address, nothing else is needed. *Another website reads it (headless)*: the pages go out as data for a website or app elsewhere. | +| **Show the real page next to the editor** | While building a page you see it on a phone, tablet and computer before you save. | +| **Let another website read the pages** | The pages as JSON at `/api/manager/pages/{slug}`. Always on in headless mode. | + +Switching does not delete anything: a page is the same whoever draws it. + +## The simple face (for people who are not webmasters) + +An account in the **simple** face sees the same page editor with plainer words and fewer buttons: + +- "The parts of your page", "Add something to the page"; every block type has a sentence of its own ("A text with a picture next to it"). +- A part is **taken off the site** (and put back) instead of deleted; there is no drag-and-drop, no duplicate, no red delete. The arrows move a part. +- How a part looks (width, background, …) is folded away under "Change how it looks". +- A photo is **picked, not managed**: "Choose a photo" opens the phone's own photo picker (or the camera); several at once for a gallery. The photo is turned upright and made smaller in the browser (longest side 2400 pixels), which also drops where and when it was taken. There is no file name or address to see. +- Fields marked `advanced` are left out. + +A field or block type of your own gets plain words with `'simple' => ['label' => '…', 'help' => '…']`. + +## Which photos do I need? + +| Where | Shape | At least | Tip | +| --- | --- | --- | --- | +| Big opening (hero) | wide (landscape) | 1600 px across | the edges are cut to fit: keep what matters in the middle | +| Text with picture | landscape or square | 1000 px across | any sharp photo | +| One picture | any | 1200 px across | shown as wide as the part allows | +| Several pictures | any | 800 px across each | shown as squares or a grid; pick them in one go, the first comes first | +| Before and after | same spot, same angle | 800 px across | take both from the same place | + +A phone photo is big enough for all of these. Nobody has to resize anything; a photo of up to 40 MB is accepted (`manager.media.max_file_mb`), and the library has room for `manager.media.max_total_gb`. +The tour's own pictures (the mascot) live in `manager.mascot.path`; the names are `welcome`, `point`, `calm`, `write`, `photos`, `pages`, `undo`, `oops`, `party`, `profile` and `peek`, as 512 × 512 `.webp` or `.png` with a transparent background. This release needs no new ones; a missing one is a paw. + +## For the person who sets it up + +1. `manager.frontend.mode` (`MANAGER_FRONTEND`): `site`, `package` or `headless`. In `package` mode `manager.frontend.layout` is the Blade view (`manager::public.layout`, publish and change it, or point it at a view of your own with `$title`, `$description`, `$blocks`, `$css` and `$slug`). +2. Give a page definition `'blocks' => true` and give the accounts that build pages `pages.layout` (and `pages.edit`, `media.view`, `media.upload`). +3. Switch on the preview with `manager.blocks.preview.enabled` and set its address if the page is not at `/{slug}`. +4. Look at the page as an account in the simple face: press "Simple view" in the menu. If you cannot do it without help, so cannot the owner. diff --git a/resources/ai/INTEGRATION.md b/resources/ai/INTEGRATION.md new file mode 100644 index 0000000..8f8e750 --- /dev/null +++ b/resources/ai/INTEGRATION.md @@ -0,0 +1,39 @@ +# Integrating iriks-it/laravel-manager (guide for AI agents) + +Goal: the manager runs in this Laravel app and `php artisan manager:doctor --json` says `"ok": true`. Do the steps in +order and never edit files inside `vendor/`. + +1. `composer require iriks-it/laravel-manager` + (A version that is not on Packagist yet: first `composer config repositories.manager --json '{"type":"path","url":"/path/to/laravel-manager","options":{"symlink":false}}'`, then require `@dev`.) +2. Pick the modules. `users` and `media` are on; `pages` and `posts` are on by default; `reviews`, `audit` and `statistics` are off + (audit and statistics store visitor data: only switch them on when the owner says so). +3. `php artisan manager:install --modules=users,media,posts --user-model="App\Models\User"` + It writes the `MANAGER_*` switches to `.env` and publishes `config/manager.php`. Add `--path=admin` to move the URL. + It does not run the check itself (this process still has the old config): that is step 7. +4. Add the trait to the user model: `use \IriksIT\Manager\Concerns\HasManagerAccess;`. Never put `is_super_admin` in `$fillable`. +5. `php artisan config:clear && php artisan migrate && php artisan storage:link` (a new process, so it sees the switches of step 3). +6. Create the first super admin: `php artisan manager:create-user --name="..." --email="..." --password="<12+ chars>"`. +7. `php artisan manager:doctor --json`. Every check must be `ok` or an understood `warn`; each `fail` and `warn` has a `fix`. + Repeat until `"ok": true`. + +Facts that matter: +- A site that already has `manager.*` route names, `manager_*` tables or its own posts and pages: `manager:doctor` has a `names` check that says + so. Set `route_name`, `table_prefix` or `tables` in `config/manager.php` before the first `migrate`, then copy what exists with + `php artisan manager:import posts|pages|reviews --table= --map== --dry-run` (the source is only read). +- What the site's own content looks like is configuration, not code: `manager.pages.definitions` (texts with keys, read with `Page::contentFor('slug')`), + `manager.resources` (lists such as services or testimonials, in a model of the site or the package's table) and `manager.menu` (order, sections, + icons, own links). A screen that needs code is a JavaScript module in `manager.extensions`; it registers with `IriksManager.register`. +- Who may do what: the groups of the package, or the roles of the site (`manager.permissions`); more on the login: `manager.login.checks`, Turnstile + with two env keys. The public pages count visits with `` when `statistics` is on. +- The screens are part of the package (`MANAGER_UI=package`, the default): open `/manager` in a browser. The app does not need a + login of its own: when it has no route named `login`, the manager's own login at `/manager/login` is used. With + `MANAGER_UI=none` there are only the JSON routes. +- A browser address gets the screens, a request with `Accept: application/json` gets the data. To call the JSON routes from a + script: `GET /manager/login` once for the `XSRF-TOKEN` cookie, then `POST /manager/login` with header `X-XSRF-TOKEN` (the cookie + value, URL-decoded), `Accept: application/json` and body `{"email": "...", "password": "..."}`; the answer is `{"redirect": "/manager"}`. +- The look: `MANAGER_THEME=dark|light` or your own (`php artisan manager:make-theme acme --brand=#e4002b --name="Acme" --logo=/img/logo.svg`, + then `MANAGER_THEME=acme`). Each account can pick its own in its profile (`MANAGER_USER_THEMES=false` stops that). +- Anything that is off has no routes, tables or permissions. A module that needs another one fails at boot when that one is off. +- Do not add site-specific code to the package: a site's own part is its own module class (`Contracts\Module`, extend + `Modules\BaseModule`, add it to `manager.available`). +- Behind a proxy set trusted proxies before switching `audit` on. diff --git a/resources/blocks/blocks.css b/resources/blocks/blocks.css new file mode 100644 index 0000000..d9870fe --- /dev/null +++ b/resources/blocks/blocks.css @@ -0,0 +1,81 @@ +/* + * A plain stylesheet for the blocks of a page, the same for the Blade views and the Vue components. Everything hangs on CSS + * variables, so a site sets its own look by overriding them (`:root { --mb-accent: #c2410c; }`) or replaces the file. + * Classes: `.mb-block` on every block, `.mb-`, and one `mb--