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

only show imminent user limit warning when limit has been passed

Markus Kahl2920dab7dd3c
diff --git a/lib/open_project/enterprise.rb b/lib/open_project/enterprise.rb
index f7959ba7d08..74f313ad1a8 100644
--- a/lib/open_project/enterprise.rb
+++ b/lib/open_project/enterprise.rb
@@ -61,7 +61,7 @@ module OpenProject
# While the active user limit has not been reached yet it would be reached
# if all registered and invited users were to activate their accounts.
def imminent_user_limit?
- User.human.not_locked.count >= user_limit if user_limit
+ User.human.not_locked.count > user_limit if user_limit
end
def fail_fast?
diff --git a/spec/lib/open_project/enterprise_spec.rb b/spec/lib/open_project/enterprise_spec.rb
index 342c63cf2bd..a1bf635bc56 100644
--- a/spec/lib/open_project/enterprise_spec.rb
+++ b/spec/lib/open_project/enterprise_spec.rb
@@ -30,21 +30,22 @@ require 'spec_helper'
require 'open_project/passwords'
describe OpenProject::Enterprise do
- describe "#user_limit_reached?" do
- let(:user_limit) { 2 }
- # create 3 built-in users, only 2 of which are active
- # Also create a placeholder user which will not count against the limit
- let!(:system_user) { User.system }
- let!(:anonymous_user) { User.anonymous }
- let!(:deleted_user) { DeletedUser.first } # locked, not active
- let!(:placeholder_user) { FactoryBot.create(:placeholder_user) }
-
- before do
- allow(OpenProject::Enterprise)
- .to receive(:user_limit)
- .and_return(user_limit)
- end
+ # create 3 built-in users, only 2 of which are active
+ # Also create a placeholder user which will not count against the limit
+ let!(:system_user) { User.system }
+ let!(:anonymous_user) { User.anonymous }
+ let!(:deleted_user) { DeletedUser.first } # locked, not active
+ let!(:placeholder_user) { FactoryBot.create(:placeholder_user) }
+
+ let(:user_limit) { 2 }
+
+ before do
+ allow(OpenProject::Enterprise)
+ .to receive(:user_limit)
+ .and_return(user_limit)
+ end
+ describe "#user_limit_reached?" do
context "with fewer active users than the limit allows" do
before do
FactoryBot.create :user
@@ -85,4 +86,46 @@ describe OpenProject::Enterprise do
end
end
end
+
+ describe "#imminent_user_limit?" do
+ context "with the number of active + invited users below (or at) the user limit" do
+ shared_examples "user limit is not imminent" do
+ let(:num_invited_users) { 0 }
+
+ before do
+ FactoryBot.create :user
+ FactoryBot.create_list :invited_user, num_invited_users
+
+ expect(User.human.not_locked.count).to eq num_invited_users + 1
+ end
+
+ it "is true" do
+ expect(subject).not_to be_imminent_user_limit
+ end
+ end
+
+ context "(less)" do
+ it_behaves_like "user limit is not imminent" do
+ let(:num_invited_users) { 0 }
+ end
+ end
+
+ context "(equal)" do
+ it_behaves_like "user limit is not imminent" do
+ let(:num_invited_users) { 1 }
+ end
+ end
+ end
+
+ context "with the number of active + invited users over the user limit" do
+ before do
+ FactoryBot.create :user
+ FactoryBot.create_list :invited_user, user_limit
+ end
+
+ it "is true" do
+ expect(subject).to be_imminent_user_limit
+ end
+ end
+ end
end