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 duplicate not_locked scope (#9166)
Oliver Günther174427fc0501
diff --git a/app/models/principal.rb b/app/models/principal.rbindex cf226598f1b..1fd121dbbf7 100644--- a/app/models/principal.rb+++ b/app/models/principal.rb@@ -32,12 +32,13 @@ class Principal < ApplicationRecordinclude ::Scopes::Scoped# Account statuses+ # Disables enum scopes to include not_builtin (cf. Principals::Scopes::Status)enum status: {active: 1,registered: 2,locked: 3,invited: 4- }.freeze+ }.freeze, _scopes: falseself.table_name = "#{table_name_prefix}users#{table_name_suffix}"@@ -63,11 +64,8 @@ class Principal < ApplicationRecord:possible_assignee,:possible_member,:user,- :ordered_by_name-- scope :not_locked, -> {- not_builtin.where.not(status: statuses[:locked])- }+ :ordered_by_name,+ :statusscope :in_project, ->(project) {where(id: Member.of(project).select(:user_id))diff --git a/app/models/principals/scopes/status.rb b/app/models/principals/scopes/status.rbnew file mode 100644index 00000000000..dc09129489d--- /dev/null+++ b/app/models/principals/scopes/status.rb@@ -0,0 +1,52 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See docs/COPYRIGHT.rdoc for more details.+#++++# Creates scopes for the :status enums but ensuring that not_builtin is used at the same time+# Excludes+# * DeletedUser+# * SystemUser+# * AnonymousUser+module Principals::Scopes+ module Status+ extend ActiveSupport::Concern++ included do+ statuses.each do |key, val|+ define_singleton_method(key) do+ not_builtin.where(status: val)+ end++ define_singleton_method("not_#{key}") do+ not_builtin.where.not(status: val)+ end+ end+ end+ end+enddiff --git a/spec/lib/open_project/enterprise_spec.rb b/spec/lib/open_project/enterprise_spec.rbindex 93c439506bb..342c63cf2bd 100644--- a/spec/lib/open_project/enterprise_spec.rb+++ b/spec/lib/open_project/enterprise_spec.rb@@ -32,7 +32,6 @@ require 'open_project/passwords'describe OpenProject::Enterprise dodescribe "#user_limit_reached?" dolet(:user_limit) { 2 }- let(:builtin_user_count) { 2 }# create 3 built-in users, only 2 of which are active# Also create a placeholder user which will not count against the limitlet!(:system_user) { User.system }@@ -50,7 +49,7 @@ describe OpenProject::Enterprise dobefore doFactoryBot.create :user- expect(User.active.count).to eq 1 + builtin_user_count # created user + built-in ones+ expect(User.active.count).to eq 1 # created userendit "is false" do@@ -65,7 +64,7 @@ describe OpenProject::Enterprise dobefore doFactoryBot.create_list :user, num_active_users- expect(User.active.count).to eq num_active_users + builtin_user_count+ expect(User.active.count).to eq num_active_usersendit "is true" do