Skip to content

Commit

Permalink
Merge branch 'decidim-ice:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
microstudi authored Jan 9, 2023
2 parents d7115a8 + 7fa52a0 commit b0959f7
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 72 deletions.
2 changes: 1 addition & 1 deletion app/forms/decidim/decidim_awesome/admin/menu_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module DecidimAwesome
module Admin
class MenuForm < Decidim::Form
include Decidim::TranslatableAttributes
VISIBILITY_STATES = %w(default hidden logged non_logged).freeze
VISIBILITY_STATES = %w(default hidden logged non_logged verified_user).freeze

translatable_attribute :raw_label, String
attribute :url, String
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ en:
hidden: Always hidden
logged: Only visible for logged users
non_logged: Only visible for non-logged users
verified_user: Only visible for users with a valid authorization
index:
confirm_destroy: Are you sure to remove this customization?
edit: Edit
Expand Down
4 changes: 4 additions & 0 deletions lib/decidim/decidim_awesome/menu_hacker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ def visible?(item)
user.present?
when "non_logged"
user.blank?
when "verified_user"
# the cleaner version should be user.authorizations.any?
# but there is not relationship between users and authorizations
Decidim::Authorization.where(user: user).any? { |auth| auth.granted? && !auth.expired? }
else
true
end
Expand Down
181 changes: 110 additions & 71 deletions spec/system/menu_hacks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,96 +181,135 @@
end
end
end
end
end

describe "active" do
let!(:component) { create(:proposal_component, participatory_space: participatory_process) }
let!(:participatory_process2) { create :participatory_process, organization: organization }
let!(:component2) { create(:proposal_component, participatory_space: participatory_process2) }
let(:menu) do
[
{
url: "/",
label: {
"en" => "A new beggining"
},
position: 1
},
{
url: "/processes/#{participatory_process.slug}",
label: {
"en" => "A single process"
},
position: 2
}
]
end
context "when only verified user", with_authorization_workflows: ["dummy_authorization_handler"] do
let!(:authorization) { create(:authorization, granted_at: Time.zone.now, user: user, name: "dummy_authorization_handler") }
let(:visibility) { "verified_user" }

it_behaves_like "has active link", "A new beggining"
before do
switch_to_host(organization.host)
login_as user, scope: :user
visit decidim.root_path
end

context "when visiting all processes list" do
before do
visit decidim_participatory_processes.participatory_processes_path
end
context "when user is verified" do
it "shows the item" do
within ".main-nav" do
expect(page).to have_content("A new beggining")
end
end
end

it_behaves_like "has active link", "Processes"
end
context "when user is not verified" do
let(:authorization) { nil }

context "when visiting a process in a custom link" do
before do
visit decidim_participatory_processes.participatory_process_path(participatory_process.slug)
end
it "shows the item" do
within ".main-nav" do
expect(page).not_to have_content("A new beggining")
end
end
end

it_behaves_like "has active link", "A single process"
end
context "when verification is expired" do
let!(:authorization) { create(:authorization, granted_at: 3.months.ago, user: user, name: "dummy_authorization_handler") }

context "when visiting a sublink of a process in a custom link" do
before do
visit main_component_path(component)
it "shows the item" do
within ".main-nav" do
expect(page).not_to have_content("A new beggining")
end
end
end
end

it_behaves_like "has active link", "A single process"
end
describe "active" do
let!(:component) { create(:proposal_component, participatory_space: participatory_process) }
let!(:participatory_process2) { create :participatory_process, organization: organization }
let!(:component2) { create(:proposal_component, participatory_space: participatory_process2) }
let(:menu) do
[
{
url: "/",
label: {
"en" => "A new beggining"
},
position: 1
},
{
url: "/processes/#{participatory_process.slug}",
label: {
"en" => "A single process"
},
position: 2
}
]
end

context "when visiting a process not in a custom link" do
before do
visit decidim_participatory_processes.participatory_process_path(participatory_process2.slug)
end
it_behaves_like "has active link", "A new beggining"

it_behaves_like "has active link", "Processes"
end
context "when visiting all processes list" do
before do
visit decidim_participatory_processes.participatory_processes_path
end

context "when visiting a sublink of a process not in a custom link" do
before do
visit main_component_path(component2)
end
it_behaves_like "has active link", "Processes"
end

it_behaves_like "has active link", "Processes"
end
end
context "when visiting a process in a custom link" do
before do
visit decidim_participatory_processes.participatory_process_path(participatory_process.slug)
end

context "when menu is :disabled" do
let(:disabled_features) { [:menu] }
it_behaves_like "has active link", "A single process"
end

it "renders the normal menu" do
within ".main-nav" do
expect(page).to have_content("Home")
expect(page).to have_content("Processes")
expect(page).to have_content("Help")
expect(page).not_to have_content("A new beggining")
expect(page).not_to have_content("Blog")
end
end
context "when visiting a sublink of a process in a custom link" do
before do
visit main_component_path(component)
end

it_behaves_like "has active link", "Home"
it_behaves_like "has active link", "A single process"
end

context "when visiting another page" do
before do
visit decidim_participatory_processes.participatory_processes_path
context "when visiting a process not in a custom link" do
before do
visit decidim_participatory_processes.participatory_process_path(participatory_process2.slug)
end

it_behaves_like "has active link", "Processes"
end

context "when visiting a sublink of a process not in a custom link" do
before do
visit main_component_path(component2)
end

it_behaves_like "has active link", "Processes"
end
end

it_behaves_like "has active link", "Processes"
context "when menu is :disabled" do
let(:disabled_features) { [:menu] }

it "renders the normal menu" do
within ".main-nav" do
expect(page).to have_content("Home")
expect(page).to have_content("Processes")
expect(page).to have_content("Help")
expect(page).not_to have_content("A new beggining")
expect(page).not_to have_content("Blog")
end
end

it_behaves_like "has active link", "Home"

context "when visiting another page" do
before do
visit decidim_participatory_processes.participatory_processes_path
end

it_behaves_like "has active link", "Processes"
end
end
end
end
end

0 comments on commit b0959f7

Please sign in to comment.