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

Implement dismissable banners

Oliver Günther0dc8e166e605
diff --git a/app/components/enterprise_edition/banner_component.html.erb b/app/components/enterprise_edition/banner_component.html.erb
index 669c0e79621..b553eb23b41 100644
--- a/app/components/enterprise_edition/banner_component.html.erb
+++ b/app/components/enterprise_edition/banner_component.html.erb
@@ -1,5 +1,6 @@
<%=
- grid_layout("op-enterprise-banner", **@system_arguments) do |grid|
+ grid_layout("op-enterprise-banner",
+ **@system_arguments) do |grid|
grid.with_area(:visual) do
render(Primer::Beta::Octicon.new(icon: :"op-enterprise-addons", classes: "op-enterprise-banner--icon"))
end
@@ -38,8 +39,11 @@
Primer::Beta::IconButton.new(
classes: "op-enterprise-banner--close-icon",
scheme: :invisible,
+ tag: :a,
+ href: dismiss_enterprise_banner_path(feature_key:),
+ data: { turbo_stream: true, turbo_method: :post },
icon: :x,
- aria: { label: "Hide" }
+ aria: { label: t("ee.upsale.hide_banner") }
)
)
end
diff --git a/app/components/enterprise_edition/banner_component.rb b/app/components/enterprise_edition/banner_component.rb
index d3d20ebe492..2f258cd11ea 100644
--- a/app/components/enterprise_edition/banner_component.rb
+++ b/app/components/enterprise_edition/banner_component.rb
@@ -39,6 +39,8 @@ module EnterpriseEdition
# @param title [String] The title of the banner.
# @param description [String] The description of the banner.
# @param href [String] The URL to link to.
+ # @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,
@@ -46,11 +48,14 @@ module EnterpriseEdition
description: nil,
link_title: nil,
href: nil,
+ dismissable: false,
+ dismiss_key: feature_key,
skip_render: EnterpriseToken.hide_banners?,
**system_arguments)
@system_arguments = system_arguments
@system_arguments[:tag] = :div
- @system_arguments[:test_selector] = "op-enterprise-banner-#{feature_key.to_s.tr('_', '-')}"
+ @system_arguments[:id] = "op-enterprise-banner-#{feature_key.to_s.tr('_', '-')}"
+ @system_arguments[:test_selector] = @system_arguments[:id]
super
@feature_key = feature_key
@@ -59,7 +64,8 @@ module EnterpriseEdition
@link_title = link_title
@href = href
@skip_render = skip_render
- @dismissable = true
+ @dismissable = dismissable
+ @dismiss_key = dismiss_key
end
private
@@ -150,7 +156,13 @@ module EnterpriseEdition
end
def render?
- !skip_render
+ !(skip_render || dismissed?)
+ end
+
+ def dismissed?
+ return false unless @dismissable
+
+ User.current.pref.dismissed_banner?(@dismiss_key)
end
end
end
diff --git a/app/components/work_packages/types/subject_configuration_component.html.erb b/app/components/work_packages/types/subject_configuration_component.html.erb
index 2e21afe60ff..b5141bf2ab8 100644
--- a/app/components/work_packages/types/subject_configuration_component.html.erb
+++ b/app/components/work_packages/types/subject_configuration_component.html.erb
@@ -28,7 +28,9 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
<%=
- render(EnterpriseEdition::BannerComponent.new(:work_package_subject_generation, mb: 3))
+ render(EnterpriseEdition::BannerComponent.new(:work_package_subject_generation,
+ dismissable: true,
+ mb: 3))
%>
<%=
diff --git a/app/controllers/my/enterprise_banners_controller.rb b/app/controllers/my/enterprise_banners_controller.rb
new file mode 100644
index 00000000000..8c3ceee19b2
--- /dev/null
+++ b/app/controllers/my/enterprise_banners_controller.rb
@@ -0,0 +1,51 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+class My::EnterpriseBannersController < ApplicationController
+ before_action :require_login
+
+ authorization_checked! :dismiss
+
+ def dismiss
+ feature_key = params[:feature_key].to_s
+
+ pref = User.current.pref
+ pref.dismiss_banner(feature_key)
+ if pref.save
+ respond_to do |format|
+ format.turbo_stream do
+ id = "op-enterprise-banner-#{feature_key.tr('_', '-')}"
+ render turbo_stream: turbo_stream.remove(id)
+ end
+ end
+ else
+ respond_with_flash_error(message: call.message)
+ end
+ end
+end
diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb
index 0e90fe646d1..e34f27969f1 100644
--- a/app/models/user_preference.rb
+++ b/app/models/user_preference.rb
@@ -147,6 +147,14 @@ class UserPreference < ApplicationRecord
super.presence || { enabled: false }.with_indifferent_access
end
+ def dismissed_banner?(feature)
+ dismissed_enterprise_banners.key?(feature.to_s)
+ end
+
+ def dismiss_banner(feature)
+ dismissed_enterprise_banners[feature.to_s] = Time.zone.now.utc
+ end
+
def supported_settings_method?(method_name)
UserPreferences::Schema.properties.include?(method_name.to_s.gsub(/\?|=\z/, ""))
end
diff --git a/config/locales/en.yml b/config/locales/en.yml
index e7ef9b1fe5c..610525f1b46 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -2044,6 +2044,7 @@ en:
plan_name: "%{plan} enterprise plan"
plan_text_html: "Available only through the %{plan_name}."
link_title: "More information"
+ hide_banner: "Hide this banner"
work_package_subject_generation:
description: "Create automatically generated subjects using referenced attributes and text."
customize_life_cycle:
diff --git a/config/routes.rb b/config/routes.rb
index 6de2cba60eb..f0831aae751 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -795,6 +795,8 @@ Rails.application.routes.draw do
resources :sessions, controller: "my/sessions", as: "my_sessions", only: %i[index show destroy]
resources :auto_login_tokens, controller: "my/auto_login_tokens", as: "my_auto_login_tokens", only: %i[destroy]
+
+ post "/dismiss_banner" => "my/enterprise_banners#dismiss", as: "dismiss_enterprise_banner"
end
scope controller: "my" do
diff --git a/db/migrate/20250327071204_add_dismissed_enterprise_banners_to_user_preference.rb b/db/migrate/20250327071204_add_dismissed_enterprise_banners_to_user_preference.rb
new file mode 100644
index 00000000000..af31ff3cc3e
--- /dev/null
+++ b/db/migrate/20250327071204_add_dismissed_enterprise_banners_to_user_preference.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class AddDismissedEnterpriseBannersToUserPreference < ActiveRecord::Migration[8.0]
+ def change
+ add_column :user_preferences, :dismissed_enterprise_banners, :jsonb, default: {}, null: false
+ end
+end
diff --git a/frontend/src/global_styles/openproject/_variable_defaults.scss b/frontend/src/global_styles/openproject/_variable_defaults.scss
index a590eda1e50..48c03b3114a 100644
--- a/frontend/src/global_styles/openproject/_variable_defaults.scss
+++ b/frontend/src/global_styles/openproject/_variable_defaults.scss
@@ -138,4 +138,5 @@
--full-view-split-right-width: 550px;
--gantt-split-width: 50%;
--enterprise-upsale-color: #FB8F44;
+ --enterprise-upsale-border-color: var(--borderColor-severe-muted);
}