Merge pull request #5024 from consul/poll_officer_menu

Always show poll officer menu to officers
This commit is contained in:
Javi Martín
2023-02-17 14:33:51 +01:00
committed by GitHub
9 changed files with 155 additions and 273 deletions

View File

@@ -18,7 +18,7 @@ class Layout::AdminLoginItemsComponent < ApplicationComponent
(moderation_link if user.administrator? || user.moderator?),
(valuation_link if feature?(:budgets) && (user.administrator? || user.valuator?)),
(management_link if user.administrator? || user.manager?),
(officing_link if user.poll_officer? && Poll.current.any?),
(officing_link if user.poll_officer?),
(sdg_management_link if feature?(:sdg) && (user.administrator? || user.sdg_manager?))
]
end

View File

@@ -0,0 +1,132 @@
require "rails_helper"
describe Layout::AdminLoginItemsComponent do
it "is not rendered for anonymous users" do
render_inline Layout::AdminLoginItemsComponent.new(nil)
expect(page).not_to be_rendered
end
it "is not rendered for regular users" do
user = create(:user, :level_two)
render_inline Layout::AdminLoginItemsComponent.new(user)
expect(page).not_to be_rendered
end
it "shows access to all places except officing to administrators" do
user = create(:administrator).user
render_inline Layout::AdminLoginItemsComponent.new(user)
expect(page).to have_link "Menu"
page.find("ul") do |menu|
expect(menu).to have_link "Administration"
expect(menu).to have_link "Moderation"
expect(menu).to have_link "Valuation"
expect(menu).to have_link "Management"
expect(menu).to have_link "SDG content"
expect(menu).to have_link count: 5
end
end
it "shows the moderation link to moderators" do
user = create(:moderator).user
render_inline Layout::AdminLoginItemsComponent.new(user)
expect(page).to have_link "Menu"
page.find("ul") do |menu|
expect(menu).to have_link "Moderation"
expect(menu).to have_link count: 1
end
end
it "shows the valuation link to valuators" do
user = create(:valuator).user
render_inline Layout::AdminLoginItemsComponent.new(user)
expect(page).to have_link "Menu"
page.find("ul") do |menu|
expect(menu).to have_link "Valuation"
expect(menu).to have_link count: 1
end
end
it "shows the management link to managers" do
user = create(:manager).user
render_inline Layout::AdminLoginItemsComponent.new(user)
expect(page).to have_link "Menu"
page.find("ul") do |menu|
expect(menu).to have_link "Management"
expect(menu).to have_link count: 1
end
end
it "shows the SDG content link to SDG managers" do
user = create(:sdg_manager).user
render_inline Layout::AdminLoginItemsComponent.new(user)
expect(page).to have_link "Menu"
page.find("ul") do |menu|
expect(menu).to have_link "SDG content"
expect(menu).to have_link count: 1
end
end
it "does not show the SDG content link when the SDG feature is disabled" do
Setting["feature.sdg"] = false
user = create(:administrator).user
render_inline Layout::AdminLoginItemsComponent.new(user)
expect(page).to have_link "Menu"
page.find("ul") do |menu|
expect(menu).to have_link "Administration"
expect(menu).to have_link "Moderation"
expect(menu).to have_link "Valuation"
expect(menu).to have_link "Management"
expect(menu).to have_link count: 4
end
end
it "shows the officing link to poll officers" do
user = create(:poll_officer).user
render_inline Layout::AdminLoginItemsComponent.new(user)
expect(page).to have_link "Menu"
page.find("ul") do |menu|
expect(menu).to have_link "Polling officers"
expect(menu).to have_link count: 1
end
end
it "shows several links to users with several roles" do
user = create(:user)
create(:moderator, user: user)
create(:manager, user: user)
render_inline Layout::AdminLoginItemsComponent.new(user)
expect(page).to have_link "Menu"
page.find("ul") do |menu|
expect(menu).to have_link "Moderation"
expect(menu).to have_link "Management"
expect(menu).to have_link count: 2
end
end
end

View File

