diff --git a/app/controllers/chat_controller.rb b/app/controllers/chat_controller.rb index 21e3cd1..a692a30 100644 --- a/app/controllers/chat_controller.rb +++ b/app/controllers/chat_controller.rb @@ -9,7 +9,7 @@ class DiscourseChat::ChatController < ApplicationController providers = ::DiscourseChat::Provider.enabled_providers.map {|x| { name: x::PROVIDER_NAME, id: x::PROVIDER_NAME, - channel_regex: (defined? x::PROVIDER_CHANNEL_REGEX) ? x::PROVIDER_CHANNEL_REGEX : nil + channel_parameters: (defined? x::CHANNEL_PARAMETERS) ? x::CHANNEL_PARAMETERS : [] }} render json:providers, root: 'providers' diff --git a/app/models/channel.rb b/app/models/channel.rb index 177e6b2..7c3aeaa 100644 --- a/app/models/channel.rb +++ b/app/models/channel.rb @@ -26,13 +26,13 @@ class DiscourseChat::Channel < DiscourseChat::PluginModel params = ::DiscourseChat::Provider.get_by_name(provider)::CHANNEL_PARAMETERS - unless params.keys.sort == data.keys.sort + unless params.map {|p| p[:key]}.sort == data.keys.sort errors.add(:data, "data does not match the required structure for provider #{provider}") return end data.each do |key, value| - regex_string = params[key] + regex_string = params.find{|p| p[:key] == key}[:regex] if !Regexp.new(regex_string).match?(value) errors.add(:data, "data.#{key} is invalid") end diff --git a/lib/discourse_chat/provider/slack/slack_provider.rb b/lib/discourse_chat/provider/slack/slack_provider.rb index b212739..3146b1f 100644 --- a/lib/discourse_chat/provider/slack/slack_provider.rb +++ b/lib/discourse_chat/provider/slack/slack_provider.rb @@ -3,7 +3,9 @@ module DiscourseChat::Provider::SlackProvider PROVIDER_ENABLED_SETTING = :chat_integration_slack_enabled - CHANNEL_PARAMETERS = {"identifier" => '^[@#]\S*$'} + CHANNEL_PARAMETERS = [ + {key: "identifier", regex: '^[@#]\S*$'} + ] def self.excerpt(post, max_length = SiteSetting.chat_integration_slack_excerpt_length) doc = Nokogiri::HTML.fragment(post.excerpt(max_length, diff --git a/lib/discourse_chat/provider/telegram/telegram_provider.rb b/lib/discourse_chat/provider/telegram/telegram_provider.rb index 8e7afed..a681603 100644 --- a/lib/discourse_chat/provider/telegram/telegram_provider.rb +++ b/lib/discourse_chat/provider/telegram/telegram_provider.rb @@ -3,7 +3,7 @@ module DiscourseChat module TelegramProvider PROVIDER_NAME = "telegram".freeze PROVIDER_ENABLED_SETTING = :chat_integration_telegram_enabled - CHANNEL_PARAMETERS = {} + CHANNEL_PARAMETERS = [] end end diff --git a/spec/dummy_provider.rb b/spec/dummy_provider.rb index 19b5bc8..7a6c521 100644 --- a/spec/dummy_provider.rb +++ b/spec/dummy_provider.rb @@ -8,7 +8,7 @@ RSpec.shared_context "dummy provider" do module ::DiscourseChat::Provider::DummyProvider PROVIDER_NAME = "dummy".freeze PROVIDER_ENABLED_SETTING = :chat_integration_enabled # Tie to main plugin enabled setting - CHANNEL_PARAMETERS = {} + CHANNEL_PARAMETERS = [] @@sent_messages = [] @@raise_exception = nil @@ -47,7 +47,9 @@ RSpec.shared_context "validated dummy provider" do module ::DiscourseChat::Provider::Dummy2Provider PROVIDER_NAME = "dummy2".freeze PROVIDER_ENABLED_SETTING = :chat_integration_enabled # Tie to main plugin enabled setting - CHANNEL_PARAMETERS = {"val" => '\S+'} + CHANNEL_PARAMETERS = [ + {key: "val", regex: '\S+'} + ] @@sent_messages = []