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

Load STI models explicitly.

Pavel Balashoub78678c5ece4
diff --git a/app/models/concerns/subclass_registry.rb b/app/models/concerns/subclass_registry.rb
deleted file mode 100644
index 37159680d38..00000000000
--- a/app/models/concerns/subclass_registry.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 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 COPYRIGHT and LICENSE files for more details.
-#++
-
-module SubclassRegistry
- extend ActiveSupport::Concern
-
- included do
- class_attribute :registered_subclasses, default: []
- end
-
- class_methods do
- def register_subclass(subclass)
- raise ArgumentError, "#{subclass} needs to inherit from #{self}" unless subclass < self
-
- unless registered_subclasses.include?(subclass)
- registered_subclasses << subclass
- end
- end
- end
-end
diff --git a/app/models/deleted_user.rb b/app/models/deleted_user.rb
index ad89f12e71e..e65817ea514 100644
--- a/app/models/deleted_user.rb
+++ b/app/models/deleted_user.rb
@@ -1,3 +1,33 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 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 COPYRIGHT and LICENSE files for more details.
+#++
+
class DeletedUser < User
def self.first
super || create(type: to_s, status: statuses[:locked])
diff --git a/app/models/enumeration.rb b/app/models/enumeration.rb
index d6c653771df..e31dcdf202d 100644
--- a/app/models/enumeration.rb
+++ b/app/models/enumeration.rb
@@ -27,8 +27,6 @@
#++
class Enumeration < ApplicationRecord
- include SubclassRegistry
-
default_scope { order("#{Enumeration.table_name}.position ASC") }
belongs_to :project, optional: true
diff --git a/config/initializers/sti_eager_load.rb b/config/initializers/sti_eager_load.rb
index 686afe5db85..ea2da38bc8d 100644
--- a/config/initializers/sti_eager_load.rb
+++ b/config/initializers/sti_eager_load.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
@@ -27,5 +29,18 @@
#++
Rails.application.config.to_prepare do
- Enumeration.register_subclass(IssuePriority)
+ # Load Enumeration descendants due to STI
+ IssuePriority
+
+ # Load Principal descendants due to STI
+ User
+ PlaceholderUser
+ Group
+
+ # Use User descendants due to STI
+ SystemUser
+ AnonymousUser
+ Users::InexistentUser
+ ServiceAccount
+ DeletedUser
end
diff --git a/modules/auth_saml/lib/open_project/auth_saml/engine.rb b/modules/auth_saml/lib/open_project/auth_saml/engine.rb
index ea3dafc4dde..7e8310b2816 100644
--- a/modules/auth_saml/lib/open_project/auth_saml/engine.rb
+++ b/modules/auth_saml/lib/open_project/auth_saml/engine.rb
@@ -66,6 +66,11 @@ module OpenProject
default: {},
format: :hash
end
+
+ config.to_prepare do
+ # Load AuthProvider descendants due to STI
+ Saml::Provider
+ end
end
end
end
diff --git a/modules/costs/lib/costs/engine.rb b/modules/costs/lib/costs/engine.rb
index f62be67afc3..2771bed1cd1 100644
--- a/modules/costs/lib/costs/engine.rb
+++ b/modules/costs/lib/costs/engine.rb
@@ -311,7 +311,9 @@ module Costs
end
config.to_prepare do
- Enumeration.register_subclass(TimeEntryActivity)
+ # Load Enumeration descendants due to STI
+ TimeEntryActivity
+
OpenProject::ProjectLatestActivity.register on: "TimeEntry"
Costs::Patches::MembersPatch.mixin!
diff --git a/modules/documents/lib/open_project/documents/engine.rb b/modules/documents/lib/open_project/documents/engine.rb
index f8aae7c5b3e..d54d2e707b2 100644
--- a/modules/documents/lib/open_project/documents/engine.rb
+++ b/modules/documents/lib/open_project/documents/engine.rb
@@ -86,7 +86,8 @@ module OpenProject::Documents
additional_permitted_attributes search: %i(documents)
config.to_prepare do
- Enumeration.register_subclass(DocumentCategory)
+ # Load Enumeration descendants due to STI
+ DocumentCategory
end
end
end
diff --git a/modules/openid_connect/lib/open_project/openid_connect/engine.rb b/modules/openid_connect/lib/open_project/openid_connect/engine.rb
index 454180fde2c..02544027b16 100644
--- a/modules/openid_connect/lib/open_project/openid_connect/engine.rb
+++ b/modules/openid_connect/lib/open_project/openid_connect/engine.rb
@@ -108,6 +108,9 @@ module OpenProject::OpenIDConnect
config.to_prepare do
::OpenProject::OpenIDConnect::Hooks::Hook
+
+ # Load AuthProvider descendants due to STI
+ OpenIDConnect::Provider
end
end
end
diff --git a/modules/storages/lib/open_project/storages/engine.rb b/modules/storages/lib/open_project/storages/engine.rb
index b4465a7ac4a..c54fb8bed40 100644
--- a/modules/storages/lib/open_project/storages/engine.rb
+++ b/modules/storages/lib/open_project/storages/engine.rb
@@ -257,6 +257,11 @@ module OpenProject::Storages
# This hook is executed when the module is loaded.
config.to_prepare do
+ # Load Storages::Storage descendants due to STI
+ Storages::Storage::InexistentStorage
+ Storages::OneDriveStorage
+ Storages::NextcloudStorage
+
# Allow the browser to connect to external servers for direct file uploads.
AppendStoragesHostsToCspHook