@@ -62,35 +62,16 @@ describe "Admin" do
end
scenario "Access as administrator is authorized", :admin do
visit admin_root_path
expect(page).to have_current_path(admin_root_path)
expect(page).not_to have_content "You do not have permission to access this page"
end
scenario "Admin access links", :admin do
Setting["feature.sdg"] = true
visit root_path
click_link "Menu"
expect(page).to have_link("Administration")
expect(page).to have_link("Moderation")
expect(page).to have_link("Valuation")
expect(page).to have_link("Management")
expect(page).to have_link("SDG content")
end
scenario "Admin dashboard", :admin do
visit root_path
click_link "Menu"
click_link "Administration"
expect(page).to have_current_path(admin_root_path)
expect(page).to have_css("#admin_menu")
expect(page).not_to have_css("#moderation_menu")
expect(page).not_to have_css("#valuation_menu")
expect(page).to have_css "#admin_menu"
expect(page).not_to have_css "#moderation_menu"
expect(page).not_to have_css "#valuation_menu"
expect(page).not_to have_content "You do not have permission to access this page"
end
scenario "Admin menu does not hide active elements", :admin do

View File

@@ -6,11 +6,6 @@ describe "Moderation" do
scenario "Access as regular user is not authorized" do
login_as(user)
visit root_path
expect(page).not_to have_link("Menu")
expect(page).not_to have_link("Moderation")
visit moderation_root_path
expect(page).not_to have_current_path(moderation_root_path)
@@ -22,11 +17,6 @@ describe "Moderation" do
create(:valuator, user: user)
login_as(user)
visit root_path
click_link "Menu"
expect(page).not_to have_link("Moderation")
visit moderation_root_path
expect(page).not_to have_current_path(moderation_root_path)
@@ -38,11 +28,6 @@ describe "Moderation" do
create(:manager, user: user)
login_as(user)
visit root_path
click_link "Menu"
expect(page).not_to have_link("Moderation")
visit moderation_root_path
expect(page).not_to have_current_path(moderation_root_path)
@@ -54,11 +39,6 @@ describe "Moderation" do
create(:sdg_manager, user: user)
login_as(user)
visit root_path
click_link "Menu"
expect(page).not_to have_link("Moderation")
visit moderation_root_path
expect(page).not_to have_current_path(moderation_root_path)
@@ -70,11 +50,6 @@ describe "Moderation" do
create(:poll_officer, user: user)
login_as(user)
visit root_path
click_link "Menu"
expect(page).not_to have_link("Moderation")
visit moderation_root_path
expect(page).not_to have_current_path(moderation_root_path)
@@ -83,6 +58,7 @@ describe "Moderation" do
end
scenario "Access as a moderator is authorized" do
Setting["org_name"] = "OrgName"
create(:moderator, user: user)
login_as(user)
@@ -91,6 +67,10 @@ describe "Moderation" do
click_link "Moderation"
expect(page).to have_current_path(moderation_root_path)
expect(page).to have_link "Go back to OrgName"
expect(page).to have_css "#moderation_menu"
expect(page).not_to have_css "#admin_menu"
expect(page).not_to have_css "#valuation_menu"
expect(page).not_to have_content "You do not have permission to access this page"
end
@@ -105,37 +85,4 @@ describe "Moderation" do
expect(page).to have_current_path(moderation_root_path)
expect(page).not_to have_content "You do not have permission to access this page"
end
scenario "Moderation access links" do
create(:moderator, user: user)
login_as(user)
visit root_path
click_link "Menu"
expect(page).to have_link("Moderation")
expect(page).not_to have_link("Administration")
expect(page).not_to have_link("Valuation")
end
context "Moderation dashboard" do
before do
Setting["org_name"] = "OrgName"
end
scenario "Contains correct elements" do
create(:moderator, user: user)
login_as(user)
visit root_path
click_link "Menu"
click_link "Moderation"
expect(page).to have_link("Go back to OrgName")
expect(page).to have_current_path(moderation_root_path)
expect(page).to have_css("#moderation_menu")
expect(page).not_to have_css("#admin_menu")
expect(page).not_to have_css("#valuation_menu")
end
end
end

View File

