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

Added Payments tab in the Navbar #294

Merged
merged 4 commits into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/controllers/payments_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class PaymentsController < ApplicationController
def index
authorize :index, policy_class: PaymentPolicy
end
end
7 changes: 7 additions & 0 deletions app/policies/payment_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class PaymentPolicy < ApplicationPolicy
def index?
user_owner_or_admin?
end
end
11 changes: 11 additions & 0 deletions app/views/partial/_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<% if current_user.has_owner_or_admin_role?(current_company) %>
<a href="<%= reports_path %>" class="<%= request.path == "#{reports_path}" ? "navbar__smaller-screen_selected" : "navbar__smaller-screen_unselected" %> navbar__smaller-screen_titles"><%= t('navbar.reports') %></a>
<a href="/invoices" class="<%= request.path == "/invoices" ? "navbar__smaller-screen_selected" : "navbar__smaller-screen_unselected" %> navbar__smaller-screen_titles"><%= t('navbar.invoices') %></a>
<a href="/payments" class="<%= request.path == "/payments" ? "navbar__smaller-screen_selected" : "navbar__smaller-screen_unselected" %> navbar__smaller-screen_titles"><%= t('navbar.payments') %></a>
<% end %>
</div>
<!-- dashboard time_tracking team clients projects invoice report etc. end -->
Expand Down Expand Up @@ -118,6 +119,11 @@
<%= t('navbar.reports') %>
</a>
<% end %>
<% if policy(:payment).index? %>
<a href="/payments" class="<%= request.path == "/payments" ? "block" : "hidden" %> navbar__small-screen-second_titles">
<%= t('navbar.payments') %>
</a>
<% end %>
</div>
</div>
<!-- title smaller screen end -->
Expand Down Expand Up @@ -152,6 +158,11 @@
<%= t('navbar.reports') %>
</a>
<% end %>
<% if policy(:payment).index? %>
<a href="/payments" data-cy="invoices-tab" class="<%= request.path == "/payments" ? "navbar__large-screen_selected" : "navbar__large-screen_unselected" %> navbar__large-screen_title">
<%= t('navbar.payments') %>
</a>
<% end %>
</div>
</div>
<!-- dashboard time_tracking team clients projects invoices report etc. end -->
Expand Down
1 change: 1 addition & 0 deletions app/views/payments/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Code</h1>
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ en:
reports: Reports
settings: Settings
team: Team
payments: Payments
time_tracking: Time Tracking
view_notifications: View Notifications
projects:
Expand Down
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def draw(routes_name)
resources :projects, only: [:index, :create]
resources :reports, only: [:index]
# resources :invoices, only: [:index, :create]
# resources :payments, only: [:index]
resources :workspaces, only: [:update]

get "clients/*path", to: "clients#index", via: :all
Expand All @@ -48,6 +49,9 @@ def draw(routes_name)
get "invoices/*path", to: "invoices#index", via: :all
get "invoices", to: "invoices#index"

get "payments/*path", to: "payments#index", via: :all
get "payments", to: "payments#index"

devise_scope :user do
get "profile", to: "users/registrations#edit"
delete "profile/purge_avatar", to: "users/registrations#purge_avatar"
Expand Down
43 changes: 43 additions & 0 deletions spec/requests/payments/index_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe "Payments#index", type: :request do
let(:company) { create(:company) }
let(:user) { create(:user, current_workspace_id: company.id) }

context "when user is an admin" do
before do
create(:company_user, company:, user:)
user.add_role :admin, company
sign_in user
send_request :get, payments_path
end

it "they should be able to visit payments page successfully" do
expect(response).to be_successful
end
end

context "when the user is an employee" do
before do
create(:company_user, company:, user:)
user.add_role :employee, company
sign_in user
send_request :get, payments_path
end

it "they should not be permitted to visit index page" do
expect(response).to have_http_status(:redirect)
expect(flash["alert"]).to eq("You are not authorized to perform this action.")
end
end

context "when unauthenticated" do
it "is not be permitted to view the payments" do
send_request :get, payments_path
expect(response).to have_http_status(:redirect)
expect(flash["alert"]).to eq("You need to sign in or sign up before continuing.")
end
end
end