Skip to content

Commit 1dfcbfb

Browse files
authored
Merge pull request #24732 from opf/remove-project-types
Remove `Project#types` association as this broke with the `ProjectType` model
2 parents 50eb673 + 8699f83 commit 1dfcbfb

133 files changed

Lines changed: 323 additions & 357 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/components/work_packages/moves/form_component.html.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ See COPYRIGHT and LICENSE files for more details.
7171
<%= styled_select_tag(
7272
"new_type_id",
7373
content_tag("option", t(:label_no_change_option), value: "") +
74-
options_from_collection_for_select(available_types, "id", "name", target_type&.id),
74+
options_from_collection_for_select(available_variants, "type_id", "name", target_variant&.type_id),
7575
data: {
7676
action: "change->refresh-on-form-changes#triggerTurboStream"
7777
}
@@ -213,8 +213,8 @@ See COPYRIGHT and LICENSE files for more details.
213213
} %>
214214
</div>
215215
</div>
216-
<% if target_type_variant %>
217-
<% target_type_variant.custom_fields.required.each do |custom_field| %>
216+
<% if target_variant %>
217+
<% target_variant.custom_fields.required.each do |custom_field| %>
218218
<div class="form--field">
219219
<%= blank_custom_field_label_tag("", custom_field) %>
220220
<div class="form--field-container">

app/components/work_packages/moves/form_component.rb

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,16 @@ def turbo_stream_url
6969
url_helpers.refresh_form_move_work_packages_path
7070
end
7171

72-
def available_types
73-
@available_types ||= target_project.types.order(:position)
72+
def available_variants
73+
@available_variants ||= target_project.enabled_variants.includes(:type).to_a
7474
end
7575

76-
def target_type
77-
@target_type ||= available_types.find { |type| type.id.to_s == selected_values[:type_id].to_s }
76+
def available_type_ids
77+
@available_type_ids ||= available_variants.map(&:type_id)
7878
end
7979

80-
def target_type_variant
81-
return unless target_type
82-
83-
target_project.type_variant(target_type)
80+
def target_variant
81+
@target_variant ||= available_variants.find { |variant| variant.type_id.to_s == selected_values[:type_id].to_s }
8482
end
8583

8684
def available_versions
@@ -98,7 +96,7 @@ def unavailable_type_in_target_project?
9896
end
9997

10098
def current_types_missing_in_target?
101-
work_packages.map(&:type_id).uniq.difference(available_types.pluck(:id)).any?
99+
work_packages.map(&:type_id).uniq.difference(available_type_ids).any?
102100
end
103101

104102
def descendant_types_missing_in_target?
@@ -108,7 +106,7 @@ def descendant_types_missing_in_target?
108106
Type.where(id: hierarchies.map { it.descendant.type_id })
109107
.select("distinct id")
110108
.pluck(:id)
111-
.difference(available_types.pluck(:id))
109+
.difference(available_type_ids)
112110
.any?
113111
end
114112

app/contracts/projects/create_artifact_work_package_contract.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def allowed_to_create_work_package
5555
def validate_work_package_type
5656
if project.project_creation_wizard_work_package_type_id.blank?
5757
add_error :project_creation_wizard_work_package_type_id, :blank
58-
elsif !project.project_creation_wizard_work_package_type_id.in?(project.type_ids)
58+
elsif !project.project_types.exists?(type_id: project.project_creation_wizard_work_package_type_id)
5959
add_error :project_creation_wizard_work_package_type_id, :inclusion
6060
end
6161
end

app/contracts/projects/settings_contract.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def validate_work_package_type
5959
if model.project_creation_wizard_work_package_type_id.blank?
6060
errors.add :project_creation_wizard_work_package_type_id, :blank
6161
else
62-
unless model.types.exists?(id: model.project_creation_wizard_work_package_type_id)
62+
unless model.project_types.exists?(type_id: model.project_creation_wizard_work_package_type_id)
6363
errors.add :project_creation_wizard_work_package_type_id, :inclusion
6464
end
6565
end

app/contracts/work_packages/base_contract.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,7 @@ def assignable_statuses(include_default: false)
201201
end
202202

203203
def assignable_types
204-
scope = if model.project.nil?
205-
Type
206-
else
207-
model.project.types.includes(:color)
208-
end
204+
scope = model.project&.enabled_types || Type
209205

210206
scope.includes(:color)
211207
end
@@ -280,7 +276,7 @@ def validate_after_soonest_start(date_attribute)
280276

281277
def validate_enabled_type
282278
# Checks that the issue can not be added/moved to a disabled type
283-
if type_context_changed? && model.project.types.exclude?(model.type)
279+
if type_context_changed? && model.project.project_types.none? { |pt| pt.type_id == model.type_id }
284280
errors.add :type_id, :inclusion
285281
end
286282
end

app/controllers/versions_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class VersionsController < ApplicationController
3737
before_action :authorize
3838

3939
def index
40-
@types = @project.types.order(Arel.sql("position"))
40+
@types = @project.enabled_types
4141
retrieve_selected_type_ids(@types, @types.select(&:is_in_roadmap?))
4242

4343
@versions = find_versions(with_subprojects, params[:completed])

app/controllers/work_packages/bulk_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def destroy # rubocop:disable Metrics/AbcSize
113113
def setup_edit
114114
@available_statuses = @projects.map { |p| Workflow.available_statuses(p) }.inject(&:&)
115115
@assignables = @responsibles = Principal.possible_assignee(@projects)
116-
@types = @projects.map(&:types).inject(&:&)
116+
@types = @projects.map { |project| project.enabled_types.to_a }.inject(&:&)
117117
@custom_fields = editable_custom_fields
118118
end
119119

app/forms/projects/settings/creation_wizard/submission_form.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class SubmissionForm < ApplicationForm
4343
action: "change->refresh-on-form-changes#triggerTurboStream"
4444
}
4545
) do |list|
46-
model.types.each do |type|
46+
model.enabled_types.each do |type|
4747
list.option(
4848
value: type.id,
4949
label: type.name,

app/models/permitted_params.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,6 @@ def project
315315
:status_code,
316316
:status_explanation,
317317
work_package_custom_field_ids: [],
318-
type_ids: [],
319318
enabled_module_names: [],
320319
custom_comments: {})
321320

app/models/project.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ class Project < ApplicationRecord
7373
has_many :enabled_modules, dependent: :delete_all, after_remove: :module_disabled
7474
has_many :project_types, dependent: :delete_all
7575

76-
# Enabled root-types, variants need to be determined explicitly
77-
has_many :types, -> { order("#{::Type.table_name}.position") }, through: :project_types
7876
has_many :work_packages, -> {
7977
order("#{WorkPackage.table_name}.created_at DESC")
8078
.includes(:status, :type)

0 commit comments

Comments
 (0)