@@ -6,10 +6,6 @@ describe "Poll Officing" do
scenario "Access as regular user is not authorized" do
login_as(user)
visit root_path
expect(page).not_to have_content "Menu"
expect(page).not_to have_link "Polling officers"
visit officing_root_path
@@ -20,13 +16,7 @@ describe "Poll Officing" do
scenario "Access as moderator is not authorized" do
create(:moderator, user: user)
login_as(user)
visit root_path
click_link "Menu"
expect(page).to have_link "Moderation"
expect(page).not_to have_link "Polling officers"
visit officing_root_path
@@ -37,13 +27,7 @@ describe "Poll Officing" do
scenario "Access as manager is not authorized" do
create(:manager, user: user)
login_as(user)
visit root_path
click_link "Menu"
expect(page).to have_link "Management"
expect(page).not_to have_link "Polling officers"
visit officing_root_path
@@ -55,13 +39,7 @@ describe "Poll Officing" do
scenario "Access as SDG manager is not authorized" do
Setting["feature.sdg"] = true
create(:sdg_manager, user: user)
login_as(user)
visit root_path
click_link "Menu"
expect(page).to have_link "SDG content"
expect(page).not_to have_link "Polling officers"
visit officing_root_path
@@ -72,13 +50,7 @@ describe "Poll Officing" do
scenario "Access as a valuator is not authorized" do
create(:valuator, user: user)
login_as(user)
visit root_path
click_link "Menu"
expect(page).to have_link "Valuation"
expect(page).not_to have_link "Polling officers"
visit officing_root_path
@@ -89,15 +61,7 @@ describe "Poll Officing" do
scenario "Access as an administrator is not authorized" do
create(:administrator, user: user)
create(:poll)
login_as(user)
visit root_path
click_link "Menu"
expect(page).to have_link "Administration"
expect(page).not_to have_link "Polling officers"
visit officing_root_path
@@ -109,7 +73,6 @@ describe "Poll Officing" do
scenario "Access as an administrator with poll officer role is authorized" do
create(:administrator, user: user)
create(:poll_officer, user: user)
create(:poll)
login_as(user)
visit root_path
@@ -120,9 +83,8 @@ describe "Poll Officing" do
expect(page).not_to have_content "You do not have permission to access this page"
end
scenario "Access as an poll officer is authorized" do
scenario "Access as a poll officer is authorized" do
create(:poll_officer, user: user)
create(:poll)
login_as(user)
visit root_path
@@ -130,40 +92,14 @@ describe "Poll Officing" do
click_link "Polling officers"
expect(page).to have_current_path(officing_root_path)
expect(page).to have_css "#officing_menu"
expect(page).not_to have_link "Polling officers"
expect(page).not_to have_css "#valuation_menu"
expect(page).not_to have_css "#admin_menu"
expect(page).not_to have_css "#moderation_menu"
expect(page).not_to have_content "You do not have permission to access this page"
end
scenario "Poll officer access links" do
create(:poll)
create(:poll_officer, user: user)
login_as(user)
visit root_path
click_link "Menu"
expect(page).to have_link("Polling officers")
expect(page).not_to have_link("Valuation")
expect(page).not_to have_link("Administration")
expect(page).not_to have_link("Moderation")
end
scenario "Officing dashboard" do
create(:poll_officer, user: user)
create(:poll)
login_as(user)
visit root_path
click_link "Menu"
click_link "Polling officers"
expect(page).to have_current_path(officing_root_path)
expect(page).to have_css("#officing_menu")
expect(page).not_to have_link("Polling officers")
expect(page).not_to have_css("#valuation_menu")
expect(page).not_to have_css("#admin_menu")
expect(page).not_to have_css("#moderation_menu")
end
scenario "Officing dashboard available for multiple sessions", :with_frozen_time do
poll = create(:poll)
booth = create(:poll_booth)

View File

@@ -1,27 +0,0 @@
require "rails_helper"
describe "SDG Management" do
before { login_as(create(:administrator).user) }
context "SDG feature flag is enabled" do
before { Setting["feature.sdg"] = true }
scenario "shows the SDG content link" do
visit root_path
click_link "Menu"
expect(page).to have_link "SDG content"
end
end
context "SDG feature is disabled" do
before { Setting["feature.sdg"] = false }
scenario "does not show the SDG Content link" do
visit root_path
click_link "Menu"
expect(page).not_to have_link "SDG content"
end
end
end

View File

