Skip to content
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

Merged
merged 8 commits into from
Apr 19, 2018

Conversation

skovic
Copy link

@skovic skovic commented Apr 11, 2018

This PR makes the following changes to the Physical Server Summary page:

  1. Make the IPv4 address in the Management Networks table a link so that it's clickable.
  2. Change the name of the Assets table to Asset Details.

image

@skovic
Copy link
Author

skovic commented Apr 11, 2018

@miq-bot add_label WIP

@miq-bot miq-bot changed the title Server summary page changes [WIP] Server summary page changes Apr 11, 2018
@miq-bot miq-bot added the wip label Apr 11, 2018
@skovic
Copy link
Author

skovic commented Apr 11, 2018

@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:

image

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(", ") }
Copy link
Contributor

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}")
Copy link
Contributor

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

@AparnaKarve
Copy link
Contributor

@skovic Please take a look at the suggested inline solution.

@skovic
Copy link
Author

skovic commented Apr 13, 2018

@miq-bot remove_label wip

@miq-bot miq-bot changed the title [WIP] Server summary page changes Server summary page changes Apr 13, 2018
@miq-bot miq-bot removed the wip label Apr 13, 2018
@skovic
Copy link
Author

skovic commented Apr 13, 2018

@AparnaKarve Thank you for your suggestions. I got the links to work.

@AparnaKarve
Copy link
Contributor

@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*/)
Copy link
Contributor

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) ?

Copy link
Author

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

Copy link
Contributor

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
Copy link
Member

@martinpovolny martinpovolny Apr 16, 2018

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

Copy link
Author

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]

Copy link
Author

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.

@AparnaKarve
Copy link
Contributor

@skovic It looks like there is a security risk warning with html_safe.
Let me check if there are other alternatives to using html_safe

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 }
Copy link
Contributor

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)) }

@miq-bot
Copy link
Member

miq-bot commented Apr 18, 2018

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
3 files checked, 0 offenses detected
Everything looks fine. 🍪

@skovic
Copy link
Author

skovic commented Apr 18, 2018

@AparnaKarve Looks like using sanitize took care of the security warning. Thanks

Copy link
Contributor

@AparnaKarve AparnaKarve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@skovic LGTM!

@h-kataria h-kataria added this to the Sprint 84 Ending Apr 23, 2018 milestone Apr 19, 2018
@h-kataria h-kataria merged commit 6f3c954 into ManageIQ:master Apr 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants