Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Replace guard for LDAP groups

Oliver Günther7b70af1acf9b
diff --git a/modules/ldap_groups/app/components/ldap_groups/synchronized_filters/table_component.rb b/modules/ldap_groups/app/components/ldap_groups/synchronized_filters/table_component.rb
index 05cbcc15893..4629620135b 100644
--- a/modules/ldap_groups/app/components/ldap_groups/synchronized_filters/table_component.rb
+++ b/modules/ldap_groups/app/components/ldap_groups/synchronized_filters/table_component.rb
@@ -46,6 +46,8 @@ module LdapGroups
end
def inline_create_link
+ return unless EnterpriseToken.allows_to?(:ldap_groups)
+
link_to({ controller: target_controller, action: :new },
class: "budget-add-row wp-inline-create--add-link",
title: I18n.t("ldap_groups.synchronized_filters.add_new")) do
diff --git a/modules/ldap_groups/app/components/ldap_groups/synchronized_groups/table_component.rb b/modules/ldap_groups/app/components/ldap_groups/synchronized_groups/table_component.rb
index 836849b49b8..21398699b06 100644
--- a/modules/ldap_groups/app/components/ldap_groups/synchronized_groups/table_component.rb
+++ b/modules/ldap_groups/app/components/ldap_groups/synchronized_groups/table_component.rb
@@ -50,6 +50,8 @@ module LdapGroups
end
def inline_create_link
+ return unless EnterpriseToken.allows_to?(:ldap_groups)
+
link_to({ controller: target_controller, action: :new },
class: "budget-add-row wp-inline-create--add-link",
title: I18n.t("ldap_groups.synchronized_groups.add_new")) do
diff --git a/modules/ldap_groups/app/controllers/ldap_groups/synchronized_filters_controller.rb b/modules/ldap_groups/app/controllers/ldap_groups/synchronized_filters_controller.rb
index 39807b7af78..f9cc03e0e25 100644
--- a/modules/ldap_groups/app/controllers/ldap_groups/synchronized_filters_controller.rb
+++ b/modules/ldap_groups/app/controllers/ldap_groups/synchronized_filters_controller.rb
@@ -1,7 +1,11 @@
module LdapGroups
class SynchronizedFiltersController < ::ApplicationController
before_action :require_admin
- before_action :check_ee
+
+ guard_enterprise_feature(:ldap_groups, except: %i[show destroy]) do
+ redirect_to ldap_groups_synchronized_groups_path, status: :see_other
+ end
+
before_action :find_filter, except: %i[new create]
layout "admin"
@@ -75,13 +79,6 @@ module LdapGroups
@filter = SynchronizedFilter.find(params[:ldap_filter_id])
end
- def check_ee
- unless EnterpriseToken.allows_to?(:ldap_groups)
- render template: "ldap_groups/synchronized_groups/upsell"
- false
- end
- end
-
def permitted_params
params
.require(:synchronized_filter)
diff --git a/modules/ldap_groups/app/controllers/ldap_groups/synchronized_groups_controller.rb b/modules/ldap_groups/app/controllers/ldap_groups/synchronized_groups_controller.rb
index 481eb3efba9..673b3c2b0a4 100644
--- a/modules/ldap_groups/app/controllers/ldap_groups/synchronized_groups_controller.rb
+++ b/modules/ldap_groups/app/controllers/ldap_groups/synchronized_groups_controller.rb
@@ -1,7 +1,11 @@
module LdapGroups
class SynchronizedGroupsController < ::ApplicationController
before_action :require_admin
- before_action :check_ee
+
+ guard_enterprise_feature(:ldap_groups, except: %i[index show destroy]) do
+ redirect_to action: :index, status: :see_other
+ end
+
before_action :find_group, only: %i(show destroy_info destroy)
layout "admin"
@@ -54,13 +58,6 @@ module LdapGroups
@group = SynchronizedGroup.find(params[:ldap_group_id])
end
- def check_ee
- unless EnterpriseToken.allows_to?(:ldap_groups)
- render template: "ldap_groups/synchronized_groups/upsell"
- false
- end
- end
-
def permitted_params
params
.require(:synchronized_group)
diff --git a/modules/ldap_groups/app/views/ldap_groups/synchronized_groups/index.html.erb b/modules/ldap_groups/app/views/ldap_groups/synchronized_groups/index.html.erb
index fa65ce39ffb..cdddfabeb0d 100644
--- a/modules/ldap_groups/app/views/ldap_groups/synchronized_groups/index.html.erb
+++ b/modules/ldap_groups/app/views/ldap_groups/synchronized_groups/index.html.erb
@@ -17,6 +17,7 @@
label: I18n.t(:button_add),
anchor_align: :end,
button_arguments: { scheme: :primary,
+ disabled: !EnterpriseToken.allows_to?(:ldap_groups),
aria: { label: I18n.t(:button_add) },
test_selector: "op-admin-synchronized-groups--button-new" }) do |menu|
menu.with_item(
@@ -33,6 +34,11 @@
end
end %>
+<%= render EnterpriseEdition::BannerComponent.new(
+ :ldap_groups,
+ variant: :inline
+ ) %>
+
<div class="op-toast -info">
<div class="op-toast--content">
<strong><%= t("note") %></strong>
diff --git a/modules/ldap_groups/app/views/ldap_groups/synchronized_groups/upsell.html.erb b/modules/ldap_groups/app/views/ldap_groups/synchronized_groups/upsell.html.erb
deleted file mode 100644
index 71a17742434..00000000000
--- a/modules/ldap_groups/app/views/ldap_groups/synchronized_groups/upsell.html.erb
+++ /dev/null
@@ -1,6 +0,0 @@
-<% html_title(t(:label_administration), t("ldap_groups.synchronized_groups.plural")) -%>
-
-<%= render EnterpriseEdition::BannerComponent.new(
- :ldap_groups,
- variant: :inline, # TODO
-) %>