-
Notifications
You must be signed in to change notification settings - Fork 19
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
Conversation
@@ -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]) |
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.
This runs a database query every time you call domain
. You probably want:
def domain
@domain ||= Domain.find(params[:domain_id])
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.
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.
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.
There's an additional problem with that, at the moment it's visible only in the breadcrumb, but it might balloon to something worse.
- Go to any registrant's contact show page.
- In URL, in id field enter an id from an existing domain that does not belong to the same Registrant.
- Observe the breadcrumb - it will have a domain name from a domain that does not belong to this contact or the same user.
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.
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> |
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.
Please stick to one way of calling translations helpers inside the same file, either with or without brackets.
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.
What do you mean? I can't omit t()
along with link_to
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.
Then use t('registrant.contacts.contact_index')
here too.
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.
Why I should? I consider omitting brackets when they are not needed a good practice.
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.
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
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.
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] |
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.
Just a symbol works too, no need for an Array of one element.
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.
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) %> |
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.
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
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.
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?
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.
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
?
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.
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.
f5242bc
to
5a46620
Compare
You still have the bug I pointed out. Here's a simple test case against which you can fix it, goes into # 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 |
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. |
# Conflicts: # test/fixtures/contacts.yml
accessing registrant details is still not fixed. |
@vohmar See my question above. |
f0a56e8
to
e4db808
Compare
UI is reverted to the previous state. |
Part of #849