@@ -8,10 +8,7 @@ describe "SDGManagement" do
context "Access" do
scenario "Access as regular user is not authorized" do
login_as(user)
visit root_path
expect(page).not_to have_link("Menu")
expect(page).not_to have_link("SDG content")
visit sdg_management_root_path
expect(page).not_to have_current_path(sdg_management_root_path)
@@ -22,10 +19,7 @@ describe "SDGManagement" do
scenario "Access as manager is not authorized" do
create(:manager, user: user)
login_as(user)
visit root_path
click_on "Menu"
expect(page).not_to have_link("SDG content")
visit sdg_management_root_path
expect(page).not_to have_current_path(sdg_management_root_path)
@@ -42,35 +36,11 @@ describe "SDGManagement" do
click_on "SDG content"
expect(page).to have_current_path(sdg_management_root_path)
expect(page).to have_css ".sdg-content-menu"
expect(page).not_to have_css "#valuation_menu"
expect(page).not_to have_css "#admin_menu"
expect(page).not_to have_css "#moderation_menu"
expect(page).not_to have_content "You do not have permission to access this page"
end
end
scenario "Valuation access links" do
create(:sdg_manager, user: user)
login_as(user)
visit root_path
click_on "Menu"
expect(page).to have_link("SDG content")
expect(page).not_to have_link("Administration")
expect(page).not_to have_link("Moderation")
expect(page).not_to have_link("Valuation")
end
scenario "Valuation dashboard" do
create(:sdg_manager, user: user)
login_as(user)
visit root_path
click_on "Menu"
click_on "SDG content"
expect(page).to have_current_path(sdg_management_root_path)
expect(page).to have_css(".sdg-content-menu")
expect(page).not_to have_css("#valuation_menu")
expect(page).not_to have_css("#admin_menu")
expect(page).not_to have_css("#moderation_menu")
end
end

View File

@@ -20,13 +20,6 @@ describe "Valuation budget investments" do
end
end
scenario "Display link to valuation section" do
visit root_path
click_link "Menu"
expect(page).to have_link "Valuation", href: valuation_root_path
end
describe "Index" do
scenario "Index shows budget investments assigned to current valuator" do
investment1 = create(:budget_investment, :visible_to_valuators, budget: budget, valuators: [valuator])

View File

@@ -6,10 +6,6 @@ describe "Valuation" do
context "Access" do
scenario "Access as regular user is not authorized" do
login_as(user)
visit root_path
expect(page).not_to have_link("Menu")
expect(page).not_to have_link("Valuation")
visit valuation_root_path
@@ -22,11 +18,6 @@ describe "Valuation" do
create(:moderator, user: user)
login_as(user)
visit root_path
click_link "Menu"
expect(page).not_to have_link("Valuation")
visit valuation_root_path
expect(page).not_to have_current_path(valuation_root_path)
@@ -38,11 +29,6 @@ describe "Valuation" do
create(:manager, user: user)
login_as(user)
visit root_path
click_link "Menu"
expect(page).not_to have_link("Valuation")
visit valuation_root_path
expect(page).not_to have_current_path(valuation_root_path)
@@ -54,11 +40,6 @@ describe "Valuation" do
create(:sdg_manager, user: user)
login_as(user)
visit root_path
click_link "Menu"
expect(page).not_to have_link("Valuation")
visit valuation_root_path
expect(page).not_to have_current_path(valuation_root_path)
@@ -70,11 +51,6 @@ describe "Valuation" do
create(:poll_officer, user: user)
login_as(user)
visit root_path
click_link "Menu"
expect(page).not_to have_link("Valuation")
visit valuation_root_path
expect(page).not_to have_current_path(valuation_root_path)
@@ -92,6 +68,9 @@ describe "Valuation" do
click_link "Valuation"
expect(page).to have_current_path(valuation_root_path)
expect(page).to have_css "#valuation_menu"
expect(page).not_to have_css "#admin_menu"
expect(page).not_to have_css "#moderation_menu"
expect(page).not_to have_content "You do not have permission to access this page"
end
@@ -108,33 +87,4 @@ describe "Valuation" do
expect(page).not_to have_content "You do not have permission to access this page"
end
end
scenario "Valuation access links" do
create(:valuator, user: user)
create(:budget)
login_as(user)
visit root_path
click_link "Menu"
expect(page).to have_link("Valuation")
expect(page).not_to have_link("Administration")
expect(page).not_to have_link("Moderation")
end
scenario "Valuation dashboard" do
create(:valuator, user: user)
create(:budget)
login_as(user)
visit root_path
click_link "Menu"
click_link "Valuation"
expect(page).to have_current_path(valuation_root_path)
expect(page).to have_css("#valuation_menu")
expect(page).not_to have_css("#admin_menu")
expect(page).not_to have_css("#moderation_menu")
end
end