diff --git a/app/assets/javascripts/admin/addon/components/admin-flag-item.gjs b/app/assets/javascripts/admin/addon/components/admin-flag-item.gjs index 1b52162f4a5..8f0cbdae58b 100644 --- a/app/assets/javascripts/admin/addon/components/admin-flag-item.gjs +++ b/app/assets/javascripts/admin/addon/components/admin-flag-item.gjs @@ -127,15 +127,17 @@ export default class AdminFlagItem extends Component { }}
- {{i18n @descriptionLabel}} - {{#if @learnMoreUrl}} - {{htmlSafe (i18n "learn_more_with_link" url=@learnMoreUrl)}} +
+ {{htmlSafe this.description}} + {{#if @learnMoreUrl}} + {{htmlSafe (i18n "learn_more_with_link" url=@learnMoreUrl)}} + {{/if}} +
+ {{/if}} + + {{#unless @hideTabs}} +- {{i18n @descriptionLabel}} + {{#if this.description}} +
+ {{htmlSafe this.description}} {{#if @learnMoreUrl}} {{htmlSafe (i18n "learn_more_with_link" url=@learnMoreUrl)}} {{/if}}
{{/if}}- {{@plugin.about}} - {{#if @plugin.linkUrl}} - | - - {{i18n "admin.plugins.learn_more"}} - - {{/if}} -
-{{i18n "chat.incoming_webhooks.name"}} | +{{i18n "chat.incoming_webhooks.emoji"}} | +{{i18n "chat.incoming_webhooks.username"}} | +{{i18n "chat.incoming_webhooks.description"}} | +{{i18n "chat.incoming_webhooks.channel"}} | ++ + + + {{#each this.sortedWebhooks as |webhook|}} + |
---|---|---|---|---|---|
{{webhook.name}} | +{{replaceEmoji webhook.emoji}} | +{{webhook.username}} | +{{webhook.description}} | +
+ |
+
{{i18n "chat.admin.export_messages.description"}}
-{{@webhook.url}}
+ {{html-safe (i18n "chat.incoming_webhooks.instructions")}}
- -/hooks/:key
endpoint. The payload consists of a single text
parameter, which is limited to 2000 characters.text
parameters, extracting links and mentions based on the format at https://api.slack.com/reference/surfaces/formatting, but the /hooks/:key/slack
endpoint must be used for this."
+ saved: "Webhook changes saved"
+ created: "Webhook created"
selection:
cancel: "Cancel"
diff --git a/plugins/chat/plugin.rb b/plugins/chat/plugin.rb
index efa67c0975f..f662e3011d2 100644
--- a/plugins/chat/plugin.rb
+++ b/plugins/chat/plugin.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
# name: chat
-# about: Adds chat functionality.
+# about: Adds chat functionality to your site so it can natively support both long-form and short-form communication needs of your online community.
# meta_topic_id: 230881
# version: 0.4
# authors: Kane York, Mark VanLandingham, Martin Brennan, Joffrey Jaffeux
@@ -27,7 +27,7 @@ register_svg_icon "file-image"
register_svg_icon "stop-circle"
# route: /admin/plugins/chat
-add_admin_route "chat.admin.title", "chat"
+add_admin_route "chat.admin.title", "chat", use_new_show_route: true
GlobalSetting.add_default(:allow_unsecure_chat_uploads, false)
@@ -443,6 +443,11 @@ after_initialize do
put "/admin/plugins/chat/hooks/:incoming_chat_webhook_id" =>
"chat/admin/incoming_webhooks#update",
:constraints => StaffConstraint.new
+ get "/admin/plugins/chat/hooks/new" => "chat/admin/incoming_webhooks#new",
+ :constraints => StaffConstraint.new
+ get "/admin/plugins/chat/hooks/:incoming_chat_webhook_id" =>
+ "chat/admin/incoming_webhooks#show",
+ :constraints => StaffConstraint.new
delete "/admin/plugins/chat/hooks/:incoming_chat_webhook_id" =>
"chat/admin/incoming_webhooks#destroy",
:constraints => StaffConstraint.new
diff --git a/plugins/chat/spec/fabricators/chat_fabricator.rb b/plugins/chat/spec/fabricators/chat_fabricator.rb
index 3ace343b0a8..edfd5c2cfbf 100644
--- a/plugins/chat/spec/fabricators/chat_fabricator.rb
+++ b/plugins/chat/spec/fabricators/chat_fabricator.rb
@@ -178,8 +178,8 @@ Fabricator(:chat_webhook_event, class_name: "Chat::WebhookEvent") do
end
Fabricator(:incoming_chat_webhook, class_name: "Chat::IncomingWebhook") do
- name { sequence(:name) { |i| "#{i + 1}" } }
- key { sequence(:key) { |i| "#{i + 1}" } }
+ name { sequence(:name) { |i| "Test webhook #{i + 1}" } }
+ emoji { %w[:joy: :rocket: :handshake:].sample }
chat_channel { Fabricate(:chat_channel, chatable: Fabricate(:category)) }
end
diff --git a/plugins/chat/spec/requests/application_controller_spec.rb b/plugins/chat/spec/requests/application_controller_spec.rb
index 9d52cefc457..56e74dded6f 100644
--- a/plugins/chat/spec/requests/application_controller_spec.rb
+++ b/plugins/chat/spec/requests/application_controller_spec.rb
@@ -25,7 +25,7 @@ RSpec.describe ApplicationController do
"admin_route" => {
"label" => "chat.admin.title",
"location" => "chat",
- "use_new_show_route" => false,
+ "use_new_show_route" => true,
},
"enabled" => true,
},
diff --git a/plugins/chat/spec/system/admin/csv_exports_spec.rb b/plugins/chat/spec/system/admin/csv_exports_spec.rb
index 7bdd9455694..82d67f0cc2c 100644
--- a/plugins/chat/spec/system/admin/csv_exports_spec.rb
+++ b/plugins/chat/spec/system/admin/csv_exports_spec.rb
@@ -1,26 +1,32 @@
# frozen_string_literal: true
-RSpec.describe "Chat CSV exports", type: :system do
- fab!(:admin)
+RSpec.describe "Admin Chat CSV exports", type: :system do
+ let(:dialog) { PageObjects::Components::Dialog.new }
let(:csv_export_pm_page) { PageObjects::Pages::CSVExportPM.new }
+ fab!(:current_user) { Fabricate(:admin) }
before do
Jobs.run_immediately!
- sign_in(admin)
+ sign_in(current_user)
chat_system_bootstrap
end
- xit "exports chat messages" do
+ it "exports chat messages" do
+ Jobs.run_immediately!
message_1 = Fabricate(:chat_message, created_at: 12.months.ago)
message_2 = Fabricate(:chat_message, created_at: 6.months.ago)
message_3 = Fabricate(:chat_message, created_at: 1.months.ago)
message_4 = Fabricate(:chat_message, created_at: Time.now)
visit "/admin/plugins/chat"
- click_button "Create export"
+ click_button I18n.t("js.chat.admin.export_messages.create_export")
+ dialog.click_yes
- visit "/u/#{admin.username}/messages"
- click_link "[Chat Message] Data export complete"
+ visit "/u/#{current_user.username}/messages"
+ click_link I18n.t(
+ "system_messages.csv_export_succeeded.subject_template",
+ export_title: "Chat Message",
+ )
expect(csv_export_pm_page).to have_download_link
exported_data = csv_export_pm_page.download_and_extract
diff --git a/plugins/chat/spec/system/admin/incoming_webhooks_spec.rb b/plugins/chat/spec/system/admin/incoming_webhooks_spec.rb
new file mode 100644
index 00000000000..41deeb0686e
--- /dev/null
+++ b/plugins/chat/spec/system/admin/incoming_webhooks_spec.rb
@@ -0,0 +1,69 @@
+# frozen_string_literal: true
+
+describe "Admin Chat Incoming Webhooks", type: :system do
+ fab!(:current_user) { Fabricate(:admin) }
+ fab!(:chat_channel_1) { Fabricate(:chat_channel) }
+
+ let(:dialog) { PageObjects::Components::Dialog.new }
+ let(:admin_incoming_webhooks_page) { PageObjects::Pages::AdminIncomingWebhooks.new }
+
+ before do
+ chat_system_bootstrap(current_user)
+ sign_in(current_user)
+ end
+
+ it "can create incoming webhooks" do
+ admin_incoming_webhooks_page.visit
+ admin_incoming_webhooks_page.click_new
+ admin_incoming_webhooks_page.form.field("name").fill_in("Test webhook")
+ admin_incoming_webhooks_page.form.field("description").fill_in("Some test content")
+ admin_incoming_webhooks_page.form.field("username").fill_in("system")
+ admin_incoming_webhooks_page.channel_chooser.expand
+ admin_incoming_webhooks_page.channel_chooser.select_row_by_value(chat_channel_1.id)
+ admin_incoming_webhooks_page.channel_chooser.collapse
+ # TODO (martin) Add an emoji selection once Joffrey's emoji selector
+ # unification has landed in core.
+
+ admin_incoming_webhooks_page.form.submit
+
+ expect(page).to have_content(I18n.t("js.chat.incoming_webhooks.created"))
+ expect(page).to have_content(Chat::IncomingWebhook.find_by(name: "Test webhook").url)
+ end
+
+ describe "existing webhooks" do
+ fab!(:webhook_1) { Fabricate(:incoming_chat_webhook) }
+ fab!(:webhook_2) { Fabricate(:incoming_chat_webhook) }
+
+ it "can list existing incoming webhooks" do
+ admin_incoming_webhooks_page.visit
+ expect(page).to have_content(webhook_1.name)
+ expect(page).to have_content(webhook_1.chat_channel.title)
+ expect(page).to have_content(webhook_2.name)
+ expect(page).to have_content(webhook_2.chat_channel.title)
+ end
+
+ it "can edit an existing incoming webhook" do
+ admin_incoming_webhooks_page.visit
+ admin_incoming_webhooks_page
+ .list_row(webhook_1.id)
+ .find(".admin-chat-incoming-webhooks-edit")
+ .click
+ expect(admin_incoming_webhooks_page.form.field("name").value).to eq(webhook_1.name)
+ admin_incoming_webhooks_page.form.field("name").fill_in("Wow so cool")
+ admin_incoming_webhooks_page.form.submit
+ expect(page).to have_content(I18n.t("js.chat.incoming_webhooks.saved"))
+ admin_incoming_webhooks_page.visit
+ expect(page).to have_content("Wow so cool")
+ end
+
+ it "can delete an existing incoming webhook" do
+ admin_incoming_webhooks_page.visit
+ admin_incoming_webhooks_page
+ .list_row(webhook_1.id)
+ .find(".admin-chat-incoming-webhooks-delete")
+ .click
+ dialog.click_danger
+ expect(page).not_to have_content(webhook_1.name)
+ end
+ end
+end
diff --git a/plugins/chat/spec/system/page_objects/chat/admin_incoming_webhooks.rb b/plugins/chat/spec/system/page_objects/chat/admin_incoming_webhooks.rb
new file mode 100644
index 00000000000..09be8e1536e
--- /dev/null
+++ b/plugins/chat/spec/system/page_objects/chat/admin_incoming_webhooks.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+module PageObjects
+ module Pages
+ class AdminIncomingWebhooks < PageObjects::Pages::Base
+ def visit
+ page.visit("/admin/plugins/chat/hooks")
+ self
+ end
+
+ def click_new
+ find(".admin-incoming-webhooks-new").click
+ end
+
+ def channel_chooser
+ PageObjects::Components::SelectKit.new(".chat-channel-chooser")
+ end
+
+ def form
+ PageObjects::Components::FormKit.new(".discourse-chat-incoming-webhooks .form-kit")
+ end
+
+ def list_row(webhook_id)
+ find(".incoming-chat-webhooks-row[data-webhook-id='#{webhook_id}']")
+ end
+ end
+ end
+end