Skip to content

Commit

Permalink
882311 - remove scope-based organization hiding when deleting it
Browse files Browse the repository at this point in the history
  • Loading branch information
lzap committed Jan 10, 2013
1 parent 2d91fdc commit e990417
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 20 deletions.
14 changes: 4 additions & 10 deletions src/app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,25 @@ class Organization < ActiveRecord::Base

attr_accessor :statistics

default_scope where(:task_id=>nil) #ignore organizations that are being deleted
# Organizations which are being deleted (or deletion failed) can be filtered out with this scope.
scope :without_deleting, where(:task_id => nil)

before_create :create_library
before_create :create_redhat_provider
validates :name, :uniqueness => true, :presence => true, :katello_name_format => true
validates :label, :uniqueness => true, :presence => true, :katello_label_format => true
validates :label, :uniqueness => { :message => _("already exists (including organizations being deleted)") },
:presence => true, :katello_label_format => true
validates :description, :katello_description_format => true
validate :unique_name_and_label

before_save { |o| o.system_info_keys = Array.new unless o.system_info_keys }

if Katello.config.use_cp
before_validation :create_label, :on => :create
validate :unique_label

def create_label
self.label = self.name.tr(' ', '_') if self.label.blank? && self.name.present?
end

def unique_label
# org is being deleted
if Organization.find_by_label(self.label).nil? && Organization.unscoped.find_by_label(self.label)
errors.add(:organization, _(" '%s' already exists and either has been scheduled for deletion or failed deletion.") % self.label)
end
end
end

# Ensure that the name and label namespaces do not overlap
Expand Down
2 changes: 1 addition & 1 deletion src/app/models/organization_destroyer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def setup(organization)
end

def run
organization = Organization.unscoped.find organization_id
organization = Organization.find organization_id
organization.destroy

Notify.success _("Successfully removed organization '%s'.") % organization.name,
Expand Down
10 changes: 1 addition & 9 deletions src/app/models/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def prevent_redhat_deletion
Rails.logger.error _("Red Hat provider can not be deleted")
false
else
# organization that is being deleted via background destroyer can delete rh provider
true
end
end
Expand Down Expand Up @@ -104,15 +105,6 @@ def has_subscriptions?
redhat_provider?
end

def organization
# note i need to add 'unscoped' here
# to account for the fact that org might have been "scoped out"
# on an Org delete action.
# we need the organization info to be present in the provider
# so that we can properly phase out the orchestration and handle search indices.
(read_attribute(:organization) || Organization.unscoped.find(self.organization_id)) if self.organization_id
end

def being_deleted?
! organization.task_id.nil?
end
Expand Down

0 comments on commit e990417

Please sign in to comment.