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

Move reject_section_scoped_validation to the Projects::CreateContract

Dombi Attilaa0367277f67a
diff --git a/app/models/projects/acts_as_customizable_patches.rb b/app/models/projects/acts_as_customizable_patches.rb
index 49b6e0fdbee..6b1dc672129 100644
--- a/app/models/projects/acts_as_customizable_patches.rb
+++ b/app/models/projects/acts_as_customizable_patches.rb
@@ -41,7 +41,6 @@ module Projects::ActsAsCustomizablePatches
before_update :set_query_available_custom_fields_to_global_level
- before_create :reject_section_scoped_validation_for_creation
before_create :build_missing_project_custom_field_project_mappings
after_save :reset_section_scoped_validation
@@ -71,13 +70,6 @@ module Projects::ActsAsCustomizablePatches
self._query_available_custom_fields_on_global_level = true
end
- def reject_section_scoped_validation_for_creation
- if _limit_custom_fields_validation_to_section_id.present?
- raise ArgumentError,
- "Section scoped validation is not supported for project creation, only for project updates"
- end
- end
-
def with_all_available_custom_fields
# query the available custom fields on a global level when updating custom field values
# in order to support implicit activation of custom fields when values are provided during an update
diff --git a/app/services/projects/concerns/new_project_service.rb b/app/services/projects/concerns/new_project_service.rb
index 92f3b04f68d..eb7a6cc2c2d 100644
--- a/app/services/projects/concerns/new_project_service.rb
+++ b/app/services/projects/concerns/new_project_service.rb
@@ -42,6 +42,15 @@ module Projects::Concerns
super
end
+ def after_validate(params, service_call)
+ # we need to reset the query_available_custom_fields_on_global_level already after validation
+ # as the update service just calls .valid? and returns if invalid
+ # after_save is not touched in this case which causes the flag to stay active
+ reject_section_scoped_validation(service_call.result)
+
+ super
+ end
+
# Add default role to the newly created project
# based on the setting ('new_project_user_role_id')
# defined in the administration. Will either create a new membership
@@ -91,5 +100,12 @@ module Projects::Concerns
.where.not(custom_field_id: new_project.available_custom_fields.select(:id)))
.destroy_all
end
+
+ def reject_section_scoped_validation(new_project)
+ if new_project._limit_custom_fields_validation_to_section_id.present?
+ raise ArgumentError,
+ "Section scoped validation is not supported for project creation, only for project updates"
+ end
+ end
end
end