* Add pre_auth webapp manifest flag and RestrictUnauthenticatedWebappPlugins setting
Unauthenticated GET /api/v4/plugins/webapp now only returns plugins whose
manifest sets webapp.pre_auth, with a trimmed manifest, when the new
PluginSettings.RestrictUnauthenticatedWebappPlugins setting is enabled. The
setting defaults to true for new installations and is turned off by a one-time
migration on existing installations.
Co-authored-by: Joram Wilander <joram@mattermost.com>
* Add server tests for pre-auth webapp plugin filtering
Co-authored-by: Joram Wilander <joram@mattermost.com>
* Load remaining webapp plugins after login and add admin console toggle
The login page may only receive pre-auth plugins, so performLogin now awaits a
plugin re-sync before callers navigate, and LoggedIn re-syncs as a fallback
when the plugin list was last fetched for a different session.
Co-authored-by: Joram Wilander <joram@mattermost.com>
* Add webapp tests for post-login plugin re-sync
Co-authored-by: Joram Wilander <joram@mattermost.com>
* Add Playwright E2E coverage for pre-auth webapp plugins
Co-authored-by: Joram Wilander <joram@mattermost.com>
* Add system console E2E spec for the RestrictUnauthenticatedWebappPlugins toggle
Co-authored-by: Joram Wilander <joram@mattermost.com>
* Add upgrade E2E check that existing installs keep unauthenticated webapp plugins
Co-authored-by: Joram Wilander <joram@mattermost.com>
* Fix err shadowing lint failure in TestGetWebappPluginsUnauthenticated
Co-authored-by: Joram Wilander <joram@mattermost.com>
* Only record the plugin fetch session after a successful fetch
Co-authored-by: Joram Wilander <joram@mattermost.com>
* Document RestrictUnauthenticatedWebappPlugins and webapp.pre_auth
Co-authored-by: Joram Wilander <joram@mattermost.com>
* Note that pre-auth webapp plugin filtering is available from v12.2
Co-authored-by: Joram Wilander <joram@mattermost.com>
* Reword pre_auth version note in OpenAPI schema
Co-authored-by: Joram Wilander <joram@mattermost.com>
* Revert "Reword pre_auth version note in OpenAPI schema"
This reverts commit f5660f836b.
Co-authored-by: Joram Wilander <joram@mattermost.com>
---------
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
5.6 KiB
title, sidebar_position
| title | sidebar_position |
|---|---|
| Web app plugins | 20 |
Web app plugins extend and modify the Mattermost web and desktop apps, without having to fork and rebase on every Mattermost release.
Looking for a quick start? See our "Hello, world!" tutorial.
Want the web app SDK reference doc? Find it here.
Features
Extend existing components
Register your own React components to be added to the channel header, sidebars, user details popover, main menu and other supported components. Multiple plugins can add to the same component simultaneously. This API focuses on ease of use and maintaining compatibility with future Mattermost releases.
For example, the Mattermost Zoom Plugin registers a button in the channel header to trigger a Zoom call and post a link to the call in the current channel.
Add new root components
Register your own React components alongside other root components like the sidebars and modals. This enables whole new interactions that aren't constrained by the set of existing components. This API is geared towards power and flexibility, but may require fine tuning with future Mattermost releases.
Custom post type components
Web app plugins can also render different post components based on the post's type. Any time the web app encounters a post with this post type, it replaces the default rendering of the post component with your own custom implementation. Only one plugin can own the rendering for a given custom post type at a time: the last plugin to register will own the rendering for that custom post type.
For example, you can register a custom post type custom_poll using registerPostTypeComponent. Then, any time the web app sees that post type, it replaces the regular rendering of the post component with your own custom implementation.
Use this in conjunction with setting the post type in webhooks or slash commands, through the REST API or with a server plugin, and you can deeply integrate or extend Mattermost posts to fit your needs.
How it works
When a plugin is uploaded to a Mattermost server and activated, the server checks to see if there is a webapp portion included as part of the plugin by looking at the plugin's manifest. If one is found, the server copies the bundled JavaScript included with the plugin into the static directory for serving. A WebSocket event is then fired off to the connected clients signalling the activation of a new plugin.
On web app launch, a request is made to the server to get a list of plugins that contain web app components. The web app then proceeds to download and execute the JavaScript bundles for each plugin. A similar process happens if an already launched web app receives a WebSocket event for a newly activated plugin.
Once downloaded and executed, each plugin should have registered itself via the global registerPlugin. The web app then invokes the initialize function defined on the plugin class, passing a registry and store. The registry passed allows the plugin to register (and unregister) components, event callbacks and Redux reducers to track plugin state. The store passed is the same Redux store used by the web app, giving the plugin access to the full state of the web app.
Components registered by the plugin via the registry are tracked in the Redux store and used by Pluggable components throughout the web app. Pluggable components with a pluggableName attribute can render multiple such components registered by plugins.
Custom post types work similarly, but are registered slightly differently, use a separate reducer and have more of a custom implementation.
Redux actions
Further information on the available Redux Actions is documented here: Redux Actions
Best practices
Some best practices for working with the webapp component of a plugin are documented here: Best Practices
Loading before login with pre_auth
The webapp.pre_auth field and the Restrict Plugins Available Before Login setting require Mattermost v12.2 or later. On earlier servers, the field is ignored and all enabled plugins load before login.
Some plugins must run before users log in, such as those that provide custom login buttons, authentication handlers, or logged-out custom routes. To enable your plugin to load on the login page and other pre-authentication pages, set the webapp.pre_auth field to true in your plugin manifest:
{
"webapp": {
"bundle_path": "webapp/dist/main.js",
"pre_auth": true
}
}
When the System Console setting Restrict Plugins Available Before Login is enabled (which is the default for new installations), only plugins declaring pre_auth will be available to unauthenticated users. If this setting is disabled, all enabled plugins are available before login. For more details, see Restrict plugins available before login.
React and JSX runtime compatibility
Plugins that render inside Mattermost must use the host's React, ReactDOM, and JSX runtime. See React JSX runtime compatibility to configure the host exports and require Mattermost 12.0 or later.