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

Extract a HasMembers concern

Klaus Zanders2dd6c57a12b8
diff --git a/app/models/concerns/has_members.rb b/app/models/concerns/has_members.rb
new file mode 100644
index 00000000000..d5f05035053
--- /dev/null
+++ b/app/models/concerns/has_members.rb
@@ -0,0 +1,36 @@
+# --copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2022 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 HasMembers
+ extend ActiveSupport::Concern
+
+ included do
+ has_many :members, as: :entity, dependent: :destroy
+ has_many :member_principals, through: :members, class_name: "Principal", source: :principal
+ end
+end
diff --git a/app/models/queries/projects/project_query.rb b/app/models/queries/projects/project_query.rb
index 7bf65abb9ee..7ec9f423e8d 100644
--- a/app/models/queries/projects/project_query.rb
+++ b/app/models/queries/projects/project_query.rb
@@ -29,6 +29,7 @@
class Queries::Projects::ProjectQuery < ApplicationRecord
include Queries::BaseQuery
include Queries::Serialization::Hash
+ include HasMembers
belongs_to :user
diff --git a/app/models/work_package.rb b/app/models/work_package.rb
index a1dd265d12a..3c273544c96 100644
--- a/app/models/work_package.rb
+++ b/app/models/work_package.rb
@@ -40,6 +40,7 @@ class WorkPackage < ApplicationRecord
include WorkPackages::Costs
include WorkPackages::Relations
include ::Scopes::Scoped
+ include HasMembers
include OpenProject::Journal::AttachmentHelper
@@ -67,9 +68,6 @@ class WorkPackage < ApplicationRecord
has_and_belongs_to_many :github_pull_requests # rubocop:disable Rails/HasAndBelongsToMany
- has_many :members, as: :entity, dependent: :destroy
- has_many :member_principals, through: :members, class_name: "Principal", source: :principal
-
has_many :meeting_agenda_items, dependent: :nullify
# The MeetingAgendaItem has a default order, but the ordered field is not part of the select
# that retrieves the meetings, hence we need to remove the order.