Skip to content

Commit

Permalink
Merge pull request 'Add a configuration option to enable the "Multite…
Browse files Browse the repository at this point in the history
…nancy management mode"' (#1) from only_manage_tenants into master

Reviewed-on: https://git.nubarron.teide.int/shs-consul/isla-abierta/pulls/1
  • Loading branch information
ConsulBot committed Apr 14, 2023
2 parents 8e5b053 + 6ca5575 commit 7a90a1f
Show file tree
Hide file tree
Showing 20 changed files with 433 additions and 308 deletions.
10 changes: 9 additions & 1 deletion app/assets/stylesheets/admin/menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
padding: 0;
}

> ul > li a {
> ul > li > a {
display: flex;
font-weight: bold;

Expand Down Expand Up @@ -109,6 +109,14 @@
&.ml-link {
@include icon(brain, solid);
}

&.administrators-link {
@include icon(user, solid);
}

&.tenants-link {
@include icon(building, regular);
}
}

li {
Expand Down
54 changes: 34 additions & 20 deletions app/components/admin/menu_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,40 @@ class Admin::MenuComponent < ApplicationComponent
delegate :can?, to: :helpers

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)),
(polls_link if feature?(:polls)),
comments_link,
(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
Expand Down Expand Up @@ -388,7 +400,8 @@ def administrators_link
[
t("admin.menu.administrators"),
admin_administrators_path,
controller_name == "administrators"
controller_name == "administrators",
class: "administrators-link"
]
end

Expand Down Expand Up @@ -476,7 +489,8 @@ def tenants_link
[
t("admin.menu.multitenancy"),
admin_tenants_path,
controller_name == "tenants"
controller_name == "tenants",
class: "tenants-link"
]
end
end
Expand Down
6 changes: 4 additions & 2 deletions app/components/layout/account_menu_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<ul class="account-menu menu" data-responsive-menu="medium-dropdown">
<%= render Layout::AdminLoginItemsComponent.new(user) %>
<%= render Layout::NotificationItemComponent.new(user) %>
<% unless Rails.application.multitenancy_management_mode? %>
<%= render Layout::AdminLoginItemsComponent.new(user) %>
<%= render Layout::NotificationItemComponent.new(user) %>
<% end %>
<%= render Layout::LoginItemsComponent.new(user) %>
</ul>
6 changes: 4 additions & 2 deletions app/components/layout/admin_header_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
<div class="top-links">
<%= render Layout::LocaleSwitcherComponent.new %>
<%= link_to root_path do %>
<%= t("admin.dashboard.index.back", org: setting["org_name"]) %>
<% unless Rails.application.multitenancy_management_mode? %>
<%= link_to root_path do %>
<%= t("admin.dashboard.index.back", org: setting["org_name"]) %>
<% end %>
<% end %>
</div>

Expand Down
3 changes: 3 additions & 0 deletions app/components/layout/footer_component.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
class Layout::FooterComponent < ApplicationComponent
def render?
!Rails.application.multitenancy_management_mode?
end
end
18 changes: 10 additions & 8 deletions app/components/layout/login_items_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<% if user %>
<li>
<%= layout_menu_link_to t("layouts.header.my_activity_link"),
user_path(user),
controller_name == "users",
rel: "nofollow",
title: t("shared.go_to_page") +
t("layouts.header.my_activity_link") %>
</li>
<% unless Rails.application.multitenancy_management_mode? %>
<li>
<%= layout_menu_link_to t("layouts.header.my_activity_link"),
user_path(user),
controller_name == "users",
rel: "nofollow",
title: t("shared.go_to_page") +
t("layouts.header.my_activity_link") %>
</li>
<% end %>
<li>
<%= layout_menu_link_to t("layouts.header.my_account_link"),
account_path,
Expand Down
4 changes: 4 additions & 0 deletions app/components/layout/subnavigation_component.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
class Layout::SubnavigationComponent < ApplicationComponent
delegate :content_block, :layout_menu_link_to, to: :helpers

def render?
!Rails.application.multitenancy_management_mode?
end
end
8 changes: 7 additions & 1 deletion app/controllers/concerns/access_denied_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ module AccessDeniedHandler
included do
rescue_from CanCan::AccessDenied do |exception|
respond_to do |format|
format.html { redirect_to main_app.root_path, alert: exception.message }
format.html do
if Rails.application.multitenancy_management_mode?
redirect_to main_app.account_path, alert: exception.message
else
redirect_to main_app.root_path, alert: exception.message
end
end
format.json { render json: { error: exception.message }, status: :forbidden }
end
end
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/users/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ def destroy
private

def after_sign_in_path_for(resource)
if !verifying_via_email? && resource.show_welcome_screen?
if Rails.application.multitenancy_management_mode? && !resource.administrator?
account_path
elsif !verifying_via_email? && resource.show_welcome_screen?
welcome_path
else
super
Expand Down
6 changes: 6 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ class Application < Rails::Application

# Set to true to enable managing different tenants using the same application
config.multitenancy = Rails.application.secrets.multitenancy
# Set to true if you want that the default tenant only to be used to manage other tenants
config.multitenancy_management_mode = Rails.application.secrets.multitenancy_management_mode

def multitenancy_management_mode?
config.multitenancy && Tenant.default? && config.multitenancy_management_mode
end
end
end

Expand Down
116 changes: 75 additions & 41 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,81 @@
mount Ckeditor::Engine => "/ckeditor"
mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.development?

draw :account
draw :admin
draw :budget
draw :comment
draw :community
draw :debate
draw :account
draw :devise
draw :direct_upload
draw :document
draw :graphql
draw :legislation
draw :management
draw :moderation
draw :notification
draw :officing
draw :poll
draw :proposal
draw :related_content
draw :sdg
draw :sdg_management
draw :tag
draw :user
draw :valuation
draw :verification

root "welcome#index"
get "/welcome", to: "welcome#welcome"
get "/consul.json", to: "installation#details"
get "robots.txt", to: "robots#index"

resources :stats, only: [:index]
resources :images, only: [:destroy]
resources :documents, only: [:destroy]
resources :follows, only: [:create, :destroy]
resources :remote_translations, only: [:create]

# More info pages
get "help", to: "pages#show", id: "help/index", as: "help"
get "help/how-to-use", to: "pages#show", id: "help/how_to_use/index", as: "how_to_use"
get "help/faq", to: "pages#show", id: "faq", as: "faq"

# Static pages
resources :pages, path: "/", only: [:show]

constraints lambda { |request| Rails.application.multitenancy_management_mode? } do
get "/", to: "admin/tenants#index"
end

constraints lambda { |request| !Rails.application.multitenancy_management_mode? } do
draw :budget
draw :comment
draw :community
draw :debate
draw :direct_upload
draw :document
draw :graphql
draw :legislation
draw :management
draw :moderation
draw :notification
draw :officing
draw :poll
draw :proposal
draw :related_content
draw :sdg
draw :sdg_management
draw :tag
draw :user
draw :valuation
draw :verification

root "welcome#index"
get "/welcome", to: "welcome#welcome"
get "/consul.json", to: "installation#details"
get "robots.txt", to: "robots#index"

resources :stats, only: [:index]
resources :images, only: [:destroy]
resources :documents, only: [:destroy]
resources :follows, only: [:create, :destroy]
resources :remote_translations, only: [:create]

# More info pages
get "help", to: "pages#show", id: "help/index", as: "help"
get "help/how-to-use", to: "pages#show", id: "help/how_to_use/index", as: "how_to_use"
get "help/faq", to: "pages#show", id: "faq", as: "faq"

# Static pages
resources :pages, path: "/", only: [:show]
end

resolve "Budget::Investment" do |investment, options|
[investment.budget, :investment, options.merge(id: investment)]
end

resolve("Topic") { |topic, options| [topic.community, topic, options] }

resolve "Legislation::Proposal" do |proposal, options|
[proposal.process, :proposal, options.merge(id: proposal)]
end

resolve "Legislation::Question" do |question, options|
[question.process, :question, options.merge(id: question)]
end

resolve "Legislation::Annotation" do |annotation, options|
[annotation.draft_version.process, :draft_version, :annotation,
options.merge(draft_version_id: annotation.draft_version, id: annotation)]
end

resolve "Poll::Question" do |question, options|
[:question, options.merge(id: question)]
end

resolve "SDG::LocalTarget" do |target, options|
[:local_target, options.merge(id: target)]
end
end
Loading

0 comments on commit 7a90a1f

Please sign in to comment.