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 banner type for EnterpriseToken

Klaus Zandersaf4728db8bc5
diff --git a/app/models/enterprise_token.rb b/app/models/enterprise_token.rb
index 7aff6d7c8c0..55b2d0c44f8 100644
--- a/app/models/enterprise_token.rb
+++ b/app/models/enterprise_token.rb
@@ -53,6 +53,14 @@ class EnterpriseToken < ApplicationRecord
end
end
+ def banner_type_for(feature:)
+ if !active?
+ :no_token
+ elsif !allows_to?(feature)
+ :upsell
+ end
+ end
+
def set_current_token
token = EnterpriseToken.order(Arel.sql("created_at DESC")).first
diff --git a/spec/models/enterprise_token_spec.rb b/spec/models/enterprise_token_spec.rb
index 9a3b045ff89..1475a548211 100644
--- a/spec/models/enterprise_token_spec.rb
+++ b/spec/models/enterprise_token_spec.rb
@@ -118,6 +118,43 @@ RSpec.describe EnterpriseToken do
end
end
+ describe ".banner_type_for" do
+ before do
+ allow(described_class).to receive(:allows_to?).with(:active_feature).and_return(true)
+ allow(described_class).to receive(:allows_to?).with(:inactive_feature).and_return(false)
+ end
+
+ context "without an EnterpriseToken" do
+ before do
+ allow(described_class).to receive(:active?).and_return(false)
+ end
+
+ it "returns :no_token" do
+ expect(described_class.banner_type_for(feature: :active_feature)).to eq(:no_token)
+ end
+ end
+
+ context "with a feature that is included in the EnterpriseToken" do
+ before do
+ allow(described_class).to receive(:active?).and_return(true)
+ end
+
+ it "returns nil" do
+ expect(described_class.banner_type_for(feature: :active_feature)).to be_nil
+ end
+ end
+
+ context "with a feature that is not included in the EnterpriseToken" do
+ before do
+ allow(described_class).to receive(:active?).and_return(true)
+ end
+
+ it "returns :upsell" do
+ expect(described_class.banner_type_for(feature: :inactive_feature)).to eq(:upsell)
+ end
+ end
+ end
+
describe "existing token" do
before do
allow_any_instance_of(EnterpriseToken).to receive(:token_object).and_return(object)