Skip to content

Commit 3118187

Browse files
committed
Merge pull request #9523 from jrafanie/skip-product-feature-validation-for-tenant-dynamic-product-features
Bypass feature validation for dynamic tenant features (cherry picked from commit 71881e1)
1 parent 58b6475 commit 3118187

File tree

3 files changed

+64
-5
lines changed

3 files changed

+64
-5
lines changed

app/controllers/ops_controller/ops_rbac.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ def role_allows?(**options)
1717
end
1818

1919
options[:feature] = MiqProductFeature.tenant_identifier(options[:feature], id)
20+
# dynamic tenant feature identifiers need to bypass feature validation
21+
options[:skip_feature_validation] = true
2022
end
2123

2224
super(**options)

app/helpers/application_helper.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ def role_allows?(**options)
104104
return false
105105
end
106106

107+
# ops_rbac role_allows's dynamic tenant features are supported in rbac but not
108+
# with direct lookup in validate_features so we skip it.
109+
validate_features(features) unless !!options.delete(:skip_feature_validation)
110+
111+
Rbac.role_allows?(:user => User.current_user, **options) rescue false
112+
end
113+
module_function :role_allows?
114+
public :role_allows?
115+
116+
def validate_features(features)
107117
# Detect if queried features are missing from the database and possibly invalid
108118
if !Rails.env.production? && features.detect { |feature| !MiqProductFeature.feature_exists?(feature) }
109119
message = "#{__method__} no feature was found with identifier: #{features.inspect}. Correct the identifier or add it to miq_product_features.yml."
@@ -114,12 +124,8 @@ def role_allows?(**options)
114124
raise("#{message} Note: detected features: #{identifiers.inspect}")
115125
end
116126
end
117-
118-
Rbac.role_allows?(:user => User.current_user, **options) rescue false
119127
end
120-
121-
module_function :role_allows?
122-
public :role_allows?
128+
module_function :validate_features
123129

124130
# NB: This differs from controller_for_model; until they're unified,
125131
# make sure you have the right one.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* eslint-disable no-undef */
2+
import { flashClassMap } from '../../../../support/assertions/assertion_constants';
3+
4+
describe('Settings > Application Settings > Access Control', () => {
5+
// Navigation
6+
const PRIMARY_MENU_OPTION = 'Settings';
7+
const SECONDARY_MENU_OPTION = 'Application Settings';
8+
const ACCORDION = 'Access Control';
9+
const TOOLBAR_MENU = 'Configuration';
10+
11+
// Created item information
12+
const INITIAL_TENANT_NAME = 'Test-name';
13+
const INITIAL_TENANT_DESCRIPTION = 'test description';
14+
15+
// CRUD actions
16+
const FLASH_MESSAGE_OPERATION_ADDED = 'added';
17+
const FLASH_MESSAGE_OPERATION_DELETED = 'delete';
18+
const DELETE_ITEM = 'Delete this item';
19+
20+
beforeEach(() => {
21+
cy.login();
22+
cy.menu(PRIMARY_MENU_OPTION, SECONDARY_MENU_OPTION);
23+
cy.accordion(ACCORDION);
24+
});
25+
26+
it('should be able to create and delete a tenant', () => {
27+
cy.selectAccordionItem([
28+
/^ManageIQ Region/,
29+
'Tenants',
30+
'My Company',
31+
]);
32+
33+
cy.toolbar(TOOLBAR_MENU, 'Add child Tenant to this Tenant');
34+
cy.getFormInputFieldById('name').type(INITIAL_TENANT_NAME);
35+
cy.getFormInputFieldById('description').type(INITIAL_TENANT_DESCRIPTION);
36+
cy.getFormFooterButtonByType('Add', 'submit').click();
37+
cy.expect_flash(flashClassMap.success, FLASH_MESSAGE_OPERATION_ADDED);
38+
cy.selectAccordionItem([
39+
/^ManageIQ Region/,
40+
'Tenants',
41+
'My Company',
42+
INITIAL_TENANT_NAME
43+
]);
44+
45+
cy.expect_browser_confirm_with_text({
46+
confirmTriggerFn: () => cy.toolbar(TOOLBAR_MENU, DELETE_ITEM),
47+
containsText: DELETE_ITEM,
48+
});
49+
cy.expect_flash(flashClassMap.success, FLASH_MESSAGE_OPERATION_DELETED);
50+
});
51+
});

0 commit comments

Comments
 (0)