From 8bcc5a5217b6da2091add2c06f0f5fc223e675de Mon Sep 17 00:00:00 2001 From: Liane Hampe Date: Thu, 4 Jul 2024 13:15:20 +0200 Subject: [PATCH] Fixing NoMethodError in DmsfFileRevisionFormat When an issue with a custom field format DmsfFileRevision should be created by a non-member an exception would be raised without this commit. A non-member could always be an admin or in fact a non-member in case of a public project. --- .../field_formats/dmsf_file_revision_format.rb | 2 +- test/unit/custom_field_dmsf_file_format_test.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/redmine_dmsf/field_formats/dmsf_file_revision_format.rb b/lib/redmine_dmsf/field_formats/dmsf_file_revision_format.rb index 68a4dec8..80280f49 100644 --- a/lib/redmine_dmsf/field_formats/dmsf_file_revision_format.rb +++ b/lib/redmine_dmsf/field_formats/dmsf_file_revision_format.rb @@ -30,7 +30,7 @@ class DmsfFileRevisionFormat < Redmine::FieldFormat::Unbounded def edit_tag(view, tag_id, tag_name, custom_value, options = {}) member = Member.find_by(user_id: User.current.id, project_id: custom_value.customized.project.id) - if member.dmsf_fast_links? + if member&.dmsf_fast_links? view.text_field_tag(tag_name, custom_value.value, options.merge(id: tag_id)) else select_edit_tag(view, tag_id, tag_name, custom_value, options) diff --git a/test/unit/custom_field_dmsf_file_format_test.rb b/test/unit/custom_field_dmsf_file_format_test.rb index c30d7e98..61042b6b 100644 --- a/test/unit/custom_field_dmsf_file_format_test.rb +++ b/test/unit/custom_field_dmsf_file_format_test.rb @@ -37,4 +37,20 @@ def test_possible_values_options end assert_equal n, @field.possible_values_options(@issue).size end + + def test_edit_tag_when_member_not_found + User.current = User.generate! + view = ActionView::Base.new(ActionController::Base.view_paths, {}, ActionController::Base.new) + view.extend(ApplicationHelper) + + begin + @field.format.edit_tag(view, + "issue_custom_field_values_#{@field.id}", + "issue[custom_field_values][#{@field.id}]", + CustomValue.create!(custom_field: @field, customized: @issue)) + assert true + rescue NoMethodError => e + flunk "Test failure: #{e.message}" + end + end end