File tree Expand file tree Collapse file tree 2 files changed +35
-9
lines changed
Expand file tree Collapse file tree 2 files changed +35
-9
lines changed Original file line number Diff line number Diff line change @@ -8,14 +8,18 @@ class CommunityCustomFields::CustomFieldsController < ::ApplicationController
88
99 def update
1010 topic = Topic . find ( params [ :topic_id ] )
11- custom = params [ :custom_field ] || params . permit ( :assignee_id , :status )
12- topic . custom_fields [ "assignee_id" ] = custom [ :assignee_id ] . to_i if custom [ :assignee_id ] . present?
13- topic . custom_fields [ "status" ] = custom [ :status ] if custom [ :status ] . present?
11+ topic . custom_fields . merge! ( custom_fields_params )
1412 if topic . save_custom_fields
1513 render json : success_json
1614 else
1715 Rails . logger . error ( "Failed to save custom fields for topic #{ topic . id } : #{ topic . errors . full_messages } " )
1816 render json : { error : topic . errors . full_messages } , status : 422
1917 end
2018 end
19+
20+ private
21+
22+ def custom_fields_params
23+ params . require ( :custom_field ) . permit ( CommunityCustomFields ::CUSTOM_FIELD_NAMES )
24+ end
2125end
Original file line number Diff line number Diff line change 1010
1111module ::CommunityCustomFields
1212 PLUGIN_NAME = "community-custom-fields"
13+ CUSTOM_FIELD_NAMES = %i[
14+ assignee_id
15+ first_assigned_to_id
16+ first_assigned_at
17+ last_assigned_at
18+ last_action_by_assignee_at
19+ priority
20+ product_area
21+ status
22+ snoozed_until
23+ ]
24+ CUSTOM_FIELD_TYPES = %i[
25+ integer
26+ integer
27+ datetime
28+ datetime
29+ datetime
30+ string
31+ string
32+ string
33+ datetime
34+ ]
1335end
1436
1537require_relative 'lib/community_custom_fields/engine.rb'
1638
1739after_initialize do
18- Topic . register_custom_field_type ( 'assignee_id' , :integer )
19- Topic . register_custom_field_type ( 'status' , :string )
40+ CommunityCustomFields ::CUSTOM_FIELD_NAMES . each_with_index do |field , i |
41+ Topic . register_custom_field_type ( field , CommunityCustomFields ::CUSTOM_FIELD_TYPES [ i ] )
42+ end
2043
21- TopicList . preloaded_custom_fields << 'assignee_id' << 'status'
44+ TopicList . preloaded_custom_fields . merge ( CommunityCustomFields :: CUSTOM_FIELD_NAMES )
2245
2346 add_to_serializer ( :topic_view , :custom_fields ) do
24- object . topic . custom_fields . slice ( 'assignee_id' , 'status' )
47+ object . topic . custom_fields . slice ( * CommunityCustomFields :: CUSTOM_FIELD_NAMES )
2548 end
2649
2750 on ( :topic_created ) do |topic , params , user |
28- topic . custom_fields [ "assignee_id" ] ||= 0
29- topic . custom_fields [ "status" ] ||= "new"
51+ topic . custom_fields [ :status ] = "new"
3052 topic . save_custom_fields
3153 end
3254end
You can’t perform that action at this time.
0 commit comments