mattermost/server/public/pluginapi
Felipe Martin 1be8a68dd7
feat: pluginapi: filewillbedownloaded / sendtoastmessage (#34596)
* feat: filewillbedonwloaded hook

* feat: error popup

* chore: make generated pluginapi

* tests

* feat: different errors for different download types

* feat: allow toast positions

* fix: avoid using deprecated i18n function

* feat: add plugin API to show toasts

* feat: downloadType parameter

* tests: updated tests

* chore: make check-style

* chore: i18n

* chore: missing fields in tests

* chore: sorted i18n for webapp

* chore: run mmjstool

* test: fixed webapp tests with new changes

* test: missing mocks

* fix: ensure one-file attachments (previews) are handler properly as thumbnails

* chore: lint

* test: added new logic to tests

* chore: lint

* Add SendToastMessage API and FileWillBeDownloaded hook

- Introduced SendToastMessage method for sending toast notifications to users with customizable options.
- Added FileWillBeDownloaded hook to handle file download requests, allowing plugins to control access to files.
- Updated related types and constants for file download handling.
- Enhanced PluginSettings to include HookTimeoutSeconds for better timeout management.

* Update webapp/channels/src/components/single_image_view/single_image_view.tsx

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* chore: copilot reviews

* test: head requests

* chore: linted the webapp

* tests: fixed path

* test: fixed mocked args

* allow sending message to a connection directly

* fix: hook thread safety

* chore: formatting

* chore: remove configuration from system console

* chore: release version

* chore: update signature

* chore: update release version

* chore: addressed comments

* fix: update file rejection handling to use 403 Forbidden status and include rejection reason header

* Fix nil pointer panic in runFileWillBeDownloadedHook

The atomic.Value in runFileWillBeDownloadedHook can be nil if no
plugins implement the FileWillBeDownloaded hook. This causes a panic
when trying to assert the nil interface to string.

This fix adds a nil check before the type assertion, defaulting to
an empty string (which allows the download) when no hooks have run.

Fixes:
- TestUploadDataMultipart/success panic
- TestUploadDataMultipart/resume_success panic

* test: move the logout test last

* chore: restored accidential deletion

* chore: lint

* chore: make generated

* refactor: move websocket events to new package

* chore: go vet

* chore: missing mock

* chore: revert incorrect fmt

* chore: import ordering

* chore: npm i18n-extract

* chore: update constants.tsx from master

* chore: make i18n-extract

* revert: conflict merge

* fix: add missing isFileRejected prop to SingleImageView tests

* fix: mock fetch in SingleImageView tests for async thumbnail check

The component now performs an async fetch to check thumbnail availability
before rendering. Tests need to mock fetch and use waitFor to handle
the async state updates.

* refactor: move hook logic to app layer

* chore: update version to 11.5

* Scope file download rejection toast to the requesting connection

Thread the Connection-Id header through RunFileWillBeDownloadedHook and
sendFileDownloadRejectedEvent so the WebSocket event is sent only to the
connection that initiated the download, instead of all connections for
the user.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-02-16 17:10:39 +01:00
..
cluster [MM-64654] Migrate to modern Go features (#31820) 2025-07-18 12:54:51 +02:00
experimental MM-64486: Remove telemetry (#33606) 2025-09-04 18:46:18 +00:00
i18n Enforce use of any instead of interface{} (#30588) 2025-03-31 10:44:34 +02:00
bot.go Profile image from bytes (#26610) 2024-03-28 10:56:55 +00:00
bot_test.go Profile image from bytes (#26610) 2024-03-28 10:56:55 +00:00
channel.go [MM-64654] Migrate to modern Go features (#31820) 2025-07-18 12:54:51 +02:00
channel_test.go [MM-53968] Includes mattermost-plugin-api into the mono repo (#24235) 2023-08-21 09:50:30 +02:00
client.go MM-63285: Add property field methods to plugin API (#31035) 2025-06-10 16:10:28 -07:00
cluster.go [MM-53968] Includes mattermost-plugin-api into the mono repo (#24235) 2023-08-21 09:50:30 +02:00
cluster_test.go [MM-53968] Includes mattermost-plugin-api into the mono repo (#24235) 2023-08-21 09:50:30 +02:00
configuration.go Enforce use of any instead of interface{} (#30588) 2025-03-31 10:44:34 +02:00
email.go [MM-53968] Includes mattermost-plugin-api into the mono repo (#24235) 2023-08-21 09:50:30 +02:00
emoji.go [MM-53968] Includes mattermost-plugin-api into the mono repo (#24235) 2023-08-21 09:50:30 +02:00
emoji_test.go [MM-53968] Includes mattermost-plugin-api into the mono repo (#24235) 2023-08-21 09:50:30 +02:00
error.go [MM-53968] Includes mattermost-plugin-api into the mono repo (#24235) 2023-08-21 09:50:30 +02:00
example_client_test.go [MM-53968] Includes mattermost-plugin-api into the mono repo (#24235) 2023-08-21 09:50:30 +02:00
file.go Adding SetFileSearchableContent plugin API endpoint (#24355) 2023-08-30 13:43:40 -07:00
file_test.go [MM-53968] Includes mattermost-plugin-api into the mono repo (#24235) 2023-08-21 09:50:30 +02:00
frontend.go feat: pluginapi: filewillbedownloaded / sendtoastmessage (#34596) 2026-02-16 17:10:39 +01:00
group.go New pluginapi method for syncables (#30790) 2025-05-21 14:44:34 -04:00
kv.go [MM-64654] Migrate to modern Go features (#31820) 2025-07-18 12:54:51 +02:00
kv_memory.go [MM-64654] Migrate to modern Go features (#31820) 2025-07-18 12:54:51 +02:00
kv_memory_test.go [MM-64654] Migrate to modern Go features (#31820) 2025-07-18 12:54:51 +02:00
kv_test.go [MM-64654] Migrate to modern Go features (#31820) 2025-07-18 12:54:51 +02:00
license.go Renamed premium SKU to Enterprise Advanced (#30882) 2025-05-02 11:34:46 +05:30
license_test.go Renamed premium SKU to Enterprise Advanced (#30882) 2025-05-02 11:34:46 +05:30
log.go Enforce use of any instead of interface{} (#30588) 2025-03-31 10:44:34 +02:00
logrus.go Enforce use of any instead of interface{} (#30588) 2025-03-31 10:44:34 +02:00
logrus_test.go [MM-53968] Includes mattermost-plugin-api into the mono repo (#24235) 2023-08-21 09:50:30 +02:00
oauth.go [MM-53968] Includes mattermost-plugin-api into the mono repo (#24235) 2023-08-21 09:50:30 +02:00
plugin_test.go [MM-54014] Run tests in public/... (#24320) 2023-08-22 12:48:53 +02:00
plugins.go [MM-53968] Includes mattermost-plugin-api into the mono repo (#24235) 2023-08-21 09:50:30 +02:00
post.go [MM-64654] Migrate to modern Go features (#31820) 2025-07-18 12:54:51 +02:00
post_test.go [MM-62427] Add message attachments validation (#30180) 2025-03-20 12:53:50 +01:00
property.go Change properties search signature to support multiple TargetIDs (#33873) 2025-09-11 22:56:01 +00:00
property_test.go Change properties search signature to support multiple TargetIDs (#33873) 2025-09-11 22:56:01 +00:00
session.go [MM-53968] Includes mattermost-plugin-api into the mono repo (#24235) 2023-08-21 09:50:30 +02:00
slashcommand.go [MM-53968] Includes mattermost-plugin-api into the mono repo (#24235) 2023-08-21 09:50:30 +02:00
store.go MM-63368: Remove MySQL (#33458) 2025-07-22 20:40:55 +05:30
store_test.go fix(pluginapi/store): init master db if no replica (#29674) 2025-01-02 13:51:22 +05:30
system.go Migrate from gopkg.in/yaml.v3 to github.com/goccy/go-yaml (#34510) 2025-11-18 08:52:05 +01:00
system_test.go Migrate from gopkg.in/yaml.v3 to github.com/goccy/go-yaml (#34510) 2025-11-18 08:52:05 +01:00
team.go [MM-53968] Includes mattermost-plugin-api into the mono repo (#24235) 2023-08-21 09:50:30 +02:00
team_test.go [MM-53968] Includes mattermost-plugin-api into the mono repo (#24235) 2023-08-21 09:50:30 +02:00
user.go PluginAPI: add ability to retrieve users by ids (#26936) 2024-05-15 07:06:40 -07:00
user_test.go PluginAPI: add ability to retrieve users by ids (#26936) 2024-05-15 07:06:40 -07:00
utils.go [MM-64654] Migrate to modern Go features (#31820) 2025-07-18 12:54:51 +02:00
utils_test.go [MM-53968] Includes mattermost-plugin-api into the mono repo (#24235) 2023-08-21 09:50:30 +02:00