Skip to content

Commit 7131781

Browse files
authored
Merge pull request #24735 from opf/chore/remove-type-custom-field-accessors
Remove custom fields, attribute group accessors on type
2 parents 81010b2 + 6bd0a24 commit 7131781

39 files changed

Lines changed: 136 additions & 183 deletions

File tree

app/controllers/work_packages/bulk_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,12 @@ def editable_custom_fields
122122
@projects.map(&:all_work_package_custom_fields).inject(&:&) & custom_fields_of_type_variants
123123
end
124124

125-
# Each project may resolve a family to its own variant, so the types are resolved per project
125+
# Each project applies its own variant of a type, so the variant is resolved per project
126126
# before #custom_fields follows the form configuration link from there.
127127
def custom_fields_of_type_variants
128128
@projects.flat_map { |project| project.type_variants(*@types) }
129129
.uniq
130-
.flat_map { |type| type.custom_fields.to_a }
130+
.flat_map { |variant| variant.custom_fields.to_a }
131131
.uniq
132132
end
133133

app/helpers/types_helper.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@ def accessible_type_icon_attributes(type)
113113

114114
##
115115
# Collect active and inactive form configuration groups for editing.
116-
def form_configuration_groups(type)
117-
available = type.work_package_attributes
116+
def form_configuration_groups(variant)
117+
available = variant.work_package_attributes
118118
# First we create a complete list of all attributes.
119119
# Later we will remove those that are members of an attribute group.
120120
# This way attributes that were created after the las group definitions
121121
# will fall back into the inactives group.
122122
inactive = available.clone
123123

124-
active_form = get_active_groups(type, available, inactive)
124+
active_form = get_active_groups(variant, available, inactive)
125125
inactive_form = inactive
126126
.map { |key, attribute| attr_form_map(key, attribute) }
127127
.sort_by { |attr| attr[:translation] }
@@ -161,8 +161,8 @@ def query_to_query_props(group)
161161
# Collect active attributes from the current form configuration.
162162
# Using the available attributes from +work_package_attributes+,
163163
# determines which attributes are not used
164-
def get_active_groups(type, available, inactive)
165-
type.attribute_groups.map do |group|
164+
def get_active_groups(variant, available, inactive)
165+
variant.attribute_groups.map do |group|
166166
{
167167
key: group.key,
168168
type: group.group_type,

app/models/type.rb

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -73,54 +73,6 @@ def default_variant
7373
variants.detect(&:is_default_variant?)
7474
end
7575

76-
# Form custom fields live on the base variant. Prefer `default_variant.custom_fields`.
77-
# Kept temporarily so the many call sites that still write `type.custom_fields << cf` keep
78-
# working while they are migrated.
79-
def custom_fields
80-
OpenProject::Deprecation.replaced("Type#custom_fields", "Type#default_variant.custom_fields", caller_locations)
81-
82-
default_variant.custom_fields
83-
end
84-
85-
def custom_fields=(values)
86-
OpenProject::Deprecation.replaced("Type#custom_fields=", "Type#default_variant.custom_fields=", caller_locations)
87-
88-
default_variant.custom_fields = values
89-
end
90-
91-
def custom_field_ids
92-
OpenProject::Deprecation.replaced("Type#custom_field_ids", "Type#default_variant.custom_field_ids", caller_locations)
93-
94-
default_variant.custom_field_ids
95-
end
96-
97-
def custom_field_ids=(values)
98-
OpenProject::Deprecation.replaced("Type#custom_field_ids=", "Type#default_variant.custom_field_ids=", caller_locations)
99-
100-
default_variant.custom_field_ids = values
101-
end
102-
103-
# Form configuration lives on the base variant. Prefer `default_variant.attribute_groups`.
104-
def attribute_groups
105-
OpenProject::Deprecation.replaced("Type#attribute_groups", "Type#default_variant.attribute_groups", caller_locations)
106-
107-
default_variant.attribute_groups
108-
end
109-
110-
def attribute_groups=(values)
111-
OpenProject::Deprecation.replaced("Type#attribute_groups=", "Type#default_variant.attribute_groups=", caller_locations)
112-
113-
default_variant.attribute_groups = values
114-
end
115-
116-
def reset_attribute_groups
117-
OpenProject::Deprecation.replaced("Type#reset_attribute_groups",
118-
"Type#default_variant.reset_attribute_groups",
119-
caller_locations)
120-
121-
default_variant.reset_attribute_groups
122-
end
123-
12476
def <=>(other)
12577
name <=> other.name
12678
end

app/workers/import/jira_import_projects_job.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def import_issue(jira_issue, project, custom_field_registry)
150150
end
151151

152152
def new_custom_fields_in_type(jira_issue, type, custom_field_registry)
153-
existing_cf_ids = type.custom_field_ids
153+
existing_cf_ids = type.default_variant.custom_field_ids
154154
custom_fields_for_issue(custom_field_registry, jira_issue).reject { |cf| existing_cf_ids.include?(cf.id) }
155155
end
156156

modules/xls_export/spec/models/xls_export/work_package/exporter/xls_integration_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@
175175
end
176176
let(:type) do
177177
type = project.enabled_types.first
178-
type.custom_fields << custom_field
178+
type.default_variant.custom_fields << custom_field
179+
179180
type
180181
end
181182
let(:project) do

spec/contracts/work_packages/update_contract_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@
318318

319319
before do
320320
persisted_project.work_package_custom_fields << cf1
321-
persisted_type.custom_fields << cf1
321+
persisted_type.default_variant.custom_fields << cf1
322322
work_package.custom_field_values = { cf1.id => "test" }
323323
contract.validate
324324
end

spec/controllers/journals_controller_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
let!(:custom_field) do
139139
create(factory_name).tap do |custom_field|
140140
project.work_package_custom_fields << custom_field
141-
type.custom_fields << custom_field
141+
type.default_variant.custom_fields << custom_field
142142
end
143143
end
144144

spec/features/admin/custom_fields/work_packages/long_text_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
# textareas get carriage returns entered
4747
expect(cf.default_value.gsub("\r\n", "\n").strip).to eq default_text.strip
4848

49-
type.custom_fields << cf
49+
type.default_variant.custom_fields << cf
5050
type.save!
5151

5252
wp_page.visit!

spec/features/custom_fields/activate_in_project_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
let(:project_specific_cf) { create(:integer_wp_custom_field) }
3838
let(:work_package) do
3939
build(:work_package) do |wp|
40-
wp.type.custom_fields = [for_all_cf, project_specific_cf]
40+
wp.type.default_variant.custom_fields = [for_all_cf, project_specific_cf]
4141
wp.save!
4242
end
4343
end

spec/features/search/search_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def char_for(integer)
6262
is_filter:,
6363
searchable:).tap do |custom_field|
6464
project.work_package_custom_fields << custom_field
65-
work_packages.first.type.custom_fields << custom_field
65+
work_packages.first.type.default_variant.custom_fields << custom_field
6666

6767
create(:work_package_custom_value,
6868
custom_field:,
@@ -77,7 +77,7 @@ def char_for(integer)
7777
is_filter:,
7878
searchable:).tap do |custom_field|
7979
custom_field.save
80-
work_packages.first.type.custom_fields << custom_field
80+
work_packages.first.type.default_variant.custom_fields << custom_field
8181

8282
create(:work_package_custom_value,
8383
custom_field:,

0 commit comments

Comments
 (0)