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

made deleted user locked; exclude builtin users from active_or_registered

Markus Kahl9922cc1fe47c
diff --git a/app/models/principal.rb b/app/models/principal.rb
index e122c6cf4a4..664a9268d9d 100644
--- a/app/models/principal.rb
+++ b/app/models/principal.rb
@@ -59,7 +59,7 @@ class Principal < ActiveRecord::Base
scope :active, -> { where(status: STATUSES[:active]) }
scope :active_or_registered, -> {
- where(status: [STATUSES[:active], STATUSES[:registered], STATUSES[:invited]])
+ not_builtin.where(status: [STATUSES[:active], STATUSES[:registered], STATUSES[:invited]])
}
scope :active_or_registered_like, ->(query) { active_or_registered.like(query) }
diff --git a/app/models/user.rb b/app/models/user.rb
index e6223c5825f..fe3782e9e5a 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -893,7 +893,7 @@ class DeletedUser < User
end
def self.first
- super || create(type: to_s, status: STATUSES[:active])
+ super || create(type: to_s, status: STATUSES[:locked])
end
# Overrides a few properties
diff --git a/db/migrate/20191112111040_fix_system_user_status.rb b/db/migrate/20191112111040_fix_system_user_status.rb
index d90bba96077..d5fbb246ed4 100644
--- a/db/migrate/20191112111040_fix_system_user_status.rb
+++ b/db/migrate/20191112111040_fix_system_user_status.rb
@@ -8,19 +8,26 @@ class FixSystemUserStatus < ActiveRecord::Migration[6.0]
# 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|
+ active_users.each do |user|
user.update_all status: Principal::STATUSES[:active]
end
+
+ deleted_user.update_all status: Principal::STATUSES[:active]
end
def down
+ # reset system user to locked which would've been the state before this migration
system_user.update_all status: Principal::STATUSES[:locked]
+
+ # reset deleted usr to active which he would've been after the previous migration
+ deleted_user.update_all status: Principal::STATUSES[:active]
+
# 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
+ def active_users
[system_user, anonymous_user]
end
@@ -31,4 +38,8 @@ class FixSystemUserStatus < ActiveRecord::Migration[6.0]
def anonymous_user
AnonymousUser
end
+
+ def deleted_user
+ DeletedUser
+ end
end
diff --git a/spec/support/shared/acts_as_watchable.rb b/spec/support/shared/acts_as_watchable.rb
index 48c25e50952..3463f07e6ea 100644
--- a/spec/support/shared/acts_as_watchable.rb
+++ b/spec/support/shared/acts_as_watchable.rb
@@ -120,6 +120,9 @@ MESSAGE
Role.non_member
Role.anonymous
+
+ User.system.save!
+
admin.save!
anonymous_user.save!
user_with_permission.save!
@@ -228,6 +231,8 @@ MESSAGE
model_instance
User.destroy_all
+ User.system.save!
+
Role.non_member
Role.anonymous
admin.save!