Skip to content

Commit

Permalink
Move product feature create for a tenant into MiqProductFeature
Browse files Browse the repository at this point in the history
  • Loading branch information
Fryguy committed May 23, 2019
1 parent eba2c8d commit cb61dd4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 30 deletions.
21 changes: 17 additions & 4 deletions app/models/miq_product_feature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,27 @@ def self.with_tenant_feature_root_features
where(:identifier => TENANT_FEATURE_ROOT_IDENTIFIERS)
end

def self.seed_tenant_miq_product_features
result = with_tenant_feature_root_features.map.each do |tenant_miq_product_feature|
Tenant.in_my_region.all.map { |tenant| tenant.build_miq_product_feature(tenant_miq_product_feature) }
end.flatten
def self.seed_single_tenant_miq_product_features(tenant)
result = MiqProductFeature.with_tenant_feature_root_features.map do |miq_product_feature|
{
:name => miq_product_feature.name,
:description => miq_product_feature.description,
:feature_type => 'admin',
:hidden => false,
:identifier => tenant_identifier(miq_product_feature.identifier, tenant.id),
:tenant_id => tenant.id,
:parent_id => miq_product_feature.id
}
end

MiqProductFeature.invalidate_caches
MiqProductFeature.create(result).map(&:identifier)
end

def self.seed_tenant_miq_product_features
Tenant.in_my_region.all.flat_map { |t| seed_single_tenant_miq_product_features(t) }
end

def self.seed_features(path = FIXTURE_PATH)
fixture_yaml = feature_yaml(path)

Expand Down
22 changes: 1 addition & 21 deletions app/models/tenant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,27 +302,7 @@ def allowed?
end

def create_miq_product_features_for_tenant_nodes
result = MiqProductFeature.with_tenant_feature_root_features.map.each do |tenant_miq_product_feature|
build_miq_product_feature(tenant_miq_product_feature)
end.flatten

result = MiqProductFeature.create(result).map(&:identifier)

MiqProductFeature.invalidate_caches
result
end

def build_miq_product_feature(miq_product_feature)
attrs = {
:name => miq_product_feature.name, :description => miq_product_feature.description,
:feature_type => 'admin',
:hidden => false,
:identifier => MiqProductFeature.tenant_identifier(miq_product_feature.identifier, id),
:tenant_id => id,
:parent_id => miq_product_feature.id
}

attrs
MiqProductFeature.seed_single_tenant_miq_product_features(self)
end

private
Expand Down
8 changes: 3 additions & 5 deletions spec/models/tenant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -876,12 +876,10 @@
end
end

describe "#destroy_tenant_feature_for_tenant_node" do
it "destroys product features" do
tenant_product_feature.destroy
it "destroys product features on destroy" do
tenant_product_feature.destroy

expect(MiqProductFeature.where(:identifier => ["dialog_edit_editor_tenant_#{tenant_product_feature.id}", "ab_group_admin_tenant_#{tenant_product_feature.id}"], :feature_type => 'tenant').count).to be_zero
end
expect(MiqProductFeature.where(:identifier => ["dialog_edit_editor_tenant_#{tenant_product_feature.id}", "ab_group_admin_tenant_#{tenant_product_feature.id}"], :feature_type => 'tenant').count).to be_zero
end
end
end
Expand Down

0 comments on commit cb61dd4

Please sign in to comment.