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

added regression spec for active users and fixed anonymous user's status

Markus Kahlddb40187ba2f
diff --git a/app/models/user.rb b/app/models/user.rb
index a1c35b39bb4..e6223c5825f 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -685,7 +685,7 @@ class User < Principal
u.login = ''
u.firstname = ''
u.mail = ''
- u.status = 0
+ u.status = User::STATUSES[:active]
end).save
raise 'Unable to create the anonymous user.' if anonymous_user.new_record?
end
diff --git a/db/migrate/20191112111040_fix_system_user_status.rb b/db/migrate/20191112111040_fix_system_user_status.rb
new file mode 100644
index 00000000000..d90bba96077
--- /dev/null
+++ b/db/migrate/20191112111040_fix_system_user_status.rb
@@ -0,0 +1,34 @@
+class FixSystemUserStatus < ActiveRecord::Migration[6.0]
+ def up
+ # The previous migration was supposed to make the system user active,
+ # but doesn't since it only touches built-in (0) users while the system user
+ # used to be locked (3). An oversight on our part.
+ #
+ # We also update the anonymous user again. While it was correctly updated
+ # in the previous migration, newly created anonymous users since have the
+ # wrong status (0) because we failed to update the on-the-fly
+ # creation of the anonymous user with the correct status.
+ users.each do |user|
+ user.update_all status: Principal::STATUSES[:active]
+ end
+ end
+
+ def down
+ system_user.update_all status: Principal::STATUSES[:locked]
+ # There is no need to update the anonymous user since it was supposed to be
+ # active at this point already anyway. The previous migration then makes it
+ # built-in (0) again if we rollback even further.
+ end
+
+ def users
+ [system_user, anonymous_user]
+ end
+
+ def system_user
+ SystemUser
+ end
+
+ def anonymous_user
+ AnonymousUser
+ end
+end
diff --git a/spec/lib/open_project/enterprise_spec.rb b/spec/lib/open_project/enterprise_spec.rb
index 282be8f7510..ec80b39c994 100644
--- a/spec/lib/open_project/enterprise_spec.rb
+++ b/spec/lib/open_project/enterprise_spec.rb
@@ -32,8 +32,14 @@ require 'open_project/passwords'
describe OpenProject::Enterprise do
describe "#user_limit_reached?" do
let(:user_limit) { 2 }
+ let(:builtin_user_count) { 3 }
before do
+ # create 3 built-in users
+ User.system
+ User.anonymous
+ DeletedUser.first
+
allow(OpenProject::Enterprise).to receive(:user_limit).and_return(user_limit)
end
@@ -41,7 +47,7 @@ describe OpenProject::Enterprise do
before do
FactoryBot.create :user
- expect(User.active.count).to eq 1
+ expect(User.active.count).to eq 1 + builtin_user_count # created user + built-in ones
end
it "is false" do
@@ -56,7 +62,7 @@ describe OpenProject::Enterprise do
before do
FactoryBot.create_list :user, num_active_users
- expect(User.active.count).to eq num_active_users
+ expect(User.active.count).to eq num_active_users + builtin_user_count
end
it "is true" do