Repository navigation
Conversation
…ngs API and UI files
…I files and example plugins
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
CI runs the TimescaleDB and MariaDB jobs with NATS and two workers, where the 15 s notification dedup dropped login and user events already claimed by earlier tests.
…cure on private IPs The plugin UI cookie held the owner's full API token and outlived logout. It now holds a 30 minute token (access=plugin_ui, pid=<plugin>) that the panel API rejects and that opens only the UI files of that plugin; the cookie is a session cookie and the dashboard renews it while the page is open. Plain HTTP on a private or loopback IP no longer sets Secure, so the iframe loads there too.
…ling /sub A headers hook that returned a non latin-1 value, a CR/LF or a bad name made every /sub request answer 400. Each pair is now checked with the same rules as admin headers (moved to app/utils/headers.py), lowercased, and a bad pair is logged and skipped. Cache-Control is set lowercase so a plugin cannot add a second one.
… form A nullable string saved as '' after any save, and an empty optional enum was sent as '' and refused with 422. An empty input now becomes null when the schema allows null; otherwise the key is left out, except a text field that already had a value.
…load If loading the settings failed, the form stayed enabled and Save replaced the stored settings with empty values. Fields and Save now stay disabled until the settings load, and the error is shown with a retry button. Also link field descriptions and errors to the inputs for screen readers and reuse the common save/saving texts.
… direction The plugins pages showed "no plugins" or "not found" when the request failed; they now show the error with a retry button. The plugin name in the page header is no longer passed through i18n. The plugin frame is keyed by plugin id, and the SDK gets the text direction from the dashboard instead of guessing it from lang === "fa".
The facade argument is named api_key, which is in SENSITIVE_KEYS, so the whole key object was dropped and plugins got no id, name or status. Only plain values are dropped by name now; models keep their fields and still lose the raw api_key field.
With UVICORN_WORKERS>1 plugin events shared the notification dedup slot, keyed by event name and object id only, so a state change inside the 15 s window (disabled then enabled, failed then successful login) was lost. Plugin events now claim their own slot keyed by the event and its payload without usage counters and timestamps; notifications keep their dedup as before.
…ground The NATS listener awaits handlers one by one, so a slow on_change hook held up every other sync message (settings, nodes, cores, hosts) on all workers. A refresh now applies the values and clears the subscription cache at once, then runs the hooks in a background task; hooks of one plugin run one change at a time, in order. A sync hook runs in a worker thread with the same 10 s limit. Pending hooks are awaited at shutdown. The settings PUT still waits for the hooks in its own worker. The test of the PUT now also checks the message published to other workers and a PUT from a non-owner.
/settings, /ui-session and /ui/... under /api/plugins/<id> belong to the panel and are matched first, so such a plugin route never ran while the plugin showed as loaded. Activation now fails with a clear error, also for routes from included sub-routers.
…ngs at once The second INSERT broke the primary key and the owner got a 503. The save now rolls back and updates the row the other worker created. The extra refresh after commit is gone.
init_plugins: stored settings are applied at startup, the NATS handler is registered on the plugin topic, and a failing async setup or activation leaves the plugin failed with no routes. Changing settings clears cached subscriptions (via PUT and via a NATS refresh), and invalid stored settings fall back to defaults.
… hooks The banner opened a second pooled connection on every uncached render while the request still held its own; under load it waited for the pool timeout and the banner silently disappeared. The plugin now keeps user id -> group names in memory: loaded in an async setup at startup, refreshed in the background every 60 s, and updated from user events. The hooks only read that map.
…last Two errors on the same field overwrote each other in the 422 detail; they are joined now.
It shared its name with the PluginSettings ORM model; the env variables are unchanged.
…outes Protected plugin routes let in any admin or API key, sub-admins and limited keys included. Plugins can now require a role permission the same way panel routes do; the docstring says plainly what "admin" means.
Covers /sub/<token> with the format picked by User-Agent: the plugin sees that format, the admin's response header beats the plugin header, a built-in header the admin did not set is overridden by the plugin, and the admin's custom variable beats the plugin variable.
…in all READMEs The README is a short landing page kept in four languages, so it now has a few lines on plugins (what they are, the trust warning, PLUGINS_DIR and PLUGINS) in English, Persian, Russian and Chinese, linking to the full guide in examples/plugins/README.md. The guide is updated: what "admin" means for plugin routes and ctx.deps.permission, reserved paths, the short plugin-only UI cookie, the text direction, and keeping database reads out of subscription hooks.
With 2 workers and NATS the cross-worker claim could wait about 5 s for a NATS timeout, so the handler did not run in time.
The notification claim runs before the plugin event and can also wait for a NATS timeout with 2 workers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
RFC / draft. A small server-side plugin system, so panel owners can add their own logic and pages without forking. The goal is to cover the common needs with a minimal, explicit API, not to build a full extension framework. Common needs here: reports, notifications, subscription tweaks and small admin pages.
PLUGINS_DIR, enabled by name withPLUGINS=a,b. Nothing loads by default. Each plugin has aplugin.tomlmanifest and asetup(ctx)entry point.ctxgives a plugin:/api/plugins/<id>; every route requires an authenticated admin, and owner-only routes are available;user.created,user.status_changed,node.error,admin.login, …), the same set as panel notifications;plugin_settings(migrationd4e7a9c2b5f1), editable in the dashboard and synced to other workers over NATS;examples/plugins/:expiring-report: a page listing users that expire within N days, with CSV export and a daily log line;sub-banner: an info line on top of link subscriptions, plus a{PLAN}variable.Type of change
Checklist
Testing
By hand with
PLUGINS=expiring-report,sub-banner: both plugins load, the plugin page opens in the iframe, the settings form saves, and the banner appears in a link subscription.Screenshots
Will add in a comment.
Notes for reviewers
plugin.tomldeclare a minimum panel version?c8d2e4f6a1b3.