From: Go MAEDA Date: Thu, 18 Mar 2021 07:44:42 +0000 (+0000) Subject: Show project ID instead of name in issue journal details if the project is not visibl... X-Git-Tag: 4.2.0~33 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0d96c4ebdb1cceeb6cac8f940a11b5407a0a5211;p=redmine.git Show project ID instead of name in issue journal details if the project is not visible for the current user (#33360). Patch by Marius BALTEANU. git-svn-id: http://svn.redmine.org/redmine/trunk@20819 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index 566cd1d53..363d970c8 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -637,6 +637,7 @@ module IssuesHelper end # Find the name of an associated record stored in the field attribute + # For project, return the associated record only if is visible for the current User def find_name_by_reflection(field, id) return nil if id.blank? @@ -645,7 +646,7 @@ module IssuesHelper name = nil if association record = association.klass.find_by_id(key.last) - if record + if (record && !record.is_a?(Project)) || (record.is_a?(Project) && record.visible?) name = record.name.force_encoding('UTF-8') end end diff --git a/test/helpers/issues_helper_test.rb b/test/helpers/issues_helper_test.rb index fdd5f3598..562474f7c 100644 --- a/test/helpers/issues_helper_test.rb +++ b/test/helpers/issues_helper_test.rb @@ -145,12 +145,20 @@ class IssuesHelperTest < Redmine::HelperTest end test 'show_detail should show old and new values with a project attribute' do + User.current = User.find(2) detail = JournalDetail.new(:property => 'attr', :prop_key => 'project_id', :old_value => 1, :value => 2) assert_match 'eCookbook', show_detail(detail, true) assert_match 'OnlineStore', show_detail(detail, true) end + test 'show_detail with a project attribute should show project ID if project is not visible' do + detail = JournalDetail.new(:property => 'attr', :prop_key => 'project_id', + :old_value => 1, :value => 2) + assert_match 'eCookbook', show_detail(detail, true) + assert_match '2', show_detail(detail, true) + end + test 'show_detail should show old and new values with a issue status attribute' do detail = JournalDetail.new(:property => 'attr', :prop_key => 'status_id', :old_value => 1, :value => 2)