| 64 | end |
| 65 | |
| 66 | def update |
| 67 | return redirect_to settings_users_path, notice: I18n.t('unable_to_update_user') if Docuseal.demo? |
| 68 | |
| 69 | attrs = user_params.compact_blank |
| 70 | attrs = attrs.merge(user_params.slice(:archived_at)) if current_ability.can?(:create, @user) |
| 71 | |
| 72 | if params.dig(:user, :account_id).present? |
| 73 | account = Account.accessible_by(current_ability).find(params.dig(:user, :account_id)) |
| 74 | |
| 75 | authorize!(:manage, account) |
| 76 | |
| 77 | @user.account = account |
| 78 | end |
| 79 | |
| 80 | if @user.update(attrs.except(*(current_user == @user ? %i[password otp_required_for_login role] : %i[password]))) |
| 81 | if @user.try(:pending_reconfirmation?) && @user.previous_changes.key?(:unconfirmed_email) |
| 82 | SendConfirmationInstructionsJob.perform_async('user_id' => @user.id) |
| 83 | |
| 84 | redirect_back fallback_location: settings_users_path, |
| 85 | notice: I18n.t('a_confirmation_email_has_been_sent_to_the_new_email_address') |
| 86 | else |
| 87 | redirect_back fallback_location: settings_users_path, notice: I18n.t('user_has_been_updated') |
| 88 | end |
| 89 | else |
| 90 | render turbo_stream: turbo_stream.replace(:modal, template: 'users/edit'), status: :unprocessable_content |
| 91 | end |
| 92 | end |
| 93 | |
| 94 | def destroy |
| 95 | if Docuseal.demo? || @user.id == current_user.id |
no test coverage detected