[#70315] Ensure integrity of creation wizard flag after 'disable all' action

This commit is contained in:
Tobias Dillmann
2026-01-23 13:31:36 +01:00
parent 8fa0203984
commit d321c30dc7
3 changed files with 52 additions and 4 deletions
@@ -79,6 +79,7 @@ class Projects::Settings::CreationWizardController < Projects::SettingsControlle
toggleable = if mapping
ProjectCustomField
.toggleable_ids_in_creation_wizard_settings(@project, cf.custom_field_section_id)
.first
.include?(cf.id)
else
false
@@ -104,15 +105,23 @@ class Projects::Settings::CreationWizardController < Projects::SettingsControlle
def update_section_mappings(value)
section_id = permitted_params.project_custom_field_project_mapping[:custom_field_section_id]
cf_ids_to_toggle = ProjectCustomField.toggleable_ids_in_creation_wizard_settings(@project, section_id)
cf_ids_to_toggle, force_enabled_cf_ids = ProjectCustomField.toggleable_ids_in_creation_wizard_settings(@project, section_id)
ProjectCustomFieldProjectMapping
.where(project_id: @project.id, custom_field_id: cf_ids_to_toggle)
.update_all(creation_wizard: value)
enable_creation_wizard!(force_enabled_cf_ids)
redirect_to project_settings_creation_wizard_path(@project, tab: "attributes"), status: :see_other
end
def enable_creation_wizard!(custom_field_ids)
ProjectCustomFieldProjectMapping
.where(project_id: @project.id, custom_field_id: custom_field_ids)
.update_all(creation_wizard: true)
end
def check_feature_flag
unless OpenProject::FeatureDecisions.project_initiation_active?
render_404
+5 -3
View File
@@ -68,7 +68,7 @@ class ProjectCustomField < CustomField
project:,
custom_field_section_id:,
options: { is_for_all: false }
)
).first
end
def toggleable_ids_in_creation_wizard_settings(project, custom_field_section_id)
@@ -81,7 +81,9 @@ class ProjectCustomField < CustomField
private
# Returns a list of custom field ids that can be toggled = activated/enabled or disabled/deactivated.
# Returns an array with:
# 1. a list of custom field ids that can be toggled = activated/enabled or disabled/deactivated.
# 2. a list of custom field ids that cannot be toggled and should always be active/enabled.
def toggleable_ids(project:, custom_field_section_id:, user: User.current, options: {})
# Fetch project custom field ids that can be enabled/disabled
mutable_cf_ids = visible(user, project:)
@@ -96,7 +98,7 @@ class ProjectCustomField < CustomField
[]
end
mutable_cf_ids - immutable_cf_ids
[mutable_cf_ids - immutable_cf_ids, immutable_cf_ids]
end
def mappings_with_view_project_attributes_permission(user, project) # rubocop:disable Metrics/AbcSize
@@ -221,6 +221,9 @@ RSpec.describe "Project creation wizard settings - attributes tab",
expect_disabled_state
end
end
required_int_mapping.reload
expect(required_int_mapping.creation_wizard).to be true
end
context "with a user custom field" do
@@ -267,6 +270,23 @@ RSpec.describe "Project creation wizard settings - attributes tab",
end
end
end
it "is excluded from 'disable all' action" do
within_custom_field_section_container(section2) do
within_custom_field_container(user_custom_field) do
expect_checked_state
end
click_link "Disable all"
within_custom_field_container(user_custom_field) do
expect_checked_state
end
end
user_custom_field_mapping.reload
expect(user_custom_field_mapping.creation_wizard).to be true
end
end
end
@@ -324,6 +344,23 @@ RSpec.describe "Project creation wizard settings - attributes tab",
expect(list_mapping.creation_wizard).to be false
end
it "excludes required fields from 'disable all' action" do
within_custom_field_section_container(section2) do
within_custom_field_container(required_int_custom_field) do
expect_checked_state
end
click_link "Disable all"
within_custom_field_container(required_int_custom_field) do
expect_checked_state
end
end
required_int_mapping.reload
expect(required_int_mapping.creation_wizard).to be true
end
context "when a field is not mapped to the project" do
let!(:unmapped_field) do
create(:string_project_custom_field,