Modify admin layout to only manage tenants and admins

We only want to render the account link and login items in the header.
And we want only render the Multitenancy and Administrators sections in
the admin sidebar.

We include the administrators management so it's possible to give
permissions to other users to manage tenants.

In order to restrict access to other sections by typing the URL or
following a link, we're only enabling the rest of the routes when we
aren't in the multitenancy management mode.
This commit is contained in:
taitus
2022-12-23 12:13:35 +01:00
parent 1e6901ec34
commit a5911f5c6a
24 changed files with 535 additions and 360 deletions

View File

@@ -3,28 +3,40 @@ class Admin::MenuComponent < ApplicationComponent
use_helpers :can?
def links
[
(proposals_link if feature?(:proposals)),
(debates_link if feature?(:debates)),
comments_link,
(polls_link if feature?(:polls)),
(legislation_link if feature?(:legislation)),
(budgets_link if feature?(:budgets)),
booths_links,
(signature_sheets_link if feature?(:signature_sheets)),
messages_links,
site_customization_links,
moderated_content_links,
profiles_links,
stats_link,
settings_links,
dashboard_links,
(machine_learning_link if ::MachineLearning.enabled?)
]
if Rails.application.multitenancy_management_mode?
multitenancy_management_links
else
default_links
end
end
private
def default_links
[
(proposals_link if feature?(:proposals)),
(debates_link if feature?(:debates)),
comments_link,
(polls_link if feature?(:polls)),
(legislation_link if feature?(:legislation)),
(budgets_link if feature?(:budgets)),
booths_links,
(signature_sheets_link if feature?(:signature_sheets)),
messages_links,
site_customization_links,
moderated_content_links,
profiles_links,
stats_link,
settings_links,
dashboard_links,
(machine_learning_link if ::MachineLearning.enabled?)
]
end
def multitenancy_management_links
[tenants_link, administrators_link]
end
def moderated_content?
moderated_sections.include?(controller_name) && controller.class.module_parent != Admin::Legislation
end
@@ -395,7 +407,8 @@ class Admin::MenuComponent < ApplicationComponent
[
t("admin.menu.administrators"),
admin_administrators_path,
controller_name == "administrators"
controller_name == "administrators",
class: "administrators-link"
]
end
@@ -482,7 +495,8 @@ class Admin::MenuComponent < ApplicationComponent
[
t("admin.menu.multitenancy"),
admin_tenants_path,
controller_name == "tenants"
controller_name == "tenants",
class: "tenants-link"
]
end
end