-
Notifications
You must be signed in to change notification settings - Fork 983
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #16725 - add plugin extension point for smart proxies
- Loading branch information
1 parent
a4d7a03
commit c676093
Showing
44 changed files
with
396 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
app/controllers/concerns/foreman/controller/parameters/smart_proxies_common.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Foreman::Controller::Parameters::SmartProxiesCommon | ||
extend ActiveSupport::Concern | ||
|
||
class_methods do | ||
def add_smart_proxies_common_params_filter(filter) | ||
filter.resource_class.registered_smart_proxies.keys.each do |proxy| | ||
filter.permit proxy, :"#{proxy}_id", :"#{proxy}_name" | ||
end | ||
filter | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
module SharedSmartProxiesHelper | ||
def smart_proxy_fields(f, options = {}) | ||
object = options.fetch(:object, f.object) | ||
|
||
safe_join(object.registered_smart_proxies.map do |proxy_name, proxy_options| | ||
smart_proxy_select_f(f, proxy_name, options.merge(proxy_options)) | ||
end) | ||
end | ||
|
||
INHERIT_TEXT = N_("inherit") | ||
|
||
def smart_proxy_select_f(f, resource, options) | ||
required = options.fetch(:required, false) | ||
hidden = options[:if].present? && !options[:if].call(f.object) | ||
can_override = options.fetch(:can_override, false) | ||
override = options.fetch(:override, false) | ||
blank = options.fetch(:blank, blank_or_inherit_f(f, resource)) | ||
|
||
proxies = accessible_smart_proxies(f.object, resource, options[:feature]) | ||
return if !required && !proxies.present? | ||
|
||
select_options = { | ||
:disable_button => can_override ? _(INHERIT_TEXT) : nil, | ||
:disable_button_enabled => override && !explicit_value?(:"#{resource}_id"), | ||
:user_set => user_set?(:"#{resource}_id") | ||
} | ||
select_options[:include_blank] = blank unless required | ||
|
||
select_f f, :"#{resource}_id", proxies, :id, :name, | ||
select_options, | ||
:label => _(options[:label]), | ||
:help_inline => _(options[:description]), | ||
:wrapper_class => "form-group #{'hide' if hidden}" | ||
end | ||
|
||
def accessible_smart_proxies(obj, resource, feature) | ||
list = accessible_resource_records(:smart_proxy).with_features(feature).to_a | ||
current = obj.public_send(resource) if obj.respond_to?(resource) | ||
list |= [current] if current.present? | ||
list | ||
end | ||
end |
Oops, something went wrong.