File tree Expand file tree Collapse file tree 2 files changed +18
-22
lines changed Expand file tree Collapse file tree 2 files changed +18
-22
lines changed Original file line number Diff line number Diff line change
1
+ class CommunityCustomFields ::CustomFieldsController < ::ApplicationController
2
+ before_action :ensure_logged_in
3
+ before_action :ensure_admin
4
+
5
+ def update
6
+ topic = Topic . find ( params [ :topic_id ] )
7
+ custom = params [ :custom_field ] || params . permit ( :assignee_id , :status )
8
+ topic . custom_fields [ "assignee_id" ] = custom [ :assignee_id ] . to_i if custom [ :assignee_id ] . present?
9
+ topic . custom_fields [ "status" ] = custom [ :status ] if custom [ :status ] . present?
10
+ if topic . save_custom_fields
11
+ render json : success_json
12
+ else
13
+ Rails . logger . error ( "Failed to save custom fields for topic #{ topic . id } : #{ topic . errors . full_messages } " )
14
+ render json : { error : topic . errors . full_messages } , status : 422
15
+ end
16
+ end
17
+ end
Original file line number Diff line number Diff line change 8
8
9
9
enabled_site_setting :community_custom_fields_enabled
10
10
11
- module ::DiscourseSolved
11
+ module ::CommunityCustomFields
12
12
PLUGIN_NAME = "community-custom-fields"
13
13
end
14
14
15
15
require_relative 'lib/community_custom_fields/engine.rb'
16
16
17
17
after_initialize do
18
- require_dependency 'application_controller'
19
- class CommunityCustomFields ::CustomFieldsController < ::ApplicationController
20
- before_action :ensure_logged_in
21
- before_action :ensure_admin
22
-
23
- def update
24
- topic = Topic . find ( params [ :topic_id ] )
25
- custom = params [ :custom_field ] || params . permit ( :assignee_id , :status )
26
- topic . custom_fields [ "assignee_id" ] = custom [ :assignee_id ] . to_i if custom [ :assignee_id ] . present?
27
- topic . custom_fields [ "status" ] = custom [ :status ] if custom [ :status ] . present?
28
- if topic . save_custom_fields
29
- render json : success_json
30
- else
31
- Rails . logger . error ( "Failed to save custom fields for topic #{ topic . id } : #{ topic . errors . full_messages } " )
32
- render json : { error : topic . errors . full_messages } , status : 422
33
- end
34
- end
35
- end
36
-
37
- #############################################################################
38
-
39
18
Topic . register_custom_field_type ( 'assignee_id' , :integer )
40
19
Topic . register_custom_field_type ( 'status' , :string )
41
20
You can’t perform that action at this time.
0 commit comments