Skip to content

[WIP] bypass feature validation for dynamic tenant features #9523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/controllers/ops_controller/ops_rbac.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def role_allows?(**options)
end

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

super(**options)
Expand Down
16 changes: 11 additions & 5 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ def role_allows?(**options)
return false
end

# ops_rbac role_allows's dynamic tenant features are supported in rbac but not
# with direct lookup in validate_features so we skip it.
validate_features(features) unless !!options.delete(:skip_feature_validation)

Rbac.role_allows?(:user => User.current_user, **options) rescue false
end
module_function :role_allows?
public :role_allows?

def validate_features(features)
# Detect if queried features are missing from the database and possibly invalid
if !Rails.env.production? && features.detect { |feature| !MiqProductFeature.feature_exists?(feature) }
message = "#{__method__} no feature was found with identifier: #{features.inspect}. Correct the identifier or add it to miq_product_features.yml."
Expand All @@ -114,12 +124,8 @@ def role_allows?(**options)
raise("#{message} Note: detected features: #{identifiers.inspect}")
end
end

Rbac.role_allows?(:user => User.current_user, **options) rescue false
end

module_function :role_allows?
public :role_allows?
module_function :validate_features

# NB: This differs from controller_for_model; until they're unified,
# make sure you have the right one.
Expand Down