From bdc4b1ba82c97c715098f25398ab16773b7ca5ab Mon Sep 17 00:00:00 2001 From: Holger Just Date: Fri, 29 Jun 2018 17:07:55 +0200 Subject: [PATCH] Use the id field as project_key in ProjectCustomField#visibility_by_project_condition by default --- app/models/project_custom_field.rb | 5 +++++ test/unit/custom_field_test.rb | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/app/models/project_custom_field.rb b/app/models/project_custom_field.rb index 54e7958a37..e038313f84 100644 --- a/app/models/project_custom_field.rb +++ b/app/models/project_custom_field.rb @@ -19,4 +19,9 @@ class ProjectCustomField < CustomField def type_name :label_project_plural end + + def visibility_by_project_condition(project_key=nil, user=User.current, id_column=nil) + project_key ||= "#{Project.table_name}.id" + super(project_key, user, id_column) + end end diff --git a/test/unit/custom_field_test.rb b/test/unit/custom_field_test.rb index 3eae54efae..bdf5d48422 100644 --- a/test/unit/custom_field_test.rb +++ b/test/unit/custom_field_test.rb @@ -340,4 +340,20 @@ class CustomFieldTest < ActiveSupport::TestCase assert_equal 12.5, field.cast_value('+12.5') assert_equal -12.5, field.cast_value('-12.5') end + + def test_project_custom_field_visibility + project_field = ProjectCustomField.generate!(:visible => false, :field_format => 'list', :possible_values => %w[a b c]) + project = Project.find(3) + project.custom_field_values = { project_field.id => 'a' } + + # Admins can find projects with the field + with_current_user(User.find(1)) do + assert_includes Project.where(project_field.visibility_by_project_condition), project + end + + # The field is not visible to normal users + with_current_user(User.find(2)) do + refute_includes Project.where(project_field.visibility_by_project_condition), project + end + end end -- 2.19.0