Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add Book Keeper Role #465

Merged
aniketkaushik merged 9 commits intodevelopfrom
Add-bookkeeper-role-for-invoice-and-payment
Jun 15, 2022
Merged

Add Book Keeper Role #465
aniketkaushik merged 9 commits intodevelopfrom
Add-bookkeeper-role-for-invoice-and-payment

Conversation

@aniketkaushik
Copy link
Contributor

Notion card

https://www.notion.so/saeloun/Add-Book-keeper-role-2202d380771845bfbf23fb781afc29ae

Checklist:

  • I have manually tested all workflows
  • I have performed a self-review of my own code
  • I have added automated tests for my code

@github-actions
Copy link

github-actions bot commented Jun 11, 2022

Current Code Coverage Percent of this PR:

89.18 %

Files having coverage below 100%

Impacted Files Coverage
/lib/custom_failure.rb 80.0 %
/app/controllers/users/invitations_controller.rb 86.36 %
/app/controllers/users/sessions_controller.rb 85.71 %
/app/services/invoice_payment/checkout.rb 44.0 %
/app/services/invoice_payment/pdf_generation.rb 70.97 %
/app/controllers/internal_api/v1/companies_controller.rb 95.45 %
/app/controllers/internal_api/v1/profile_controller.rb 96.88 %
/app/controllers/internal_api/v1/payment_settings_controller.rb 93.33 %
/app/controllers/internal_api/v1/wise/recipients_controller.rb 90.0 %
/app/controllers/internal_api/v1/payments/providers_controller.rb 94.74 %
/lib/benchmarking/benchmarker.rb 0.0 %

Copy link
Contributor

@rohitjoshixyz rohitjoshixyz left a comment

Choose a reason for hiding this comment

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

Nice work @aniket-k-kaushik with the spec coverage. Added few comments

Comment on lines 5 to 11
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
Copy link
Contributor

Choose a reason for hiding this comment

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

Convert to switch case

Copy link
Contributor

Choose a reason for hiding this comment

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

Also we can DRY this bit of code out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK

Comment on lines 12 to 18
# 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
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this

Copy link
Contributor Author

@aniketkaushik aniketkaushik Jun 14, 2022

Choose a reason for hiding this comment

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

@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

Copy link
Contributor

Choose a reason for hiding this comment

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

We can add the commented code later if needed, it's simple enough but having unused commented code is bad practice

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, I will remove it

Comment on lines 94 to 109
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
Copy link
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Ruby's metaprogramming features (define_method) comes quite handy when we need to create_methods like these.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree. This creates confusion. KISS please! is_owner_or_admin?, is_employee? & is_bookkeeper? is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, will look into it.

Comment on lines 11 to 17
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
Copy link
Contributor

Choose a reason for hiding this comment

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

Adding so many methods for combinations is confusing, reuse individual methods as mentioned in above comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

<%# 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? %>
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 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

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense, but in a separate PR IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK

end
end

context "when user is an book keeper" do
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

Comment on lines 12 to 18
# 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
Copy link
Member

Choose a reason for hiding this comment

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

why these all are commented?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

@keshavbiswa keshavbiswa left a comment

Choose a reason for hiding this comment

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

Reviewed most of the codes except the tests and added few comments

Comment on lines 5 to 11
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
Copy link
Contributor

Choose a reason for hiding this comment

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

Also we can DRY this bit of code out.

Comment on lines 94 to 109
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
Copy link
Contributor

Choose a reason for hiding this comment

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

Ruby's metaprogramming features (define_method) comes quite handy when we need to create_methods like these.

Comment on lines 94 to 109
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
Copy link
Contributor

Choose a reason for hiding this comment

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

Agree. This creates confusion. KISS please! is_owner_or_admin?, is_employee? & is_bookkeeper? is fine.

@aniketkaushik aniketkaushik force-pushed the Add-bookkeeper-role-for-invoice-and-payment branch from f1d45be to 836ecde Compare June 14, 2022 12:01
@aniketkaushik aniketkaushik force-pushed the Add-bookkeeper-role-for-invoice-and-payment branch from 7185e7f to 130159b Compare June 14, 2022 18:18
@aniketkaushik
Copy link
Contributor Author

Nice work @aniket-k-kaushik with the spec coverage. Added few comments

thanks

Copy link
Contributor

@rohitjoshixyz rohitjoshixyz left a comment

Choose a reason for hiding this comment

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

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.

define_method "has_#{role}_role?" do |company|
return false if company.nil?

self.has_cached_role?("#{role}".to_sym, company)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
self.has_cached_role?("#{role}".to_sym, company)
self.has_cached_role?(role.to_sym, company)

Copy link
Contributor Author

@aniketkaushik aniketkaushik Jun 15, 2022

Choose a reason for hiding this comment

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

I tried by, removing the concerns but it didn't worked, so keeping it for now

Copy link
Contributor

Choose a reason for hiding this comment

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

What exactly didn't work?

Copy link
Contributor Author

@aniketkaushik aniketkaushik Jun 15, 2022

Choose a reason for hiding this comment

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

has_book_keeper_role? in the session_controller.rb gave an error, when I removed the user_roles.rb concern

Copy link
Contributor Author

Choose a reason for hiding this comment

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

undefined method `has_book_keeper_role?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes obviously, you will need to use the function rolify provides.

Copy link
Contributor Author

@aniketkaushik aniketkaushik Jun 15, 2022

Choose a reason for hiding this comment

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

done with the changes suggested

Copy link
Contributor

@keshavbiswa keshavbiswa left a comment

Choose a reason for hiding this comment

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

LGTM!

@aniketkaushik aniketkaushik force-pushed the Add-bookkeeper-role-for-invoice-and-payment branch from 28bc2c5 to 4f6a745 Compare June 15, 2022 10:32
@aniketkaushik aniketkaushik merged commit 20e1ab1 into develop Jun 15, 2022
@aniketkaushik aniketkaushik deleted the Add-bookkeeper-role-for-invoice-and-payment branch June 15, 2022 10:40
vipulnsward pushed a commit that referenced this pull request Feb 15, 2026
* 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
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