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

Filter out projects with disabled custom fields on the projects index page

Dombi Attila7e052786c9f1
diff --git a/app/models/queries/projects/filters/custom_field_context.rb b/app/models/queries/projects/filters/custom_field_context.rb
index 34fad024bf3..55199abde70 100644
--- a/app/models/queries/projects/filters/custom_field_context.rb
+++ b/app/models/queries/projects/filters/custom_field_context.rb
@@ -44,10 +44,15 @@ module Queries::Projects::Filters::CustomFieldContext
cv_db_table = CustomValue.table_name
project_db_table = Project.table_name
- "LEFT OUTER JOIN #{cv_db_table}
- ON #{cv_db_table}.customized_type='Project'
- AND #{cv_db_table}.customized_id=#{project_db_table}.id
- AND #{cv_db_table}.custom_field_id=#{custom_field.id}"
+ <<~SQL.squish
+ LEFT OUTER JOIN #{cv_db_table}
+ ON #{cv_db_table}.customized_type='Project'
+ AND #{cv_db_table}.customized_id=#{project_db_table}.id
+ AND #{cv_db_table}.custom_field_id=#{custom_field.id}
+ INNER JOIN project_custom_field_project_mappings
+ ON project_custom_field_project_mappings.project_id = projects.id
+ AND project_custom_field_project_mappings.custom_field_id = #{custom_field.id}
+ SQL
end
end
end
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 663f0c2b869..c26452718c1 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -2161,6 +2161,7 @@ Project attributes and sections are defined in the <a href=%{admin_settings_url}
label_project_new: "New project"
label_project_plural: "Projects"
label_project_attributes_plural: "Project attributes"
+ label_project_custom_field_plural: "Project attributes"
label_project_settings: "Project settings"
label_project_attributes_settings: "Project attributes settings"
label_project_storage_plural: "File Storages"
diff --git a/spec/features/projects/projects_index_spec.rb b/spec/features/projects/projects_index_spec.rb
index b2f27c2cccb..2ba10d85e01 100644
--- a/spec/features/projects/projects_index_spec.rb
+++ b/spec/features/projects/projects_index_spec.rb
@@ -770,6 +770,15 @@ RSpec.describe 'Projects index page',
expect(page).to have_text(project_created_on_today.name)
expect(page).to have_no_text(project_created_on_fixed_date.name)
+
+ # Disabling a CF in the project should remove the project from results
+
+ project_created_on_today.project_custom_field_project_mappings.destroy_all
+ click_on 'Apply'
+ wait_for_reload
+
+ expect(page).to have_no_text(project_created_on_today.name, wait: 1)
+ expect(page).to have_no_text(project_created_on_fixed_date.name)
end
pending "NOT WORKING YET: Date vs. DateTime issue: Selecting same date for from and to value shows projects of that date"