diff --git a/CHANGELOG.md b/CHANGELOG.md index b47f2cc67..e0257329d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ [Full changelog][unreleased] +- The date and time a user is deactivated is now stored + ## Release 156 - 2024-12-12 [Full changelog][156] diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 0737c0128..9902c6d30 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -29,7 +29,7 @@ def new end def create - @user = User.new(user_params) + @user = User.new(user_params.except(:active)) authorize @user @service_owner = service_owner @partner_organisations = partner_organisations @@ -60,10 +60,11 @@ def update @partner_organisations = partner_organisations reset_mfa = user_params.delete(:reset_mfa) - @user.assign_attributes(user_params.except(:reset_mfa)) + active = user_params[:active] === "true" + @user.assign_attributes(user_params.except(:reset_mfa, :active)) if @user.valid? - result = UpdateUser.new(user: @user, organisation: organisation, reset_mfa: reset_mfa).call + result = UpdateUser.new(user: @user, active: active, organisation: organisation, reset_mfa: reset_mfa).call if result.success? flash[:notice] = t("action.user.update.success") diff --git a/app/services/update_user.rb b/app/services/update_user.rb index 0ebd9fb80..218bb5cd2 100644 --- a/app/services/update_user.rb +++ b/app/services/update_user.rb @@ -1,10 +1,11 @@ class UpdateUser attr_accessor :user, :organisation, :reset_mfa - def initialize(user:, organisation:, reset_mfa: false) + def initialize(user:, organisation:, active: true, reset_mfa: false) self.user = user self.organisation = organisation self.reset_mfa = reset_mfa + @active = active end def call @@ -18,6 +19,8 @@ def call user.mobile_number_confirmed_at = nil end + user.deactivated_at = @active ? nil : DateTime.now + user.save end