mirror of
https://github.com/opf/openproject.git
synced 2026-06-14 03:30:14 +00:00
[#64348] Refine error message for invalid custom fields
This commit is contained in:
committed by
Tobias Dillmann
parent
080160bb43
commit
bd8e2cbfbd
@@ -95,7 +95,8 @@ module CustomField::CalculatedValue
|
||||
surplus_cfs = formula_cfs - allowed_cfs
|
||||
|
||||
if surplus_cfs.any?
|
||||
errors.add(:formula, :invalid_custom_fields, surplus_cfs:)
|
||||
custom_field_names = CustomField.where(id: surplus_cfs).pluck(:name)
|
||||
errors.add(:formula, :invalid_custom_fields, custom_fields: custom_field_names.join(", "))
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
@@ -1349,6 +1349,7 @@ en:
|
||||
inclusion_nested: "is not set to one of the allowed values at path '%{path}'."
|
||||
invalid: "is invalid."
|
||||
invalid_characters: "contains invalid characters."
|
||||
invalid_custom_fields: "contains custom fields that are not allowed: %{custom_fields}."
|
||||
invalid_url: "is not a valid URL."
|
||||
invalid_url_scheme: "is not a supported protocol (allowed: %{allowed_schemes})."
|
||||
less_than_or_equal_to: "must be less than or equal to %{count}."
|
||||
|
||||
@@ -166,5 +166,27 @@ RSpec.describe CustomField::CalculatedValue, with_flag: { calculated_value_proje
|
||||
|
||||
it_behaves_like "invalid formula", "is invalid."
|
||||
end
|
||||
|
||||
context "with a formula that contains custom fields that are not visible to the user" do
|
||||
let(:project_with_permission) { create(:project) }
|
||||
let(:project_without_permission) { create(:project) }
|
||||
let(:user) { create(:user, member_with_permissions: { project_with_permission => [:view_project_attributes] }) }
|
||||
|
||||
let!(:int) do
|
||||
create(:project_custom_field, :integer, name: "int", default_value: 4, projects: [project_without_permission])
|
||||
end
|
||||
let!(:float) do
|
||||
create(:project_custom_field, :float, name: "float", default_value: 5.5, projects: [project_without_permission])
|
||||
end
|
||||
let!(:other_calculated_value) do
|
||||
create(:calculated_value_project_custom_field, formula: "2 + 2", projects: [project_with_permission])
|
||||
end
|
||||
|
||||
let(:formula) { "1 + {{cf_#{int.id}}} + {{cf_#{float.id}}} + {{cf_#{other_calculated_value.id}}}" }
|
||||
|
||||
current_user { user }
|
||||
|
||||
it_behaves_like "invalid formula", "contains custom fields that are not allowed: int, float."
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user