-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The PasswordHelpers mixin is split into to parts: * PasswordHelpers contains helpers for updating user password * UserAdminHelpers, inheriting from PasswordHelpers, also includes helpers for creating new users Rails 7.1 by default raises exceptions when attempting to create callback for actions that do not exist. This caused exceptions with SuperAdminController, which does not have the `create` action for creating new users.
- Loading branch information
Showing
5 changed files
with
51 additions
and
30 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
module UserAdminHelpers < PasswordHelpers | ||
included do | ||
before_action :set_resource_params, only: :create | ||
before_action :set_temporary_password, only: :create | ||
end | ||
|
||
# devise mail backgrounding achieved via User#send_devise_notification | ||
def deliver_reset_password_instructions(user) | ||
token, enc = Devise.token_generator.generate(user.class, :reset_password_token) | ||
user.reset_password_token = enc | ||
user.reset_password_sent_at = Time.now.utc | ||
user.save(validate: false) | ||
DeviseMailer.reset_password_instructions(user, token, current_user.name).deliver_later | ||
rescue StandardError => e | ||
Rails.logger.error("DEVISE MAILER ERROR: '#{e.message}' while sending reset password mail") | ||
end | ||
|
||
private | ||
|
||
def user_for_controller_action | ||
instance_variable_get(:"@#{controller_name.singularize}").user | ||
end | ||
|
||
def params_with_temporary_password | ||
@resource_params['user_attributes']['password'] = @temporary_password | ||
@resource_params['user_attributes']['password_confirmation'] = @temporary_password | ||
@resource_params | ||
end | ||
|
||
def password_params | ||
%i[email first_name last_name].each { |attribute| @user_params[:user_attributes].delete(attribute) } | ||
@user_params | ||
end | ||
|
||
def set_resource_params | ||
resource = controller_name.singularize | ||
@resource_params = send((resource + '_params').to_sym) | ||
end | ||
|
||
def set_user_params | ||
@user_params = @resource_params.slice(:user_attributes) | ||
end | ||
|
||
def set_temporary_password | ||
@temporary_password = SecureRandom.uuid | ||
end | ||
end |
2 changes: 1 addition & 1 deletion
2
app/controllers/external_users/admin/external_users_controller.rb
This file contains 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
2 changes: 1 addition & 1 deletion
2
app/controllers/provider_management/external_users_controller.rb
This file contains 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