From 95d159d18d8324c7128a5326e3c94d383aaabac3 Mon Sep 17 00:00:00 2001 From: Ivan Kocienski Date: Wed, 6 Jul 2022 11:07:51 +0100 Subject: [PATCH] fix: Root users incorrectly getting warning they have no rights (#1368) * Don't show root users the no-content warning When logged in as a root user (who has no content) and on the home dashboard page then don't show the no content nag box Also: users who are editors have content even if they have no tags, neighbourhoods or partners. Like root users. --- app/helpers/users_helper.rb | 3 +++ test/integration/admin/home_integration_test.rb | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 7a740ca11..1f8e393bf 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -15,6 +15,9 @@ def options_for_roles end def user_has_no_rights?(user) + return false if user.root? + return false if user.editor? + return false if user.tag_admin? return false if user.neighbourhood_admin? return false if user.partner_admin? diff --git a/test/integration/admin/home_integration_test.rb b/test/integration/admin/home_integration_test.rb index b55783773..469bccc48 100644 --- a/test/integration/admin/home_integration_test.rb +++ b/test/integration/admin/home_integration_test.rb @@ -7,18 +7,30 @@ class AdminHomeIntegrationTest < ActionDispatch::IntegrationTest setup do @admin = create(:root) + @citizen = create(:citizen) end test "Admin home page can't be accessed without a login" do @default_site = create_default_site get "http://admin.lvh.me" assert_redirected_to "http://admin.lvh.me/users/sign_in" + end + test "Admin can access page when logged in" do sign_in @admin get "http://admin.lvh.me" assert_response :success + assert_select 'title', text: "Dashboard | PlaceCal Admin" + end + + test "Blank citizen gets a 'no content' warning" do + sign_in @citizen + get "http://admin.lvh.me" + assert_response :success + assert_select 'title', text: "Dashboard | PlaceCal Admin" assert_select 'h1', text: "Missing Permissions" end + end