プロジェクト

全般

プロフィール

Vote #79346

完了

Custom field values for enumerations not saved

Admin Redmine さんが3年以上前に追加. 3年以上前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
Custom fields_14
対象バージョン:
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
14
version_id:
143
issue_org_id:
28925
author_id:
16879
assigned_to_id:
1
comments:
10
status_id:
5
tracker_id:
1
plus1:
0
affected_version:
closed_on:
affected_version_id:
139
ステータス-->[Closed]

説明

The Enumerations controller drops @custom_field_values@ from @params@, therefore they are never saved. This is done in the code:


  def enumeration_params
    # can't require enumeration on #new action
    params.permit(:enumeration => [:name, :active, :is_default, :position])[:enumeration]
  end

Here @:custom_field_values@ is missing.

Steps to reproduce:

Add a custom field for activities (time tracking)

Edit any activity (time tracking) in Enumerations

Try to save a value for the previously created custom field (it won't be saved)


journals

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
I wrote a patch to fix this defect.
The key of custom_field_values allows only id of custom field of enumeration.
--------------------------------------------------------------------------------
I changed the test a little.
--------------------------------------------------------------------------------
Maybe we can use @available_custom_fields@ to collect ids of custom fields. I think the following change can make the patch simpler and faster. Mizuki, do you think it is correct?

<pre><code class="diff">
--- app/controllers/enumerations_controller.rb.orig 2018-06-18 15:28:18.000000000 +0000
+++ app/controllers/enumerations_controller.rb 2018-06-18 15:28:36.000000000 +0000
@@ -107,7 +107,7 @@

def enumeration_params
# can't require enumeration on #new action
- custom_field_keys = (@enumeration.try(:custom_field_values) || []).map{|c| c.custom_field_id.to_s}
+ custom_field_keys = @enumeration.available_custom_fields.map{|c| c.id.to_s}
params.permit(:enumeration => [:name, :active, :is_default, :position, :custom_field_values => custom_field_keys])[:enumeration]
end
end
</code></pre>
--------------------------------------------------------------------------------
why enumerations use strong params instead of safe_attributes like all other models do?
--------------------------------------------------------------------------------
Go MAEDA wrote:
> Maybe we can use @available_custom_fields@ to collect ids of custom fields. I think the following change can make the patch simpler and faster. Mizuki, do you think it is correct?
>
> [...]
I did not know available_custom_fields. I think that the code you propose is good.

Pavel Rosický wrote:
> why enumerations use strong params instead of safe_attributes like all other models do?
I do not know the reason, It seems that it was intentionally changed to use strong_params instead of safe_attribute in r16602 and r16603.
--------------------------------------------------------------------------------
Mizuki ISHIKAWA wrote:
> I did not know available_custom_fields. I think that the code you propose is good.

Thank you for reviewing the change I suggested in #28925#note-5. I have slightly changed your patch.

Setting target version to 3.4.7.

--------------------------------------------------------------------------------
Committed, thanks.
--------------------------------------------------------------------------------
Patch broke 3.4-stable, fixed.
--------------------------------------------------------------------------------


related_issues

relates,Closed,26564,Enumerations sorting does not work

Admin Redmine さんが3年以上前に更新

  • カテゴリCustom fields_14 にセット
  • 対象バージョン3.4.7_143 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0