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

rework `show_banners?` check to also allow feature specific banners

Klaus Zandersab4915105224
diff --git a/app/models/enterprise_token.rb b/app/models/enterprise_token.rb
index dd43d7de04b..87d5f7cacca 100644
--- a/app/models/enterprise_token.rb
+++ b/app/models/enterprise_token.rb
@@ -37,16 +37,20 @@ class EnterpriseToken < ApplicationRecord
connection.data_source_exists? table_name
end
- def allows_to?(action)
- Authorization::EnterpriseService.new(current).call(action).result
+ def allows_to?(feature)
+ Authorization::EnterpriseService.new(current).call(feature).result
end
def active?
current && !current.expired?
end
- def show_banners?
- OpenProject::Configuration.ee_manager_visible? && !active?
+ def show_banners?(feature: nil)
+ if feature
+ OpenProject::Configuration.ee_manager_visible? && (!active? || !allows_to?(feature))
+ else
+ OpenProject::Configuration.ee_manager_visible? && !active?
+ end
end
def set_current_token
diff --git a/spec/models/enterprise_token_spec.rb b/spec/models/enterprise_token_spec.rb
index 850a9dc4205..9a3b045ff89 100644
--- a/spec/models/enterprise_token_spec.rb
+++ b/spec/models/enterprise_token_spec.rb
@@ -2,12 +2,13 @@ require "spec_helper"
RSpec.describe EnterpriseToken do
let(:object) { OpenProject::Token.new domain: Setting.host_name }
+ let(:ee_manager_visible) { true }
subject { EnterpriseToken.new(encoded_token: "foo") }
before do
RequestStore.delete :current_ee_token
- allow(OpenProject::Configuration).to receive(:ee_manager_visible?).and_return(true)
+ allow(OpenProject::Configuration).to receive(:ee_manager_visible?).and_return(ee_manager_visible)
end
describe ".active?" do
@@ -38,6 +39,85 @@ RSpec.describe EnterpriseToken do
end
end
+ describe ".show_banners?" 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 "when ee manager is visible" do
+ let(:ee_manager_visible) { true }
+
+ context "when token is active" do
+ before { allow(described_class).to receive(:active?).and_return(true) }
+
+ it "returns false when requesting without a feature" do
+ expect(described_class).not_to be_show_banners
+ end
+
+ it "returns false when requesting with a feature that is enabled in the token" do
+ expect(described_class).not_to be_show_banners(feature: :active_feature)
+ end
+
+ it "returns true when requesting with a feature that is disabled in the token" do
+ expect(described_class).to be_show_banners(feature: :inactive_feature)
+ end
+ end
+
+ context "when token is inactive" do
+ before { allow(described_class).to receive(:active?).and_return(false) }
+
+ it "returns true when requesting without a feature" do
+ expect(described_class).to be_show_banners
+ end
+
+ it "returns true when requesting with a feature that is enabled in the token" do
+ expect(described_class).to be_show_banners(feature: :active_feature)
+ end
+
+ it "returns true when requesting with a feature that is disabled in the token" do
+ expect(described_class).to be_show_banners(feature: :inactive_feature)
+ end
+ end
+ end
+
+ context "when ee manager is not visible" do
+ let(:ee_manager_visible) { false }
+
+ context "when token is active" do
+ before { allow(described_class).to receive(:active?).and_return(true) }
+
+ it "returns false when requesting without a feature" do
+ expect(described_class).not_to be_show_banners
+ end
+
+ it "returns false when requesting with a feature that is enabled in the token" do
+ expect(described_class).not_to be_show_banners(feature: :active_feature)
+ end
+
+ it "returns false when requesting with a feature that is disabled in the token" do
+ expect(described_class).not_to be_show_banners(feature: :inactive_feature)
+ end
+ end
+
+ context "when token is inactive" do
+ before { allow(described_class).to receive(:active?).and_return(false) }
+
+ it "returns false when requesting without a feature" do
+ expect(described_class).not_to be_show_banners
+ end
+
+ it "returns false when requesting with a feature that is enabled in the token" do
+ expect(described_class).not_to be_show_banners(feature: :active_feature)
+ end
+
+ it "returns false when requesting with a feature that is disabled in the token" do
+ expect(described_class).not_to be_show_banners(feature: :inactive_feature)
+ end
+ end
+ end
+ end
+
describe "existing token" do
before do
allow_any_instance_of(EnterpriseToken).to receive(:token_object).and_return(object)