-
Notifications
You must be signed in to change notification settings - Fork 356
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
Server summary page changes #3754
Server summary page changes #3754
Conversation
@miq-bot add_label WIP |
@AparnaKarve I would like to make external links for the IPv4 addresses, but it doesn't seem to be interpreting the tag correctly. See the screenshot below: Any idea on how I can get this to work? Thanks |
@@ -109,7 +109,7 @@ def textual_ipv4 | |||
# It is possible for guest devices not to have network data (or a network | |||
# hash). As a result, we need to exclude guest devices that don't have | |||
# network data to prevent a nil class error from occurring. | |||
{:label => _("IPv4 Address"), :value => @record.hardware.guest_devices.reject { |device| device.network.nil? }.collect { |device| device.network.ipaddress }.join(", ") } | |||
{:label => _("IPv4 Address"), :value => @record.hardware.guest_devices.reject { |device| device.network.nil? }.collect { |device| create_https_url(device.network.ipaddress) }.join(", ") } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this to -
{:label => _("IPv4 Address"), :value => @record.hardware.guest_devices.reject { |device| device.network.nil? }.collect { |device| create_https_url(device.network.ipaddress) }.join(", ").html_safe }
url = "" | ||
|
||
unless ip.nil? | ||
url = link_to(ip, "https://#{ip}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change this to -
url = link_to(ip, "https://#{ip}", :target => "_blank")
to open the link in a new browser tab
@skovic Please take a look at the suggested inline solution. |
… are displayed properly
@miq-bot remove_label wip |
@AparnaKarve Thank you for your suggestions. I got the links to work. |
@skovic Great! Thanks for the update. |
# with a comma. Then split this string back into an array using a comma, possibly | ||
# followed by whitespace as the delimiter. Finally, iterate through the array | ||
# and convert each element into a URL containing an IP address. | ||
ip_addresses = ip_addresses.join(",").split(/,\s*/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@skovic Can you write a spec for textual_ipv4
for some of these IP address related use cases (comma separated multiple IP addresses, single IP addresses etc) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AparnaKarve As requested, I wrote a spec test for textual_ipv4. Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@skovic Thanks - the spec looks good!
end | ||
|
||
url | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def create_https_url(id)
ip.present? ? link_to(ip, "https://#{ip}", :target => "_blank") : ''
end
or better use the URI
module
def create_https_url(id)
ip.present? ? link_to(ip, URI::HTTPS.build(:host => ip), :target => "_blank") : ''
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@martinpovolny I tried using the URI::HTTPS.build method, but it's causing the following error:
undefined method 'to_model' for #<URI::HTTPS https://10.243.6.68> [physical_server/show]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@martinpovolny Never mind, I got past the error by calling the to_s method on the object that's returned by the build method.
@skovic It looks like there is a security risk warning with |
ip_addresses = ip_addresses.join(",").split(/,\s*/) | ||
ip_address_urls = ip_addresses.collect { |ip_address| create_https_url(ip_address) } | ||
|
||
{:label => _("IPv4 Address"), :value => ip_address_urls.join(", ").html_safe } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the sanitize
method as shown below would be a good substitute for html_safe
and would take care of the rubocop security risk warning -
{:label => _("IPv4 Address"), :value => sanitize(ip_address_urls.join(", "), :attributes => %w(href target)) }
Checked commits skovic/manageiq-ui-classic@77dd19c~...d6a7f4d with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 |
@AparnaKarve Looks like using sanitize took care of the security warning. Thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@skovic LGTM!
This PR makes the following changes to the Physical Server Summary page: