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

Improve registrant area #932

Merged
merged 16 commits into from
Sep 19, 2018
Merged

Improve registrant area #932

merged 16 commits into from
Sep 19, 2018

Conversation

artur-intech
Copy link
Contributor

@artur-intech artur-intech commented Aug 12, 2018

  • Improved UI
  • Contacts are now nested under domains
  • Tests added

Part of #849

@@ -26,4 +27,8 @@ def domain_ids
BusinessRegistryCache.fetch_by_ident_and_cc(ident, ident_cc).associated_domain_ids
end
end

def domain
Domain.find(params[:domain_id])
Copy link
Contributor

Choose a reason for hiding this comment

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

This runs a database query every time you call domain. You probably want:

def domain
  @domain ||= Domain.find(params[:domain_id])
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not necessarily true https://guides.rubyonrails.org/caching_with_rails.html#sql-caching.

In general, I agree that ||= is better, but I think it is still a premature optimization, and it's not worth paying too much attention to this.

Copy link
Contributor

@maciej-szlosarczyk maciej-szlosarczyk Aug 14, 2018

Choose a reason for hiding this comment

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

There's an additional problem with that, at the moment it's visible only in the breadcrumb, but it might balloon to something worse.

  1. Go to any registrant's contact show page.
  2. In URL, in id field enter an id from an existing domain that does not belong to the same Registrant.
  3. Observe the breadcrumb - it will have a domain name from a domain that does not belong to this contact or the same user.

image

Copy link
Contributor Author

@artur-intech artur-intech Aug 16, 2018

Choose a reason for hiding this comment

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

Good catch! Not sure if it's worth the effort, since I had to copy-paste some chunk that needs refactoring.

Anyway, it is now fixed. The bug is quite nasty, that's for sure.

<ol class="breadcrumb">
<li><%= link_to t('registrant.domains.index.header'), registrant_domains_path %></li>
<li><%= link_to domain, registrant_domain_path(domain) %></li>
<li><%= t 'registrant.contacts.contact_index' %></li>
Copy link
Contributor

Choose a reason for hiding this comment

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

Please stick to one way of calling translations helpers inside the same file, either with or without brackets.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean? I can't omit t() along with link_to

Copy link
Contributor

Choose a reason for hiding this comment

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

Then use t('registrant.contacts.contact_index') here too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why I should? I consider omitting brackets when they are not needed a good practice.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's assume that it's an internal DSL, and leave it be, but generally, that's not a good practice:
https://github.com/rubocop-hq/ruby-style-guide#method-invocation-parens

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it is DSL. I just find it a bit more clear to omit braces in this particular case.

resources :domains, only: %i[index show] do
resources :contacts, only: %i[show]
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a symbol works too, no need for an Array of one element.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another branch already adds other actions, so it will anyway become an array

<% contacts.each do |contact| %>
<tr>
<td>
<%= link_to contact, registrant_domain_contact_path(domain, contact) %>
Copy link
Contributor

Choose a reason for hiding this comment

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

This is error prone, it depends on us overwriting to_s method for Contact. It would be better if this would be made explicit (contact.name)

https://github.com/internetee/registry/blob/master/app/models/contact.rb#L284-L286

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why providing a custom implementation of to_s for Contact class is a bad thing and what exactly is prone to error given we have tests for that part?

Copy link
Contributor

@maciej-szlosarczyk maciej-szlosarczyk Aug 14, 2018

Choose a reason for hiding this comment

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

It is prone to error because as being implicit, it relies on undocumented behaviour.
None of this is publicly documented, neither in examples for link_to or not in anything that goes deeper than that.
This is where this comes from: https://github.com/rails/rails/blob/v4.2.9/actionview/lib/action_view/helpers/tag_helper.rb#L146

In Rails 5.2, that is changed quite a lot: rails/rails@a65a3bd#diff-2eb399a01976bca6aad9e85aa67b403d

On top of everything, none of the actual tag helper tests test for this scenario (passing an object instead of a string to a tag. https://github.com/rails/rails/blob/master/actionview/test/template/tag_helper_test.rb


Where's the test for this link? Or do you mean the fact that we do have a test for Contact#to_s?

Copy link
Contributor

@maciej-szlosarczyk maciej-szlosarczyk left a comment

Choose a reason for hiding this comment

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

It would be also really good if you'd add tests for the domain/show action and for the new contact/show action. They're missing.

@vohmar vohmar assigned artur-intech and unassigned vohmar Aug 14, 2018
@artur-intech artur-intech force-pushed the improve-registrant-area branch from f5242bc to 5a46620 Compare August 15, 2018 09:58
@maciej-szlosarczyk
Copy link
Contributor

You still have the bug I pointed out. Here's a simple test case against which you can fix it, goes into RegistrantAreaContactDetailsTest.

  # Domain metro belongs to jack, not john. It also does not have any contacts.
  def test_domain_from_different_registrar_does_not_leak_in_view
    visit registrant_domain_contact_url(domains(:metro), @contact)
    refute_text('metro.test')
  end

@artur-intech artur-intech assigned vohmar and unassigned artur-intech Aug 16, 2018
@vohmar
Copy link
Contributor

vohmar commented Aug 16, 2018

Logic of accessing registrant contact data has changed - why? This is not good as throuout the application everywhere user accesses contact data by clicking on the name of the contact (look at admin and tech contacts and registrar records). This change is confusing.
image

@vohmar vohmar assigned artur-intech and unassigned vohmar Aug 16, 2018
@artur-intech
Copy link
Contributor Author

artur-intech commented Aug 16, 2018

From my point of view it's just the opposite. The link explicitly tells a user that he can click on it to see the details of a registrant. As a shortcut, I might revert old behavior as well, if it works for you.

@artur-intech artur-intech mentioned this pull request Sep 1, 2018
@artur-intech artur-intech assigned vohmar and unassigned artur-intech Sep 15, 2018
@vohmar
Copy link
Contributor

vohmar commented Sep 17, 2018

accessing registrant details is still not fixed.

@vohmar vohmar assigned artur-intech and unassigned vohmar Sep 17, 2018
@artur-intech
Copy link
Contributor Author

@vohmar See my question above.

@artur-intech artur-intech force-pushed the improve-registrant-area branch from f0a56e8 to e4db808 Compare September 18, 2018 11:03
@artur-intech
Copy link
Contributor Author

UI is reverted to the previous state.

@artur-intech artur-intech assigned vohmar and unassigned artur-intech Sep 18, 2018
@vohmar vohmar merged commit 64d8be0 into master Sep 19, 2018
@vohmar vohmar deleted the improve-registrant-area branch October 3, 2018 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants