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
Create Projects::CustomField and Projects::WorkPackageCustomFields concerns.
Dombi Attila2f42f97f36b5
diff --git a/app/models/project.rb b/app/models/project.rbindex 2cfd86fd350..4a94b25291b 100644--- a/app/models/project.rb+++ b/app/models/project.rb@@ -33,9 +33,10 @@ class Project < ApplicationRecordinclude Projects::Activityinclude Projects::Hierarchyinclude Projects::AncestorsFromRoot+ include Projects::CustomFields+ include Projects::WorkPackageCustomFieldsinclude ::Scopes::Scoped- include Projects::ActsAsCustomizablePatches# Maximum length for project identifiersIDENTIFIER_MAX_LENGTH = 100@@ -79,11 +80,6 @@ class Project < ApplicationRecordhas_one :repository, dependent: :destroyhas_many :changesets, through: :repositoryhas_one :wiki, dependent: :destroy- # Custom field for the project's work_packages- has_and_belongs_to_many :work_package_custom_fields,- -> { order("#{CustomField.table_name}.position") },- join_table: :custom_fields_projects,- association_foreign_key: "custom_field_id"has_many :budgets, dependent: :destroyhas_many :notification_settings, dependent: :destroyhas_many :project_storages, dependent: :destroy, class_name: "Storages::ProjectStorage"@@ -93,8 +89,8 @@ class Project < ApplicationRecordacts_as_favorable- acts_as_customizable # partially overridden via Projects::ActsAsCustomizablePatches in order to support sections and- # project-leval activation of custom fields+ acts_as_customizable # extended in Projects::CustomFields in order to support sections+ # and project-level activation of custom fieldsacts_as_searchable columns: %W(#{table_name}.name #{table_name}.identifier #{table_name}.description),date_column: "#{table_name}.created_at",@@ -282,14 +278,6 @@ class Project < ApplicationRecordendend- # Returns an AR scope of all custom fields enabled for project's work packages- # (explicitly associated custom fields and custom fields enabled for all projects)- def all_work_package_custom_fields- WorkPackageCustomField- .for_all- .or(WorkPackageCustomField.where(id: work_package_custom_fields))- end-def projectselfenddiff --git a/app/models/projects/acts_as_customizable_patches.rb b/app/models/projects/custom_fields.rbsimilarity index 92%rename from app/models/projects/acts_as_customizable_patches.rbrename to app/models/projects/custom_fields.rbindex 3ce2f0eb656..55369e14c72 100644--- a/app/models/projects/acts_as_customizable_patches.rb+++ b/app/models/projects/custom_fields.rb@@ -26,14 +26,11 @@# See COPYRIGHT and LICENSE files for more details.#++-module Projects::ActsAsCustomizablePatches+module Projects::CustomFieldsextend ActiveSupport::Concernattr_accessor :_limit_custom_fields_validation_to_section_id- # attr_accessor :_limit_custom_fields_validation_to_field_id- # not needed for now, but might be relevant if we want to have edit dialogs just for one custom field-included dohas_many :project_custom_field_project_mappings, class_name: "ProjectCustomFieldProjectMapping", foreign_key: :project_id,dependent: :destroy, inverse_of: :projectdiff --git a/app/models/projects/work_package_custom_fields.rb b/app/models/projects/work_package_custom_fields.rbnew file mode 100644index 00000000000..9df42bbe268--- /dev/null+++ b/app/models/projects/work_package_custom_fields.rb@@ -0,0 +1,47 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2024 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 Projects::WorkPackageCustomFields+ extend ActiveSupport::Concern++ included do+ # Custom field for the project's work_packages+ has_and_belongs_to_many :work_package_custom_fields, # rubocop:disable Rails/HasAndBelongsToMany+ -> { order("#{CustomField.table_name}.position") },+ join_table: :custom_fields_projects,+ association_foreign_key: "custom_field_id"++ # Returns an AR scope of all custom fields enabled for project's work packages+ # (explicitly associated custom fields and custom fields enabled for all projects)+ def all_work_package_custom_fields+ WorkPackageCustomField+ .for_all+ .or(WorkPackageCustomField.where(id: work_package_custom_fields))+ end+ end+end