Skip to content

Commit 68592cf

Browse files
committed
publish v0.1
1 parent 0bab2a6 commit 68592cf

File tree

11 files changed

+65
-97
lines changed

11 files changed

+65
-97
lines changed

.discourse-compatibility

Whitespace-only changes.

.github/workflows/discourse-plugin.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

LICENSE

Lines changed: 0 additions & 21 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
# **Darren Test** Plugin
2-
3-
**Plugin Summary**
4-
5-
For more information, please see: **url to meta topic**
1+
# **Community Custom Fields** Plugin

app/controllers/darren_test/examples_controller.rb

Lines changed: 0 additions & 11 deletions
This file was deleted.

config/locales/client.en.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ en:
33
admin:
44
site_settings:
55
categories:
6-
darren_test: "Darren Test"
6+
community_custom_fields: "Community Custom Fields"
77
js:
8-
darren_test:
8+
community_custom_fields:
99
placeholder: placeholder

config/routes.rb

Lines changed: 0 additions & 8 deletions
This file was deleted.

config/settings.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
darren_test:
2-
darren_test_enabled:
3-
default: false
4-
client: true
1+
plugins:
2+
community_custom_fields_enabled:
3+
default: true

lib/darren_test/engine.rb

Lines changed: 0 additions & 13 deletions
This file was deleted.

plugin.rb

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,65 @@
11
# frozen_string_literal: true
22

3-
# name: darren-test
4-
# about: TODO
5-
# meta_topic_id: TODO
6-
# version: 0.0.1
7-
# authors: Discourse
8-
# url: TODO
9-
# required_version: 2.7.0
10-
11-
enabled_site_setting :darren_test_enabled
12-
13-
module ::DarrenTest
14-
PLUGIN_NAME = "darren-test"
15-
end
3+
# name: community-custom-fields
4+
# about: Adds custom fields for using Discourse as a support platform
5+
# url:
6+
# version: 0.1
7+
# authors: Retool
168

17-
require_relative "lib/darren_test/engine"
9+
enabled_site_setting :community_custom_fields_enabled
1810

1911
after_initialize do
20-
# Code which should run after Rails has finished booting
12+
module ::CommunityCustomFields
13+
class Engine < ::Rails::Engine
14+
engine_name "community_custom_fields"
15+
isolate_namespace CommunityCustomFields
16+
config.autoload_paths << File.join(config.root, "lib")
17+
scheduled_job_dir = "#{config.root}/app/jobs/scheduled"
18+
config.to_prepare do
19+
Rails.autoloaders.main.eager_load_dir(scheduled_job_dir) if Dir.exist?(scheduled_job_dir)
20+
end
21+
end
22+
end
23+
24+
#############################################################################
25+
26+
CommunityCustomFields::Engine.routes.draw do
27+
put '/:topic_id' => 'custom_fields#update'
28+
end
29+
30+
Discourse::Application.routes.append do
31+
mount ::CommunityCustomFields::Engine, at: '/admin/plugins/community-custom-fields'
32+
end
33+
34+
#############################################################################
35+
36+
require_dependency 'application_controller'
37+
class CommunityCustomFields::CustomFieldsController < ::ApplicationController
38+
before_action :ensure_logged_in
39+
before_action :ensure_admin
40+
41+
def update
42+
topic = Topic.find(params[:topic_id])
43+
custom = params[:custom_field] || params.permit(:assignee_id, :status)
44+
topic.custom_fields["assignee_id"] = custom[:assignee_id].to_i if custom[:assignee_id].present?
45+
topic.custom_fields["status"] = custom[:status] if custom[:status].present?
46+
if topic.save_custom_fields
47+
render json: success_json
48+
else
49+
Rails.logger.error("Failed to save custom fields for topic #{topic.id}: #{topic.errors.full_messages}")
50+
render json: { error: topic.errors.full_messages }, status: 422
51+
end
52+
end
53+
end
54+
55+
#############################################################################
56+
57+
Topic.register_custom_field_type('assignee_id', :integer)
58+
Topic.register_custom_field_type('status', :string)
59+
60+
TopicList.preloaded_custom_fields << 'assignee_id' << 'status'
61+
62+
add_to_serializer(:topic_view, :custom_fields) do
63+
object.topic.custom_fields.slice('assignee_id', 'status')
64+
end
2165
end

0 commit comments

Comments
 (0)