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

Remove builtin status

Oliver Günther51e8387e78b1
diff --git a/app/contracts/members/create_contract.rb b/app/contracts/members/create_contract.rb
index 4646509a2f4..80479f7e86f 100644
--- a/app/contracts/members/create_contract.rb
+++ b/app/contracts/members/create_contract.rb
@@ -37,8 +37,10 @@ module Members
private
def principal_assignable
- if principal &&
- [Principal::STATUSES[:builtin], Principal::STATUSES[:locked]].include?(principal.status)
+ return if principal.nil?
+
+ # Only users have the `locked?` shorthand
+ if principal.builtin? || principal.status == Principal::STATUSES[:locked]
errors.add(:principal, :unassignable)
end
end
diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb
index c7e3f3125cf..ba7ec65b7c1 100644
--- a/app/helpers/users_helper.rb
+++ b/app/helpers/users_helper.rb
@@ -51,7 +51,7 @@ module UsersHelper
# Format user status, including brute force prevention status
def full_user_status(user, include_num_failed_logins = false)
user_status = ''
- unless [User::STATUSES[:active], User::STATUSES[:builtin]].include?(user.status)
+ unless user.active?
user_status = translate_user_status(user.status_name)
end
brute_force_status = ''
diff --git a/app/models/principal.rb b/app/models/principal.rb
index feefb8d4671..e122c6cf4a4 100644
--- a/app/models/principal.rb
+++ b/app/models/principal.rb
@@ -32,7 +32,6 @@ class Principal < ActiveRecord::Base
# Account statuses
# Code accessing the keys assumes they are ordered, which they are since Ruby 1.9
STATUSES = {
- builtin: 0,
active: 1,
registered: 2,
locked: 3,
@@ -73,8 +72,6 @@ class Principal < ActiveRecord::Base
where.not(id: Member.of(project).select(:user_id))
}
- # Builtin status cannot be used here as the SystemUser is locked typically but
- # is a builtin user anyway.
scope :not_builtin, -> {
where.not(type: [SystemUser.name, AnonymousUser.name, DeletedUser.name])
}
@@ -138,6 +135,11 @@ class Principal < ActiveRecord::Base
[STATUSES[:active], STATUSES[:registered], STATUSES[:invited]].include?(status)
end
+ # Helper method to identify internal users
+ def builtin?
+ false
+ end
+
##
# Allows the API and other sources to determine locking actions
# on represented collections of children of Principals.
diff --git a/app/models/system_user.rb b/app/models/system_user.rb
index 69ed3dd7fc4..c3dd6c73a74 100644
--- a/app/models/system_user.rb
+++ b/app/models/system_user.rb
@@ -42,6 +42,8 @@ class SystemUser < User
# Overrides a few properties
def logged?; false end
+ def builtin?; true end
+
def name(*_args); 'System' end
def mail; nil end
@@ -54,12 +56,10 @@ class SystemUser < User
def grant_privileges
self.admin = true
- self.status = STATUSES[:builtin]
end
def remove_privileges
self.admin = false
- self.status = STATUSES[:locked]
end
def run_given(&_block)
diff --git a/app/models/user.rb b/app/models/user.rb
index f7d823aa4a3..a1c35b39bb4 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -320,11 +320,11 @@ class User < Principal
end
def status_name
- STATUSES.keys[status].to_s
+ STATUSES.invert[status].to_s
end
def active?
- [STATUSES[:active], STATUSES[:builtin]].include? status
+ status == STATUSES[:active]
end
def registered?
@@ -702,7 +702,7 @@ class User < Principal
login: "",
mail: "",
admin: false,
- status: User::STATUSES[:locked],
+ status: User::STATUSES[:active],
first_login: false
)
@@ -869,6 +869,8 @@ class AnonymousUser < User
# Overrides a few properties
def logged?; false end
+ def builtin?; true end
+
def admin; false end
def name(*_args); I18n.t(:label_user_anonymous) end
@@ -885,20 +887,20 @@ end
class DeletedUser < User
validate :validate_unique_deleted_user, on: :create
- default_scope { where(status: STATUSES[:builtin]) }
-
# There should be only one DeletedUser in the database
def validate_unique_deleted_user
errors.add :base, 'A DeletedUser already exists.' if DeletedUser.any?
end
def self.first
- super || create(type: to_s, status: STATUSES[:builtin])
+ super || create(type: to_s, status: STATUSES[:active])
end
# Overrides a few properties
def logged?; false end
+ def builtin?; true end
+
def admin; false end
def name(*_args); I18n.t('user.deleted') end
diff --git a/db/migrate/20191106132533_make_system_user_active.rb b/db/migrate/20191106132533_make_system_user_active.rb
new file mode 100644
index 00000000000..f7729f5c674
--- /dev/null
+++ b/db/migrate/20191106132533_make_system_user_active.rb
@@ -0,0 +1,14 @@
+class MakeSystemUserActive < ActiveRecord::Migration[6.0]
+ # Remember the integer mapped to previous builtin status
+ BUILTIN_STATUS ||= 0
+
+ def up
+ Principal.where(status: BUILTIN_STATUS).update_all(status: Principal::STATUSES[:active])
+ end
+
+ def down
+ AnonymousUser.update_all(status: BUILTIN_STATUS)
+ DeletedUser.update_all(status: BUILTIN_STATUS)
+ SystemUser.update_all(status: Principal::STATUSES[:locked])
+ end
+end
diff --git a/frontend/src/app/modules/common/path-helper/apiv3/apiv3-paths.ts b/frontend/src/app/modules/common/path-helper/apiv3/apiv3-paths.ts
index 9d2cc3b4e29..9153fbc1523 100644
--- a/frontend/src/app/modules/common/path-helper/apiv3/apiv3-paths.ts
+++ b/frontend/src/app/modules/common/path-helper/apiv3/apiv3-paths.ts
@@ -145,7 +145,7 @@ export class ApiV3Paths {
public principals(projectId:string|number, term:string|null) {
let filters:ApiV3FilterBuilder = new ApiV3FilterBuilder();
// Only real and activated users:
- filters.add('status', '!', ['0', '3']);
+ filters.add('status', '!', ['3']);
// that are members of that project:
filters.add('member', '=', [projectId.toString()]);
// That are users:
diff --git a/frontend/src/app/modules/common/path-helper/path-helper.service.spec.ts b/frontend/src/app/modules/common/path-helper/path-helper.service.spec.ts
index cf7d7168990..84fb1ae2bda 100644
--- a/frontend/src/app/modules/common/path-helper/path-helper.service.spec.ts
+++ b/frontend/src/app/modules/common/path-helper/path-helper.service.spec.ts
@@ -44,7 +44,7 @@ describe('PathHelper', function() {
expect(
PathHelper.api.v3.principals(projectId, term)
- ).toEqual('/api/v3/principals?filters=' + encodeURI('[{"status":{"operator":"!","values":["0","3"]}},{"member":{"operator":"=","values":["1"]}},{"type":{"operator":"=","values":["User","Group"]}},{"id":{"operator":"!","values":["me"]}},{"name":{"operator":"~","values":["Maria"]}}]&sortBy=[["name","asc"]]&offset=1&pageSize=10'));
+ ).toEqual('/api/v3/principals?filters=' + encodeURI('[{"status":{"operator":"!","values":["3"]}},{"member":{"operator":"=","values":["1"]}},{"type":{"operator":"=","values":["User","Group"]}},{"id":{"operator":"!","values":["me"]}},{"name":{"operator":"~","values":["Maria"]}}]&sortBy=[["name","asc"]]&offset=1&pageSize=10'));
});
it('should provide a path to work package query on subject or ID ', function() {
diff --git a/lib/api/v3/memberships/schemas/membership_schema_representer.rb b/lib/api/v3/memberships/schemas/membership_schema_representer.rb
index 2a2d93e1011..dd58666fc91 100644
--- a/lib/api/v3/memberships/schemas/membership_schema_representer.rb
+++ b/lib/api/v3/memberships/schemas/membership_schema_representer.rb
@@ -95,8 +95,7 @@ module API
end
def allowed_principals_filters
- statuses = [Principal::STATUSES[:builtin].to_s,
- Principal::STATUSES[:locked].to_s]
+ statuses = [Principal::STATUSES[:locked].to_s]
status_filter = { status: { operator: '!', values: statuses } }
filters = [status_filter]
diff --git a/lib/api/v3/queries/schemas/all_principals_filter_dependency_representer.rb b/lib/api/v3/queries/schemas/all_principals_filter_dependency_representer.rb
index 7cf95c1173c..d017b685f88 100644
--- a/lib/api/v3/queries/schemas/all_principals_filter_dependency_representer.rb
+++ b/lib/api/v3/queries/schemas/all_principals_filter_dependency_representer.rb
@@ -47,8 +47,7 @@ module API
def filter_query
params = [{ status: { operator: '!',
- values: [Principal::STATUSES[:builtin].to_s,
- Principal::STATUSES[:locked].to_s] } }]
+ values: [Principal::STATUSES[:locked].to_s] } }]
unless Setting.work_package_group_assignment?
params << { type: { operator: '=', values: ['User'] } }
diff --git a/lib/api/v3/queries/schemas/user_filter_dependency_representer.rb b/lib/api/v3/queries/schemas/user_filter_dependency_representer.rb
index efb67ba1168..c6de66ed4f8 100644
--- a/lib/api/v3/queries/schemas/user_filter_dependency_representer.rb
+++ b/lib/api/v3/queries/schemas/user_filter_dependency_representer.rb
@@ -45,8 +45,7 @@ module API
params = [{ type: { operator: '=',
values: ['User'] } },
{ status: { operator: '!',
- values: [Principal::STATUSES[:builtin].to_s,
- Principal::STATUSES[:locked].to_s] } }]
+ values: [Principal::STATUSES[:locked].to_s] } }]
if filter.project
params << { member: { operator: '=', values: [filter.project.id.to_s] } }
diff --git a/lib/api/v3/utilities/custom_field_injector.rb b/lib/api/v3/utilities/custom_field_injector.rb
index c30365065c2..1ce81b4f352 100644
--- a/lib/api/v3/utilities/custom_field_injector.rb
+++ b/lib/api/v3/utilities/custom_field_injector.rb
@@ -351,8 +351,7 @@ module API
def allowed_users_static_filters
[{ status: { operator: '!',
- values: [Principal::STATUSES[:builtin].to_s,
- Principal::STATUSES[:locked].to_s] } },
+ values: [Principal::STATUSES[:locked].to_s] } },
{ type: { operator: '=', values: ['User'] } }]
end
diff --git a/spec/factories/user_factory.rb b/spec/factories/user_factory.rb
index 436cb3e6772..e8189d2a783 100644
--- a/spec/factories/user_factory.rb
+++ b/spec/factories/user_factory.rb
@@ -51,9 +51,7 @@ FactoryBot.define do
first_login { false if User.table_exists? and User.columns.map(&:name).include? 'first_login' }
end
- factory :deleted_user, class: DeletedUser do
- status { User::STATUSES[:builtin] }
- end
+ factory :deleted_user, class: DeletedUser
factory :locked_user do
firstname { 'Locked' }
@@ -71,12 +69,10 @@ FactoryBot.define do
end
factory :anonymous, class: AnonymousUser do
- status { User::STATUSES[:builtin] }
initialize_with { User.anonymous }
end
factory :system, class: SystemUser do
- status { User::STATUSES[:locked] }
initialize_with { User.system }
end
end
diff --git a/spec/lib/api/v3/memberships/schemas/membership_schema_representer_spec.rb b/spec/lib/api/v3/memberships/schemas/membership_schema_representer_spec.rb
index 8ecccb4cd48..60f28ac8bd1 100644
--- a/spec/lib/api/v3/memberships/schemas/membership_schema_representer_spec.rb
+++ b/spec/lib/api/v3/memberships/schemas/membership_schema_representer_spec.rb
@@ -190,7 +190,7 @@ describe ::API::V3::Memberships::Schemas::MembershipSchemaRepresenter do
context 'if having no project' do
it_behaves_like 'links to allowed values via collection link' do
let(:href) do
- statuses = [Principal::STATUSES[:builtin].to_s, Principal::STATUSES[:locked].to_s]
+ statuses = [Principal::STATUSES[:locked].to_s]
filters = [{ 'status' => { 'operator' => '!', 'values' => statuses } }]
api_v3_paths.path_for(:principals, filters: filters)
@@ -203,7 +203,7 @@ describe ::API::V3::Memberships::Schemas::MembershipSchemaRepresenter do
it_behaves_like 'links to allowed values via collection link' do
let(:href) do
- statuses = [Principal::STATUSES[:builtin].to_s, Principal::STATUSES[:locked].to_s]
+ statuses = [Principal::STATUSES[:locked].to_s]
status_filter = { 'status' => { 'operator' => '!', 'values' => statuses } }
member_filter = { 'member' => { 'operator' => '!', 'values' => [assigned_project.id.to_s] } }
diff --git a/spec/lib/api/v3/queries/schemas/all_principals_filter_dependency_representer_spec.rb b/spec/lib/api/v3/queries/schemas/all_principals_filter_dependency_representer_spec.rb
index 5fae2e5624f..8e74a53e7f6 100644
--- a/spec/lib/api/v3/queries/schemas/all_principals_filter_dependency_representer_spec.rb
+++ b/spec/lib/api/v3/queries/schemas/all_principals_filter_dependency_representer_spec.rb
@@ -74,7 +74,7 @@ describe ::API::V3::Queries::Schemas::AllPrincipalsFilterDependencyRepresenter,
context 'within a project with group assignment' do
let(:filter_query) do
- [{ status: { operator: '!', values: ['0', '3'] } },
+ [{ status: { operator: '!', values: ['3'] } },
{ member: { operator: '=', values: [project.id.to_s] } }]
end
let(:group_assignment_enabled) { true }
@@ -94,7 +94,7 @@ describe ::API::V3::Queries::Schemas::AllPrincipalsFilterDependencyRepresenter,
context 'within a project without group assignment' do
let(:filter_query) do
- [{ status: { operator: '!', values: ['0', '3'] } },
+ [{ status: { operator: '!', values: ['3'] } },
{ type: { operator: '=', values: ['User'] } },
{ member: { operator: '=', values: [project.id.to_s] } }]
end
@@ -115,7 +115,7 @@ describe ::API::V3::Queries::Schemas::AllPrincipalsFilterDependencyRepresenter,
context 'global with no group assignments' do
let(:project) { nil }
let(:filter_query) do
- [{ status: { operator: '!', values: ['0', '3'] } },
+ [{ status: { operator: '!', values: ['3'] } },
{ type: { operator: '=', values: ['User'] } },
{ member: { operator: '*', values: [] } }]
end
@@ -136,7 +136,7 @@ describe ::API::V3::Queries::Schemas::AllPrincipalsFilterDependencyRepresenter,
context 'global with group assignments' do
let(:project) { nil }
let(:filter_query) do
- [{ status: { operator: '!', values: ['0', '3'] } },
+ [{ status: { operator: '!', values: ['3'] } },
{ member: { operator: '*', values: [] } }]
end
let(:group_assignment_enabled) { true }
diff --git a/spec/lib/api/v3/queries/schemas/user_filter_dependency_representer_spec.rb b/spec/lib/api/v3/queries/schemas/user_filter_dependency_representer_spec.rb
index d0f43e59be3..e2385c50eaf 100644
--- a/spec/lib/api/v3/queries/schemas/user_filter_dependency_representer_spec.rb
+++ b/spec/lib/api/v3/queries/schemas/user_filter_dependency_representer_spec.rb
@@ -51,7 +51,7 @@ describe ::API::V3::Queries::Schemas::UserFilterDependencyRepresenter, clear_cac
let(:type) { '[]User' }
let(:filter_query) do
[{ type: { operator: '=', values: ['User'] } },
- { status: { operator: '!', values: ['0', '3'] } },
+ { status: { operator: '!', values: ['3'] } },
{ member: { operator: '=', values: [project.id.to_s] } }]
end
let(:href) do
@@ -74,7 +74,7 @@ describe ::API::V3::Queries::Schemas::UserFilterDependencyRepresenter, clear_cac
let(:project) { nil }
let(:filter_query) do
[{ type: { operator: '=', values: ['User'] } },
- { status: { operator: '!', values: ['0', '3'] } }]
+ { status: { operator: '!', values: ['3'] } }]
end
context "for operator 'Queries::Operators::Equals'" do
diff --git a/spec/lib/api/v3/utilities/custom_field_injector_spec.rb b/spec/lib/api/v3/utilities/custom_field_injector_spec.rb
index 27574272084..fd96380455d 100644
--- a/spec/lib/api/v3/utilities/custom_field_injector_spec.rb
+++ b/spec/lib/api/v3/utilities/custom_field_injector_spec.rb
@@ -223,8 +223,7 @@ describe ::API::V3::Utilities::CustomFieldInjector do
let(:path) { cf_path }
let(:href) do
params = [{ status: { operator: '!',
- values: [Principal::STATUSES[:builtin].to_s,
- Principal::STATUSES[:locked].to_s] } },
+ values: [Principal::STATUSES[:locked].to_s] } },
{ type: { operator: '=', values: ['User'] } },
{ member: { operator: '=', values: [schema.project_id.to_s] } }]
diff --git a/spec/models/system_user_spec.rb b/spec/models/system_user_spec.rb
index 6c904e38707..39f8292f398 100644
--- a/spec/models/system_user_spec.rb
+++ b/spec/models/system_user_spec.rb
@@ -34,23 +34,18 @@ describe SystemUser, type: :model do
describe '#grant_privileges' do
before do
expect(system_user.admin).to be_falsey
- expect(system_user.status).to eq(User::STATUSES[:locked])
+ expect(system_user.status).to eq(User::STATUSES[:active])
system_user.grant_privileges
end
it 'grant admin rights' do
expect(system_user.admin).to be_truthy
end
-
- it 'unlocks the user' do
- expect(system_user.status).to eq(User::STATUSES[:builtin])
- end
end
describe '#remove_privileges' do
before do
system_user.admin = true
- system_user.status = User::STATUSES[:active]
system_user.save
system_user.remove_privileges
end
@@ -58,10 +53,6 @@ describe SystemUser, type: :model do
it 'removes admin rights' do
expect(system_user.admin).to be_falsey
end
-
- it 'locks the user' do
- expect(system_user.status).to eq(User::STATUSES[:locked])
- end
end
describe '#run_given' do
diff --git a/spec_legacy/fixtures/users.yml b/spec_legacy/fixtures/users.yml
index 4dd0eebcb43..8cd1c0435b3 100644
--- a/spec_legacy/fixtures/users.yml
+++ b/spec_legacy/fixtures/users.yml
@@ -111,7 +111,7 @@ users_005:
users_006:
id: 6
created_on: 2006-07-19 19:33:19 +02:00
- status: 0
+ status: 1
last_login_on:
language: ''
updated_on: 2006-07-19 19:33:19 +02:00