Commit Graph
25 Commits
Author SHA1 Message Date
Sky Mulleyandrobert dennis 71dd1911a5 Implement native support for hooking into forms with extensions (#7256)
## Problem

Extensions can render content before and after most admin pages, but not
inside the forms on them. The only exception was
`panel.users.detail.form`, and it could only re-render or validate the
user's existing fields. An extension had no way to add a field of its
own, because the Panel's save requests had nowhere to carry the value
and nothing loaded it back.

## Changes

### Slots inside every admin form

The create and edit forms for users, nodes, servers, eggs, locations,
mounts and database hosts each render a slot inside the form, such as
`panel.servers.create.form` and `panel.servers.detail.details.form`. The
slot receives the native `form`, the form's `kind` (`admin.server`), and
`mode` (`'create'` or `'edit'`). Edit slots also receive the saved
`resource`. Contributed `form.AppField` controls share the form's
validation, pending state and submit action.

### Extension-owned fields

An extension registers fields in its provider:

```php
$this->registerFormFields('admin.user', ['plan' => ['required', 'in:free,pro']]);

$this->registerFormFields(
    'admin.node',
    ['region' => ['required', 'string', 'max:32']],
    fn (Node $node): array => ['region' => NodeRegion::for($node)],
    fn (Node $node, array $values) => NodeRegion::store($node, $values['region']),
);
```

The 14 create and update endpoints accept an optional `extensions: {
[extensionId]: { [field]: value } }` body field. Each extension's rules
are applied as `extensions.{id}.{field}`, and only when the request
includes that extension's values. The extension's `save` callback runs
in the same database transaction as the core change, so a failure rolls
both back.

Server creation is the exception. Wings reads the new server while
provisioning it, so extension values are saved after provisioning
succeeds, outside the transaction.

For Node updates when Wings is unreachable. `UpdateNode` saves the node
and then throws `ConfigurationNotPersistedException` as a warning. The
node controller defers that exception until the extension values are
saved, so the node update is no longer rolled back.

`GET /api/admin/extensions/forms/{form}/{id}` returns every extension's
current values. It requires the resource's read permission. Edit pages
fetch it before rendering the form, but only when an extension has
registered fields for that form; the bootstrap payload now lists them
per extension in `forms`.

For users and servers the callbacks are optional, and values are stored
in the extension's scoped settings (`settings()->forUser($user)`,
`forServer($server)`). Values are limited to strings, numbers, booleans,
`null`, or lists of strings and numbers, which keeps the OpenAPI schema
and generated types concrete.

A `load` callback that throws, or returns an invalid value, is recorded
against the extension in the `form` phase. The frontend then hides that
extension's slot contributions on the edit page, so a save cannot
overwrite its stored values with defaults. Fields of a disabled or
failed extension are neither validated, saved nor loaded.

---------

Co-authored-by: robert dennis <31261583+robertdrakedennis@users.noreply.github.com>
2026-10-09 01:26:45 -04:00
robert dennis e217e42360 complexity cleanup 2026-10-08 18:49:15 -04:00
robert dennis cceaa535b8 lint cleanup 2026-10-08 16:54:59 -04:00
6c0413e39b Start 2.0 development
Co-authored-by: Anthony <anthony@infraly.co>
Co-authored-by: Sky Mulley <daniel.mulley@outlook.com>
2026-10-05 18:10:18 -04:00
DaneEveritt dc84af9937 Apply new eslint rules; default to prettier for styling 2022-06-26 15:13:52 -04:00
DaneEveritt 06427f8d13 Don't make two API calls for activity log data 2022-06-11 14:52:33 -04:00
DaneEveritt 0bfba306bf Add filtering support for activity logs 2022-06-05 19:23:25 -04:00
DaneEveritt c6e8b893c8 Add basic activity log view 2022-06-05 18:35:53 -04:00
DaneEveritt a5521ecb79 Add support for returning transforming activity logs on the front-end 2022-05-29 20:34:48 -04:00
DaneEveritt 4d3362b24f Perform a bit of code cleanup 2022-05-22 17:23:48 -04:00
DaneEveritt be88e4e893 Ignore migrations, pass credentials 2022-05-22 17:01:39 -04:00
DaneEveritt f5ad9b9e11 Replace debug bar with clockwork 2022-05-04 19:19:00 -04:00
Dane Everitt bf9cbe2c6d Add consistent CSRF token verification to API endpoints; address security concern with non-CSRF protected endpoints 2021-11-16 20:02:18 -08:00
Dane Everitt b4c64d3dc0 Better handling of file uploads 2020-08-22 22:35:53 -07:00
Dane Everitt fc9054312d Support modifying the primary allocation for a server 2020-07-09 19:56:46 -07:00
Dane Everitt c419d15907 eslint cleanup 2020-07-04 18:30:50 -07:00
Dane Everitt e044e8db1c Show a nicer error message when server is installing 2020-04-17 11:07:32 -07:00
Dane Everitt 1aa3e0fb63 Set bar completed when a request fails 2020-04-17 10:26:36 -07:00
Dane Everitt b9239594ca Don't flood the progress bars when listing resources 2020-04-12 16:08:29 -07:00
Dane Everitt d3a06e1ca8 Add progress bar to top of page for nicer loading indicator styles 2020-04-10 12:41:08 -07:00
Dane Everitt f9878d842c Fix error handling for large files (and endpoints called as non-json) 2020-04-06 21:59:14 -07:00
Dane Everitt 543884876f Add basic subuser listing for servers 2019-11-03 12:20:11 -08:00
Dane Everitt fb9c106448 Update server listing and associated logic to pull from the panel dynamiacally 2019-08-17 16:03:10 -07:00
Dane Everitt b93b40ba31 Begin working on password reset page 2019-06-11 22:02:18 -07:00
Dane Everitt d9f30294de Migrate the existing login form to use React 2019-06-09 19:26:20 -07:00