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

Add trial banner

Mir Bhatia81d34331a0c1
diff --git a/app/components/enterprise_edition/banner_component.rb b/app/components/enterprise_edition/banner_component.rb
index 9f778e107d2..d92a4edc3f2 100644
--- a/app/components/enterprise_edition/banner_component.rb
+++ b/app/components/enterprise_edition/banner_component.rb
@@ -68,12 +68,15 @@ module EnterpriseEdition
@image = image
@video = video
@dismissable = dismissable
- @dismiss_key = dismiss_key
+ @dismiss_key = dismiss_key.to_s
+
@show_always = show_always
self.feature_key = feature_key
self.i18n_scope = i18n_scope
+ trial_overrides! if trial_feature?
+
if @variant == :medium && @image.nil?
raise ArgumentError, "The 'image' parameter is required when the variant is :medium."
end
@@ -82,17 +85,7 @@ module EnterpriseEdition
raise ArgumentError, "The 'video' parameter is required when the variant is :large."
end
- @system_arguments = system_arguments
- @system_arguments[:tag] = :div
- @system_arguments[:mb] ||= 2
- @system_arguments[:id] = "op-enterprise-banner-#{feature_key.to_s.tr('_', '-')}"
- @system_arguments[:test_selector] = "op-enterprise-banner"
- @system_arguments[:classes] = class_names(
- @system_arguments[:classes],
- "op-enterprise-banner",
- @variant == :medium ? "op-enterprise-banner_medium" : nil,
- @variant == :large ? "op-enterprise-banner_large" : nil
- )
+ set_system_arguments(system_arguments, feature_key)
super
end
@@ -115,15 +108,38 @@ module EnterpriseEdition
end
def wrapper_key
- "enterprise_banner_#{feature_key}"
+ "enterprise_banner_#{@dismiss_key}"
end
private
+ def set_system_arguments(system_arguments, feature_key)
+ @system_arguments = system_arguments
+ @system_arguments[:tag] = :div
+ @system_arguments[:mb] ||= 2
+ @system_arguments[:id] = "op-enterprise-banner-#{feature_key.to_s.tr('_', '-')}"
+ @system_arguments[:test_selector] = "op-enterprise-banner"
+ @system_arguments[:classes] = class_names(
+ @system_arguments[:classes],
+ "op-enterprise-banner",
+ @variant == :medium ? "op-enterprise-banner_medium" : nil,
+ @variant == :large ? "op-enterprise-banner_large" : nil
+ )
+ end
+
+ def trial_overrides!
+ @dismissable = true
+ @dismiss_key += "_trial" unless @dismiss_key.end_with?("_trial")
+ @variant = :inline
+ end
+
def render?
return true if @show_always
- !(EnterpriseToken.hide_banners? || feature_available? || dismissed?)
+ suppress_banner = EnterpriseToken.hide_banners? || feature_available? || dismissed?
+ allow_trial_exception = feature_available? && trial_feature? && !dismissed?
+
+ !suppress_banner || allow_trial_exception
end
def feature_available?
@@ -135,5 +151,9 @@ module EnterpriseEdition
User.current.pref.dismissed_banner?(@dismiss_key)
end
+
+ def trial_feature?
+ EnterpriseToken.trialling?(feature_key)
+ end
end
end
diff --git a/app/components/enterprise_edition/upsell_buttons_component.rb b/app/components/enterprise_edition/upsell_buttons_component.rb
index 2eaf28d164b..996631ade61 100644
--- a/app/components/enterprise_edition/upsell_buttons_component.rb
+++ b/app/components/enterprise_edition/upsell_buttons_component.rb
@@ -58,6 +58,7 @@ module EnterpriseEdition
def buttons
[
+ buy_now_button,
free_trial_button,
upgrade_now_button,
more_info_button
@@ -65,7 +66,7 @@ module EnterpriseEdition
end
def free_trial_button
- return if EnterpriseToken.active?
+ return if EnterpriseToken.active? && EnterpriseToken.trial?
return unless User.current.admin?
helpers.angular_component_tag(
@@ -74,6 +75,20 @@ module EnterpriseEdition
)
end
+ def buy_now_button
+ return unless EnterpriseToken.active? && EnterpriseToken.trial?
+ return unless User.current.admin?
+
+ render(Primer::Beta::Button.new(
+ classes: "upsell-colored-background",
+ tag: :a,
+ href: "/admin/subscriptions/new",
+ align_self: :center
+ )) do
+ I18n.t("ee.upsell.buy_now_button")
+ end
+ end
+
# Allow providing a custom upgrade now button
def upgrade_now_button
nil
diff --git a/app/controllers/my/enterprise_banners_controller.rb b/app/controllers/my/enterprise_banners_controller.rb
index e627b18ae77..c9cca555a87 100644
--- a/app/controllers/my/enterprise_banners_controller.rb
+++ b/app/controllers/my/enterprise_banners_controller.rb
@@ -47,9 +47,13 @@ class My::EnterpriseBannersController < ApplicationController
def dismiss
pref = User.current.pref
- pref.dismiss_banner(@feature_key)
+ pref.dismiss_banner(@dismiss_key)
if pref.save
- remove_via_turbo_stream(component: EnterpriseEdition::BannerComponent.new(@feature_key))
+ remove_via_turbo_stream(component: EnterpriseEdition::BannerComponent.new(
+ @feature_key,
+ dismiss_key: @dismiss_key,
+ show_always: true
+ ))
respond_with_turbo_streams
else
respond_with_flash_error(message: call.message)
@@ -59,7 +63,11 @@ class My::EnterpriseBannersController < ApplicationController
private
def get_feature_key
- @feature_key = params[:feature_key].to_sym
+ raw_key = params[:feature_key]
+
+ @dismiss_key = raw_key
+ @feature_key = raw_key.gsub(/_trial$/, "").to_sym
+
render_400 unless OpenProject::Token.lowest_plan_for(@feature_key)
end
end
diff --git a/app/models/enterprise_token.rb b/app/models/enterprise_token.rb
index 2dcad4af441..be817e7ba69 100644
--- a/app/models/enterprise_token.rb
+++ b/app/models/enterprise_token.rb
@@ -45,6 +45,10 @@ class EnterpriseToken < ApplicationRecord
current && !current.expired?
end
+ def trialling?(feature)
+ allows_to?(feature) && EnterpriseToken.current.trial?
+ end
+
def hide_banners?
OpenProject::Configuration.ee_hide_banners?
end
@@ -88,6 +92,7 @@ class EnterpriseToken < ApplicationRecord
:plan,
:features,
:version,
+ :trial?,
to: :token_object
def token_object
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 6068dc3f4f9..a122ce78654 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -2100,6 +2100,7 @@ en:
work_package_sharing: Share work packages with external users
work_package_subject_generation: Work Package Subject Generation
upsell:
+ buy_now_button: "Buy now"
plans_title: "Enterprise plans"
title: "Enterprise add-on"
plan_title: "Enterprise %{plan} add-on"