Skip to content

Commit

Permalink
Clean out cashe of MiqProductFeature at CUD tenant actions
Browse files Browse the repository at this point in the history
  • Loading branch information
lpichler committed Dec 20, 2018
1 parent 615df01 commit c5057e5
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 7 deletions.
7 changes: 5 additions & 2 deletions app/assets/javascripts/components/ops/tenant-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ ManageIQ.angular.app.component('tenantComponent', {
templateUrl: '/static/ops/tenant/tenant.html.haml',
});

tenantFormController.$inject = ['API', 'miqService'];
tenantFormController.$inject = ['API', 'miqService', '$http'];

function tenantFormController(API, miqService) {
function tenantFormController(API, miqService, $http) {
var vm = this;

vm.$onInit = function() {
Expand Down Expand Up @@ -67,6 +67,9 @@ function tenantFormController(API, miqService) {
API[method](url, saveObject, {
skipErrors: [400], // server-side validation
})
.then(function() {
return $http.post('/ops/invalidate_miq_product_feature_caches', {});
})
.then(miqService.redirectBack.bind(vm, saveMsg, 'success', vm.redirectUrl))
.catch(miqService.handleFailure);
};
Expand Down
12 changes: 11 additions & 1 deletion app/controllers/ops_controller/ops_rbac.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ module OpsController::OpsRbac
'Tenant' => 'tenant'
}.freeze

def invalidate_miq_product_feature_caches
MiqProductFeature.invalidate_caches
render :json => {}
end

# Edit user or group tags
def rbac_tags_edit
case params[:button]
Expand Down Expand Up @@ -298,7 +303,12 @@ def rbac_tenant_delete
parent_id = Tenant.find(params[:id]).parent.id
self.x_node = "tn-#{parent_id}"
end
process_tenants(tenants, "destroy") unless tenants.empty?

unless tenants.empty?
process_tenants(tenants, "destroy")
MiqProductFeature.invalidate_caches
end

get_node_info(x_node)
replace_right_cell(:nodetype => x_node, :replace_trees => [:rbac])
end
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2563,6 +2563,7 @@
forest_form_field_changed
forest_select
help_menu_form_field_changed
invalidate_miq_product_feature_caches
label_tag_mapping_delete
label_tag_mapping_edit
label_tag_mapping_update
Expand Down
9 changes: 9 additions & 0 deletions spec/controllers/ops_controller/ops_rbac_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
stub_user(:features => :all)
end

it 'confirms existence of route and action with name invalidate_miq_product_feature_caches ' do
EvmSpecHelper.local_miq_server

post :invalidate_miq_product_feature_caches
expect(response.status).to eq(200)
end

describe "rbac_edit_tags_reset" do
let(:admin_user) { FactoryBot.create(:user, :role => "super_administrator") }
let(:another_tenant) { FactoryBot.create(:tenant) }
Expand Down Expand Up @@ -104,6 +111,8 @@

it "deletes a tenant record successfully" do
expect(controller).to receive(:x_active_tree_replace_cell)
expect(MiqProductFeature).to receive(:invalidate_caches)

controller.send(:rbac_tenant_delete)

expect(response.status).to eq(200)
Expand Down
17 changes: 13 additions & 4 deletions spec/javascripts/components/ops/tenant-component_spec.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
describe('tenant-component', function() {
var $componentController, vm, miqService, API;
var $componentController, vm, miqService, API, $httpBackend, deferred;

describe('when the vm.recordId is not defined', function () {

beforeEach(module('ManageIQ'));
beforeEach(inject(function (_$componentController_, _API_, _miqService_, $q) {
beforeEach(inject(function (_$componentController_, _API_, _miqService_, $q, _$httpBackend_) {
$componentController = _$componentController_;
API = _API_;
miqService = _miqService_;

$httpBackend = _$httpBackend_;
spyOn(miqService.redirectBack, 'bind');

var deferred = $q.defer();
deferred = $q.defer();
spyOn(API, 'post').and.callFake(function() {return deferred.promise;});

var bindings = {redirectUrl: '/controller/go_back', divisible: true};
Expand All @@ -28,6 +28,8 @@ describe('tenant-component', function() {
});

it('adds a Tenant record', function () {
$httpBackend.expectPOST('/ops/invalidate_miq_product_feature_caches').respond({});

vm.tenantModel.name = 'newTenant';
vm.tenantModel.description = 'newTenant_desc';
vm.tenantModel.ancestry = null;
Expand All @@ -43,8 +45,15 @@ describe('tenant-component', function() {
}, {
skipErrors: [400],
});

deferred.resolve({});

expect(miqService.redirectBack.bind).toHaveBeenCalledWith(vm, 'Tenant \"newTenant\" has been successfully added.', 'success', vm.redirectUrl);
});

afterEach(function () {
$httpBackend.verifyNoOutstandingExpectation();
});
});

describe('when the vm.recordId is defined', function () {
Expand Down

0 comments on commit c5057e5

Please sign in to comment.