DEV: Allow plugins to hook into user preferences update process on the server (#21737)

This commit introduces a new `within_user_updater_transaction` event that's triggered inside the transaction that saves user updates in `UserUpdater`. Plugins can hook into the transaction using the event to include custom changes in the transaction. Callbacks for this event receive 2 arguments:

1. the user being saved
2. the changed attributes that are passed to `UserUpdater`.

There's also new modifier in this commit called `users_controller_update_user_params` to allow plugins to allowlist custom params in the `UsersController` which eventually end up getting passed as attributes to the `UserUpdater` and the new `within_user_updater_transaction` event where they can be used to perform additional updates using the custom params.

-----

New API is used in https://github.com/discourse/discourse-mailinglist-integration/pull/1.
This commit is contained in:
Osama Sayegh
2023-05-26 03:26:38 +03:00
committed by GitHub
parent 9268bb92bd
commit bb3c05ba0e
4 changed files with 70 additions and 1 deletions

View File

@@ -2015,7 +2015,13 @@ class UsersController < ApplicationController
end
deprecate_modify_user_params_method
modify_user_params(result)
result = modify_user_params(result)
DiscoursePluginRegistry.apply_modifier(
:users_controller_update_user_params,
result,
current_user,
params,
)
end
# Plugins can use this to modify user parameters