Skip to content

Commit

Permalink
Move reset_current_group to :around_destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
lgalis committed Jan 17, 2018
1 parent 2670de6 commit 27caac8
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/models/miq_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class MiqGroup < ApplicationRecord
validates :description, :presence => true, :unique_within_region => true
validate :validate_default_tenant, :on => :update, :if => :tenant_id_changed?
before_destroy :ensure_can_be_destroyed
around_destroy :reset_current_group_for_users

# For REST API compatibility only; Don't use otherwise!
accepts_nested_attributes_for :entitlement
Expand Down Expand Up @@ -282,10 +283,10 @@ def ensure_can_be_destroyed
raise _("The group has users assigned that do not belong to any other group") if single_group_users?
raise _("A tenant default group can not be deleted") if tenant_group? && referenced_by_tenant?
raise _("A read only group cannot be deleted.") if system_group?
reset_current_group_for_users if current_group_for_any_user?
end

def reset_current_group_for_users
users.where(:current_group_id => id).each(&:change_current_group)
users.where(:current_group_id => id).each(&:change_current_group) if current_group_for_any_user?
yield
end
end

0 comments on commit 27caac8

Please sign in to comment.