Skip to content

Commit

Permalink
Hide Dashboard (#306)
Browse files Browse the repository at this point in the history
* hide dashboard

* removed project_params from erb project_controller

* added test
  • Loading branch information
aniketkaushik authored Apr 21, 2022
1 parent 0576f27 commit c8a3f46
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 37 deletions.
1 change: 0 additions & 1 deletion app/controllers/concerns/error_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def user_not_authorized(exception)
error_key = policy.try(:error_message_key) || exception.query

message = I18n.t("#{policy_name}.#{error_key}", scope: "pundit", default: :default)

case policy.try(:error_message_key)
when :company_not_present
redirect_path = new_company_path
Expand Down
6 changes: 0 additions & 6 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,4 @@ class ProjectsController < ApplicationController
def index
authorize Project
end

private

def project_params
params.require(:project).permit(:client_id, :name, :billable)
end
end
13 changes: 8 additions & 5 deletions app/controllers/users/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ class Users::SessionsController < Devise::SessionsController
def after_sign_in_path_for(resource)
return new_company_path if resource.companies.empty? && resource.has_role?(:owner)

if resource.has_owner_or_admin_role?(current_company)
dashboard_index_path
else
time_tracking_index_path
end
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_owner_or_admin_role?(current_company)
# dashboard_index_path
# else
# time_tracking_index_path
# end
end
end
26 changes: 13 additions & 13 deletions app/views/partial/_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
<% if current_company %>
<!-- dashboard time_tracking team clients projects invoices report etc. Start -->
<div class="border-t border-gray-200 pt-4 pb-3 pl-3">
<% 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(: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 %>
<a href="/time-tracking" class="<%= request.path == "/time-tracking" ? "navbar__smaller-screen_selected" : "navbar__smaller-screen_unselected" %> navbar__smaller-screen_titles"><%= t('navbar.time_tracking') %></a>
<a href="/team" class="<%= request.path == "/team" ? "navbar__smaller-screen_selected" : "navbar__smaller-screen_unselected" %> navbar__smaller-screen_titles"><%= t('navbar.team') %></a>
<a href="/clients" class="<%= request.path == "/clients" ? "navbar__smaller-screen_selected" : "navbar__smaller-screen_unselected" %> navbar__smaller-screen_titles"><%= t('navbar.clients') %></a>
Expand Down Expand Up @@ -92,11 +92,11 @@
<!-- title smaller screen size -->
<div class="relative z-0 flex-1 flex items-center justify-center xsm:absolute xsm:inset-0">
<div class="block lg:hidden">
<% if policy(:dashboard).index? %>
<a href="/dashboard" class="<%= request.path == "/dashboard" ? "block" : "hidden" %> navbar__small-screen-second_titles">
<%= t('navbar.dashboard') %>
</a>
<% end %>
<%# if policy(:dashboard).index? %>
<!-- <a href="/dashboard" class="<%#= request.path == "/dashboard" ? "block" : "hidden" %> navbar__small-screen-second_titles">-->
<%#= t('navbar.dashboard') %>
<!-- </a>-->
<%# end %>
<a href="/time-tracking" class="<%= request.path == "/time-tracking" ? "block" : "hidden" %> navbar__small-screen-second_titles">
<%= t('navbar.time_tracking') %>
</a>
Expand Down Expand Up @@ -131,11 +131,11 @@
<!-- dashboard time_tracking team clients projects invoices report etc. start -->
<div class="relative z-0 flex-auto flex items-center justify-center sm:absolute sm:inset-0">
<div class="ml-12 hidden lg:block lg:flex lg:space-x-10 xl:pr-80 <%= "lg:mr-86" if current_user.has_role?(:employee, current_company) %>">
<% if policy(:dashboard).index? %>
<a href="/dashboard" data-cy="dashboard-tab" class="<%= request.path == "/dashboard" ? "navbar__large-screen_selected" : "navbar__large-screen_unselected" %> navbar__large-screen_title">
<%= t('navbar.dashboard') %>
</a>
<% end %>
<%# if policy(:dashboard).index? %>
<!-- <a href="/dashboard" data-cy="dashboard-tab" class="<%#= request.path == "/dashboard" ? "navbar__large-screen_selected" : "navbar__large-screen_unselected" %> navbar__large-screen_title">-->
<%#= t('navbar.dashboard') %>
<!-- </a>-->
<%# end %>
<a href="/time-tracking" data-cy="time-tracking-tab" class="<%= request.path == "/time-tracking" ? "navbar__large-screen_selected" : "navbar__large-screen_unselected" %> navbar__large-screen_title">
<%= t('navbar.time_tracking') %>
</a>
Expand Down
38 changes: 38 additions & 0 deletions spec/concerns/error_handler/test_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,42 @@ def show
end
end
end

describe "#company_not_present" do
before do
routes.draw { get "show" => "test#show" }
user.update(current_workspace_id: nil)
sign_in user
end

context "when request is HTML type" do
before do
get :show
end

it "redirects" do
expect(response).to have_http_status(:redirect)
end

it "redirects to new_company_path" do
expect(response).to redirect_to(new_company_path)
end

it "shows alert You are not authorized to perform this action." do
expect(flash[:alert]).to eq("You are not authorized to perform this action.")
end
end

context "when request is JSON type" do
before do
get :show, format: :json
end

it "shows error You are not authorized to perform this action" do
actual_response = JSON.parse(response.body)
expect(response).to have_http_status(:forbidden)
expect(actual_response["errors"]).to eq("You are not authorized to perform this action.")
end
end
end
end
37 changes: 25 additions & 12 deletions spec/requests/users/sessions/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let(:company) { create(:company) }
let(:user) { create(:user, current_workspace_id: company.id, password: "testing!") }

context "when user is not admin or owner" do
context "when user is admin owner employee" do
before do
create(:company_user, company:, user:)
send_request :post, user_session_path, params: { user: { email: user.email, password: user.password } }
Expand All @@ -17,17 +17,30 @@
end
end

context "when user is admin or owner of current company" do
before do
create(:company_user, company:, user:)
user.add_role :admin, company
send_request :post, user_session_path, params: { user: { email: user.email, password: user.password } }
end

it "then after_sign_in_path_for returns the dashboard path" do
expect(response).to redirect_to(dashboard_index_path)
end
end
# As per discussion we want to redirect all the users to time-tracking page as dashboard is blank.
#
# context "when user is not admin or owner" do
# before do
# create(:company_user, company:, user:)
# send_request :post, user_session_path, params: { user: { email: user.email, password: user.password } }
# end
#
# it "then after_sign_in_path_for returns the time_tracking path" do
# expect(response).to redirect_to(time_tracking_index_path)
# end
# end

# context "when user is admin or owner of current company" do
# before do
# create(:company_user, company:, user:)
# user.add_role :admin, company
# send_request :post, user_session_path, params: { user: { email: user.email, password: user.password } }
# end
#
# it "then after_sign_in_path_for returns the dashboard path" do
# expect(response).to redirect_to(dashboard_index_path)
# end
# end

context "when user has owner role but not associated with any company" do
before do
Expand Down

0 comments on commit c8a3f46

Please sign in to comment.