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

Allow i18n_scope, use banner for SAML and OIDC

Oliver Güntherb531ad3ec812
diff --git a/app/components/enterprise_edition/banner_component.rb b/app/components/enterprise_edition/banner_component.rb
index dbb825c8bd9..89992f90a1e 100644
--- a/app/components/enterprise_edition/banner_component.rb
+++ b/app/components/enterprise_edition/banner_component.rb
@@ -37,11 +37,14 @@ module EnterpriseEdition
include PlanForFeature
# @param feature_key [Symbol, NilClass] The key of the feature to show the banner for.
+ # @param i18n_scope [String] Provide the i18n scope to look for title, description, and features.
+ # Defaults to "ee.upsale.{feature_key}"
# @param dismissable [boolean] Allow this banner to be dismissed.
# @param dismiss_key [String] Provide a string to identify this banner when being dismissed. Defaults to feature_key
# @param skip_render [Boolean] Whether to skip rendering the banner.
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
def initialize(feature_key,
+ i18n_scope: "ee.upsale.#{feature_key}",
dismissable: false,
dismiss_key: feature_key,
skip_render: EnterpriseToken.hide_banners?,
@@ -53,7 +56,8 @@ module EnterpriseEdition
@system_arguments[:test_selector] = @system_arguments[:id]
super
- @feature_key = feature_key
+ self.feature_key = feature_key
+ self.i18n_scope = i18n_scope
@skip_render = skip_render
@dismissable = dismissable
@dismiss_key = dismiss_key
@@ -61,8 +65,7 @@ module EnterpriseEdition
private
- attr_reader :skip_render,
- :feature_key
+ attr_reader :skip_render
def render?
!(skip_render || dismissed?)
diff --git a/app/components/enterprise_edition/plan_for_feature.rb b/app/components/enterprise_edition/plan_for_feature.rb
index bd1e57fe6a7..192884ca65a 100644
--- a/app/components/enterprise_edition/plan_for_feature.rb
+++ b/app/components/enterprise_edition/plan_for_feature.rb
@@ -34,10 +34,11 @@ module EnterpriseEdition
included do
attr_accessor :feature_key
+ attr_accessor :i18n_scope
end
def title
- I18n.t("ee.upsale.#{feature_key}.title", default: default_title)
+ I18n.t(:title, scope: i18n_scope, default: default_title)
end
def default_title
@@ -46,16 +47,16 @@ module EnterpriseEdition
def description
@description || begin
- if I18n.exists?(:"ee.upsale.#{feature_key}.description_html")
- I18n.t("ee.upsale.#{feature_key}.description_html").html_safe
+ if I18n.exists?(:description_html, scope: i18n_scope)
+ I18n.t(:description_html, scope: i18n_scope).html_safe
else
- I18n.t("ee.upsale.#{feature_key}.description")
+ I18n.t(:description, scope: i18n_scope)
end
end
rescue I18n::MissingTranslationData => e
raise e.exception(
<<~TEXT.squish
- The expected '#{I18n.locale}.ee.upsale.#{feature_key}.description' nor '#{I18n.locale}.ee.upsale.#{feature_key}.description_html' key does not exist.
+ The expected '#{I18n.locale}.#{i18n_scope}.description' nor '#{I18n.locale}.#{i18n_scope}.description_html' key does not exist.
Ideally, provide it in the locale file.
If that isn't applicable, a description parameter needs to be provided.
TEXT
@@ -65,7 +66,7 @@ module EnterpriseEdition
def features
return @features if defined?(@features)
- @features = I18n.t("ee.upsale.#{feature_key}.features", default: nil)&.values
+ @features = I18n.t(:features, scope: i18n_scope, default: nil)&.values
end
def plan
diff --git a/modules/auth_saml/app/controllers/saml/providers_controller.rb b/modules/auth_saml/app/controllers/saml/providers_controller.rb
index f9f51af7d14..f0cfb72c966 100644
--- a/modules/auth_saml/app/controllers/saml/providers_controller.rb
+++ b/modules/auth_saml/app/controllers/saml/providers_controller.rb
@@ -6,7 +6,7 @@ module Saml
menu_item :plugin_saml
before_action :require_admin
- before_action :check_ee
+ before_action :check_ee, except: %i[index]
before_action :find_provider, only: %i[show edit import_metadata update confirm_destroy destroy]
before_action :check_provider_writable, only: %i[update import_metadata]
before_action :set_edit_state, only: %i[create edit update import_metadata]
@@ -141,10 +141,7 @@ module Saml
end
def check_ee
- unless EnterpriseToken.allows_to?(:sso_auth_providers)
- render template: "/saml/providers/upsale"
- false
- end
+ redirect_to action: :index unless EnterpriseToken.allows_to?(:sso_auth_providers)
end
def default_breadcrumb; end
diff --git a/modules/auth_saml/app/views/saml/providers/index.html.erb b/modules/auth_saml/app/views/saml/providers/index.html.erb
index 80174c824c9..da5a68c158f 100644
--- a/modules/auth_saml/app/views/saml/providers/index.html.erb
+++ b/modules/auth_saml/app/views/saml/providers/index.html.erb
@@ -15,6 +15,7 @@
aria: { label: I18n.t("saml.providers.label_add_new") },
title: I18n.t("saml.providers.label_add_new"),
tag: :a,
+ disabled: !EnterpriseToken.allows_to?(:sso_auth_providers),
href: new_saml_provider_path
) do |button|
button.with_leading_visual_icon(icon: :plus)
@@ -23,4 +24,5 @@
end %>
<% end %>
+<%= render EnterpriseEdition::BannerComponent.new(:sso_auth_providers, i18n_scope: "saml.providers.upsale")%>
<%= render ::Saml::Providers::TableComponent.new(rows: @providers) %>
diff --git a/modules/auth_saml/app/views/saml/providers/upsale.html.erb b/modules/auth_saml/app/views/saml/providers/upsale.html.erb
deleted file mode 100644
index de8a2c51eae..00000000000
--- a/modules/auth_saml/app/views/saml/providers/upsale.html.erb
+++ /dev/null
@@ -1,9 +0,0 @@
-<% html_title(t(:label_administration), t("saml.providers.plural")) -%>
-
-<%= render template: "common/upsale",
- locals: {
- feature_title: t("saml.providers.plural"),
- feature_description: t("saml.providers.upsale.description"),
- feature_reference: "enterprise-openid-connect",
- feature_image: "enterprise/open-id-providers.jpg" # TODO
- } %>
diff --git a/modules/auth_saml/config/locales/en.yml b/modules/auth_saml/config/locales/en.yml
index 9fe4c38fed4..a0257e2f061 100644
--- a/modules/auth_saml/config/locales/en.yml
+++ b/modules/auth_saml/config/locales/en.yml
@@ -67,6 +67,7 @@ en:
metadata:
dialog: "This is the URL where the OpenProject SAML metadata is available. Optionally use it to configure your identity provider:"
upsale:
+ title: "Single Sign-On (SSO) with SAML"
description: Connect OpenProject to a SAML identity provider
request_attributes:
title: 'Requested attributes'
diff --git a/modules/openid_connect/app/controllers/openid_connect/providers_controller.rb b/modules/openid_connect/app/controllers/openid_connect/providers_controller.rb
index a4aadf58f8b..074b04917e0 100644
--- a/modules/openid_connect/app/controllers/openid_connect/providers_controller.rb
+++ b/modules/openid_connect/app/controllers/openid_connect/providers_controller.rb
@@ -36,7 +36,7 @@ module OpenIDConnect
menu_item :plugin_openid_connect
before_action :require_admin
- before_action :check_ee
+ before_action :check_ee, except: %i[index]
before_action :find_provider, only: %i[edit show update confirm_destroy destroy]
before_action :set_edit_state, only: %i[create edit update]
@@ -123,10 +123,7 @@ module OpenIDConnect
private
def check_ee
- unless EnterpriseToken.allows_to?(:sso_auth_providers)
- render template: "/openid_connect/providers/upsale"
- false
- end
+ redirect_to action: :index unless EnterpriseToken.allows_to?(:sso_auth_providers)
end
def find_provider
diff --git a/modules/openid_connect/app/views/openid_connect/providers/index.html.erb b/modules/openid_connect/app/views/openid_connect/providers/index.html.erb
index e912d3269d4..33ae7abd753 100644
--- a/modules/openid_connect/app/views/openid_connect/providers/index.html.erb
+++ b/modules/openid_connect/app/views/openid_connect/providers/index.html.erb
@@ -21,6 +21,7 @@
) do |menu|
menu.with_show_button(
scheme: :primary,
+ disabled: !EnterpriseToken.allows_to?(:sso_auth_providers),
aria: { label: I18n.t("openid_connect.providers.label_add_new") }
) do |button|
button.with_leading_visual_icon(icon: :plus)
@@ -39,4 +40,5 @@
end
%>
+<%= render EnterpriseEdition::BannerComponent.new(:sso_auth_providers, i18n_scope: "openid_connect.providers.upsale") %>
<%= render ::OpenIDConnect::Providers::TableComponent.new(rows: @providers) %>
diff --git a/modules/openid_connect/app/views/openid_connect/providers/upsale.html.erb b/modules/openid_connect/app/views/openid_connect/providers/upsale.html.erb
deleted file mode 100644
index 6b6063a75b6..00000000000
--- a/modules/openid_connect/app/views/openid_connect/providers/upsale.html.erb
+++ /dev/null
@@ -1,9 +0,0 @@
-<% html_title(t(:label_administration), t("openid_connect.providers.plural")) -%>
-
-<%= render template: "common/upsale",
- locals: {
- feature_title: t("openid_connect.providers.plural"),
- feature_description: t("openid_connect.providers.upsale.description"),
- feature_reference: "enterprise-openid-connect",
- feature_image: "enterprise/open-id-providers.jpg"
- } %>
diff --git a/modules/openid_connect/config/locales/en.yml b/modules/openid_connect/config/locales/en.yml
index 9b0f42e7842..d4869fc40cf 100644
--- a/modules/openid_connect/config/locales/en.yml
+++ b/modules/openid_connect/config/locales/en.yml
@@ -97,6 +97,7 @@ en:
custom:
name: Custom
upsale:
+ title: "Single Sign-On (SSO) with OpenID connect"
description: Connect OpenProject to an OpenID connect identity provider
label_add_new: Add a new OpenID provider
label_edit: Edit OpenID provider %{name}