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

adding a cf via form configuration no longer enables the cf in all projects

ulferts899445c339af
diff --git a/app/controllers/types_controller.rb b/app/controllers/types_controller.rb
index 31c8ad25cd7..7deb8391fcd 100644
--- a/app/controllers/types_controller.rb
+++ b/app/controllers/types_controller.rb
@@ -83,7 +83,7 @@ class TypesController < ApplicationController
.new(@type, current_user)
.call(permitted_type_params) do |call|
call.on_success do
- redirect_to_type_tab_path(@type, update_success_message)
+ redirect_to_type_tab_path(@type, t(:notice_successful_update))
end
call.on_failure do |result|
@@ -151,14 +151,6 @@ class TypesController < ApplicationController
false
end
- def update_success_message
- if params[:tab].in?(%w[form_configuration projects])
- t(:notice_successful_update_custom_fields_added_to_type)
- else
- t(:notice_successful_update)
- end
- end
-
def destroy_error_message
if @type.is_standard?
t(:error_can_not_delete_standard_type)
diff --git a/app/services/base_type_service.rb b/app/services/base_type_service.rb
index d536cb3a79b..0188dc4f8b1 100644
--- a/app/services/base_type_service.rb
+++ b/app/services/base_type_service.rb
@@ -80,9 +80,7 @@ class BaseTypeService
set_milestone_param(params) unless params[:is_milestone].nil?
set_active_custom_fields
- if params[:project_ids].present?
- set_active_custom_fields_for_project_ids(params[:project_ids])
- end
+ set_active_custom_fields_for_project_ids(params[:project_ids]) if params[:project_ids].present?
set_scalar_params(params)
@@ -167,24 +165,21 @@ class BaseTypeService
# for this type. If a custom field is not in a group, it is removed from the
# custom_field_ids list.
def set_active_custom_fields
- new_cf_ids_to_add = active_custom_field_ids - type.custom_field_ids
- type.custom_field_ids = active_custom_field_ids
- set_active_custom_fields_for_projects(type.projects,
- new_cf_ids_to_add)
+ active_cf_ids = []
+
+ type.attribute_groups.each do |group|
+ group.members.each do |attribute|
+ if CustomField.custom_field_attribute? attribute
+ active_cf_ids << attribute.gsub(/^custom_field_/, "").to_i
+ end
+ end
+ end
+
+ type.custom_field_ids = active_cf_ids.uniq
end
def active_custom_field_ids
@active_custom_field_ids ||= begin
- active_cf_ids = []
-
- type.attribute_groups.each do |group|
- group.members.each do |attribute|
- if CustomField.custom_field_attribute? attribute
- active_cf_ids << attribute.gsub(/^custom_field_/, "").to_i
- end
- end
- end
- active_cf_ids.uniq
end
end
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 8e6d1760a2c..31acc182029 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -2960,9 +2960,6 @@ en:
notice_successful_update_custom_fields_added_to_project: |
Successful update. The custom fields of the activated types are automatically activated
on the work package form. <a href="%{url}" target="_blank">See more</a>.
- notice_successful_update_custom_fields_added_to_type: |
- Successful update. The active custom fields are automatically activated for
- the associated projects of this type.
notice_to_many_principals_to_display: "There are too many results.\nNarrow down the search by typing in the name of the new member (or group)."
notice_user_missing_authentication_method: User has yet to choose a password or another way to sign in.
notice_user_invitation_resent: An invitation has been sent to %{email}.
diff --git a/spec/features/types/form_configuration_spec.rb b/spec/features/types/form_configuration_spec.rb
index 5e6fc5ed76f..0457df023ee 100644
--- a/spec/features/types/form_configuration_spec.rb
+++ b/spec/features/types/form_configuration_spec.rb
@@ -305,19 +305,6 @@ RSpec.describe "form configuration", :js do
context "if inactive in project" do
it "can be added to the type, but is not shown" do
add_cf_to_group
- # Disable in project, should be invisible
- # This step is necessary, since we auto-activate custom fields
- # when adding them to the form configuration
- project_settings_page.visit_tab!("custom_fields")
-
- expect(page).to have_css(".custom-field-#{custom_field.id} td", text: "MyNumber")
- expect(page).to have_css(".custom-field-#{custom_field.id} td", text: type.name)
-
- id_checkbox = find("#project_work_package_custom_field_ids_#{custom_field.id}")
- expect(id_checkbox).to be_checked
- id_checkbox.set(false)
-
- click_button "Save"
# Visit work package with that type
wp_page.visit!
diff --git a/spec/services/shared_type_service.rb b/spec/services/shared_type_service.rb
index 07b68e22e90..f327d2f5129 100644
--- a/spec/services/shared_type_service.rb
+++ b/spec/services/shared_type_service.rb
@@ -149,29 +149,15 @@ RSpec.shared_examples_for "type service" do
expect(type).to have_received(:custom_field_ids=)
end
- context "when all the projects are associated with the type" do
+ context "when all the projects are already associated with the type" do
before do
type.projects = create_list :project, 2
end
- it "enables the custom fields in the projects" do
+ it "does not enable the custom fields in the projects (used to be different until OP 15.0)" do
expect { service_call }
- .to change { Project.where(id: type.project_ids).map(&:work_package_custom_fields) }
+ .not_to change { Project.where(id: type.project_ids).map(&:work_package_custom_field_ids) }
.from([[], []])
- .to([[cf1, cf2], [cf1, cf2]])
- end
-
- context "when a custom field is already associated with the type" do
- before do
- type.custom_field_ids = [cf1.id]
- end
-
- it "enables the new custom field only" do
- expect { service_call }
- .to change { Project.where(id: type.project_ids).map(&:work_package_custom_fields) }
- .from([[], []])
- .to([[cf2], [cf2]])
- end
end
context "when all custom fields are already associated with the type" do
@@ -189,8 +175,9 @@ RSpec.shared_examples_for "type service" do
context "when a project is being set on the type" do
let(:projects) { create_list(:project, 2) }
- let(:active_project) { projects.first }
- let(:project_ids) { { project_ids: [*projects.map { |p| p.id.to_s }, ""] } }
+ let(:active_project) { create(:project) }
+ let(:new_project) { create(:project) }
+ let(:project_ids) { { project_ids: [*[active_project, new_project].map { |p| p.id.to_s }, ""] } }
let(:params) do
attribute_groups.merge(project_ids)
end
@@ -199,11 +186,17 @@ RSpec.shared_examples_for "type service" do
type.projects << active_project
end
- it "enables the custom fields for all the projects" do
+ it "enables the custom field on the newly added project" do
expect { service_call }
- .to change { Project.where(id: type.project_ids).map(&:work_package_custom_fields) }
- .from([[]])
- .to([[cf1, cf2], [cf1, cf2]])
+ .to change { Project.find(new_project.id).work_package_custom_field_ids }
+ .from([])
+ .to([cf1.id, cf2.id])
+ end
+
+ it "does not enable the custom fields on the project the type was already active in" do
+ expect { service_call }
+ .not_to change { Project.find(active_project.id).work_package_custom_field_ids }
+ .from([])
end
context "when a custom field is already associated with the type" do
@@ -211,11 +204,17 @@ RSpec.shared_examples_for "type service" do
type.custom_field_ids = [cf1.id]
end
- it "enables the new cf for the existing project and enables both cfs for the new project" do
+ it "enables the custom field on the newly added project" do
expect { service_call }
- .to change { Project.where(id: type.project_ids).map(&:work_package_custom_fields) }
- .from([[]])
- .to([[cf2], [cf1, cf2]])
+ .to change { Project.find(new_project.id).work_package_custom_field_ids }
+ .from([])
+ .to([cf1.id, cf2.id])
+ end
+
+ it "does not enable the custom fields on the project the type was already active in" do
+ expect { service_call }
+ .not_to change { Project.find(active_project.id).work_package_custom_field_ids }
+ .from([])
end
end
@@ -226,11 +225,17 @@ RSpec.shared_examples_for "type service" do
type.custom_field_ids = [cf1.id, cf2.id]
end
- it "enables the custom fields in the new project only" do
+ it "enables the custom field on the newly added project" do
+ expect { service_call }
+ .to change { Project.find(new_project.id).work_package_custom_field_ids }
+ .from([])
+ .to([cf1.id, cf2.id])
+ end
+
+ it "does not enable the custom fields on the project the type was already active in" do
expect { service_call }
- .to change { Project.where(id: type.project_ids).map(&:work_package_custom_fields) }
- .from([[]])
- .to([[], [cf1, cf2]])
+ .not_to change { Project.find(active_project.id).work_package_custom_field_ids }
+ .from([])
end
end
end