Skip to content

Commit a669234

Browse files
committed
store custom field info as constant
1 parent 26fbacc commit a669234

File tree

3 files changed

+17
-27
lines changed

3 files changed

+17
-27
lines changed

app/controllers/community_custom_fields/custom_fields_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ def update
2020
private
2121

2222
def custom_fields_params
23-
params.require(:custom_field).permit(CommunityCustomFields::CUSTOM_FIELD_NAMES)
23+
params.require(:custom_field).permit(*CommunityCustomFields::CUSTOM_FIELDS.keys)
2424
end
2525
end

app/jobs/scheduled/.gitkeep

Whitespace-only changes.

plugin.rb

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,45 +10,35 @@
1010

1111
module ::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-
]
13+
CUSTOM_FIELDS = {
14+
assignee_id: :integer,
15+
first_assigned_to_id: :integer,
16+
first_assigned_at: :datetime,
17+
last_assigned_at: :datetime,
18+
last_action_by_assignee_at: :datetime,
19+
priority: :string,
20+
product_area: :string,
21+
status: :string,
22+
snoozed_until: :datetime
23+
}
3524
end
3625

3726
require_relative 'lib/community_custom_fields/engine.rb'
3827

3928
after_initialize do
40-
CommunityCustomFields::CUSTOM_FIELD_NAMES.each_with_index do |field, i|
41-
Topic.register_custom_field_type(field, CommunityCustomFields::CUSTOM_FIELD_TYPES[i])
29+
CommunityCustomFields::CUSTOM_FIELDS.each do |name, type|
30+
Topic.register_custom_field_type(name, type)
4231
end
4332

44-
TopicList.preloaded_custom_fields.merge(CommunityCustomFields::CUSTOM_FIELD_NAMES)
33+
TopicList.preloaded_custom_fields.merge(CommunityCustomFields::CUSTOM_FIELDS.keys)
4534

4635
add_to_serializer(:topic_view, :custom_fields) do
47-
object.topic.custom_fields.slice(*CommunityCustomFields::CUSTOM_FIELD_NAMES)
36+
object.topic.custom_fields.slice(*CommunityCustomFields::CUSTOM_FIELDS.keys)
4837
end
4938

5039
on(:topic_created) do |topic, params, user|
5140
topic.custom_fields[:status] = "new"
41+
topic.custom_fields[:assignee_id] = 0
5242
topic.save_custom_fields
5343
end
5444
end

0 commit comments

Comments
 (0)