Conversation
Current Code Coverage Percent of this PR:89.18 %Files having coverage below 100%
|
rohitjoshixyz
left a comment
There was a problem hiding this comment.
Nice work @aniket-k-kaushik with the spec coverage. Added few comments
| return new_company_path if resource.companies.empty? && resource.has_role?(:owner) | ||
|
|
||
| time_tracking_index_path | ||
|
|
||
| # As per discussion we want to redirect all the users to time-tracking page as dashboard is blank. | ||
| if resource.has_book_keeper_role?(current_company) | ||
| payments_path | ||
| else | ||
| time_tracking_index_path | ||
| end |
There was a problem hiding this comment.
Convert to switch case
There was a problem hiding this comment.
Also we can DRY this bit of code out.
| # if resource.has_owner_or_admin_role?(current_company) | ||
| # dashboard_index_path | ||
| # elsif resource.has_book_keeper_role?(current_company) | ||
| # payments_path | ||
| # else | ||
| # time_tracking_index_path | ||
| # end |
There was a problem hiding this comment.
@supriya3105 Suggested to redirect all users to time-sheet page temporally as we don't have dashboard yet so, once the dashboard is done, we can uncomment these lines and remove the current conditions.
if resource.has_book_keeper_role?(current_company)
payments_path
else
time_tracking_index_path
end
There was a problem hiding this comment.
We can add the commented code later if needed, it's simple enough but having unused commented code is bad practice
There was a problem hiding this comment.
ok, I will remove it
app/models/user.rb
Outdated
| def has_owner_or_admin_or_employee_role?(company) | ||
| return false if company.nil? | ||
|
|
||
| self.has_cached_role?( | ||
| :owner, | ||
| company) || self.has_cached_role?(:admin, company) || self.has_cached_role?(:employee, company) | ||
| end | ||
|
|
||
| def has_owner_or_admin_or_book_keeper_role?(company) | ||
| return false if company.nil? | ||
|
|
||
| self.has_cached_role?( | ||
| :owner, | ||
| company) || self.has_cached_role?(:admin, company) || self.has_cached_role?(:book_keeper, company) | ||
| end |
There was a problem hiding this comment.
We have created separate methods to check role, I don't think creating new methods for all combinations is a good idea.
Add one method for employee role and we can then use
has_owner_or_admin_role? || has_employee_role? in the policy which is equivalent to the above method
There was a problem hiding this comment.
Ruby's metaprogramming features (define_method) comes quite handy when we need to create_methods like these.
There was a problem hiding this comment.
Agree. This creates confusion. KISS please! is_owner_or_admin?, is_employee? & is_bookkeeper? is fine.
There was a problem hiding this comment.
OK, will look into it.
app/policies/application_policy.rb
Outdated
| def user_owner_or_admin_or_book_keeper_role?(resource = user.current_workspace) | ||
| user.has_owner_or_admin_or_book_keeper_role?(resource) | ||
| end | ||
|
|
||
| def user_owner_or_admin_or_employee?(resource = user.current_workspace) | ||
| user.has_owner_or_admin_or_employee_role?(resource) | ||
| end |
There was a problem hiding this comment.
Adding so many methods for combinations is confusing, reuse individual methods as mentioned in above comment
| <%# if policy(:dashboard).index? %> | ||
| <!-- <a href="/dashboard" class="<%#= request.path == "/dashboard" ? "navbar__smaller-screen_selected" : "navbar__smaller-screen_unselected" %> navbar__smaller-screen_titles"><%#= t('navbar.dashboard') %></a>--> | ||
| <%# end %> | ||
| <% if policy(:timesheet_entry).index? %> |
There was a problem hiding this comment.
This is too much repetition. Let's use a helper method to render the navbar. It will return a hash with the title and path of the authorized nav links and then we can iterate it here cc @apoorv-mishra @akhilgkrishnan @keshavbiswa
There was a problem hiding this comment.
Makes sense, but in a separate PR IMO.
| end | ||
| end | ||
|
|
||
| context "when user is an book keeper" do |
There was a problem hiding this comment.
| context "when user is an book keeper" do | |
| context "when user is a book keeper" do |
Check for grammar in all spec descriptions. I see the B of book keeper is unnecessarily capitalized at some places
| # if resource.has_owner_or_admin_role?(current_company) | ||
| # dashboard_index_path | ||
| # elsif resource.has_book_keeper_role?(current_company) | ||
| # payments_path | ||
| # else | ||
| # time_tracking_index_path | ||
| # end |
There was a problem hiding this comment.
why these all are commented?
There was a problem hiding this comment.
Supriya Suggested to redirect all users to time-sheet page temporally as we don't have dashboard yet so, once the dashboard is done, we can uncomment these lines and remove the current conditions.
keshavbiswa
left a comment
There was a problem hiding this comment.
Reviewed most of the codes except the tests and added few comments
| return new_company_path if resource.companies.empty? && resource.has_role?(:owner) | ||
|
|
||
| time_tracking_index_path | ||
|
|
||
| # As per discussion we want to redirect all the users to time-tracking page as dashboard is blank. | ||
| if resource.has_book_keeper_role?(current_company) | ||
| payments_path | ||
| else | ||
| time_tracking_index_path | ||
| end |
There was a problem hiding this comment.
Also we can DRY this bit of code out.
app/models/user.rb
Outdated
| def has_owner_or_admin_or_employee_role?(company) | ||
| return false if company.nil? | ||
|
|
||
| self.has_cached_role?( | ||
| :owner, | ||
| company) || self.has_cached_role?(:admin, company) || self.has_cached_role?(:employee, company) | ||
| end | ||
|
|
||
| def has_owner_or_admin_or_book_keeper_role?(company) | ||
| return false if company.nil? | ||
|
|
||
| self.has_cached_role?( | ||
| :owner, | ||
| company) || self.has_cached_role?(:admin, company) || self.has_cached_role?(:book_keeper, company) | ||
| end |
There was a problem hiding this comment.
Ruby's metaprogramming features (define_method) comes quite handy when we need to create_methods like these.
app/models/user.rb
Outdated
| def has_owner_or_admin_or_employee_role?(company) | ||
| return false if company.nil? | ||
|
|
||
| self.has_cached_role?( | ||
| :owner, | ||
| company) || self.has_cached_role?(:admin, company) || self.has_cached_role?(:employee, company) | ||
| end | ||
|
|
||
| def has_owner_or_admin_or_book_keeper_role?(company) | ||
| return false if company.nil? | ||
|
|
||
| self.has_cached_role?( | ||
| :owner, | ||
| company) || self.has_cached_role?(:admin, company) || self.has_cached_role?(:book_keeper, company) | ||
| end |
There was a problem hiding this comment.
Agree. This creates confusion. KISS please! is_owner_or_admin?, is_employee? & is_bookkeeper? is fine.
f1d45be to
836ecde
Compare
7185e7f to
130159b
Compare
thanks |
rohitjoshixyz
left a comment
There was a problem hiding this comment.
LGTM 🎉 perform a self-review of the code before merging. There are many minor changes in the specs similar to the ones I have commented.
app/models/concerns/user_roles.rb
Outdated
| define_method "has_#{role}_role?" do |company| | ||
| return false if company.nil? | ||
|
|
||
| self.has_cached_role?("#{role}".to_sym, company) |
There was a problem hiding this comment.
| self.has_cached_role?("#{role}".to_sym, company) | |
| self.has_cached_role?(role.to_sym, company) |
There was a problem hiding this comment.
I tried by, removing the concerns but it didn't worked, so keeping it for now
There was a problem hiding this comment.
What exactly didn't work?
There was a problem hiding this comment.
has_book_keeper_role? in the session_controller.rb gave an error, when I removed the user_roles.rb concern
There was a problem hiding this comment.
undefined method `has_book_keeper_role?
There was a problem hiding this comment.
Yes obviously, you will need to use the function rolify provides.
There was a problem hiding this comment.
done with the changes suggested
28bc2c5 to
4f6a745
Compare
* added book keeper role * removed comment from client controller * review comments resolved * provider policy * review comments * test fix * session controller more readable * test fix * removed user_roles.rb concerns
Notion card
https://www.notion.so/saeloun/Add-Book-keeper-role-2202d380771845bfbf23fb781afc29ae
Checklist: