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

remove acts_as_customizable from enumerable

ulfertseae67495629c
diff --git a/app/helpers/custom_fields_helper.rb b/app/helpers/custom_fields_helper.rb
index e433e6e31e7..3aff71dff4f 100644
--- a/app/helpers/custom_fields_helper.rb
+++ b/app/helpers/custom_fields_helper.rb
@@ -66,18 +66,6 @@ module CustomFieldsHelper
partial: 'custom_fields/tab',
path: custom_fields_path(tab: :GroupCustomField),
label: :label_group_plural
- },
- {
- name: 'TimeEntryActivityCustomField',
- partial: 'custom_fields/tab',
- path: custom_fields_path(tab: :TimeEntryActivityCustomField),
- label: TimeEntryActivity::OptionName
- },
- {
- name: 'IssuePriorityCustomField',
- partial: 'custom_fields/tab',
- path: custom_fields_path(tab: :IssuePriorityCustomField),
- label: IssuePriority::OptionName
}
]
end
diff --git a/app/models/enumeration.rb b/app/models/enumeration.rb
index c0732290f77..258e111e157 100644
--- a/app/models/enumeration.rb
+++ b/app/models/enumeration.rb
@@ -34,7 +34,6 @@ class Enumeration < ApplicationRecord
belongs_to :project
acts_as_list scope: 'type = \'#{type}\''
- acts_as_customizable
acts_as_tree order: 'position ASC'
before_destroy :check_integrity
diff --git a/app/views/enumerations/_form.html.erb b/app/views/enumerations/_form.html.erb
index 75858ad1bd9..6e0feb76129 100644
--- a/app/views/enumerations/_form.html.erb
+++ b/app/views/enumerations/_form.html.erb
@@ -48,8 +48,4 @@ See COPYRIGHT and LICENSE files for more details.
label: @enumeration.color_label
} %>
<% end %>
-
- <% @enumeration.custom_field_values.each do |value| %>
- <div class="form--field"><%= custom_field_tag_with_label :enumeration, value %></div>
- <% end %>
</section>
diff --git a/db/migrate/20211102161932_remove_custom_field_types.rb b/db/migrate/20211102161932_remove_custom_field_types.rb
new file mode 100644
index 00000000000..499e5f626e6
--- /dev/null
+++ b/db/migrate/20211102161932_remove_custom_field_types.rb
@@ -0,0 +1,35 @@
+class RemoveCustomFieldTypes < ActiveRecord::Migration[6.1]
+ def up
+ delete_custom_field('TimeEntryActivityCustomField')
+ delete_custom_field('DocumentCategoryCustomField')
+ delete_custom_field('IssuePriorityCustomField')
+
+ delete_custom_values
+ end
+
+ def delete_custom_field(type)
+ execute <<~SQL.squish
+ DELETE FROM
+ custom_fields
+ WHERE
+ type = '#{type}'
+ SQL
+ end
+
+ def delete_custom_values
+ execute <<~SQL.squish
+ DELETE FROM
+ custom_values values_delete
+ USING
+ custom_values values_select
+ LEFT OUTER JOIN
+ custom_fields
+ ON
+ custom_fields.id = values_select.custom_field_id
+ WHERE
+ values_delete.id = values_select.id
+ AND
+ custom_fields.id IS NULL
+ SQL
+ end
+end
diff --git a/modules/costs/app/models/time_entry_activity_custom_field.rb b/modules/costs/app/models/time_entry_activity_custom_field.rb
deleted file mode 100644
index df9ab482087..00000000000
--- a/modules/costs/app/models/time_entry_activity_custom_field.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-#-- 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 COPYRIGHT and LICENSE files for more details.
-#++
-
-class TimeEntryActivityCustomField < CustomField
- def type_name
- :enumeration_activities
- end
-end
diff --git a/app/models/issue_priority_custom_field.rb b/modules/costs/spec/models/time_entry_activity_spec.rb
similarity index 64%
rename from app/models/issue_priority_custom_field.rb
rename to modules/costs/spec/models/time_entry_activity_spec.rb
index a67e7292063..49be71957d7 100644
--- a/app/models/issue_priority_custom_field.rb
+++ b/modules/costs/spec/models/time_entry_activity_spec.rb
@@ -28,8 +28,30 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class IssuePriorityCustomField < CustomField
- def type_name
- :enumeration_work_package_priorities
+require 'spec_helper'
+
+describe TimeEntryActivity, type: :model do
+ let(:new_activity) { described_class.new }
+ let(:saved_activity) { described_class.create name: 'Design' }
+
+ it 'is an enumeration' do
+ expect(new_activity)
+ .to be_a(Enumeration)
+ end
+
+ describe '#objects_count' do
+ it 'represents the count of time entries of that activity' do
+ expect { FactoryBot.create(:time_entry, activity: saved_activity) }
+ .to change(saved_activity, :objects_count)
+ .from(0)
+ .to(1)
+ end
+ end
+
+ describe '#option_name' do
+ it 'is enumeration_activities' do
+ expect(new_activity.option_name)
+ .to eq :enumeration_activities
+ end
end
end
diff --git a/modules/documents/app/models/document_category_custom_field.rb b/modules/documents/app/models/document_category_custom_field.rb
deleted file mode 100644
index 4a381ceedbc..00000000000
--- a/modules/documents/app/models/document_category_custom_field.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-#-- 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 COPYRIGHT and LICENSE files for more details.
-#++
-
-class DocumentCategoryCustomField < CustomField
- def type_name
- :enumeration_doc_categories
- end
-end
diff --git a/modules/documents/lib/open_project/documents/engine.rb b/modules/documents/lib/open_project/documents/engine.rb
index 7b44248c018..7e0fde687ed 100644
--- a/modules/documents/lib/open_project/documents/engine.rb
+++ b/modules/documents/lib/open_project/documents/engine.rb
@@ -54,7 +54,7 @@ module OpenProject::Documents
activity_provider :documents, class_name: 'Activities::DocumentActivityProvider', default: false
- patches %i[CustomFieldsHelper Project]
+ patches %i[Project]
add_api_path :documents do
"#{root}/documents"
@@ -78,7 +78,6 @@ module OpenProject::Documents
config.to_prepare do
require_dependency 'document'
require_dependency 'document_category'
- require_dependency 'document_category_custom_field'
require_dependency 'open_project/documents/patches/textile_converter_patch'
end
diff --git a/modules/documents/lib/open_project/documents/patches/custom_fields_helper_patch.rb b/modules/documents/lib/open_project/documents/patches/custom_fields_helper_patch.rb
deleted file mode 100644
index ff65da43f8f..00000000000
--- a/modules/documents/lib/open_project/documents/patches/custom_fields_helper_patch.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-#-- 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 COPYRIGHT and LICENSE files for more details.
-#++
-
-module OpenProject::Documents::Patches
- module CustomFieldsHelperPatch
- def self.included(base)
- base.prepend InstanceMethods
- end
-
- module InstanceMethods
- def custom_fields_tabs
- super << {
- name: 'DocumentCategoryCustomField',
- partial: 'custom_fields/tab',
- path: custom_fields_path(tab: :DocumentCategoryCustomField),
- label: DocumentCategory::OptionName
- }
- end
- end
- end
-end
-
-unless CustomFieldsHelper.included_modules.include?(OpenProject::Documents::Patches::CustomFieldsHelperPatch)
- CustomFieldsHelper.include OpenProject::Documents::Patches::CustomFieldsHelperPatch
-end
diff --git a/spec_legacy/fixtures/custom_fields.yml b/spec_legacy/fixtures/custom_fields.yml
index a38842e8069..7be6fe87be2 100644
--- a/spec_legacy/fixtures/custom_fields.yml
+++ b/spec_legacy/fixtures/custom_fields.yml
@@ -97,18 +97,6 @@ custom_fields_006:
is_required: false
field_format: float
editable: true
-custom_fields_007:
- name: "Billable"
- min_length: 0
- regexp: ""
- is_for_all: false
- is_filter: true
- type: TimeEntryActivityCustomField
- max_length: 0
- id: 7
- is_required: false
- field_format: bool
- editable: true
custom_fields_008:
name: "Custom date"
min_length: 0
diff --git a/spec_legacy/unit/enumeration_spec.rb b/spec_legacy/unit/enumeration_spec.rb
index d89ac54975b..f38eeef3488 100644
--- a/spec_legacy/unit/enumeration_spec.rb
+++ b/spec_legacy/unit/enumeration_spec.rb
@@ -86,10 +86,6 @@ describe Enumeration, type: :model do
assert_equal @issues.size, new_priority.objects_count
end
- it 'should be customizable' do
- assert Enumeration.included_modules.include?(Redmine::Acts::Customizable::InstanceMethods)
- end
-
it 'should belong to a project' do
association = Enumeration.reflect_on_association(:project)
assert association, 'No Project association found'
diff --git a/spec_legacy/unit/time_entry_activity_spec.rb b/spec_legacy/unit/time_entry_activity_spec.rb
deleted file mode 100644
index df0f7bc5aa3..00000000000
--- a/spec_legacy/unit/time_entry_activity_spec.rb
+++ /dev/null
@@ -1,98 +0,0 @@
-#-- 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 COPYRIGHT and LICENSE files for more details.
-#++
-require_relative '../legacy_spec_helper'
-
-describe TimeEntryActivity, type: :model do
- include MiniTest::Assertions # refute
-
- fixtures :all
-
- it 'should be an enumeration' do
- assert TimeEntryActivity.ancestors.include?(Enumeration)
- end
-
- it 'should objects count' do
- assert_equal 3, TimeEntryActivity.find_by(name: 'Design').objects_count
- assert_equal 1, TimeEntryActivity.find_by(name: 'Development').objects_count
- end
-
- it 'should option name' do
- assert_equal :enumeration_activities, TimeEntryActivity.new.option_name
- end
-
- it 'should create with custom field' do
- field = TimeEntryActivityCustomField.find_by(name: 'Billable')
- e = TimeEntryActivity.new(name: 'Custom Data')
- e.custom_field_values = { field.id => '1' }
- assert e.save
-
- e.reload
- assert_equal 't', e.custom_value_for(field).value
- end
-
- it 'should create without required custom field should fail' do
- field = TimeEntryActivityCustomField.find_by(name: 'Billable')
- field.update_attribute(:is_required, true)
-
- e = TimeEntryActivity.new(name: 'Custom Data')
- assert !e.save
- assert_includes e.errors["custom_field_#{field.id}"],
- I18n.translate('activerecord.errors.messages.blank')
- end
-
- it 'should create with required custom field should succeed' do
- field = TimeEntryActivityCustomField.find_by(name: 'Billable')
- field.update_attribute(:is_required, true)
-
- e = TimeEntryActivity.new(name: 'Custom Data')
- e.custom_field_values = { field.id => '1' }
- assert e.save
- end
-
- it 'should update issue with required custom field change' do
- field = TimeEntryActivityCustomField.find_by(name: 'Billable')
- field.update_attribute(:is_required, true)
-
- e = TimeEntryActivity.find(10)
- assert e.available_custom_fields.include?(field)
- # No change to custom field, record can be saved
- assert e.save
- # Blanking custom field, save should fail
- e.custom_field_values = { field.id => '' }
- assert !e.save
- refute_empty e.errors["custom_field_#{field.id}"]
-
- # Update custom field to valid value, save should succeed
- e.custom_field_values = { field.id => '0' }
- assert e.save
- e.reload
- assert_equal 'f', e.custom_value_for(field).value
- end
-end