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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Remove builtin status
Oliver Günther51e8387e78b1
diff --git a/app/contracts/members/create_contract.rb b/app/contracts/members/create_contract.rbindex 4646509a2f4..80479f7e86f 100644--- a/app/contracts/members/create_contract.rb+++ b/app/contracts/members/create_contract.rb@@ -37,8 +37,10 @@ module Membersprivatedef 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)endenddiff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rbindex 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 statusdef 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)endbrute_force_status = ''diff --git a/app/models/principal.rb b/app/models/principal.rbindex 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.9STATUSES = {- builtin: 0,active: 1,registered: 2,locked: 3,@@ -73,8 +72,6 @@ class Principal < ActiveRecord::Basewhere.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.rbindex 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 propertiesdef logged?; false end+ def builtin?; true end+def name(*_args); 'System' enddef mail; nil end@@ -54,12 +56,10 @@ class SystemUser < Userdef grant_privilegesself.admin = true- self.status = STATUSES[:builtin]enddef remove_privilegesself.admin = false- self.status = STATUSES[:locked]enddef run_given(&_block)diff --git a/app/models/user.rb b/app/models/user.rbindex f7d823aa4a3..a1c35b39bb4 100644--- a/app/models/user.rb+++ b/app/models/user.rb@@ -320,11 +320,11 @@ class User < Principalenddef status_name- STATUSES.keys[status].to_s+ STATUSES.invert[status].to_senddef active?- [STATUSES[:active], STATUSES[:builtin]].include? status+ status == STATUSES[:active]enddef registered?@@ -702,7 +702,7 @@ class User < Principallogin: "",mail: "",admin: false,- status: User::STATUSES[:locked],+ status: User::STATUSES[:active],first_login: false)@@ -869,6 +869,8 @@ class AnonymousUser < User# Overrides a few propertiesdef logged?; false end+ def builtin?; true end+def admin; false enddef name(*_args); I18n.t(:label_user_anonymous) end@@ -885,20 +887,20 @@ endclass DeletedUser < Uservalidate :validate_unique_deleted_user, on: :create- default_scope { where(status: STATUSES[:builtin]) }-# There should be only one DeletedUser in the databasedef validate_unique_deleted_usererrors.add :base, 'A DeletedUser already exists.' if DeletedUser.any?enddef self.first- super || create(type: to_s, status: STATUSES[:builtin])+ super || create(type: to_s, status: STATUSES[:active])end# Overrides a few propertiesdef logged?; false end+ def builtin?; true end+def admin; false enddef name(*_args); I18n.t('user.deleted') enddiff --git a/db/migrate/20191106132533_make_system_user_active.rb b/db/migrate/20191106132533_make_system_user_active.rbnew file mode 100644index 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+enddiff --git a/frontend/src/app/modules/common/path-helper/apiv3/apiv3-paths.ts b/frontend/src/app/modules/common/path-helper/apiv3/apiv3-paths.tsindex 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.tsindex 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.rbindex 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 APIenddef 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.rbindex 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 APIdef filter_queryparams = [{ 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.rbindex 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 APIparams = [{ 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.projectparams << { 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.rbindex 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 APIdef 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'] } }]enddiff --git a/spec/factories/user_factory.rb b/spec/factories/user_factory.rbindex 436cb3e6772..e8189d2a783 100644--- a/spec/factories/user_factory.rb+++ b/spec/factories/user_factory.rb@@ -51,9 +51,7 @@ FactoryBot.define dofirst_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: DeletedUserfactory :locked_user dofirstname { 'Locked' }@@ -71,12 +69,10 @@ FactoryBot.define doendfactory :anonymous, class: AnonymousUser do- status { User::STATUSES[:builtin] }initialize_with { User.anonymous }endfactory :system, class: SystemUser do- status { User::STATUSES[:locked] }initialize_with { User.system }endenddiff --git a/spec/lib/api/v3/memberships/schemas/membership_schema_representer_spec.rb b/spec/lib/api/v3/memberships/schemas/membership_schema_representer_spec.rbindex 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 docontext 'if having no project' doit_behaves_like 'links to allowed values via collection link' dolet(: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 doit_behaves_like 'links to allowed values via collection link' dolet(: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.rbindex 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' dolet(:filter_query) do- [{ status: { operator: '!', values: ['0', '3'] } },+ [{ status: { operator: '!', values: ['3'] } },{ member: { operator: '=', values: [project.id.to_s] } }]endlet(:group_assignment_enabled) { true }@@ -94,7 +94,7 @@ describe ::API::V3::Queries::Schemas::AllPrincipalsFilterDependencyRepresenter,context 'within a project without group assignment' dolet(: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' dolet(: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' dolet(:project) { nil }let(:filter_query) do- [{ status: { operator: '!', values: ['0', '3'] } },+ [{ status: { operator: '!', values: ['3'] } },{ member: { operator: '*', values: [] } }]endlet(: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.rbindex 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_caclet(: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] } }]endlet(:href) do@@ -74,7 +74,7 @@ describe ::API::V3::Queries::Schemas::UserFilterDependencyRepresenter, clear_caclet(:project) { nil }let(:filter_query) do[{ type: { operator: '=', values: ['User'] } },- { status: { operator: '!', values: ['0', '3'] } }]+ { status: { operator: '!', values: ['3'] } }]endcontext "for operator 'Queries::Operators::Equals'" dodiff --git a/spec/lib/api/v3/utilities/custom_field_injector_spec.rb b/spec/lib/api/v3/utilities/custom_field_injector_spec.rbindex 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 dolet(:path) { cf_path }let(:href) doparams = [{ 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.rbindex 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 dodescribe '#grant_privileges' dobefore doexpect(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_privilegesendit 'grant admin rights' doexpect(system_user.admin).to be_truthyend-- it 'unlocks the user' do- expect(system_user.status).to eq(User::STATUSES[:builtin])- endenddescribe '#remove_privileges' dobefore dosystem_user.admin = true- system_user.status = User::STATUSES[:active]system_user.savesystem_user.remove_privilegesend@@ -58,10 +53,6 @@ describe SystemUser, type: :model doit 'removes admin rights' doexpect(system_user.admin).to be_falseyend-- it 'locks the user' do- expect(system_user.status).to eq(User::STATUSES[:locked])- endenddescribe '#run_given' dodiff --git a/spec_legacy/fixtures/users.yml b/spec_legacy/fixtures/users.ymlindex 4dd0eebcb43..8cd1c0435b3 100644--- a/spec_legacy/fixtures/users.yml+++ b/spec_legacy/fixtures/users.yml@@ -111,7 +111,7 @@ users_005:users_006:id: 6created_on: 2006-07-19 19:33:19 +02:00- status: 0+ status: 1last_login_on:language: ''updated_on: 2006-07-19 19:33:19 +02:00