Skip to content

Commit

Permalink
Remove NeedsMenuSnippets and use menu.remove_item instead
Browse files Browse the repository at this point in the history
  • Loading branch information
fblupi committed Oct 30, 2023
1 parent 00aadff commit 72a6faf
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 89 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Decidim
module CatcomuManagers
module UserOverride
extend ActiveSupport::Concern

included do
alias_method :original_admin_terms_accepted?, :admin_terms_accepted?

def admin_terms_accepted?
return true unless attributes["admin"]

original_admin_terms_accepted?
end
end
end
end
end

This file was deleted.

This file was deleted.

3 changes: 1 addition & 2 deletions decidim-module-catcomu_managers/config/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@
# SCSS files within the entrypoints, they become available for inclusion using
# `stylesheet_pack_tag`.
Decidim::Webpacker.register_entrypoints(
decidim_admin_catcomu_managers: "#{base_path}/app/packs/entrypoints/decidim_admin_catcomu_managers.js",
decidim_admin_catcomu_managers_menu_overrides: "#{base_path}/app/packs/entrypoints/decidim_admin_catcomu_managers_menu_overrides.scss"
decidim_admin_catcomu_managers: "#{base_path}/app/packs/entrypoints/decidim_admin_catcomu_managers.js"
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AdminEngine < ::Rails::Engine
# some overrides
config.to_prepare do
Decidim::ParticipatoryProcesses::Admin::ParticipatoryProcessForm.include(Decidim::CatcomuManagers::Admin::ParticipatoryProcessFormOverride)
# Decidim::Admin::ApplicationController.include(Decidim::CatcomuManagers::Admin::NeedsMenuSnippets)
Decidim::User.include(Decidim::CatcomuManagers::UserOverride)
end

initializer "decidim_catcomu_managers.admin_menu" do
Expand All @@ -31,6 +31,35 @@ class AdminEngine < ::Rails::Engine
position: 1,
active: is_active_link?(decidim_catcomu_managers_admin.root_path, :inclusive),
if: defined?(current_user)

next if current_user && current_user.attributes["admin"]

menu.remove_item(:dashboard)
menu.remove_item(:moderations)
menu.remove_item(:static_pages)
menu.remove_item(:impersonatable_users)
menu.remove_item(:newsletters)
menu.remove_item(:edit_organization)
menu.remove_item(:logs)

managers_menu_spaces = Decidim.participatory_space_manifests.map do |manifest|
[manifest.name.to_s, "#{manifest.model_class_name}UserRole".safe_constantize&.exists?(user: current_user)]
end.to_h

# add awesome scoped parts too
(Decidim::DecidimAwesome::AwesomeConfig.find_by(organization: current_organization, var: "scoped_admins")&.value || []).each do |key, user_ids|
next unless user_ids.include?(current_user.id.to_s)

Decidim::DecidimAwesome::AwesomeConfig.find_by(organization: current_organization, var: "scoped_admin_#{key}").constraints.pluck(:settings).each do |constraint|
manifest = constraint["participatory_space_manifest"]
manifest = "participatory_processes" if manifest == "process_groups"
managers_menu_spaces[manifest] = true
end
end

managers_menu_spaces.each do |space, visible|
menu.remove_item(space.to_sym) unless visible
end
end
end

Expand Down

0 comments on commit 72a6faf

Please sign in to comment.