Rename DiscourseChat to DiscourseChatIntegration (#82)
This commit is contained in:
parent
c0bd802f78
commit
a73f5da114
|
@ -1,14 +1,14 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class DiscourseChat::ChatController < ApplicationController
|
||||
requires_plugin DiscourseChat::PLUGIN_NAME
|
||||
class DiscourseChatIntegration::ChatController < ApplicationController
|
||||
requires_plugin DiscourseChatIntegration::PLUGIN_NAME
|
||||
|
||||
def respond
|
||||
render
|
||||
end
|
||||
|
||||
def list_providers
|
||||
providers = ::DiscourseChat::Provider.enabled_providers.map do |x|
|
||||
providers = ::DiscourseChatIntegration::Provider.enabled_providers.map do |x|
|
||||
{
|
||||
name: x::PROVIDER_NAME,
|
||||
id: x::PROVIDER_NAME,
|
||||
|
@ -24,11 +24,11 @@ class DiscourseChat::ChatController < ApplicationController
|
|||
channel_id = params[:channel_id].to_i
|
||||
topic_id = params[:topic_id].to_i
|
||||
|
||||
channel = DiscourseChat::Channel.find(channel_id)
|
||||
channel = DiscourseChatIntegration::Channel.find(channel_id)
|
||||
|
||||
provider = ::DiscourseChat::Provider.get_by_name(channel.provider)
|
||||
provider = ::DiscourseChatIntegration::Provider.get_by_name(channel.provider)
|
||||
|
||||
if !DiscourseChat::Provider.is_enabled(provider)
|
||||
if !DiscourseChatIntegration::Provider.is_enabled(provider)
|
||||
raise Discourse::NotFound
|
||||
end
|
||||
|
||||
|
@ -39,7 +39,7 @@ class DiscourseChat::ChatController < ApplicationController
|
|||
render json: success_json
|
||||
rescue Discourse::InvalidParameters, ActiveRecord::RecordNotFound => e
|
||||
render json: { errors: [e.message] }, status: 422
|
||||
rescue DiscourseChat::ProviderError => e
|
||||
rescue DiscourseChatIntegration::ProviderError => e
|
||||
Rails.logger.error("Test provider failed #{e.info}")
|
||||
if e.info.key?(:error_key) && !e.info[:error_key].nil?
|
||||
render json: { error_key: e.info[:error_key] }, status: 422
|
||||
|
@ -50,18 +50,18 @@ class DiscourseChat::ChatController < ApplicationController
|
|||
end
|
||||
|
||||
def list_channels
|
||||
providers = ::DiscourseChat::Provider.enabled_provider_names
|
||||
providers = ::DiscourseChatIntegration::Provider.enabled_provider_names
|
||||
requested_provider = params[:provider]
|
||||
|
||||
raise Discourse::InvalidParameters if !providers.include?(requested_provider)
|
||||
|
||||
channels = DiscourseChat::Channel.with_provider(requested_provider)
|
||||
render_serialized channels, DiscourseChat::ChannelSerializer, root: 'channels'
|
||||
channels = DiscourseChatIntegration::Channel.with_provider(requested_provider)
|
||||
render_serialized channels, DiscourseChatIntegration::ChannelSerializer, root: 'channels'
|
||||
end
|
||||
|
||||
def create_channel
|
||||
begin
|
||||
providers = ::DiscourseChat::Provider.enabled_providers.map { |x| x::PROVIDER_NAME }
|
||||
providers = ::DiscourseChatIntegration::Provider.enabled_providers.map { |x| x::PROVIDER_NAME }
|
||||
|
||||
if !defined?(params[:channel]) && defined?(params[:channel][:provider])
|
||||
raise Discourse::InvalidParameters, 'Provider is not valid'
|
||||
|
@ -73,17 +73,17 @@ class DiscourseChat::ChatController < ApplicationController
|
|||
raise Discourse::InvalidParameters, 'Provider is not valid'
|
||||
end
|
||||
|
||||
allowed_keys = DiscourseChat::Provider.get_by_name(requested_provider)::CHANNEL_PARAMETERS.map { |p| p[:key].to_sym }
|
||||
allowed_keys = DiscourseChatIntegration::Provider.get_by_name(requested_provider)::CHANNEL_PARAMETERS.map { |p| p[:key].to_sym }
|
||||
|
||||
hash = params.require(:channel).permit(:provider, data: allowed_keys)
|
||||
|
||||
channel = DiscourseChat::Channel.new(hash)
|
||||
channel = DiscourseChatIntegration::Channel.new(hash)
|
||||
|
||||
if !channel.save
|
||||
raise Discourse::InvalidParameters, 'Channel is not valid'
|
||||
end
|
||||
|
||||
render_serialized channel, DiscourseChat::ChannelSerializer, root: 'channel'
|
||||
render_serialized channel, DiscourseChatIntegration::ChannelSerializer, root: 'channel'
|
||||
rescue Discourse::InvalidParameters => e
|
||||
render json: { errors: [e.message] }, status: 422
|
||||
end
|
||||
|
@ -91,10 +91,10 @@ class DiscourseChat::ChatController < ApplicationController
|
|||
|
||||
def update_channel
|
||||
begin
|
||||
channel = DiscourseChat::Channel.find(params[:id].to_i)
|
||||
channel = DiscourseChatIntegration::Channel.find(params[:id].to_i)
|
||||
channel.error_key = nil # Reset any error on the rule
|
||||
|
||||
allowed_keys = DiscourseChat::Provider.get_by_name(channel.provider)::CHANNEL_PARAMETERS.map { |p| p[:key].to_sym }
|
||||
allowed_keys = DiscourseChatIntegration::Provider.get_by_name(channel.provider)::CHANNEL_PARAMETERS.map { |p| p[:key].to_sym }
|
||||
|
||||
hash = params.require(:channel).permit(data: allowed_keys)
|
||||
|
||||
|
@ -102,14 +102,14 @@ class DiscourseChat::ChatController < ApplicationController
|
|||
raise Discourse::InvalidParameters, 'Channel is not valid'
|
||||
end
|
||||
|
||||
render_serialized channel, DiscourseChat::ChannelSerializer, root: 'channel'
|
||||
render_serialized channel, DiscourseChatIntegration::ChannelSerializer, root: 'channel'
|
||||
rescue Discourse::InvalidParameters => e
|
||||
render json: { errors: [e.message] }, status: 422
|
||||
end
|
||||
end
|
||||
|
||||
def destroy_channel
|
||||
rule = DiscourseChat::Channel.find_by(id: params[:id])
|
||||
rule = DiscourseChatIntegration::Channel.find_by(id: params[:id])
|
||||
raise Discourse::InvalidParameters unless rule
|
||||
rule.destroy!
|
||||
|
||||
|
@ -119,13 +119,13 @@ class DiscourseChat::ChatController < ApplicationController
|
|||
def create_rule
|
||||
begin
|
||||
hash = params.require(:rule).permit(:channel_id, :type, :filter, :group_id, :category_id, tags: [])
|
||||
rule = DiscourseChat::Rule.new(hash)
|
||||
rule = DiscourseChatIntegration::Rule.new(hash)
|
||||
|
||||
if !rule.save
|
||||
raise Discourse::InvalidParameters, 'Rule is not valid'
|
||||
end
|
||||
|
||||
render_serialized rule, DiscourseChat::RuleSerializer, root: 'rule'
|
||||
render_serialized rule, DiscourseChatIntegration::RuleSerializer, root: 'rule'
|
||||
rescue Discourse::InvalidParameters => e
|
||||
render json: { errors: [e.message] }, status: 422
|
||||
end
|
||||
|
@ -133,21 +133,21 @@ class DiscourseChat::ChatController < ApplicationController
|
|||
|
||||
def update_rule
|
||||
begin
|
||||
rule = DiscourseChat::Rule.find(params[:id].to_i)
|
||||
rule = DiscourseChatIntegration::Rule.find(params[:id].to_i)
|
||||
hash = params.require(:rule).permit(:type, :filter, :group_id, :category_id, tags: [])
|
||||
|
||||
if !rule.update(hash)
|
||||
raise Discourse::InvalidParameters, 'Rule is not valid'
|
||||
end
|
||||
|
||||
render_serialized rule, DiscourseChat::RuleSerializer, root: 'rule'
|
||||
render_serialized rule, DiscourseChatIntegration::RuleSerializer, root: 'rule'
|
||||
rescue Discourse::InvalidParameters => e
|
||||
render json: { errors: [e.message] }, status: 422
|
||||
end
|
||||
end
|
||||
|
||||
def destroy_rule
|
||||
rule = DiscourseChat::Rule.find_by(id: params[:id])
|
||||
rule = DiscourseChatIntegration::Rule.find_by(id: params[:id])
|
||||
raise Discourse::InvalidParameters.new unless rule
|
||||
rule.destroy!
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class DiscourseChat::PublicController < ApplicationController
|
||||
requires_plugin DiscourseChat::PLUGIN_NAME
|
||||
class DiscourseChatIntegration::PublicController < ApplicationController
|
||||
requires_plugin DiscourseChatIntegration::PLUGIN_NAME
|
||||
|
||||
def post_transcript
|
||||
params.require(:secret)
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module DiscourseChat
|
||||
module DiscourseChatIntegration
|
||||
module Helper
|
||||
|
||||
def self.process_command(channel, tokens)
|
||||
guardian = DiscourseChat::Manager.guardian
|
||||
guardian = DiscourseChatIntegration::Manager.guardian
|
||||
|
||||
provider = channel.provider
|
||||
|
||||
|
@ -47,7 +47,7 @@ module DiscourseChat
|
|||
end
|
||||
|
||||
category_id = category.nil? ? nil : category.id
|
||||
case DiscourseChat::Helper.smart_create_rule(channel: channel, filter: cmd, category_id: category_id, tags: tags)
|
||||
case DiscourseChatIntegration::Helper.smart_create_rule(channel: channel, filter: cmd, category_id: category_id, tags: tags)
|
||||
when :created
|
||||
I18n.t("chat_integration.provider.#{provider}.create.created")
|
||||
when :updated
|
||||
|
@ -61,13 +61,13 @@ module DiscourseChat
|
|||
rule_number = tokens[0].to_i
|
||||
return error_text unless rule_number.to_s == tokens[0] # Check we were given a number
|
||||
|
||||
if DiscourseChat::Helper.delete_by_index(channel, rule_number)
|
||||
if DiscourseChatIntegration::Helper.delete_by_index(channel, rule_number)
|
||||
I18n.t("chat_integration.provider.#{provider}.delete.success")
|
||||
else
|
||||
I18n.t("chat_integration.provider.#{provider}.delete.error")
|
||||
end
|
||||
when "status"
|
||||
DiscourseChat::Helper.status_for_channel(channel)
|
||||
DiscourseChatIntegration::Helper.status_for_channel(channel)
|
||||
when "help"
|
||||
I18n.t("chat_integration.provider.#{provider}.help")
|
||||
else
|
||||
|
@ -144,7 +144,7 @@ module DiscourseChat
|
|||
# :created if a new rule has been created
|
||||
# false if there was an error
|
||||
def self.smart_create_rule(channel:, filter:, category_id: nil, tags: nil)
|
||||
existing_rules = DiscourseChat::Rule.with_channel(channel).with_type('normal')
|
||||
existing_rules = DiscourseChatIntegration::Rule.with_channel(channel).with_type('normal')
|
||||
|
||||
# Select the ones that have the same category
|
||||
same_category = existing_rules.select { |rule| rule.category_id == category_id }
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module ::DiscourseChat
|
||||
module ::DiscourseChatIntegration
|
||||
PLUGIN_NAME = "discourse-chat-integration".freeze
|
||||
|
||||
class AdminEngine < ::Rails::Engine
|
||||
engine_name "#{DiscourseChat::PLUGIN_NAME}-admin"
|
||||
isolate_namespace DiscourseChat
|
||||
engine_name "#{::DiscourseChatIntegration::PLUGIN_NAME}-admin"
|
||||
isolate_namespace ::DiscourseChatIntegration
|
||||
end
|
||||
|
||||
class PublicEngine < ::Rails::Engine
|
||||
engine_name "#{DiscourseChat::PLUGIN_NAME}-public"
|
||||
isolate_namespace DiscourseChat
|
||||
engine_name "#{::DiscourseChatIntegration::PLUGIN_NAME}-public"
|
||||
isolate_namespace ::DiscourseChatIntegration
|
||||
end
|
||||
|
||||
def self.plugin_name
|
||||
DiscourseChat::PLUGIN_NAME
|
||||
::DiscourseChatIntegration::PLUGIN_NAME
|
||||
end
|
||||
|
||||
def self.pstore_get(key)
|
||||
|
@ -40,7 +40,7 @@ require_relative "../serializers/rule_serializer"
|
|||
require_relative "../controllers/chat_controller"
|
||||
require_relative "../controllers/public_controller"
|
||||
|
||||
require_relative "../routes/discourse_chat"
|
||||
require_relative "../routes/discourse_chat_integration"
|
||||
require_relative "../routes/discourse"
|
||||
|
||||
require_relative "../helpers/helper"
|
||||
|
@ -49,7 +49,7 @@ require_relative "../services/manager"
|
|||
|
||||
require_relative "../jobs/regular/notify_chats"
|
||||
|
||||
require_relative "../../lib/discourse_chat/provider"
|
||||
require_relative "../../lib/discourse_chat_integration/provider"
|
||||
|
||||
require_relative "../jobs/onceoff/add_type_field"
|
||||
require_relative "../jobs/onceoff/migrate_from_slack_official"
|
|
@ -3,7 +3,7 @@
|
|||
module Jobs
|
||||
class DiscourseChatAddTypeField < ::Jobs::Onceoff
|
||||
def execute_onceoff(args)
|
||||
DiscourseChat::Rule.find_each do |rule|
|
||||
DiscourseChatIntegration::Rule.find_each do |rule|
|
||||
rule.save(validate: false)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ module Jobs
|
|||
slack_installed = PluginStoreRow.where(plugin_name: 'discourse-slack-official').exists?
|
||||
|
||||
if slack_installed
|
||||
already_setup_rules = DiscourseChat::Channel.with_provider('slack').exists?
|
||||
already_setup_rules = DiscourseChatIntegration::Channel.with_provider('slack').exists?
|
||||
|
||||
already_setup_sitesettings =
|
||||
SiteSetting.chat_integration_slack_enabled ||
|
||||
|
@ -65,9 +65,9 @@ module Jobs
|
|||
rows.each do |row|
|
||||
# Load an existing channel with this identifier. If none, create it
|
||||
row[:channel] = "##{row[:channel]}" unless row[:channel].start_with?("#")
|
||||
channel = DiscourseChat::Channel.with_provider('slack').with_data_value('identifier', row[:channel]).first
|
||||
channel = DiscourseChatIntegration::Channel.with_provider('slack').with_data_value('identifier', row[:channel]).first
|
||||
if !channel
|
||||
channel = DiscourseChat::Channel.create(provider: 'slack', data: { identifier: row[:channel] })
|
||||
channel = DiscourseChatIntegration::Channel.create(provider: 'slack', data: { identifier: row[:channel] })
|
||||
if !channel.id
|
||||
Rails.logger.warn("Error creating channel for #{row}")
|
||||
next
|
||||
|
@ -75,7 +75,7 @@ module Jobs
|
|||
end
|
||||
|
||||
# Create the rule, with clever logic for avoiding duplicates
|
||||
success = DiscourseChat::Helper.smart_create_rule(channel: channel, filter: row[:filter], category_id: row[:category_id], tags: row[:tags])
|
||||
success = DiscourseChatIntegration::Helper.smart_create_rule(channel: channel, filter: row[:filter], category_id: row[:category_id], tags: row[:tags])
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ module Jobs
|
|||
|
||||
def execute(args)
|
||||
return if !SiteSetting.chat_integration_enabled?
|
||||
::DiscourseChat::Manager.trigger_notifications(args[:post_id])
|
||||
::DiscourseChatIntegration::Manager.trigger_notifications(args[:post_id])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class DiscourseChat::Channel < DiscourseChat::PluginModel
|
||||
class DiscourseChatIntegration::Channel < DiscourseChatIntegration::PluginModel
|
||||
# Setup ActiveRecord::Store to use the JSON field to read/write these values
|
||||
store :value, accessors: [ :provider, :error_key, :error_info, :data ], coder: JSON
|
||||
|
||||
|
@ -17,7 +17,7 @@ class DiscourseChat::Channel < DiscourseChat::PluginModel
|
|||
end
|
||||
|
||||
def rules
|
||||
DiscourseChat::Rule.with_channel_id(id).order_by_precedence
|
||||
DiscourseChatIntegration::Rule.with_channel_id(id).order_by_precedence
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -31,16 +31,16 @@ class DiscourseChat::Channel < DiscourseChat::PluginModel
|
|||
end
|
||||
|
||||
def provider_valid?
|
||||
if !DiscourseChat::Provider.provider_names.include?(provider)
|
||||
if !DiscourseChatIntegration::Provider.provider_names.include?(provider)
|
||||
errors.add(:provider, "#{provider} is not a valid provider")
|
||||
end
|
||||
end
|
||||
|
||||
def data_valid?
|
||||
# If provider is invalid, don't try and check data
|
||||
return unless ::DiscourseChat::Provider.provider_names.include? provider
|
||||
return unless ::DiscourseChatIntegration::Provider.provider_names.include? provider
|
||||
|
||||
params = ::DiscourseChat::Provider.get_by_name(provider)::CHANNEL_PARAMETERS
|
||||
params = ::DiscourseChatIntegration::Provider.get_by_name(provider)::CHANNEL_PARAMETERS
|
||||
|
||||
unless params.map { |p| p[:key] }.sort == data.keys.sort
|
||||
errors.add(:data, "data does not match the required structure for provider #{provider}")
|
||||
|
@ -48,7 +48,7 @@ class DiscourseChat::Channel < DiscourseChat::PluginModel
|
|||
end
|
||||
|
||||
check_unique = false
|
||||
matching_channels = DiscourseChat::Channel.with_provider(provider).where.not(id: id)
|
||||
matching_channels = DiscourseChatIntegration::Channel.with_provider(provider).where.not(id: id)
|
||||
|
||||
data.each do |key, value|
|
||||
regex_string = params.find { |p| p[:key] == key }[:regex]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class DiscourseChat::PluginModel < PluginStoreRow
|
||||
class DiscourseChatIntegration::PluginModel < PluginStoreRow
|
||||
PLUGIN_NAME = 'discourse-chat-integration'
|
||||
|
||||
default_scope { self.default_scope }
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class DiscourseChat::Rule < DiscourseChat::PluginModel
|
||||
class DiscourseChatIntegration::Rule < DiscourseChatIntegration::PluginModel
|
||||
# Setup ActiveRecord::Store to use the JSON field to read/write these values
|
||||
store :value, accessors: [ :channel_id, :type, :group_id, :category_id, :tags, :filter ], coder: JSON
|
||||
|
||||
|
@ -75,7 +75,7 @@ class DiscourseChat::Rule < DiscourseChat::PluginModel
|
|||
# Mock foreign key
|
||||
# Could return nil
|
||||
def channel
|
||||
DiscourseChat::Channel.find_by(id: channel_id)
|
||||
DiscourseChatIntegration::Channel.find_by(id: channel_id)
|
||||
end
|
||||
|
||||
def channel=(val)
|
||||
|
@ -85,7 +85,7 @@ class DiscourseChat::Rule < DiscourseChat::PluginModel
|
|||
private
|
||||
|
||||
def channel_valid?
|
||||
if !(DiscourseChat::Channel.where(id: channel_id).exists?)
|
||||
if !(DiscourseChatIntegration::Channel.where(id: channel_id).exists?)
|
||||
errors.add(:channel_id, "#{channel_id} is not a valid channel id")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
Discourse::Application.routes.append do
|
||||
mount ::DiscourseChat::AdminEngine, at: '/admin/plugins/chat', constraints: AdminConstraint.new
|
||||
mount ::DiscourseChat::PublicEngine, at: '/chat-transcript/', as: 'chat-transcript'
|
||||
mount ::DiscourseChat::Provider::HookEngine, at: '/chat-integration/'
|
||||
mount ::DiscourseChatIntegration::AdminEngine, at: '/admin/plugins/chat', constraints: AdminConstraint.new
|
||||
mount ::DiscourseChatIntegration::PublicEngine, at: '/chat-transcript/', as: 'chat-transcript'
|
||||
mount ::DiscourseChatIntegration::Provider::HookEngine, at: '/chat-integration/'
|
||||
|
||||
# For backwards compatibility with Slack plugin
|
||||
post "/slack/command" => "discourse_chat/provider/slack_provider/slack_command#command"
|
||||
post "/slack/command" => "discourse_chat_integration/provider/slack_provider/slack_command#command"
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require_dependency 'admin_constraint'
|
||||
|
||||
module DiscourseChat
|
||||
module ::DiscourseChatIntegration
|
||||
AdminEngine.routes.draw do
|
||||
get "" => "chat#respond"
|
||||
get '/providers' => "chat#list_providers"
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
require_relative './rule_serializer'
|
||||
|
||||
class DiscourseChat::ChannelSerializer < ApplicationSerializer
|
||||
class DiscourseChatIntegration::ChannelSerializer < ApplicationSerializer
|
||||
attributes :id, :provider, :error_key, :error_info, :data, :rules
|
||||
|
||||
def rules
|
||||
object.rules.order_by_precedence.map do |rule|
|
||||
DiscourseChat::RuleSerializer.new(rule, root: false)
|
||||
DiscourseChatIntegration::RuleSerializer.new(rule, root: false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class DiscourseChat::RuleSerializer < ApplicationSerializer
|
||||
class DiscourseChatIntegration::RuleSerializer < ApplicationSerializer
|
||||
attributes :id, :channel_id, :type, :group_id, :group_name, :category_id, :tags, :filter
|
||||
|
||||
def group_name
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module DiscourseChat
|
||||
module DiscourseChatIntegration
|
||||
module Manager
|
||||
|
||||
def self.guardian
|
||||
|
@ -23,11 +23,11 @@ module DiscourseChat
|
|||
if topic.archetype == Archetype.private_message
|
||||
group_ids_with_access = topic.topic_allowed_groups.pluck(:group_id)
|
||||
return if group_ids_with_access.empty?
|
||||
matching_rules = DiscourseChat::Rule.with_type('group_message').with_group_ids(group_ids_with_access)
|
||||
matching_rules = DiscourseChatIntegration::Rule.with_type('group_message').with_group_ids(group_ids_with_access)
|
||||
else
|
||||
matching_rules = DiscourseChat::Rule.with_type('normal').with_category_id(topic.category_id)
|
||||
matching_rules = DiscourseChatIntegration::Rule.with_type('normal').with_category_id(topic.category_id)
|
||||
if topic.category # Also load the rules for the wildcard category
|
||||
matching_rules += DiscourseChat::Rule.with_type('normal').with_category_id(nil)
|
||||
matching_rules += DiscourseChatIntegration::Rule.with_type('normal').with_category_id(nil)
|
||||
end
|
||||
|
||||
# If groups are mentioned, check for any matching rules and append them
|
||||
|
@ -35,7 +35,7 @@ module DiscourseChat
|
|||
if mentions && mentions.length > 0
|
||||
groups = Group.where('LOWER(name) IN (?)', mentions)
|
||||
if groups.exists?
|
||||
matching_rules += DiscourseChat::Rule.with_type('group_mention').with_group_ids(groups.map(&:id))
|
||||
matching_rules += DiscourseChatIntegration::Rule.with_type('group_mention').with_group_ids(groups.map(&:id))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -76,14 +76,14 @@ module DiscourseChat
|
|||
matching_rules.each do |rule|
|
||||
# If there are any issues, skip to the next rule
|
||||
next unless channel = rule.channel
|
||||
next unless provider = ::DiscourseChat::Provider.get_by_name(channel.provider)
|
||||
next unless is_enabled = ::DiscourseChat::Provider.is_enabled(provider)
|
||||
next unless provider = ::DiscourseChatIntegration::Provider.get_by_name(channel.provider)
|
||||
next unless is_enabled = ::DiscourseChatIntegration::Provider.is_enabled(provider)
|
||||
|
||||
begin
|
||||
provider.trigger_notification(post, channel, rule)
|
||||
channel.update_attribute('error_key', nil) if channel.error_key
|
||||
rescue => e
|
||||
if e.class == (DiscourseChat::ProviderError) && e.info.key?(:error_key) && !e.info[:error_key].nil?
|
||||
if e.class == (DiscourseChatIntegration::ProviderError) && e.info.key?(:error_key) && !e.info[:error_key].nil?
|
||||
channel.update_attribute('error_key', e.info[:error_key])
|
||||
else
|
||||
channel.update_attribute('error_key', 'chat_integration.channel_exception')
|
||||
|
@ -96,7 +96,7 @@ module DiscourseChat
|
|||
# extra: { provider_name: provider::PROVIDER_NAME,
|
||||
# channel: rule.channel,
|
||||
# post_id: post.id,
|
||||
# error_info: e.class == DiscourseChat::ProviderError ? e.info : nil }
|
||||
# error_info: e.class == DiscourseChatIntegration::ProviderError ? e.info : nil }
|
||||
# )
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module DiscourseChat
|
||||
module DiscourseChatIntegration
|
||||
class ProviderError < StandardError
|
||||
attr_accessor :info
|
||||
|
||||
|
@ -44,12 +44,12 @@ module DiscourseChat
|
|||
end
|
||||
|
||||
class HookEngine < ::Rails::Engine
|
||||
engine_name DiscourseChat::PLUGIN_NAME + "-hooks"
|
||||
isolate_namespace DiscourseChat::Provider
|
||||
engine_name DiscourseChatIntegration::PLUGIN_NAME + "-hooks"
|
||||
isolate_namespace DiscourseChatIntegration::Provider
|
||||
end
|
||||
|
||||
class HookController < ::ApplicationController
|
||||
requires_plugin DiscourseChat::PLUGIN_NAME
|
||||
requires_plugin DiscourseChatIntegration::PLUGIN_NAME
|
||||
|
||||
class ProviderDisabled < StandardError; end
|
||||
|
||||
|
@ -71,7 +71,7 @@ module DiscourseChat
|
|||
# Automatically mount each provider's engine inside the HookEngine
|
||||
def self.mount_engines
|
||||
engines = []
|
||||
DiscourseChat::Provider.providers.each do |provider|
|
||||
DiscourseChatIntegration::Provider.providers.each do |provider|
|
||||
engine = provider.constants.select do |constant|
|
||||
constant.to_s =~ (/Engine$/) && (constant.to_s != "HookEngine")
|
||||
end.map(&provider.method(:const_get)).first
|
||||
|
@ -81,7 +81,7 @@ module DiscourseChat
|
|||
end
|
||||
end
|
||||
|
||||
DiscourseChat::Provider::HookEngine.routes.draw do
|
||||
DiscourseChatIntegration::Provider::HookEngine.routes.draw do
|
||||
engines.each do |engine|
|
||||
mount engine[:engine], at: engine[:name]
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module DiscourseChat
|
||||
module DiscourseChatIntegration
|
||||
module Provider
|
||||
module DiscordProvider
|
||||
PROVIDER_NAME = "discord".freeze
|
||||
|
@ -70,7 +70,7 @@ module DiscourseChat
|
|||
response = send_message(webhook_url, message)
|
||||
|
||||
if !response.kind_of?(Net::HTTPSuccess)
|
||||
raise ::DiscourseChat::ProviderError.new(info: {
|
||||
raise ::DiscourseChatIntegration::ProviderError.new(info: {
|
||||
error_key: nil, message: message, response_body: response.body
|
||||
})
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module DiscourseChat::Provider::FlowdockProvider
|
||||
module DiscourseChatIntegration::Provider::FlowdockProvider
|
||||
|
||||
PROVIDER_NAME = "flowdock".freeze
|
||||
PROVIDER_ENABLED_SETTING = :chat_integration_flowdock_enabled
|
||||
|
@ -55,7 +55,7 @@ module DiscourseChat::Provider::FlowdockProvider
|
|||
|
||||
unless response.kind_of?(Net::HTTPSuccess)
|
||||
error_key = nil
|
||||
raise ::DiscourseChat::ProviderError.new info: { error_key: error_key, message: message, response_body: response.body }
|
||||
raise ::DiscourseChatIntegration::ProviderError.new info: { error_key: error_key, message: message, response_body: response.body }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module DiscourseChat
|
||||
module DiscourseChatIntegration
|
||||
module Provider
|
||||
module GitterProvider
|
||||
PROVIDER_NAME = 'gitter'.freeze
|
||||
|
@ -15,7 +15,7 @@ module DiscourseChat
|
|||
response = Net::HTTP.post_form(URI(channel.data['webhook_url']), message: message)
|
||||
unless response.kind_of? Net::HTTPSuccess
|
||||
error_key = nil
|
||||
raise ::DiscourseChat::ProviderError.new info: { error_key: error_key, message: message, response_body: response.body }
|
||||
raise ::DiscourseChatIntegration::ProviderError.new info: { error_key: error_key, message: message, response_body: response.body }
|
||||
end
|
||||
end
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module DiscourseChat
|
||||
module DiscourseChatIntegration
|
||||
module Provider
|
||||
module GoogleProvider
|
||||
PROVIDER_NAME = 'google'.freeze
|
||||
|
@ -22,7 +22,7 @@ module DiscourseChat
|
|||
response = http.request(req)
|
||||
|
||||
unless response.kind_of? Net::HTTPSuccess
|
||||
raise ::DiscourseChat::ProviderError.new info: { request: req.body, response_code: response.code, response_body: response.body }
|
||||
raise ::DiscourseChatIntegration::ProviderError.new info: { request: req.body, response_code: response.code, response_body: response.body }
|
||||
end
|
||||
end
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
module DiscourseChat::Provider::GroupmeProvider
|
||||
module DiscourseChatIntegration::Provider::GroupmeProvider
|
||||
PROVIDER_NAME = "groupme".freeze
|
||||
PROVIDER_ENABLED_SETTING = :chat_integration_groupme_enabled
|
||||
CHANNEL_PARAMETERS = [
|
||||
|
@ -69,7 +69,7 @@ module DiscourseChat::Provider::GroupmeProvider
|
|||
if last_error_raised
|
||||
successfully_sent = instance_names.length() - num_errors
|
||||
last_error_raised[:success_rate] = "#{successfully_sent}/#{instance_names.length()}"
|
||||
raise ::DiscourseChat::ProviderError.new info: last_error_raised
|
||||
raise ::DiscourseChatIntegration::ProviderError.new info: last_error_raised
|
||||
end
|
||||
end
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module DiscourseChat
|
||||
module DiscourseChatIntegration
|
||||
module Provider
|
||||
module MatrixProvider
|
||||
PROVIDER_NAME = "matrix".freeze
|
||||
|
@ -71,7 +71,7 @@ module DiscourseChat
|
|||
error_key = 'chat_integration.provider.matrix.errors.unknown_room'
|
||||
end
|
||||
ensure
|
||||
raise ::DiscourseChat::ProviderError.new info: { error_key: error_key, message: message, response_body: response.body }
|
||||
raise ::DiscourseChatIntegration::ProviderError.new info: { error_key: error_key, message: message, response_body: response.body }
|
||||
end
|
||||
end
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module DiscourseChat::Provider::MattermostProvider
|
||||
class MattermostCommandController < DiscourseChat::Provider::HookController
|
||||
requires_provider ::DiscourseChat::Provider::MattermostProvider::PROVIDER_NAME
|
||||
module DiscourseChatIntegration::Provider::MattermostProvider
|
||||
class MattermostCommandController < DiscourseChatIntegration::Provider::HookController
|
||||
requires_provider ::DiscourseChatIntegration::Provider::MattermostProvider::PROVIDER_NAME
|
||||
|
||||
before_action :mattermost_token_valid?, only: :command
|
||||
|
||||
|
@ -36,14 +36,14 @@ module DiscourseChat::Provider::MattermostProvider
|
|||
"##{params[:channel_name]}"
|
||||
end
|
||||
|
||||
provider = DiscourseChat::Provider::MattermostProvider::PROVIDER_NAME
|
||||
provider = DiscourseChatIntegration::Provider::MattermostProvider::PROVIDER_NAME
|
||||
|
||||
channel = DiscourseChat::Channel.with_provider(provider).with_data_value('identifier', channel_id).first
|
||||
channel = DiscourseChatIntegration::Channel.with_provider(provider).with_data_value('identifier', channel_id).first
|
||||
|
||||
# Create channel if doesn't exist
|
||||
channel ||= DiscourseChat::Channel.create!(provider: provider, data: { identifier: channel_id })
|
||||
channel ||= DiscourseChatIntegration::Channel.create!(provider: provider, data: { identifier: channel_id })
|
||||
|
||||
::DiscourseChat::Helper.process_command(channel, tokens)
|
||||
::DiscourseChatIntegration::Helper.process_command(channel, tokens)
|
||||
|
||||
end
|
||||
|
||||
|
@ -59,8 +59,8 @@ module DiscourseChat::Provider::MattermostProvider
|
|||
end
|
||||
|
||||
class MattermostEngine < ::Rails::Engine
|
||||
engine_name DiscourseChat::PLUGIN_NAME + "-mattermost"
|
||||
isolate_namespace DiscourseChat::Provider::MattermostProvider
|
||||
engine_name DiscourseChatIntegration::PLUGIN_NAME + "-mattermost"
|
||||
isolate_namespace DiscourseChatIntegration::Provider::MattermostProvider
|
||||
end
|
||||
|
||||
MattermostEngine.routes.draw do
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module DiscourseChat
|
||||
module DiscourseChatIntegration
|
||||
module Provider
|
||||
module MattermostProvider
|
||||
PROVIDER_NAME = "mattermost".freeze
|
||||
|
@ -25,7 +25,7 @@ module DiscourseChat
|
|||
else
|
||||
error_key = nil
|
||||
end
|
||||
raise ::DiscourseChat::ProviderError.new info: { error_key: error_key, request: req.body, response_code: response.code, response_body: response.body }
|
||||
raise ::DiscourseChatIntegration::ProviderError.new info: { error_key: error_key, request: req.body, response_code: response.code, response_body: response.body }
|
||||
end
|
||||
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module DiscourseChat::Provider::RocketchatProvider
|
||||
module DiscourseChatIntegration::Provider::RocketchatProvider
|
||||
PROVIDER_NAME = "rocketchat".freeze
|
||||
|
||||
PROVIDER_ENABLED_SETTING = :chat_integration_rocketchat_enabled
|
||||
|
@ -63,7 +63,7 @@ module DiscourseChat::Provider::RocketchatProvider
|
|||
else
|
||||
error_key = nil
|
||||
end
|
||||
raise ::DiscourseChat::ProviderError.new info: { error_key: error_key, request: req.body, response_code: response.code, response_body: response.body }
|
||||
raise ::DiscourseChatIntegration::ProviderError.new info: { error_key: error_key, request: req.body, response_code: response.code, response_body: response.body }
|
||||
end
|
||||
|
||||
end
|
|
@ -1,8 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module DiscourseChat::Provider::SlackProvider
|
||||
class SlackCommandController < DiscourseChat::Provider::HookController
|
||||
requires_provider ::DiscourseChat::Provider::SlackProvider::PROVIDER_NAME
|
||||
module DiscourseChatIntegration::Provider::SlackProvider
|
||||
class SlackCommandController < DiscourseChatIntegration::Provider::HookController
|
||||
requires_provider ::DiscourseChatIntegration::Provider::SlackProvider::PROVIDER_NAME
|
||||
|
||||
before_action :slack_token_valid?, only: :command
|
||||
before_action :slack_payload_token_valid?, only: :interactive
|
||||
|
@ -42,13 +42,13 @@ module DiscourseChat::Provider::SlackProvider
|
|||
"##{params[:channel_name]}"
|
||||
end
|
||||
|
||||
provider = DiscourseChat::Provider::SlackProvider::PROVIDER_NAME
|
||||
provider = DiscourseChatIntegration::Provider::SlackProvider::PROVIDER_NAME
|
||||
|
||||
channel = DiscourseChat::Channel.with_provider(provider)
|
||||
channel = DiscourseChatIntegration::Channel.with_provider(provider)
|
||||
.with_data_value('identifier', channel_id)
|
||||
.first
|
||||
|
||||
channel ||= DiscourseChat::Channel.create!(
|
||||
channel ||= DiscourseChatIntegration::Channel.create!(
|
||||
provider: provider,
|
||||
data: { identifier: channel_id }
|
||||
)
|
||||
|
@ -56,7 +56,7 @@ module DiscourseChat::Provider::SlackProvider
|
|||
if tokens[0] == 'post'
|
||||
process_post_request(channel, tokens, params[:channel_id], channel_id, params[:response_url])
|
||||
else
|
||||
{ text: ::DiscourseChat::Helper.process_command(channel, tokens) }
|
||||
{ text: ::DiscourseChatIntegration::Helper.process_command(channel, tokens) }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -67,7 +67,7 @@ module DiscourseChat::Provider::SlackProvider
|
|||
|
||||
Scheduler::Defer.later "Processing slack transcript request" do
|
||||
response = build_post_request_response(channel, tokens, slack_channel_id, channel_name, response_url)
|
||||
http = DiscourseChat::Provider::SlackProvider.slack_api_http
|
||||
http = DiscourseChatIntegration::Provider::SlackProvider.slack_api_http
|
||||
req = Net::HTTP::Post.new(URI(response_url), 'Content-Type' => 'application/json')
|
||||
req.body = response.to_json
|
||||
http.request(req)
|
||||
|
@ -117,7 +117,7 @@ module DiscourseChat::Provider::SlackProvider
|
|||
|
||||
def process_interactive(json)
|
||||
Scheduler::Defer.later "Processing slack transcript update" do
|
||||
http = DiscourseChat::Provider::SlackProvider.slack_api_http
|
||||
http = DiscourseChatIntegration::Provider::SlackProvider.slack_api_http
|
||||
|
||||
if json[:type] == "block_actions" && json[:actions][0][:action_id] == "null_action"
|
||||
# Do nothing
|
||||
|
@ -248,8 +248,8 @@ module DiscourseChat::Provider::SlackProvider
|
|||
end
|
||||
|
||||
class SlackEngine < ::Rails::Engine
|
||||
engine_name DiscourseChat::PLUGIN_NAME + "-slack"
|
||||
isolate_namespace DiscourseChat::Provider::SlackProvider
|
||||
engine_name DiscourseChatIntegration::PLUGIN_NAME + "-slack"
|
||||
isolate_namespace DiscourseChatIntegration::Provider::SlackProvider
|
||||
end
|
||||
|
||||
SlackEngine.routes.draw do
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module DiscourseChat::Provider::SlackProvider
|
||||
module DiscourseChatIntegration::Provider::SlackProvider
|
||||
class SlackMessage
|
||||
def initialize(raw_message, transcript)
|
||||
@raw = raw_message
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module DiscourseChat::Provider::SlackProvider
|
||||
module DiscourseChatIntegration::Provider::SlackProvider
|
||||
class SlackMessageFormatter < Nokogiri::XML::SAX::Document
|
||||
attr_reader :excerpt
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module DiscourseChat::Provider::SlackProvider
|
||||
module DiscourseChatIntegration::Provider::SlackProvider
|
||||
PROVIDER_NAME = "slack".freeze
|
||||
THREAD = "thread".freeze
|
||||
|
||||
|
@ -11,14 +11,14 @@ module DiscourseChat::Provider::SlackProvider
|
|||
]
|
||||
|
||||
require_dependency 'topic'
|
||||
::Topic.register_custom_field_type(DiscourseChat::Provider::SlackProvider::THREAD, :text)
|
||||
::Topic.register_custom_field_type(DiscourseChatIntegration::Provider::SlackProvider::THREAD, :text)
|
||||
|
||||
class ::Topic
|
||||
def slack_thread_id=(ts)
|
||||
self.custom_fields[DiscourseChat::Provider::SlackProvider::THREAD] = ts
|
||||
self.custom_fields[DiscourseChatIntegration::Provider::SlackProvider::THREAD] = ts
|
||||
end
|
||||
def slack_thread_id
|
||||
self.custom_fields[DiscourseChat::Provider::SlackProvider::THREAD]
|
||||
self.custom_fields[DiscourseChatIntegration::Provider::SlackProvider::THREAD]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -121,7 +121,7 @@ module DiscourseChat::Provider::SlackProvider
|
|||
response = http.request(req)
|
||||
|
||||
unless response.kind_of? Net::HTTPSuccess
|
||||
raise ::DiscourseChat::ProviderError.new info: { request: uri, response_code: response.code, response_body: response.body }
|
||||
raise ::DiscourseChatIntegration::ProviderError.new info: { request: uri, response_code: response.code, response_body: response.body }
|
||||
end
|
||||
|
||||
json = JSON.parse(response.body)
|
||||
|
@ -132,7 +132,7 @@ module DiscourseChat::Provider::SlackProvider
|
|||
else
|
||||
error_key = nil
|
||||
end
|
||||
raise ::DiscourseChat::ProviderError.new info: { error_key: error_key, request: uri, response_code: response.code, response_body: response.body }
|
||||
raise ::DiscourseChatIntegration::ProviderError.new info: { error_key: error_key, request: uri, response_code: response.code, response_body: response.body }
|
||||
end
|
||||
|
||||
ts = json["ts"]
|
||||
|
@ -159,7 +159,7 @@ module DiscourseChat::Provider::SlackProvider
|
|||
else
|
||||
error_key = nil
|
||||
end
|
||||
raise ::DiscourseChat::ProviderError.new info: { error_key: error_key, request: req.body, response_code: response.code, response_body: response.body }
|
||||
raise ::DiscourseChatIntegration::ProviderError.new info: { error_key: error_key, request: req.body, response_code: response.code, response_body: response.body }
|
||||
end
|
||||
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module DiscourseChat::Provider::SlackProvider
|
||||
module DiscourseChatIntegration::Provider::SlackProvider
|
||||
class SlackTranscript
|
||||
attr_reader :users, :channel_id, :messages
|
||||
|
||||
|
@ -145,7 +145,7 @@ module DiscourseChat::Provider::SlackProvider
|
|||
|
||||
if @messages
|
||||
post_content = build_transcript
|
||||
secret = DiscourseChat::Helper.save_transcript(post_content)
|
||||
secret = DiscourseChatIntegration::Helper.save_transcript(post_content)
|
||||
link = "#{Discourse.base_url}/chat-transcript/#{secret}"
|
||||
|
||||
data[:blocks] << {
|
||||
|
@ -181,7 +181,7 @@ module DiscourseChat::Provider::SlackProvider
|
|||
|
||||
def build_slack_ui
|
||||
post_content = build_transcript
|
||||
secret = DiscourseChat::Helper.save_transcript(post_content)
|
||||
secret = DiscourseChatIntegration::Helper.save_transcript(post_content)
|
||||
link = "#{Discourse.base_url}/chat-transcript/#{secret}"
|
||||
|
||||
return { text: "<#{link}|#{I18n.t("chat_integration.provider.slack.transcript.post_to_discourse")}>" } if @requested_thread_ts
|
||||
|
@ -250,7 +250,7 @@ module DiscourseChat::Provider::SlackProvider
|
|||
end
|
||||
|
||||
def load_user_data
|
||||
http = ::DiscourseChat::Provider::SlackProvider.slack_api_http
|
||||
http = ::DiscourseChatIntegration::Provider::SlackProvider.slack_api_http
|
||||
|
||||
cursor = nil
|
||||
req = Net::HTTP::Post.new(URI('https://slack.com/api/users.list'))
|
||||
|
@ -279,7 +279,7 @@ module DiscourseChat::Provider::SlackProvider
|
|||
end
|
||||
|
||||
def load_chat_history(count: 500)
|
||||
http = DiscourseChat::Provider::SlackProvider.slack_api_http
|
||||
http = DiscourseChatIntegration::Provider::SlackProvider.slack_api_http
|
||||
|
||||
endpoint = @requested_thread_ts ? "replies" : "history"
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module DiscourseChat::Provider::TeamsProvider
|
||||
module DiscourseChatIntegration::Provider::TeamsProvider
|
||||
PROVIDER_NAME = "teams".freeze
|
||||
PROVIDER_ENABLED_SETTING = :chat_integration_teams_enabled
|
||||
CHANNEL_PARAMETERS = [
|
||||
|
@ -25,7 +25,7 @@ module DiscourseChat::Provider::TeamsProvider
|
|||
else
|
||||
error_key = nil
|
||||
end
|
||||
raise ::DiscourseChat::ProviderError.new info: { error_key: error_key, request: req.body, response_code: response.code, response_body: response.body }
|
||||
raise ::DiscourseChatIntegration::ProviderError.new info: { error_key: error_key, request: req.body, response_code: response.code, response_body: response.body }
|
||||
end
|
||||
|
||||
end
|
|
@ -1,8 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module DiscourseChat::Provider::TelegramProvider
|
||||
class TelegramCommandController < DiscourseChat::Provider::HookController
|
||||
requires_provider ::DiscourseChat::Provider::TelegramProvider::PROVIDER_NAME
|
||||
module DiscourseChatIntegration::Provider::TelegramProvider
|
||||
class TelegramCommandController < DiscourseChatIntegration::Provider::HookController
|
||||
requires_provider ::DiscourseChatIntegration::Provider::TelegramProvider::PROVIDER_NAME
|
||||
|
||||
before_action :telegram_token_valid?, only: :command
|
||||
|
||||
|
@ -27,7 +27,7 @@ module DiscourseChat::Provider::TelegramProvider
|
|||
disable_web_page_preview: true,
|
||||
}
|
||||
|
||||
DiscourseChat::Provider::TelegramProvider.sendMessage(message)
|
||||
DiscourseChatIntegration::Provider::TelegramProvider.sendMessage(message)
|
||||
|
||||
elsif params.dig('channel_post', 'text')&.include?('/getchatid')
|
||||
chat_id = params['channel_post']['chat']['id']
|
||||
|
@ -45,7 +45,7 @@ module DiscourseChat::Provider::TelegramProvider
|
|||
disable_web_page_preview: true,
|
||||
}
|
||||
|
||||
DiscourseChat::Provider::TelegramProvider.sendMessage(message)
|
||||
DiscourseChatIntegration::Provider::TelegramProvider.sendMessage(message)
|
||||
end
|
||||
|
||||
# Always give telegram a success message, otherwise we'll stop receiving webhooks
|
||||
|
@ -58,9 +58,9 @@ module DiscourseChat::Provider::TelegramProvider
|
|||
def process_command(message)
|
||||
chat_id = params['message']['chat']['id']
|
||||
|
||||
provider = DiscourseChat::Provider::TelegramProvider::PROVIDER_NAME
|
||||
provider = DiscourseChatIntegration::Provider::TelegramProvider::PROVIDER_NAME
|
||||
|
||||
channel = DiscourseChat::Channel.with_provider(provider).with_data_value('chat_id', chat_id).first
|
||||
channel = DiscourseChatIntegration::Channel.with_provider(provider).with_data_value('chat_id', chat_id).first
|
||||
|
||||
text_key = "unknown_chat" if channel.nil?
|
||||
# If slash commands disabled, send a generic message
|
||||
|
@ -80,7 +80,7 @@ module DiscourseChat::Provider::TelegramProvider
|
|||
tokens[0][0] = '' # Remove the slash from the first token
|
||||
tokens[0] = tokens[0].split('@')[0] # Remove the bot name from the command (necessary for group chats)
|
||||
|
||||
::DiscourseChat::Helper.process_command(channel, tokens)
|
||||
::DiscourseChatIntegration::Helper.process_command(channel, tokens)
|
||||
end
|
||||
|
||||
def telegram_token_valid?
|
||||
|
@ -95,8 +95,8 @@ module DiscourseChat::Provider::TelegramProvider
|
|||
end
|
||||
|
||||
class TelegramEngine < ::Rails::Engine
|
||||
engine_name DiscourseChat::PLUGIN_NAME + "-telegram"
|
||||
isolate_namespace DiscourseChat::Provider::TelegramProvider
|
||||
engine_name DiscourseChatIntegration::PLUGIN_NAME + "-telegram"
|
||||
isolate_namespace DiscourseChatIntegration::Provider::TelegramProvider
|
||||
end
|
||||
|
||||
TelegramEngine.routes.draw do
|
|
@ -9,7 +9,7 @@ DiscourseEvent.on(:site_setting_changed) do |setting_name, old_value, new_value|
|
|||
|
||||
if enabled && SiteSetting.chat_integration_telegram_access_token.present?
|
||||
Scheduler::Defer.later("Setup Telegram Webhook") do
|
||||
DiscourseChat::Provider::TelegramProvider.setup_webhook
|
||||
DiscourseChatIntegration::Provider::TelegramProvider.setup_webhook
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module DiscourseChat
|
||||
module DiscourseChatIntegration
|
||||
module Provider
|
||||
module TelegramProvider
|
||||
PROVIDER_NAME = "telegram".freeze
|
||||
|
@ -98,7 +98,7 @@ module DiscourseChat
|
|||
elsif response['description'].include? 'Forbidden'
|
||||
error_key = 'chat_integration.provider.telegram.errors.forbidden'
|
||||
end
|
||||
raise ::DiscourseChat::ProviderError.new info: { error_key: error_key, message: message, response_body: response }
|
||||
raise ::DiscourseChatIntegration::ProviderError.new info: { error_key: error_key, message: message, response_body: response }
|
||||
end
|
||||
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module DiscourseChat::Provider::WebexProvider
|
||||
module DiscourseChatIntegration::Provider::WebexProvider
|
||||
PROVIDER_NAME = "webex".freeze
|
||||
PROVIDER_ENABLED_SETTING = :chat_integration_webex_enabled
|
||||
CHANNEL_PARAMETERS = [
|
||||
|
@ -28,10 +28,10 @@ module DiscourseChat::Provider::WebexProvider
|
|||
else
|
||||
error_key = nil
|
||||
end
|
||||
raise ::DiscourseChat::ProviderError.new info: { error_key: error_key,
|
||||
request: req.body,
|
||||
response_code: response.code,
|
||||
response_body: response.body }
|
||||
raise ::DiscourseChatIntegration::ProviderError.new info: { error_key: error_key,
|
||||
request: req.body,
|
||||
response_code: response.code,
|
||||
response_body: response.body }
|
||||
end
|
||||
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module DiscourseChat
|
||||
module DiscourseChatIntegration
|
||||
module Provider
|
||||
module ZulipProvider
|
||||
PROVIDER_NAME = "zulip".freeze
|
||||
|
@ -58,7 +58,7 @@ module DiscourseChat
|
|||
if !response.kind_of?(Net::HTTPSuccess)
|
||||
error_key = nil
|
||||
error_key = 'chat_integration.provider.zulip.errors.does_not_exist' if response.body.include?('does not exist')
|
||||
raise ::DiscourseChat::ProviderError.new info: { error_key: error_key, message: message, response_code: response.code, response_body: response.body }
|
||||
raise ::DiscourseChatIntegration::ProviderError.new info: { error_key: error_key, message: message, response_code: response.code, response_body: response.body }
|
||||
end
|
||||
|
||||
end
|
|
@ -14,10 +14,10 @@ register_svg_icon "rocket" if respond_to?(:register_svg_icon)
|
|||
register_svg_icon "fa-arrow-circle-o-right" if respond_to?(:register_svg_icon)
|
||||
|
||||
# Site setting validators must be loaded before initialize
|
||||
require_relative "lib/discourse_chat/provider/slack/slack_enabled_setting_validator"
|
||||
require_relative "lib/discourse_chat_integration/provider/slack/slack_enabled_setting_validator"
|
||||
|
||||
after_initialize do
|
||||
require_relative "app/initializers/discourse_chat"
|
||||
require_relative "app/initializers/discourse_chat_integration"
|
||||
|
||||
on(:post_created) do |post|
|
||||
# This will run for every post, even PMs. Don't worry, they're filtered out later.
|
||||
|
@ -29,7 +29,7 @@ after_initialize do
|
|||
|
||||
AdminDashboardData.add_problem_check do
|
||||
error = false
|
||||
DiscourseChat::Channel.find_each do |channel|
|
||||
DiscourseChatIntegration::Channel.find_each do |channel|
|
||||
error = true unless channel.error_key.blank?
|
||||
end
|
||||
|
||||
|
@ -39,5 +39,5 @@ after_initialize do
|
|||
end
|
||||
end
|
||||
|
||||
DiscourseChat::Provider.mount_engines
|
||||
DiscourseChatIntegration::Provider.mount_engines
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
RSpec.shared_context "dummy provider" do
|
||||
before(:each) do
|
||||
module ::DiscourseChat::Provider::DummyProvider
|
||||
module ::DiscourseChatIntegration::Provider::DummyProvider
|
||||
PROVIDER_NAME = "dummy".freeze
|
||||
PROVIDER_ENABLED_SETTING = :chat_integration_enabled # Tie to main plugin enabled setting
|
||||
CHANNEL_PARAMETERS = []
|
||||
|
@ -33,15 +33,15 @@ RSpec.shared_context "dummy provider" do
|
|||
end
|
||||
|
||||
after(:each) do
|
||||
::DiscourseChat::Provider.send(:remove_const, :DummyProvider)
|
||||
::DiscourseChatIntegration::Provider.send(:remove_const, :DummyProvider)
|
||||
end
|
||||
|
||||
let(:provider) { ::DiscourseChat::Provider::DummyProvider }
|
||||
let(:provider) { ::DiscourseChatIntegration::Provider::DummyProvider }
|
||||
end
|
||||
|
||||
RSpec.shared_context "validated dummy provider" do
|
||||
before(:each) do
|
||||
module ::DiscourseChat::Provider::Dummy2Provider
|
||||
module ::DiscourseChatIntegration::Provider::Dummy2Provider
|
||||
PROVIDER_NAME = "dummy2".freeze
|
||||
PROVIDER_ENABLED_SETTING = :chat_integration_enabled # Tie to main plugin enabled setting
|
||||
CHANNEL_PARAMETERS = [
|
||||
|
@ -62,6 +62,6 @@ RSpec.shared_context "validated dummy provider" do
|
|||
end
|
||||
|
||||
after(:each) do
|
||||
::DiscourseChat::Provider.send(:remove_const, :Dummy2Provider)
|
||||
::DiscourseChatIntegration::Provider.send(:remove_const, :Dummy2Provider)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
require 'rails_helper'
|
||||
require_relative '../dummy_provider'
|
||||
|
||||
RSpec.describe DiscourseChat::Manager do
|
||||
RSpec.describe DiscourseChatIntegration::Manager do
|
||||
include_context "dummy provider"
|
||||
|
||||
let(:chan1) { DiscourseChat::Channel.create!(provider: 'dummy') }
|
||||
let(:chan2) { DiscourseChat::Channel.create!(provider: 'dummy') }
|
||||
let(:chan1) { DiscourseChatIntegration::Channel.create!(provider: 'dummy') }
|
||||
let(:chan2) { DiscourseChatIntegration::Channel.create!(provider: 'dummy') }
|
||||
|
||||
let(:category) { Fabricate(:category) }
|
||||
let(:tag1) { Fabricate(:tag) }
|
||||
|
@ -21,11 +21,11 @@ RSpec.describe DiscourseChat::Manager do
|
|||
# We just want to make sure the commands are being interpretted correctly
|
||||
|
||||
it 'should add a new rule correctly' do
|
||||
response = DiscourseChat::Helper.process_command(chan1, ['watch', category.slug])
|
||||
response = DiscourseChatIntegration::Helper.process_command(chan1, ['watch', category.slug])
|
||||
|
||||
expect(response).to eq(I18n.t("chat_integration.provider.dummy.create.created"))
|
||||
|
||||
rule = DiscourseChat::Rule.all.first
|
||||
rule = DiscourseChatIntegration::Rule.all.first
|
||||
expect(rule.channel).to eq(chan1)
|
||||
expect(rule.filter).to eq('watch')
|
||||
expect(rule.category_id).to eq(category.id)
|
||||
|
@ -33,29 +33,29 @@ RSpec.describe DiscourseChat::Manager do
|
|||
end
|
||||
|
||||
it 'should work with all four filter types' do
|
||||
response = DiscourseChat::Helper.process_command(chan1, ['thread', category.slug])
|
||||
response = DiscourseChatIntegration::Helper.process_command(chan1, ['thread', category.slug])
|
||||
|
||||
rule = DiscourseChat::Rule.all.first
|
||||
rule = DiscourseChatIntegration::Rule.all.first
|
||||
expect(rule.filter).to eq('thread')
|
||||
|
||||
response = DiscourseChat::Helper.process_command(chan1, ['watch', category.slug])
|
||||
response = DiscourseChatIntegration::Helper.process_command(chan1, ['watch', category.slug])
|
||||
|
||||
rule = DiscourseChat::Rule.all.first
|
||||
rule = DiscourseChatIntegration::Rule.all.first
|
||||
expect(rule.filter).to eq('watch')
|
||||
|
||||
response = DiscourseChat::Helper.process_command(chan1, ['follow', category.slug])
|
||||
response = DiscourseChatIntegration::Helper.process_command(chan1, ['follow', category.slug])
|
||||
|
||||
rule = DiscourseChat::Rule.all.first
|
||||
rule = DiscourseChatIntegration::Rule.all.first
|
||||
expect(rule.filter).to eq('follow')
|
||||
|
||||
response = DiscourseChat::Helper.process_command(chan1, ['mute', category.slug])
|
||||
response = DiscourseChatIntegration::Helper.process_command(chan1, ['mute', category.slug])
|
||||
|
||||
rule = DiscourseChat::Rule.all.first
|
||||
rule = DiscourseChatIntegration::Rule.all.first
|
||||
expect(rule.filter).to eq('mute')
|
||||
end
|
||||
|
||||
it 'errors on incorrect categories' do
|
||||
response = DiscourseChat::Helper.process_command(chan1, ['watch', 'blah'])
|
||||
response = DiscourseChatIntegration::Helper.process_command(chan1, ['watch', 'blah'])
|
||||
|
||||
expect(response).to eq(I18n.t("chat_integration.provider.dummy.not_found.category", name: 'blah', list: 'uncategorized'))
|
||||
end
|
||||
|
@ -66,11 +66,11 @@ RSpec.describe DiscourseChat::Manager do
|
|||
end
|
||||
|
||||
it 'should add a new tag rule correctly' do
|
||||
response = DiscourseChat::Helper.process_command(chan1, ['watch', "tag:#{tag1.name}"])
|
||||
response = DiscourseChatIntegration::Helper.process_command(chan1, ['watch', "tag:#{tag1.name}"])
|
||||
|
||||
expect(response).to eq(I18n.t("chat_integration.provider.dummy.create.created"))
|
||||
|
||||
rule = DiscourseChat::Rule.all.first
|
||||
rule = DiscourseChatIntegration::Rule.all.first
|
||||
expect(rule.channel).to eq(chan1)
|
||||
expect(rule.filter).to eq('watch')
|
||||
expect(rule.category_id).to eq(nil)
|
||||
|
@ -79,11 +79,11 @@ RSpec.describe DiscourseChat::Manager do
|
|||
|
||||
it 'should work with a category and multiple tags' do
|
||||
|
||||
response = DiscourseChat::Helper.process_command(chan1, ['watch', category.slug, "tag:#{tag1.name}", "tag:#{tag2.name}"])
|
||||
response = DiscourseChatIntegration::Helper.process_command(chan1, ['watch', category.slug, "tag:#{tag1.name}", "tag:#{tag2.name}"])
|
||||
|
||||
expect(response).to eq(I18n.t("chat_integration.provider.dummy.create.created"))
|
||||
|
||||
rule = DiscourseChat::Rule.all.first
|
||||
rule = DiscourseChatIntegration::Rule.all.first
|
||||
expect(rule.channel).to eq(chan1)
|
||||
expect(rule.filter).to eq('watch')
|
||||
expect(rule.category_id).to eq(category.id)
|
||||
|
@ -91,7 +91,7 @@ RSpec.describe DiscourseChat::Manager do
|
|||
end
|
||||
|
||||
it 'errors on incorrect tags' do
|
||||
response = DiscourseChat::Helper.process_command(chan1, ['watch', category.slug, "tag:blah"])
|
||||
response = DiscourseChatIntegration::Helper.process_command(chan1, ['watch', category.slug, "tag:blah"])
|
||||
expect(response).to eq(I18n.t("chat_integration.provider.dummy.not_found.tag", name: "blah"))
|
||||
end
|
||||
end
|
||||
|
@ -99,44 +99,44 @@ RSpec.describe DiscourseChat::Manager do
|
|||
|
||||
describe 'remove rule' do
|
||||
it 'removes the rule' do
|
||||
rule1 = DiscourseChat::Rule.create(channel: chan1,
|
||||
filter: 'watch',
|
||||
category_id: category.id,
|
||||
tags: [tag1.name, tag2.name]
|
||||
rule1 = DiscourseChatIntegration::Rule.create(channel: chan1,
|
||||
filter: 'watch',
|
||||
category_id: category.id,
|
||||
tags: [tag1.name, tag2.name]
|
||||
)
|
||||
|
||||
expect(DiscourseChat::Rule.all.size).to eq(1)
|
||||
expect(DiscourseChatIntegration::Rule.all.size).to eq(1)
|
||||
|
||||
response = DiscourseChat::Helper.process_command(chan1, ['remove', '1'])
|
||||
response = DiscourseChatIntegration::Helper.process_command(chan1, ['remove', '1'])
|
||||
|
||||
expect(response).to eq(I18n.t("chat_integration.provider.dummy.delete.success"))
|
||||
|
||||
expect(DiscourseChat::Rule.all.size).to eq(0)
|
||||
expect(DiscourseChatIntegration::Rule.all.size).to eq(0)
|
||||
end
|
||||
|
||||
it 'errors correctly' do
|
||||
response = DiscourseChat::Helper.process_command(chan1, ['remove', '1'])
|
||||
response = DiscourseChatIntegration::Helper.process_command(chan1, ['remove', '1'])
|
||||
expect(response).to eq(I18n.t("chat_integration.provider.dummy.delete.error"))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'help command' do
|
||||
it 'should return the right response' do
|
||||
response = DiscourseChat::Helper.process_command(chan1, ["help"])
|
||||
response = DiscourseChatIntegration::Helper.process_command(chan1, ["help"])
|
||||
expect(response).to eq(I18n.t("chat_integration.provider.dummy.help"))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'status command' do
|
||||
it 'should return the right response' do
|
||||
response = DiscourseChat::Helper.process_command(chan1, ['status'])
|
||||
expect(response).to eq(DiscourseChat::Helper.status_for_channel(chan1))
|
||||
response = DiscourseChatIntegration::Helper.process_command(chan1, ['status'])
|
||||
expect(response).to eq(DiscourseChatIntegration::Helper.status_for_channel(chan1))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'unknown command' do
|
||||
it 'should return the right response' do
|
||||
response = DiscourseChat::Helper.process_command(chan1, ['somerandomtext'])
|
||||
response = DiscourseChatIntegration::Helper.process_command(chan1, ['somerandomtext'])
|
||||
expect(response).to eq(I18n.t("chat_integration.provider.dummy.parse_error"))
|
||||
end
|
||||
end
|
||||
|
@ -146,12 +146,12 @@ RSpec.describe DiscourseChat::Manager do
|
|||
|
||||
context 'with no rules' do
|
||||
it 'includes the heading' do
|
||||
string = DiscourseChat::Helper.status_for_channel(chan1)
|
||||
string = DiscourseChatIntegration::Helper.status_for_channel(chan1)
|
||||
expect(string).to include('dummy.status.header')
|
||||
end
|
||||
|
||||
it 'includes the no_rules string' do
|
||||
string = DiscourseChat::Helper.status_for_channel(chan1)
|
||||
string = DiscourseChatIntegration::Helper.status_for_channel(chan1)
|
||||
expect(string).to include('dummy.status.no_rules')
|
||||
end
|
||||
end
|
||||
|
@ -159,26 +159,26 @@ RSpec.describe DiscourseChat::Manager do
|
|||
context 'with some rules' do
|
||||
let(:group) { Fabricate(:group) }
|
||||
before do
|
||||
DiscourseChat::Rule.create!(channel: chan1, filter: 'watch', category_id: category.id, tags: nil)
|
||||
DiscourseChat::Rule.create!(channel: chan1, filter: 'mute', category_id: nil, tags: nil)
|
||||
DiscourseChat::Rule.create!(channel: chan1, filter: 'follow', category_id: nil, tags: [tag1.name])
|
||||
DiscourseChat::Rule.create!(channel: chan1, filter: 'watch', type: 'group_message', group_id: group.id)
|
||||
DiscourseChat::Rule.create!(channel: chan2, filter: 'watch', category_id: 1, tags: nil)
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan1, filter: 'watch', category_id: category.id, tags: nil)
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan1, filter: 'mute', category_id: nil, tags: nil)
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan1, filter: 'follow', category_id: nil, tags: [tag1.name])
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan1, filter: 'watch', type: 'group_message', group_id: group.id)
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan2, filter: 'watch', category_id: 1, tags: nil)
|
||||
|
||||
SiteSetting.tagging_enabled = false
|
||||
end
|
||||
|
||||
it 'displays the correct rules' do
|
||||
string = DiscourseChat::Helper.status_for_channel(chan1)
|
||||
string = DiscourseChatIntegration::Helper.status_for_channel(chan1)
|
||||
expect(string.scan('status.rule_string').size).to eq(4)
|
||||
end
|
||||
|
||||
it 'only displays tags for rules with tags' do
|
||||
string = DiscourseChat::Helper.status_for_channel(chan1)
|
||||
string = DiscourseChatIntegration::Helper.status_for_channel(chan1)
|
||||
expect(string.scan('rule_string_tags_suffix').size).to eq(0)
|
||||
|
||||
SiteSetting.tagging_enabled = true
|
||||
string = DiscourseChat::Helper.status_for_channel(chan1)
|
||||
string = DiscourseChatIntegration::Helper.status_for_channel(chan1)
|
||||
expect(string.scan('rule_string_tags_suffix').size).to eq(1)
|
||||
end
|
||||
|
||||
|
@ -194,42 +194,42 @@ RSpec.describe DiscourseChat::Manager do
|
|||
# Three identical rules, with different filters
|
||||
# Status will be sorted by precedence
|
||||
# be in this order
|
||||
rule1 = DiscourseChat::Rule.create(channel: chan1,
|
||||
filter: 'mute',
|
||||
category_id: category.id,
|
||||
tags: [tag1.name, tag2.name]
|
||||
rule1 = DiscourseChatIntegration::Rule.create(channel: chan1,
|
||||
filter: 'mute',
|
||||
category_id: category.id,
|
||||
tags: [tag1.name, tag2.name]
|
||||
)
|
||||
rule2 = DiscourseChat::Rule.create(channel: chan1,
|
||||
filter: 'watch',
|
||||
category_id: category2.id,
|
||||
tags: [tag1.name, tag2.name]
|
||||
rule2 = DiscourseChatIntegration::Rule.create(channel: chan1,
|
||||
filter: 'watch',
|
||||
category_id: category2.id,
|
||||
tags: [tag1.name, tag2.name]
|
||||
)
|
||||
rule3 = DiscourseChat::Rule.create(channel: chan1,
|
||||
filter: 'follow',
|
||||
category_id: category3.id,
|
||||
tags: [tag1.name, tag2.name]
|
||||
rule3 = DiscourseChatIntegration::Rule.create(channel: chan1,
|
||||
filter: 'follow',
|
||||
category_id: category3.id,
|
||||
tags: [tag1.name, tag2.name]
|
||||
)
|
||||
|
||||
expect(DiscourseChat::Rule.all.size).to eq(3)
|
||||
expect(DiscourseChatIntegration::Rule.all.size).to eq(3)
|
||||
|
||||
expect(DiscourseChat::Helper.delete_by_index(chan1, 2)).to eq(:deleted)
|
||||
expect(DiscourseChatIntegration::Helper.delete_by_index(chan1, 2)).to eq(:deleted)
|
||||
|
||||
expect(DiscourseChat::Rule.all.size).to eq(2)
|
||||
expect(DiscourseChat::Rule.all.map(&:category_id)).to contain_exactly(category.id, category3.id)
|
||||
expect(DiscourseChatIntegration::Rule.all.size).to eq(2)
|
||||
expect(DiscourseChatIntegration::Rule.all.map(&:category_id)).to contain_exactly(category.id, category3.id)
|
||||
end
|
||||
|
||||
it 'fails gracefully for out of range indexes' do
|
||||
rule1 = DiscourseChat::Rule.create(channel: chan1,
|
||||
filter: 'watch',
|
||||
category_id: category.id,
|
||||
tags: [tag1.name, tag2.name]
|
||||
rule1 = DiscourseChatIntegration::Rule.create(channel: chan1,
|
||||
filter: 'watch',
|
||||
category_id: category.id,
|
||||
tags: [tag1.name, tag2.name]
|
||||
)
|
||||
|
||||
expect(DiscourseChat::Helper.delete_by_index(chan1, -1)).to eq(false)
|
||||
expect(DiscourseChat::Helper.delete_by_index(chan1, 0)).to eq(false)
|
||||
expect(DiscourseChat::Helper.delete_by_index(chan1, 2)).to eq(false)
|
||||
expect(DiscourseChatIntegration::Helper.delete_by_index(chan1, -1)).to eq(false)
|
||||
expect(DiscourseChatIntegration::Helper.delete_by_index(chan1, 0)).to eq(false)
|
||||
expect(DiscourseChatIntegration::Helper.delete_by_index(chan1, 2)).to eq(false)
|
||||
|
||||
expect(DiscourseChat::Helper.delete_by_index(chan1, 1)).to eq(:deleted)
|
||||
expect(DiscourseChatIntegration::Helper.delete_by_index(chan1, 1)).to eq(:deleted)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -237,14 +237,14 @@ RSpec.describe DiscourseChat::Manager do
|
|||
describe '.smart_create_rule' do
|
||||
|
||||
it 'creates a rule when there are none' do
|
||||
val = DiscourseChat::Helper.smart_create_rule(channel: chan1,
|
||||
filter: 'watch',
|
||||
category_id: category.id,
|
||||
tags: [tag1.name]
|
||||
val = DiscourseChatIntegration::Helper.smart_create_rule(channel: chan1,
|
||||
filter: 'watch',
|
||||
category_id: category.id,
|
||||
tags: [tag1.name]
|
||||
)
|
||||
expect(val).to eq(:created)
|
||||
|
||||
record = DiscourseChat::Rule.all.first
|
||||
record = DiscourseChatIntegration::Rule.all.first
|
||||
expect(record.channel).to eq(chan1)
|
||||
expect(record.filter).to eq('watch')
|
||||
expect(record.category_id).to eq(category.id)
|
||||
|
@ -252,58 +252,58 @@ RSpec.describe DiscourseChat::Manager do
|
|||
end
|
||||
|
||||
it 'updates a rule when it has the same category and tags' do
|
||||
existing = DiscourseChat::Rule.create!(channel: chan1,
|
||||
filter: 'watch',
|
||||
category_id: category.id,
|
||||
tags: [tag2.name, tag1.name]
|
||||
existing = DiscourseChatIntegration::Rule.create!(channel: chan1,
|
||||
filter: 'watch',
|
||||
category_id: category.id,
|
||||
tags: [tag2.name, tag1.name]
|
||||
)
|
||||
|
||||
val = DiscourseChat::Helper.smart_create_rule(channel: chan1,
|
||||
filter: 'mute',
|
||||
category_id: category.id,
|
||||
tags: [tag1.name, tag2.name]
|
||||
val = DiscourseChatIntegration::Helper.smart_create_rule(channel: chan1,
|
||||
filter: 'mute',
|
||||
category_id: category.id,
|
||||
tags: [tag1.name, tag2.name]
|
||||
)
|
||||
|
||||
expect(val).to eq(:updated)
|
||||
|
||||
expect(DiscourseChat::Rule.all.size).to eq(1)
|
||||
expect(DiscourseChat::Rule.all.first.filter).to eq('mute')
|
||||
expect(DiscourseChatIntegration::Rule.all.size).to eq(1)
|
||||
expect(DiscourseChatIntegration::Rule.all.first.filter).to eq('mute')
|
||||
end
|
||||
|
||||
it 'updates a rule when it has the same category and filter' do
|
||||
existing = DiscourseChat::Rule.create(channel: chan1,
|
||||
filter: 'watch',
|
||||
category_id: category.id,
|
||||
tags: [tag1.name, tag2.name]
|
||||
existing = DiscourseChatIntegration::Rule.create(channel: chan1,
|
||||
filter: 'watch',
|
||||
category_id: category.id,
|
||||
tags: [tag1.name, tag2.name]
|
||||
)
|
||||
|
||||
val = DiscourseChat::Helper.smart_create_rule(channel: chan1,
|
||||
filter: 'watch',
|
||||
category_id: category.id,
|
||||
tags: [tag1.name, tag3.name]
|
||||
val = DiscourseChatIntegration::Helper.smart_create_rule(channel: chan1,
|
||||
filter: 'watch',
|
||||
category_id: category.id,
|
||||
tags: [tag1.name, tag3.name]
|
||||
)
|
||||
|
||||
expect(val).to eq(:updated)
|
||||
|
||||
expect(DiscourseChat::Rule.all.size).to eq(1)
|
||||
expect(DiscourseChat::Rule.all.first.tags).to contain_exactly(tag1.name, tag2.name, tag3.name)
|
||||
expect(DiscourseChatIntegration::Rule.all.size).to eq(1)
|
||||
expect(DiscourseChatIntegration::Rule.all.first.tags).to contain_exactly(tag1.name, tag2.name, tag3.name)
|
||||
end
|
||||
|
||||
it 'destroys duplicate rules on save' do
|
||||
DiscourseChat::Rule.create!(channel: chan1, filter: 'watch')
|
||||
DiscourseChat::Rule.create!(channel: chan1, filter: 'watch')
|
||||
expect(DiscourseChat::Rule.all.size).to eq(2)
|
||||
val = DiscourseChat::Helper.smart_create_rule(channel: chan1,
|
||||
filter: 'watch',
|
||||
category_id: nil,
|
||||
tags: nil
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan1, filter: 'watch')
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan1, filter: 'watch')
|
||||
expect(DiscourseChatIntegration::Rule.all.size).to eq(2)
|
||||
val = DiscourseChatIntegration::Helper.smart_create_rule(channel: chan1,
|
||||
filter: 'watch',
|
||||
category_id: nil,
|
||||
tags: nil
|
||||
)
|
||||
expect(val).to eq(:updated)
|
||||
expect(DiscourseChat::Rule.all.size).to eq(1)
|
||||
expect(DiscourseChatIntegration::Rule.all.size).to eq(1)
|
||||
end
|
||||
|
||||
it 'returns false on error' do
|
||||
val = DiscourseChat::Helper.smart_create_rule(channel: chan1, filter: 'blah')
|
||||
val = DiscourseChatIntegration::Helper.smart_create_rule(channel: chan1, filter: 'blah')
|
||||
|
||||
expect(val).to eq(false)
|
||||
end
|
||||
|
@ -312,7 +312,7 @@ RSpec.describe DiscourseChat::Manager do
|
|||
describe '.save_transcript' do
|
||||
|
||||
it 'saves a transcript to redis' do
|
||||
key = DiscourseChat::Helper.save_transcript("Some content here")
|
||||
key = DiscourseChatIntegration::Helper.save_transcript("Some content here")
|
||||
|
||||
expect(Discourse.redis.get("chat_integration:transcript:#{key}")).to eq("Some content here")
|
||||
|
||||
|
|
|
@ -71,26 +71,26 @@ RSpec.describe Jobs::DiscourseChatMigrateFromSlackOfficial do
|
|||
it 'should create the right channels and rules' do
|
||||
described_class.new.execute_onceoff({})
|
||||
|
||||
expect(DiscourseChat::Channel.count).to eq(2)
|
||||
expect(DiscourseChat::Rule.count).to eq(2)
|
||||
expect(DiscourseChatIntegration::Channel.count).to eq(2)
|
||||
expect(DiscourseChatIntegration::Rule.count).to eq(2)
|
||||
|
||||
channel = DiscourseChat::Channel.first
|
||||
channel = DiscourseChatIntegration::Channel.first
|
||||
|
||||
expect(channel.value['provider']).to eq("slack")
|
||||
expect(channel.value['data']['identifier']).to eq("#channel1")
|
||||
|
||||
rule = DiscourseChat::Rule.first
|
||||
rule = DiscourseChatIntegration::Rule.first
|
||||
|
||||
expect(rule.value['channel_id']).to eq(channel.id)
|
||||
expect(rule.value['filter']).to eq('mute')
|
||||
expect(rule.value['category_id']).to eq(nil)
|
||||
|
||||
channel = DiscourseChat::Channel.last
|
||||
channel = DiscourseChatIntegration::Channel.last
|
||||
|
||||
expect(channel.value['provider']).to eq("slack")
|
||||
expect(channel.value['data']['identifier']).to eq("#channel2")
|
||||
|
||||
rule = DiscourseChat::Rule.last
|
||||
rule = DiscourseChatIntegration::Rule.last
|
||||
|
||||
expect(rule.value['channel_id']).to eq(channel.id)
|
||||
expect(rule.value['filter']).to eq('follow')
|
||||
|
@ -113,7 +113,7 @@ RSpec.describe Jobs::DiscourseChatMigrateFromSlackOfficial do
|
|||
it 'should discard invalid tags' do
|
||||
described_class.new.execute_onceoff({})
|
||||
|
||||
rule = DiscourseChat::Rule.first
|
||||
rule = DiscourseChatIntegration::Rule.first
|
||||
|
||||
expect(rule.value['tags']).to eq([tag.name])
|
||||
end
|
||||
|
@ -132,12 +132,12 @@ RSpec.describe Jobs::DiscourseChatMigrateFromSlackOfficial do
|
|||
it 'should migrate the settings correctly' do
|
||||
described_class.new.execute_onceoff({})
|
||||
|
||||
channel = DiscourseChat::Channel.first
|
||||
channel = DiscourseChatIntegration::Channel.first
|
||||
|
||||
expect(channel.value['provider']).to eq("slack")
|
||||
expect(channel.value['data']['identifier']).to eq("#slack-channel")
|
||||
|
||||
rule = DiscourseChat::Rule.first
|
||||
rule = DiscourseChatIntegration::Rule.first
|
||||
|
||||
expect(rule.value['channel_id']).to eq(channel.id)
|
||||
expect(rule.value['filter']).to eq('mute')
|
||||
|
@ -158,8 +158,8 @@ RSpec.describe Jobs::DiscourseChatMigrateFromSlackOfficial do
|
|||
it 'should not migrate the settings' do
|
||||
described_class.new.execute_onceoff({})
|
||||
|
||||
expect(DiscourseChat::Channel.count).to eq(0)
|
||||
expect(DiscourseChat::Rule.count).to eq(0)
|
||||
expect(DiscourseChatIntegration::Channel.count).to eq(0)
|
||||
expect(DiscourseChatIntegration::Rule.count).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe DiscourseChat::Provider::DiscordProvider do
|
||||
RSpec.describe DiscourseChatIntegration::Provider::DiscordProvider do
|
||||
let(:post) { Fabricate(:post) }
|
||||
|
||||
describe '.trigger_notifications' do
|
||||
|
@ -10,7 +10,7 @@ RSpec.describe DiscourseChat::Provider::DiscordProvider do
|
|||
SiteSetting.chat_integration_discord_enabled = true
|
||||
end
|
||||
|
||||
let(:chan1) { DiscourseChat::Channel.create!(provider: 'discord', data: { name: "Awesome Channel", webhook_url: 'https://discordapp.com/api/webhooks/1234/abcd' }) }
|
||||
let(:chan1) { DiscourseChatIntegration::Channel.create!(provider: 'discord', data: { name: "Awesome Channel", webhook_url: 'https://discordapp.com/api/webhooks/1234/abcd' }) }
|
||||
|
||||
it 'sends a webhook request' do
|
||||
stub1 = stub_request(:post, 'https://discordapp.com/api/webhooks/1234/abcd?wait=true').to_return(status: 200)
|
||||
|
@ -29,7 +29,7 @@ RSpec.describe DiscourseChat::Provider::DiscordProvider do
|
|||
it 'handles errors correctly' do
|
||||
stub1 = stub_request(:post, "https://discordapp.com/api/webhooks/1234/abcd?wait=true").to_return(status: 400)
|
||||
expect(stub1).to have_been_requested.times(0)
|
||||
expect { described_class.trigger_notification(post, chan1, nil) }.to raise_exception(::DiscourseChat::ProviderError)
|
||||
expect { described_class.trigger_notification(post, chan1, nil) }.to raise_exception(::DiscourseChatIntegration::ProviderError)
|
||||
expect(stub1).to have_been_requested.once
|
||||
end
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe DiscourseChat::Provider::FlowdockProvider do
|
||||
RSpec.describe DiscourseChatIntegration::Provider::FlowdockProvider do
|
||||
let(:post) { Fabricate(:post) }
|
||||
|
||||
describe '.trigger_notifications' do
|
||||
|
@ -10,7 +10,7 @@ RSpec.describe DiscourseChat::Provider::FlowdockProvider do
|
|||
SiteSetting.chat_integration_flowdock_enabled = true
|
||||
end
|
||||
|
||||
let(:chan1) { DiscourseChat::Channel.create!(provider: 'flowdock', data: { flow_token: '5d1fe04cf66e078d6a2b579ddb8a465b' }) }
|
||||
let(:chan1) { DiscourseChatIntegration::Channel.create!(provider: 'flowdock', data: { flow_token: '5d1fe04cf66e078d6a2b579ddb8a465b' }) }
|
||||
|
||||
it 'sends a request' do
|
||||
stub1 = stub_request(:post, "https://api.flowdock.com/messages").to_return(status: 200)
|
||||
|
@ -21,7 +21,7 @@ RSpec.describe DiscourseChat::Provider::FlowdockProvider do
|
|||
it 'handles errors correctly' do
|
||||
stub1 = stub_request(:post, "https://api.flowdock.com/messages").to_return(status: 404, body: "{ \"error\": \"Not Found\"}")
|
||||
expect(stub1).to have_been_requested.times(0)
|
||||
expect { described_class.trigger_notification(post, chan1, nil) }.to raise_exception(::DiscourseChat::ProviderError)
|
||||
expect { described_class.trigger_notification(post, chan1, nil) }.to raise_exception(::DiscourseChatIntegration::ProviderError)
|
||||
expect(stub1).to have_been_requested.once
|
||||
end
|
||||
end
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe DiscourseChat::Provider::GitterProvider do
|
||||
RSpec.describe DiscourseChatIntegration::Provider::GitterProvider do
|
||||
let(:post) { Fabricate(:post) }
|
||||
|
||||
describe '.trigger_notifications' do
|
||||
|
@ -10,7 +10,7 @@ RSpec.describe DiscourseChat::Provider::GitterProvider do
|
|||
SiteSetting.chat_integration_gitter_enabled = true
|
||||
end
|
||||
|
||||
let(:chan1) { DiscourseChat::Channel.create!(provider: 'gitter', data: { name: 'gitterHQ/services', webhook_url: 'https://webhooks.gitter.im/e/a1e2i3o4u5' }) }
|
||||
let(:chan1) { DiscourseChatIntegration::Channel.create!(provider: 'gitter', data: { name: 'gitterHQ/services', webhook_url: 'https://webhooks.gitter.im/e/a1e2i3o4u5' }) }
|
||||
|
||||
it 'sends a webhook request' do
|
||||
stub1 = stub_request(:post, chan1.data['webhook_url']).to_return(body: "OK")
|
||||
|
@ -21,7 +21,7 @@ RSpec.describe DiscourseChat::Provider::GitterProvider do
|
|||
it 'handles errors correctly' do
|
||||
stub1 = stub_request(:post, chan1.data['webhook_url']).to_return(status: 404, body: "{ \"error\": \"Not Found\"}")
|
||||
expect(stub1).to have_been_requested.times(0)
|
||||
expect { described_class.trigger_notification(post, chan1, nil) }.to raise_exception(::DiscourseChat::ProviderError)
|
||||
expect { described_class.trigger_notification(post, chan1, nil) }.to raise_exception(::DiscourseChatIntegration::ProviderError)
|
||||
expect(stub1).to have_been_requested.once
|
||||
end
|
||||
end
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe DiscourseChat::Provider::GoogleProvider do
|
||||
RSpec.describe DiscourseChatIntegration::Provider::GoogleProvider do
|
||||
let(:post) { Fabricate(:post) }
|
||||
|
||||
describe '.trigger_notifications' do
|
||||
|
@ -10,7 +10,7 @@ RSpec.describe DiscourseChat::Provider::GoogleProvider do
|
|||
SiteSetting.chat_integration_google_enabled = true
|
||||
end
|
||||
|
||||
let(:chan1) { DiscourseChat::Channel.create!(provider: 'google', data: { name: 'discourse', webhook_url: 'https://chat.googleapis.com/v1/abcdefg' }) }
|
||||
let(:chan1) { DiscourseChatIntegration::Channel.create!(provider: 'google', data: { name: 'discourse', webhook_url: 'https://chat.googleapis.com/v1/abcdefg' }) }
|
||||
|
||||
it 'sends a webhook request' do
|
||||
stub1 = stub_request(:post, chan1.data['webhook_url']).to_return(body: "1")
|
||||
|
@ -21,7 +21,7 @@ RSpec.describe DiscourseChat::Provider::GoogleProvider do
|
|||
it 'handles errors correctly' do
|
||||
stub1 = stub_request(:post, chan1.data['webhook_url']).to_return(status: 400, body: "{}")
|
||||
expect(stub1).to have_been_requested.times(0)
|
||||
expect { described_class.trigger_notification(post, chan1, nil) }.to raise_exception(::DiscourseChat::ProviderError)
|
||||
expect { described_class.trigger_notification(post, chan1, nil) }.to raise_exception(::DiscourseChatIntegration::ProviderError)
|
||||
expect(stub1).to have_been_requested.once
|
||||
end
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe DiscourseChat::Provider::GroupmeProvider do
|
||||
RSpec.describe DiscourseChatIntegration::Provider::GroupmeProvider do
|
||||
let(:post) { Fabricate(:post) }
|
||||
|
||||
describe '.trigger_notifications' do
|
||||
|
@ -11,7 +11,7 @@ RSpec.describe DiscourseChat::Provider::GroupmeProvider do
|
|||
SiteSetting.chat_integration_groupme_bot_ids = '1a2b3c4d5e6f7g'
|
||||
end
|
||||
|
||||
let(:chan1) { DiscourseChat::Channel.create!(provider: 'groupme', data: { groupme_bot_id: '1a2b3c4d5e6f7g' }) }
|
||||
let(:chan1) { DiscourseChatIntegration::Channel.create!(provider: 'groupme', data: { groupme_bot_id: '1a2b3c4d5e6f7g' }) }
|
||||
|
||||
it 'sends a request' do
|
||||
stub1 = stub_request(:post, "https://api.groupme.com/v3/bots/post").to_return(status: 200)
|
||||
|
@ -22,7 +22,7 @@ RSpec.describe DiscourseChat::Provider::GroupmeProvider do
|
|||
it 'handles errors correctly' do
|
||||
stub1 = stub_request(:post, "https://api.groupme.com/v3/bots/post").to_return(status: 404, body: "{ \"error\": \"Not Found\"}")
|
||||
expect(stub1).to have_been_requested.times(0)
|
||||
expect { described_class.trigger_notification(post, chan1, nil) }.to raise_exception(::DiscourseChat::ProviderError)
|
||||
expect { described_class.trigger_notification(post, chan1, nil) }.to raise_exception(::DiscourseChatIntegration::ProviderError)
|
||||
expect(stub1).to have_been_requested.once
|
||||
end
|
||||
end
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe DiscourseChat::Provider::MatrixProvider do
|
||||
RSpec.describe DiscourseChatIntegration::Provider::MatrixProvider do
|
||||
let(:post) { Fabricate(:post) }
|
||||
|
||||
describe '.trigger_notifications' do
|
||||
|
@ -11,7 +11,7 @@ RSpec.describe DiscourseChat::Provider::MatrixProvider do
|
|||
SiteSetting.chat_integration_matrix_access_token = 'abcd'
|
||||
end
|
||||
|
||||
let(:chan1) { DiscourseChat::Channel.create!(provider: 'matrix', data: { name: "Awesome Channel", room_id: '!blah:matrix.org' }) }
|
||||
let(:chan1) { DiscourseChatIntegration::Channel.create!(provider: 'matrix', data: { name: "Awesome Channel", room_id: '!blah:matrix.org' }) }
|
||||
|
||||
it 'sends the message' do
|
||||
stub1 = stub_request(:put, %r{https://matrix.org/_matrix/client/r0/rooms/!blah:matrix.org/send/m.room.message/*}).to_return(status: 200)
|
||||
|
@ -22,7 +22,7 @@ RSpec.describe DiscourseChat::Provider::MatrixProvider do
|
|||
it 'handles errors correctly' do
|
||||
stub1 = stub_request(:put, %r{https://matrix.org/_matrix/client/r0/rooms/!blah:matrix.org/send/m.room.message/*}).to_return(status: 400, body: '{"errmsg":"M_UNKNOWN"}')
|
||||
expect(stub1).to have_been_requested.times(0)
|
||||
expect { described_class.trigger_notification(post, chan1, nil) }.to raise_exception(::DiscourseChat::ProviderError)
|
||||
expect { described_class.trigger_notification(post, chan1, nil) }.to raise_exception(::DiscourseChatIntegration::ProviderError)
|
||||
expect(stub1).to have_been_requested.once
|
||||
end
|
||||
|
|
@ -6,7 +6,7 @@ describe 'Mattermost Command Controller', type: :request do
|
|||
let(:category) { Fabricate(:category) }
|
||||
let(:tag) { Fabricate(:tag) }
|
||||
let(:tag2) { Fabricate(:tag) }
|
||||
let!(:chan1) { DiscourseChat::Channel.create!(provider: 'mattermost', data: { identifier: '#welcome' }) }
|
||||
let!(:chan1) { DiscourseChatIntegration::Channel.create!(provider: 'mattermost', data: { identifier: '#welcome' }) }
|
||||
|
||||
describe 'with plugin disabled' do
|
||||
it 'should return a 404' do
|
||||
|
@ -88,7 +88,7 @@ describe 'Mattermost Command Controller', type: :request do
|
|||
|
||||
expect(json["text"]).to eq(I18n.t("chat_integration.provider.mattermost.create.created"))
|
||||
|
||||
rule = DiscourseChat::Rule.all.first
|
||||
rule = DiscourseChatIntegration::Rule.all.first
|
||||
expect(rule.channel).to eq(chan1)
|
||||
expect(rule.filter).to eq('watch')
|
||||
expect(rule.category_id).to eq(category.id)
|
||||
|
@ -107,7 +107,7 @@ describe 'Mattermost Command Controller', type: :request do
|
|||
|
||||
expect(json["text"]).to eq(I18n.t("chat_integration.provider.mattermost.create.created"))
|
||||
|
||||
chan = DiscourseChat::Channel.with_provider('mattermost').with_data_value('identifier', '#general').first
|
||||
chan = DiscourseChatIntegration::Channel.with_provider('mattermost').with_data_value('identifier', '#general').first
|
||||
expect(chan.provider).to eq('mattermost')
|
||||
|
||||
rule = chan.rules.first
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe DiscourseChat::Provider::MattermostProvider do
|
||||
RSpec.describe DiscourseChatIntegration::Provider::MattermostProvider do
|
||||
let(:post) { Fabricate(:post) }
|
||||
|
||||
describe '.trigger_notifications' do
|
||||
|
@ -14,7 +14,7 @@ RSpec.describe DiscourseChat::Provider::MattermostProvider do
|
|||
SiteSetting.logo_small = upload
|
||||
end
|
||||
|
||||
let(:chan1) { DiscourseChat::Channel.create!(provider: 'mattermost', data: { identifier: "#awesomechannel" }) }
|
||||
let(:chan1) { DiscourseChatIntegration::Channel.create!(provider: 'mattermost', data: { identifier: "#awesomechannel" }) }
|
||||
|
||||
it 'sends a webhook request' do
|
||||
stub1 = stub_request(:post, 'https://mattermost.blah/hook/abcd').to_return(status: 200)
|
||||
|
@ -40,7 +40,7 @@ RSpec.describe DiscourseChat::Provider::MattermostProvider do
|
|||
it 'handles errors correctly' do
|
||||
stub1 = stub_request(:post, "https://mattermost.blah/hook/abcd").to_return(status: 500, body: "error")
|
||||
expect(stub1).to have_been_requested.times(0)
|
||||
expect { described_class.trigger_notification(post, chan1, nil) }.to raise_exception(::DiscourseChat::ProviderError)
|
||||
expect { described_class.trigger_notification(post, chan1, nil) }.to raise_exception(::DiscourseChatIntegration::ProviderError)
|
||||
expect(stub1).to have_been_requested.once
|
||||
end
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe DiscourseChat::Provider::RocketchatProvider do
|
||||
RSpec.describe DiscourseChatIntegration::Provider::RocketchatProvider do
|
||||
let(:post) { Fabricate(:post) }
|
||||
|
||||
describe '.trigger_notifications' do
|
||||
|
@ -11,7 +11,7 @@ RSpec.describe DiscourseChat::Provider::RocketchatProvider do
|
|||
SiteSetting.chat_integration_rocketchat_webhook_url = "https://example.com/abcd"
|
||||
end
|
||||
|
||||
let(:chan1) { DiscourseChat::Channel.create!(provider: 'rocketchat', data: { identifier: "#general" }) }
|
||||
let(:chan1) { DiscourseChatIntegration::Channel.create!(provider: 'rocketchat', data: { identifier: "#general" }) }
|
||||
|
||||
it 'sends a webhook request' do
|
||||
stub1 = stub_request(:post, 'https://example.com/abcd').to_return(body: "{\"success\":true}")
|
||||
|
@ -22,7 +22,7 @@ RSpec.describe DiscourseChat::Provider::RocketchatProvider do
|
|||
it 'handles errors correctly' do
|
||||
stub1 = stub_request(:post, 'https://example.com/abcd').to_return(status: 400, body: "{}")
|
||||
expect(stub1).to have_been_requested.times(0)
|
||||
expect { described_class.trigger_notification(post, chan1, nil) }.to raise_exception(::DiscourseChat::ProviderError)
|
||||
expect { described_class.trigger_notification(post, chan1, nil) }.to raise_exception(::DiscourseChatIntegration::ProviderError)
|
||||
expect(stub1).to have_been_requested.once
|
||||
end
|
||||
|
|
@ -6,7 +6,7 @@ describe 'Slack Command Controller', type: :request do
|
|||
let(:category) { Fabricate(:category) }
|
||||
let(:tag) { Fabricate(:tag) }
|
||||
let(:tag2) { Fabricate(:tag) }
|
||||
let!(:chan1) { DiscourseChat::Channel.create!(provider: 'slack', data: { identifier: '#welcome' }) }
|
||||
let!(:chan1) { DiscourseChatIntegration::Channel.create!(provider: 'slack', data: { identifier: '#welcome' }) }
|
||||
|
||||
describe 'with plugin disabled' do
|
||||
it 'should return a 404' do
|
||||
|
@ -102,7 +102,7 @@ describe 'Slack Command Controller', type: :request do
|
|||
|
||||
expect(json["text"]).to eq(I18n.t("chat_integration.provider.slack.create.created"))
|
||||
|
||||
rule = DiscourseChat::Rule.all.first
|
||||
rule = DiscourseChatIntegration::Rule.all.first
|
||||
expect(rule.channel).to eq(chan1)
|
||||
expect(rule.filter).to eq('watch')
|
||||
expect(rule.category_id).to eq(category.id)
|
||||
|
@ -121,7 +121,7 @@ describe 'Slack Command Controller', type: :request do
|
|||
|
||||
expect(json["text"]).to eq(I18n.t("chat_integration.provider.slack.create.created"))
|
||||
|
||||
chan = DiscourseChat::Channel.with_provider('slack').with_data_value('identifier', '#general').first
|
||||
chan = DiscourseChatIntegration::Channel.with_provider('slack').with_data_value('identifier', '#general').first
|
||||
expect(chan.provider).to eq('slack')
|
||||
|
||||
rule = chan.rules.first
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe DiscourseChat::Provider::SlackProvider::SlackMessageFormatter do
|
||||
RSpec.describe DiscourseChatIntegration::Provider::SlackProvider::SlackMessageFormatter do
|
||||
describe '.format' do
|
||||
context 'links' do
|
||||
it 'should return the right message' do
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe DiscourseChat::Provider::SlackProvider do
|
||||
RSpec.describe DiscourseChatIntegration::Provider::SlackProvider do
|
||||
let(:post) { Fabricate(:post) }
|
||||
|
||||
describe '.excerpt' do
|
||||
|
@ -71,7 +71,7 @@ RSpec.describe DiscourseChat::Provider::SlackProvider do
|
|||
SiteSetting.chat_integration_slack_enabled = true
|
||||
end
|
||||
|
||||
let(:chan1) { DiscourseChat::Channel.create!(provider: 'slack', data: { identifier: '#general' }) }
|
||||
let(:chan1) { DiscourseChatIntegration::Channel.create!(provider: 'slack', data: { identifier: '#general' }) }
|
||||
|
||||
it 'sends a webhook request' do
|
||||
stub1 = stub_request(:post, SiteSetting.chat_integration_slack_outbound_webhook_url).to_return(body: "success")
|
||||
|
@ -82,7 +82,7 @@ RSpec.describe DiscourseChat::Provider::SlackProvider do
|
|||
it 'handles errors correctly' do
|
||||
stub1 = stub_request(:post, SiteSetting.chat_integration_slack_outbound_webhook_url).to_return(status: 400, body: "error")
|
||||
expect(stub1).to have_been_requested.times(0)
|
||||
expect { described_class.trigger_notification(post, chan1, nil) }.to raise_exception(::DiscourseChat::ProviderError)
|
||||
expect { described_class.trigger_notification(post, chan1, nil) }.to raise_exception(::DiscourseChatIntegration::ProviderError)
|
||||
expect(stub1).to have_been_requested.once
|
||||
end
|
||||
|
||||
|
@ -93,7 +93,7 @@ RSpec.describe DiscourseChat::Provider::SlackProvider do
|
|||
@stub1 = stub_request(:post, SiteSetting.chat_integration_slack_outbound_webhook_url).to_return(body: "success")
|
||||
@thread_stub = stub_request(:post, %r{https://slack.com/api/chat.postMessage}).with(body: hash_including("thread_ts" => @ts)).to_return(body: "{\"ok\":true, \"ts\": \"12345.67890\", \"message\": {\"attachments\": [], \"username\":\"blah\", \"text\":\"blah2\"} }", headers: { 'Content-Type' => 'application/json' })
|
||||
@stub2 = stub_request(:post, %r{https://slack.com/api/chat.postMessage}).to_return(body: "{\"ok\":true, \"ts\": \"#{@ts}\", \"message\": {\"attachments\": [], \"username\":\"blah\", \"text\":\"blah2\"} }", headers: { 'Content-Type' => 'application/json' })
|
||||
@channel = DiscourseChat::Channel.create(provider: 'dummy')
|
||||
@channel = DiscourseChatIntegration::Channel.create(provider: 'dummy')
|
||||
end
|
||||
|
||||
it 'sends an api request' do
|
||||
|
@ -110,7 +110,7 @@ RSpec.describe DiscourseChat::Provider::SlackProvider do
|
|||
it 'sends thread id for thread' do
|
||||
expect(@thread_stub).to have_been_requested.times(0)
|
||||
|
||||
rule = DiscourseChat::Rule.create(channel: @channel, filter: "thread")
|
||||
rule = DiscourseChatIntegration::Rule.create(channel: @channel, filter: "thread")
|
||||
post.topic.slack_thread_id = @ts
|
||||
|
||||
described_class.trigger_notification(post, chan1, rule)
|
||||
|
@ -124,7 +124,7 @@ RSpec.describe DiscourseChat::Provider::SlackProvider do
|
|||
RAW
|
||||
)
|
||||
|
||||
rule = DiscourseChat::Rule.create(channel: @channel, filter: "thread")
|
||||
rule = DiscourseChatIntegration::Rule.create(channel: @channel, filter: "thread")
|
||||
post.topic.slack_thread_id = nil
|
||||
|
||||
described_class.trigger_notification(post, chan1, rule)
|
||||
|
@ -135,7 +135,7 @@ RSpec.describe DiscourseChat::Provider::SlackProvider do
|
|||
|
||||
it 'handles errors correctly' do
|
||||
@stub2 = stub_request(:post, %r{https://slack.com/api/chat.postMessage}).to_return(body: "{\"ok\":false }", headers: { 'Content-Type' => 'application/json' })
|
||||
expect { described_class.trigger_notification(post, chan1, nil) }.to raise_exception(::DiscourseChat::ProviderError)
|
||||
expect { described_class.trigger_notification(post, chan1, nil) }.to raise_exception(::DiscourseChatIntegration::ProviderError)
|
||||
expect(@stub2).to have_been_requested.once
|
||||
end
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe DiscourseChat::Provider::SlackProvider::SlackTranscript do
|
||||
RSpec.describe DiscourseChatIntegration::Provider::SlackProvider::SlackTranscript do
|
||||
|
||||
let(:messages_fixture) {
|
||||
[
|
||||
|
@ -336,7 +336,7 @@ RSpec.describe DiscourseChat::Provider::SlackProvider::SlackTranscript do
|
|||
|
||||
describe "message formatting" do
|
||||
it 'handles code block newlines' do
|
||||
message = DiscourseChat::Provider::SlackProvider::SlackMessage.new(
|
||||
message = DiscourseChatIntegration::Provider::SlackProvider::SlackMessage.new(
|
||||
{
|
||||
"type" => "message",
|
||||
"user" => "U5Z773QLS",
|
||||
|
@ -355,7 +355,7 @@ RSpec.describe DiscourseChat::Provider::SlackProvider::SlackTranscript do
|
|||
end
|
||||
|
||||
it 'handles multiple code blocks' do
|
||||
message = DiscourseChat::Provider::SlackProvider::SlackMessage.new(
|
||||
message = DiscourseChatIntegration::Provider::SlackProvider::SlackMessage.new(
|
||||
{
|
||||
"type" => "message",
|
||||
"user" => "U5Z773QLS",
|
||||
|
@ -378,7 +378,7 @@ RSpec.describe DiscourseChat::Provider::SlackProvider::SlackTranscript do
|
|||
end
|
||||
|
||||
it 'handles strikethrough' do
|
||||
message = DiscourseChat::Provider::SlackProvider::SlackMessage.new(
|
||||
message = DiscourseChatIntegration::Provider::SlackProvider::SlackMessage.new(
|
||||
{
|
||||
"type" => "message",
|
||||
"user" => "U5Z773QLS",
|
||||
|
@ -391,7 +391,7 @@ RSpec.describe DiscourseChat::Provider::SlackProvider::SlackTranscript do
|
|||
end
|
||||
|
||||
it 'handles slack links' do
|
||||
message = DiscourseChat::Provider::SlackProvider::SlackMessage.new(
|
||||
message = DiscourseChatIntegration::Provider::SlackProvider::SlackMessage.new(
|
||||
{
|
||||
"type" => "message",
|
||||
"user" => "U5Z773QLS",
|
||||
|
@ -404,7 +404,7 @@ RSpec.describe DiscourseChat::Provider::SlackProvider::SlackTranscript do
|
|||
end
|
||||
|
||||
it 'does not format things inside backticks' do
|
||||
message = DiscourseChat::Provider::SlackProvider::SlackMessage.new(
|
||||
message = DiscourseChatIntegration::Provider::SlackProvider::SlackMessage.new(
|
||||
{
|
||||
"type" => "message",
|
||||
"user" => "U5Z773QLS",
|
||||
|
@ -418,7 +418,7 @@ RSpec.describe DiscourseChat::Provider::SlackProvider::SlackTranscript do
|
|||
|
||||
it 'unescapes html in backticks' do
|
||||
# Because Slack escapes HTML entities, even in backticks
|
||||
message = DiscourseChat::Provider::SlackProvider::SlackMessage.new(
|
||||
message = DiscourseChatIntegration::Provider::SlackProvider::SlackMessage.new(
|
||||
{
|
||||
"type" => "message",
|
||||
"user" => "U5Z773QLS",
|
||||
|
@ -432,7 +432,7 @@ RSpec.describe DiscourseChat::Provider::SlackProvider::SlackTranscript do
|
|||
|
||||
it 'updates emoji dashes to underscores' do
|
||||
# Discourse does not allow dashes in emoji names, so this helps communities have matching custom emojis
|
||||
message = DiscourseChat::Provider::SlackProvider::SlackMessage.new(
|
||||
message = DiscourseChatIntegration::Provider::SlackProvider::SlackMessage.new(
|
||||
{
|
||||
"type" => "message",
|
||||
"user" => "U5Z773QLS",
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe DiscourseChat::Provider::TeamsProvider do
|
||||
RSpec.describe DiscourseChatIntegration::Provider::TeamsProvider do
|
||||
let(:post) { Fabricate(:post) }
|
||||
|
||||
describe '.trigger_notifications' do
|
||||
|
@ -10,7 +10,7 @@ RSpec.describe DiscourseChat::Provider::TeamsProvider do
|
|||
SiteSetting.chat_integration_teams_enabled = true
|
||||
end
|
||||
|
||||
let(:chan1) { DiscourseChat::Channel.create!(provider: 'teams', data: { name: 'discourse', webhook_url: 'https://outlook.office.com/webhook/677980e4-e03b-4a5e-ad29-dc1ee0c32a80@9e9b5238-5ab2-496a-8e6a-e9cf05c7eb5c/IncomingWebhook/e7a1006ded44478992769d0c4f391e34/e028ca8a-e9c8-4c6c-a4d8-578f881a3cff' }) }
|
||||
let(:chan1) { DiscourseChatIntegration::Channel.create!(provider: 'teams', data: { name: 'discourse', webhook_url: 'https://outlook.office.com/webhook/677980e4-e03b-4a5e-ad29-dc1ee0c32a80@9e9b5238-5ab2-496a-8e6a-e9cf05c7eb5c/IncomingWebhook/e7a1006ded44478992769d0c4f391e34/e028ca8a-e9c8-4c6c-a4d8-578f881a3cff' }) }
|
||||
|
||||
it 'sends a webhook request' do
|
||||
stub1 = stub_request(:post, chan1.data['webhook_url']).to_return(body: "1")
|
||||
|
@ -21,7 +21,7 @@ RSpec.describe DiscourseChat::Provider::TeamsProvider do
|
|||
it 'handles errors correctly' do
|
||||
stub1 = stub_request(:post, chan1.data['webhook_url']).to_return(status: 400, body: "{}")
|
||||
expect(stub1).to have_been_requested.times(0)
|
||||
expect { described_class.trigger_notification(post, chan1, nil) }.to raise_exception(::DiscourseChat::ProviderError)
|
||||
expect { described_class.trigger_notification(post, chan1, nil) }.to raise_exception(::DiscourseChatIntegration::ProviderError)
|
||||
expect(stub1).to have_been_requested.once
|
||||
end
|
||||
|
|
@ -4,7 +4,7 @@ require 'rails_helper'
|
|||
|
||||
describe 'Telegram Command Controller', type: :request do
|
||||
let(:category) { Fabricate(:category) }
|
||||
let!(:chan1) { DiscourseChat::Channel.create!(provider: 'telegram', data: { name: 'Amazing Channel', chat_id: '123' }) }
|
||||
let!(:chan1) { DiscourseChatIntegration::Channel.create!(provider: 'telegram', data: { name: 'Amazing Channel', chat_id: '123' }) }
|
||||
let!(:webhook_stub) { stub_request(:post, 'https://api.telegram.org/botTOKEN/setWebhook').to_return(body: "{\"ok\":true}") }
|
||||
|
||||
describe 'with plugin disabled' do
|
||||
|
@ -86,7 +86,7 @@ describe 'Telegram Command Controller', type: :request do
|
|||
expect(response.status).to eq(200)
|
||||
expect(stub).to have_been_requested.once
|
||||
|
||||
rule = DiscourseChat::Rule.all.first
|
||||
rule = DiscourseChatIntegration::Rule.all.first
|
||||
expect(rule.channel).to eq(chan1)
|
||||
expect(rule.filter).to eq('watch')
|
||||
expect(rule.category_id).to eq(category.id)
|
||||
|
@ -101,7 +101,7 @@ describe 'Telegram Command Controller', type: :request do
|
|||
expect(response.status).to eq(200)
|
||||
expect(stub).to have_been_requested.once
|
||||
|
||||
rule = DiscourseChat::Rule.all.first
|
||||
rule = DiscourseChatIntegration::Rule.all.first
|
||||
expect(rule.channel).to eq(chan1)
|
||||
expect(rule.filter).to eq('watch')
|
||||
expect(rule.category_id).to eq(category.id)
|
||||
|
@ -114,8 +114,8 @@ describe 'Telegram Command Controller', type: :request do
|
|||
message: { chat: { id: 456 }, text: "/watch #{category.slug}" }
|
||||
}
|
||||
|
||||
expect(DiscourseChat::Rule.all.size).to eq(0)
|
||||
expect(DiscourseChat::Channel.all.size).to eq(1)
|
||||
expect(DiscourseChatIntegration::Rule.all.size).to eq(0)
|
||||
expect(DiscourseChatIntegration::Channel.all.size).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe DiscourseChat::Provider::TelegramProvider do
|
||||
RSpec.describe DiscourseChatIntegration::Provider::TelegramProvider do
|
||||
let(:post) { Fabricate(:post) }
|
||||
let!(:webhook_stub) { stub_request(:post, 'https://api.telegram.org/botTOKEN/setWebhook').to_return(body: "{\"ok\":true}") }
|
||||
|
||||
|
@ -13,7 +13,7 @@ RSpec.describe DiscourseChat::Provider::TelegramProvider do
|
|||
SiteSetting.chat_integration_telegram_secret = 'shhh'
|
||||
end
|
||||
|
||||
let(:chan1) { DiscourseChat::Channel.create!(provider: 'telegram', data: { name: "Awesome Channel", chat_id: '123' }) }
|
||||
let(:chan1) { DiscourseChatIntegration::Channel.create!(provider: 'telegram', data: { name: "Awesome Channel", chat_id: '123' }) }
|
||||
|
||||
it 'sends a webhook request' do
|
||||
stub1 = stub_request(:post, 'https://api.telegram.org/botTOKEN/sendMessage').to_return(body: "{\"ok\":true}")
|
||||
|
@ -24,7 +24,7 @@ RSpec.describe DiscourseChat::Provider::TelegramProvider do
|
|||
it 'handles errors correctly' do
|
||||
stub1 = stub_request(:post, 'https://api.telegram.org/botTOKEN/sendMessage').to_return(body: "{\"ok\":false, \"description\":\"chat not found\"}")
|
||||
expect(stub1).to have_been_requested.times(0)
|
||||
expect { described_class.trigger_notification(post, chan1, nil) }.to raise_exception(::DiscourseChat::ProviderError)
|
||||
expect { described_class.trigger_notification(post, chan1, nil) }.to raise_exception(::DiscourseChatIntegration::ProviderError)
|
||||
expect(stub1).to have_been_requested.once
|
||||
end
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe DiscourseChat::Provider::WebexProvider do
|
||||
RSpec.describe DiscourseChatIntegration::Provider::WebexProvider do
|
||||
let(:post) { Fabricate(:post) }
|
||||
|
||||
describe '.trigger_notifications' do
|
||||
|
@ -10,7 +10,7 @@ RSpec.describe DiscourseChat::Provider::WebexProvider do
|
|||
SiteSetting.chat_integration_webex_enabled = true
|
||||
end
|
||||
|
||||
let(:chan1) { DiscourseChat::Channel.create!(provider: 'webex', data: { name: 'discourse', webhook_url: 'https://webexapis.com/v1/webhooks/incoming/jAHJjVVQ1cgEwb4ikQQawIrGdUtlocKA9fSNvIyADQoYo0mI70pztWUDOu22gDRPJOEJtCsc688zi1RMa' }) }
|
||||
let(:chan1) { DiscourseChatIntegration::Channel.create!(provider: 'webex', data: { name: 'discourse', webhook_url: 'https://webexapis.com/v1/webhooks/incoming/jAHJjVVQ1cgEwb4ikQQawIrGdUtlocKA9fSNvIyADQoYo0mI70pztWUDOu22gDRPJOEJtCsc688zi1RMa' }) }
|
||||
|
||||
it 'sends a webhook request' do
|
||||
stub1 = stub_request(:post, chan1.data['webhook_url']).to_return(body: "1")
|
||||
|
@ -21,7 +21,7 @@ RSpec.describe DiscourseChat::Provider::WebexProvider do
|
|||
it 'handles errors correctly' do
|
||||
stub1 = stub_request(:post, chan1.data['webhook_url']).to_return(status: 400, body: "{}")
|
||||
expect(stub1).to have_been_requested.times(0)
|
||||
expect { described_class.trigger_notification(post, chan1, nil) }.to raise_exception(::DiscourseChat::ProviderError)
|
||||
expect { described_class.trigger_notification(post, chan1, nil) }.to raise_exception(::DiscourseChatIntegration::ProviderError)
|
||||
expect(stub1).to have_been_requested.once
|
||||
end
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe DiscourseChat::Provider::ZulipProvider do
|
||||
RSpec.describe DiscourseChatIntegration::Provider::ZulipProvider do
|
||||
let(:post) { Fabricate(:post) }
|
||||
|
||||
describe '.trigger_notifications' do
|
||||
|
@ -13,7 +13,7 @@ RSpec.describe DiscourseChat::Provider::ZulipProvider do
|
|||
SiteSetting.chat_integration_zulip_bot_api_key = "secret"
|
||||
end
|
||||
|
||||
let(:chan1) { DiscourseChat::Channel.create!(provider: 'zulip', data: { stream: "general", subject: "Discourse Notifications" }) }
|
||||
let(:chan1) { DiscourseChatIntegration::Channel.create!(provider: 'zulip', data: { stream: "general", subject: "Discourse Notifications" }) }
|
||||
|
||||
it 'sends a webhook request' do
|
||||
stub1 = stub_request(:post, 'https://hello.world/api/v1/messages').to_return(status: 200)
|
||||
|
@ -24,7 +24,7 @@ RSpec.describe DiscourseChat::Provider::ZulipProvider do
|
|||
it 'handles errors correctly' do
|
||||
stub1 = stub_request(:post, 'https://hello.world/api/v1/messages').to_return(status: 400, body: '{}')
|
||||
expect(stub1).to have_been_requested.times(0)
|
||||
expect { described_class.trigger_notification(post, chan1, nil) }.to raise_exception(::DiscourseChat::ProviderError)
|
||||
expect { described_class.trigger_notification(post, chan1, nil) }.to raise_exception(::DiscourseChatIntegration::ProviderError)
|
||||
expect(stub1).to have_been_requested.once
|
||||
end
|
||||
|
|
@ -3,103 +3,103 @@
|
|||
require 'rails_helper'
|
||||
require_relative '../dummy_provider'
|
||||
|
||||
RSpec.describe DiscourseChat::Channel do
|
||||
RSpec.describe DiscourseChatIntegration::Channel do
|
||||
include_context "dummy provider"
|
||||
include_context "validated dummy provider"
|
||||
|
||||
it 'should save and load successfully' do
|
||||
expect(DiscourseChat::Channel.all.length).to eq(0)
|
||||
expect(DiscourseChatIntegration::Channel.all.length).to eq(0)
|
||||
|
||||
chan = DiscourseChat::Channel.create(provider: "dummy")
|
||||
chan = DiscourseChatIntegration::Channel.create(provider: "dummy")
|
||||
|
||||
expect(DiscourseChat::Channel.all.length).to eq(1)
|
||||
expect(DiscourseChatIntegration::Channel.all.length).to eq(1)
|
||||
|
||||
loadedChan = DiscourseChat::Channel.find(chan.id)
|
||||
loadedChan = DiscourseChatIntegration::Channel.find(chan.id)
|
||||
|
||||
expect(loadedChan.provider).to eq('dummy')
|
||||
|
||||
end
|
||||
|
||||
it 'should edit successfully' do
|
||||
channel = DiscourseChat::Channel.create!(provider: "dummy2", data: { val: "hello" })
|
||||
channel = DiscourseChatIntegration::Channel.create!(provider: "dummy2", data: { val: "hello" })
|
||||
expect(channel.valid?).to eq(true)
|
||||
channel.save!
|
||||
end
|
||||
|
||||
it 'can be filtered by provider' do
|
||||
channel1 = DiscourseChat::Channel.create!(provider: 'dummy')
|
||||
channel2 = DiscourseChat::Channel.create!(provider: 'dummy2', data: { val: "blah" })
|
||||
channel3 = DiscourseChat::Channel.create!(provider: 'dummy2', data: { val: "blah2" })
|
||||
channel1 = DiscourseChatIntegration::Channel.create!(provider: 'dummy')
|
||||
channel2 = DiscourseChatIntegration::Channel.create!(provider: 'dummy2', data: { val: "blah" })
|
||||
channel3 = DiscourseChatIntegration::Channel.create!(provider: 'dummy2', data: { val: "blah2" })
|
||||
|
||||
expect(DiscourseChat::Channel.all.length).to eq(3)
|
||||
expect(DiscourseChatIntegration::Channel.all.length).to eq(3)
|
||||
|
||||
expect(DiscourseChat::Channel.with_provider('dummy2').length).to eq(2)
|
||||
expect(DiscourseChat::Channel.with_provider('dummy').length).to eq(1)
|
||||
expect(DiscourseChatIntegration::Channel.with_provider('dummy2').length).to eq(2)
|
||||
expect(DiscourseChatIntegration::Channel.with_provider('dummy').length).to eq(1)
|
||||
end
|
||||
|
||||
it 'can be filtered by data value' do
|
||||
channel2 = DiscourseChat::Channel.create!(provider: 'dummy2', data: { val: "foo" })
|
||||
channel3 = DiscourseChat::Channel.create!(provider: 'dummy2', data: { val: "blah" })
|
||||
channel2 = DiscourseChatIntegration::Channel.create!(provider: 'dummy2', data: { val: "foo" })
|
||||
channel3 = DiscourseChatIntegration::Channel.create!(provider: 'dummy2', data: { val: "blah" })
|
||||
|
||||
expect(DiscourseChat::Channel.all.length).to eq(2)
|
||||
expect(DiscourseChatIntegration::Channel.all.length).to eq(2)
|
||||
|
||||
for_provider = DiscourseChat::Channel.with_provider('dummy2')
|
||||
for_provider = DiscourseChatIntegration::Channel.with_provider('dummy2')
|
||||
expect(for_provider.length).to eq(2)
|
||||
|
||||
expect(DiscourseChat::Channel.with_provider('dummy2').with_data_value('val', 'blah').length).to eq(1)
|
||||
expect(DiscourseChatIntegration::Channel.with_provider('dummy2').with_data_value('val', 'blah').length).to eq(1)
|
||||
end
|
||||
|
||||
it 'can find its own rules' do
|
||||
channel = DiscourseChat::Channel.create(provider: 'dummy')
|
||||
channel = DiscourseChatIntegration::Channel.create(provider: 'dummy')
|
||||
expect(channel.rules.size).to eq(0)
|
||||
DiscourseChat::Rule.create(channel: channel)
|
||||
DiscourseChat::Rule.create(channel: channel)
|
||||
DiscourseChatIntegration::Rule.create(channel: channel)
|
||||
DiscourseChatIntegration::Rule.create(channel: channel)
|
||||
expect(channel.rules.size).to eq(2)
|
||||
end
|
||||
|
||||
it 'destroys its rules on destroy' do
|
||||
channel = DiscourseChat::Channel.create(provider: 'dummy')
|
||||
channel = DiscourseChatIntegration::Channel.create(provider: 'dummy')
|
||||
expect(channel.rules.size).to eq(0)
|
||||
rule1 = DiscourseChat::Rule.create(channel: channel)
|
||||
rule2 = DiscourseChat::Rule.create(channel: channel)
|
||||
rule1 = DiscourseChatIntegration::Rule.create(channel: channel)
|
||||
rule2 = DiscourseChatIntegration::Rule.create(channel: channel)
|
||||
|
||||
expect(DiscourseChat::Rule.with_channel(channel).exists?).to eq(true)
|
||||
expect(DiscourseChatIntegration::Rule.with_channel(channel).exists?).to eq(true)
|
||||
channel.destroy()
|
||||
expect(DiscourseChat::Rule.with_channel(channel).exists?).to eq(false)
|
||||
expect(DiscourseChatIntegration::Rule.with_channel(channel).exists?).to eq(false)
|
||||
end
|
||||
|
||||
describe 'validations' do
|
||||
|
||||
it 'validates provider correctly' do
|
||||
channel = DiscourseChat::Channel.create!(provider: "dummy")
|
||||
channel = DiscourseChatIntegration::Channel.create!(provider: "dummy")
|
||||
expect(channel.valid?).to eq(true)
|
||||
channel.provider = 'somerandomprovider'
|
||||
expect(channel.valid?).to eq(false)
|
||||
end
|
||||
|
||||
it 'succeeds with valid data' do
|
||||
channel2 = DiscourseChat::Channel.new(provider: "dummy2", data: { val: "hello" })
|
||||
channel2 = DiscourseChatIntegration::Channel.new(provider: "dummy2", data: { val: "hello" })
|
||||
expect(channel2.valid?).to eq(true)
|
||||
end
|
||||
|
||||
it 'disallows invalid data' do
|
||||
channel2 = DiscourseChat::Channel.new(provider: "dummy2", data: { val: ' ' })
|
||||
channel2 = DiscourseChatIntegration::Channel.new(provider: "dummy2", data: { val: ' ' })
|
||||
expect(channel2.valid?).to eq(false)
|
||||
end
|
||||
|
||||
it 'disallows unknown keys' do
|
||||
channel2 = DiscourseChat::Channel.new(provider: "dummy2", data: { val: "hello", unknown: "world" })
|
||||
channel2 = DiscourseChatIntegration::Channel.new(provider: "dummy2", data: { val: "hello", unknown: "world" })
|
||||
expect(channel2.valid?).to eq(false)
|
||||
end
|
||||
|
||||
it 'requires all keys' do
|
||||
channel2 = DiscourseChat::Channel.new(provider: "dummy2", data: {})
|
||||
channel2 = DiscourseChatIntegration::Channel.new(provider: "dummy2", data: {})
|
||||
expect(channel2.valid?).to eq(false)
|
||||
end
|
||||
|
||||
it 'disallows duplicate channels' do
|
||||
channel1 = DiscourseChat::Channel.create(provider: "dummy2", data: { val: "hello" })
|
||||
channel2 = DiscourseChat::Channel.new(provider: "dummy2", data: { val: "hello" })
|
||||
channel1 = DiscourseChatIntegration::Channel.create(provider: "dummy2", data: { val: "hello" })
|
||||
channel2 = DiscourseChatIntegration::Channel.new(provider: "dummy2", data: { val: "hello" })
|
||||
expect(channel2.valid?).to eq(false)
|
||||
channel2.data[:val] = "hello2"
|
||||
expect(channel2.valid?).to eq(true)
|
||||
|
|
|
@ -3,41 +3,41 @@
|
|||
require 'rails_helper'
|
||||
require_relative '../dummy_provider'
|
||||
|
||||
RSpec.describe DiscourseChat::Rule do
|
||||
RSpec.describe DiscourseChatIntegration::Rule do
|
||||
include_context "dummy provider"
|
||||
|
||||
let(:tag1) { Fabricate(:tag) }
|
||||
let(:tag2) { Fabricate(:tag) }
|
||||
|
||||
let(:channel) { DiscourseChat::Channel.create(provider: 'dummy') }
|
||||
let(:channel) { DiscourseChatIntegration::Channel.create(provider: 'dummy') }
|
||||
let(:category) { Fabricate(:category) }
|
||||
let(:group) { Fabricate(:group) }
|
||||
|
||||
describe '.alloc_key' do
|
||||
it 'should return sequential numbers' do
|
||||
expect(DiscourseChat::Rule.create(channel: channel).key).to eq("rule:1")
|
||||
expect(DiscourseChat::Rule.create(channel: channel).key).to eq("rule:2")
|
||||
expect(DiscourseChat::Rule.create(channel: channel).key).to eq("rule:3")
|
||||
expect(DiscourseChatIntegration::Rule.create(channel: channel).key).to eq("rule:1")
|
||||
expect(DiscourseChatIntegration::Rule.create(channel: channel).key).to eq("rule:2")
|
||||
expect(DiscourseChatIntegration::Rule.create(channel: channel).key).to eq("rule:3")
|
||||
end
|
||||
end
|
||||
|
||||
it 'should convert between channel and channel_id successfully' do
|
||||
rule = DiscourseChat::Rule.create(channel: channel)
|
||||
rule = DiscourseChatIntegration::Rule.create(channel: channel)
|
||||
expect(rule.channel_id).to eq(channel.id)
|
||||
expect(rule.channel.id).to eq(channel.id)
|
||||
end
|
||||
|
||||
it 'should save and load successfully' do
|
||||
expect(DiscourseChat::Rule.all.length).to eq(0)
|
||||
expect(DiscourseChatIntegration::Rule.all.length).to eq(0)
|
||||
|
||||
rule = DiscourseChat::Rule.create(channel: channel,
|
||||
category_id: category.id,
|
||||
tags: [tag1.name, tag2.name],
|
||||
filter: 'watch')
|
||||
rule = DiscourseChatIntegration::Rule.create(channel: channel,
|
||||
category_id: category.id,
|
||||
tags: [tag1.name, tag2.name],
|
||||
filter: 'watch')
|
||||
|
||||
expect(DiscourseChat::Rule.all.length).to eq(1)
|
||||
expect(DiscourseChatIntegration::Rule.all.length).to eq(1)
|
||||
|
||||
loadedRule = DiscourseChat::Rule.find(rule.id)
|
||||
loadedRule = DiscourseChatIntegration::Rule.find(rule.id)
|
||||
|
||||
expect(loadedRule.channel.id).to eq(channel.id)
|
||||
expect(loadedRule.category_id).to eq(category.id)
|
||||
|
@ -48,114 +48,114 @@ RSpec.describe DiscourseChat::Rule do
|
|||
|
||||
describe 'general operations' do
|
||||
before do
|
||||
rule = DiscourseChat::Rule.create(channel: channel,
|
||||
category_id: category.id,
|
||||
tags: [tag1.name, tag2.name])
|
||||
rule = DiscourseChatIntegration::Rule.create(channel: channel,
|
||||
category_id: category.id,
|
||||
tags: [tag1.name, tag2.name])
|
||||
end
|
||||
|
||||
it 'can be modified' do
|
||||
rule = DiscourseChat::Rule.all.first
|
||||
rule = DiscourseChatIntegration::Rule.all.first
|
||||
rule.tags = [tag1.name]
|
||||
|
||||
rule.save!
|
||||
|
||||
rule = DiscourseChat::Rule.all.first
|
||||
rule = DiscourseChatIntegration::Rule.all.first
|
||||
expect(rule.tags).to contain_exactly(tag1.name)
|
||||
end
|
||||
|
||||
it 'can be deleted' do
|
||||
DiscourseChat::Rule.new(channel: channel).save!
|
||||
expect(DiscourseChat::Rule.all.length).to eq(2)
|
||||
DiscourseChatIntegration::Rule.new(channel: channel).save!
|
||||
expect(DiscourseChatIntegration::Rule.all.length).to eq(2)
|
||||
|
||||
rule = DiscourseChat::Rule.all.first
|
||||
rule = DiscourseChatIntegration::Rule.all.first
|
||||
rule.destroy
|
||||
|
||||
expect(DiscourseChat::Rule.all.length).to eq(1)
|
||||
expect(DiscourseChatIntegration::Rule.all.length).to eq(1)
|
||||
end
|
||||
|
||||
it 'can delete all' do
|
||||
DiscourseChat::Rule.create(channel: channel)
|
||||
DiscourseChat::Rule.create(channel: channel)
|
||||
DiscourseChat::Rule.create(channel: channel)
|
||||
DiscourseChat::Rule.create(channel: channel)
|
||||
DiscourseChatIntegration::Rule.create(channel: channel)
|
||||
DiscourseChatIntegration::Rule.create(channel: channel)
|
||||
DiscourseChatIntegration::Rule.create(channel: channel)
|
||||
DiscourseChatIntegration::Rule.create(channel: channel)
|
||||
|
||||
expect(DiscourseChat::Rule.all.length).to eq(5)
|
||||
expect(DiscourseChatIntegration::Rule.all.length).to eq(5)
|
||||
|
||||
DiscourseChat::Rule.destroy_all
|
||||
DiscourseChatIntegration::Rule.destroy_all
|
||||
|
||||
expect(DiscourseChat::Rule.all.length).to eq(0)
|
||||
expect(DiscourseChatIntegration::Rule.all.length).to eq(0)
|
||||
end
|
||||
|
||||
it 'can be filtered by channel' do
|
||||
channel2 = DiscourseChat::Channel.create(provider: 'dummy')
|
||||
channel3 = DiscourseChat::Channel.create(provider: 'dummy')
|
||||
channel2 = DiscourseChatIntegration::Channel.create(provider: 'dummy')
|
||||
channel3 = DiscourseChatIntegration::Channel.create(provider: 'dummy')
|
||||
|
||||
rule2 = DiscourseChat::Rule.create(channel: channel)
|
||||
rule3 = DiscourseChat::Rule.create(channel: channel)
|
||||
rule4 = DiscourseChat::Rule.create(channel: channel2)
|
||||
rule5 = DiscourseChat::Rule.create(channel: channel3)
|
||||
rule2 = DiscourseChatIntegration::Rule.create(channel: channel)
|
||||
rule3 = DiscourseChatIntegration::Rule.create(channel: channel)
|
||||
rule4 = DiscourseChatIntegration::Rule.create(channel: channel2)
|
||||
rule5 = DiscourseChatIntegration::Rule.create(channel: channel3)
|
||||
|
||||
expect(DiscourseChat::Rule.all.length).to eq(5)
|
||||
expect(DiscourseChatIntegration::Rule.all.length).to eq(5)
|
||||
|
||||
expect(DiscourseChat::Rule.with_channel(channel).length).to eq(3)
|
||||
expect(DiscourseChat::Rule.with_channel(channel2).length).to eq(1)
|
||||
expect(DiscourseChatIntegration::Rule.with_channel(channel).length).to eq(3)
|
||||
expect(DiscourseChatIntegration::Rule.with_channel(channel2).length).to eq(1)
|
||||
end
|
||||
|
||||
it 'can be filtered by category' do
|
||||
rule2 = DiscourseChat::Rule.create(channel: channel, category_id: category.id)
|
||||
rule3 = DiscourseChat::Rule.create(channel: channel, category_id: nil)
|
||||
rule2 = DiscourseChatIntegration::Rule.create(channel: channel, category_id: category.id)
|
||||
rule3 = DiscourseChatIntegration::Rule.create(channel: channel, category_id: nil)
|
||||
|
||||
expect(DiscourseChat::Rule.all.length).to eq(3)
|
||||
expect(DiscourseChatIntegration::Rule.all.length).to eq(3)
|
||||
|
||||
expect(DiscourseChat::Rule.with_category_id(category.id).length).to eq(2)
|
||||
expect(DiscourseChat::Rule.with_category_id(nil).length).to eq(1)
|
||||
expect(DiscourseChatIntegration::Rule.with_category_id(category.id).length).to eq(2)
|
||||
expect(DiscourseChatIntegration::Rule.with_category_id(nil).length).to eq(1)
|
||||
end
|
||||
|
||||
it 'can be filtered by group' do
|
||||
group1 = Fabricate(:group)
|
||||
group2 = Fabricate(:group)
|
||||
rule2 = DiscourseChat::Rule.create!(channel: channel, type: 'group_message', group_id: group1.id)
|
||||
rule3 = DiscourseChat::Rule.create!(channel: channel, type: 'group_message', group_id: group2.id)
|
||||
rule2 = DiscourseChatIntegration::Rule.create!(channel: channel, type: 'group_message', group_id: group1.id)
|
||||
rule3 = DiscourseChatIntegration::Rule.create!(channel: channel, type: 'group_message', group_id: group2.id)
|
||||
|
||||
expect(DiscourseChat::Rule.all.length).to eq(3)
|
||||
expect(DiscourseChatIntegration::Rule.all.length).to eq(3)
|
||||
|
||||
expect(DiscourseChat::Rule.with_category_id(category.id).length).to eq(1)
|
||||
expect(DiscourseChat::Rule.with_group_ids([group1.id, group2.id]).length).to eq(2)
|
||||
expect(DiscourseChat::Rule.with_group_ids([group1.id]).length).to eq(1)
|
||||
expect(DiscourseChat::Rule.with_group_ids([group2.id]).length).to eq(1)
|
||||
expect(DiscourseChatIntegration::Rule.with_category_id(category.id).length).to eq(1)
|
||||
expect(DiscourseChatIntegration::Rule.with_group_ids([group1.id, group2.id]).length).to eq(2)
|
||||
expect(DiscourseChatIntegration::Rule.with_group_ids([group1.id]).length).to eq(1)
|
||||
expect(DiscourseChatIntegration::Rule.with_group_ids([group2.id]).length).to eq(1)
|
||||
end
|
||||
|
||||
it 'can be filtered by type' do
|
||||
group1 = Fabricate(:group)
|
||||
|
||||
rule2 = DiscourseChat::Rule.create!(channel: channel, type: 'group_message', group_id: group1.id)
|
||||
rule3 = DiscourseChat::Rule.create!(channel: channel, type: 'group_mention', group_id: group1.id)
|
||||
rule2 = DiscourseChatIntegration::Rule.create!(channel: channel, type: 'group_message', group_id: group1.id)
|
||||
rule3 = DiscourseChatIntegration::Rule.create!(channel: channel, type: 'group_mention', group_id: group1.id)
|
||||
|
||||
expect(DiscourseChat::Rule.all.length).to eq(3)
|
||||
expect(DiscourseChatIntegration::Rule.all.length).to eq(3)
|
||||
|
||||
expect(DiscourseChat::Rule.with_type('group_message').length).to eq(1)
|
||||
expect(DiscourseChat::Rule.with_type('group_mention').length).to eq(1)
|
||||
expect(DiscourseChat::Rule.with_type('normal').length).to eq(1)
|
||||
expect(DiscourseChatIntegration::Rule.with_type('group_message').length).to eq(1)
|
||||
expect(DiscourseChatIntegration::Rule.with_type('group_mention').length).to eq(1)
|
||||
expect(DiscourseChatIntegration::Rule.with_type('normal').length).to eq(1)
|
||||
end
|
||||
|
||||
it 'can be sorted by precedence' do
|
||||
rule2 = DiscourseChat::Rule.create(channel: channel, filter: 'mute')
|
||||
rule3 = DiscourseChat::Rule.create(channel: channel, filter: 'follow')
|
||||
rule4 = DiscourseChat::Rule.create(channel: channel, filter: 'thread')
|
||||
rule5 = DiscourseChat::Rule.create(channel: channel, filter: 'mute')
|
||||
rule2 = DiscourseChatIntegration::Rule.create(channel: channel, filter: 'mute')
|
||||
rule3 = DiscourseChatIntegration::Rule.create(channel: channel, filter: 'follow')
|
||||
rule4 = DiscourseChatIntegration::Rule.create(channel: channel, filter: 'thread')
|
||||
rule5 = DiscourseChatIntegration::Rule.create(channel: channel, filter: 'mute')
|
||||
|
||||
expect(DiscourseChat::Rule.all.length).to eq(5)
|
||||
expect(DiscourseChatIntegration::Rule.all.length).to eq(5)
|
||||
|
||||
expect(DiscourseChat::Rule.all.order_by_precedence.map(&:filter)).to eq(["mute", "mute", "thread", "watch", "follow"])
|
||||
expect(DiscourseChatIntegration::Rule.all.order_by_precedence.map(&:filter)).to eq(["mute", "mute", "thread", "watch", "follow"])
|
||||
end
|
||||
end
|
||||
|
||||
describe 'validations' do
|
||||
|
||||
let(:rule) do
|
||||
DiscourseChat::Rule.create(filter: 'watch',
|
||||
channel: channel,
|
||||
category_id: category.id)
|
||||
DiscourseChatIntegration::Rule.create(filter: 'watch',
|
||||
channel: channel,
|
||||
category_id: category.id)
|
||||
end
|
||||
|
||||
it 'validates channel correctly' do
|
||||
|
|
|
@ -10,7 +10,7 @@ describe 'Chat Controller', type: :request do
|
|||
let(:category) { Fabricate(:category) }
|
||||
let(:category2) { Fabricate(:category) }
|
||||
let(:tag) { Fabricate(:tag) }
|
||||
let(:channel) { DiscourseChat::Channel.create(provider: 'dummy') }
|
||||
let(:channel) { DiscourseChatIntegration::Channel.create(provider: 'dummy') }
|
||||
|
||||
include_context "dummy provider"
|
||||
include_context "validated dummy provider"
|
||||
|
@ -97,7 +97,7 @@ describe 'Chat Controller', type: :request do
|
|||
end
|
||||
|
||||
it 'should return the right response' do
|
||||
rule = DiscourseChat::Rule.create(
|
||||
rule = DiscourseChatIntegration::Rule.create(
|
||||
channel: channel,
|
||||
filter: 'follow',
|
||||
category_id: category.id,
|
||||
|
@ -149,7 +149,7 @@ describe 'Chat Controller', type: :request do
|
|||
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
channel = DiscourseChat::Channel.all.last
|
||||
channel = DiscourseChatIntegration::Channel.all.last
|
||||
|
||||
expect(channel.provider).to eq('dummy')
|
||||
end
|
||||
|
@ -168,7 +168,7 @@ describe 'Chat Controller', type: :request do
|
|||
end
|
||||
|
||||
describe 'updating a channel' do
|
||||
let(:channel) { DiscourseChat::Channel.create(provider: 'dummy2', data: { val: "something" }) }
|
||||
let(:channel) { DiscourseChatIntegration::Channel.create(provider: 'dummy2', data: { val: "something" }) }
|
||||
|
||||
include_examples 'admin constraints', 'put', "/admin/plugins/chat/channels/1.json"
|
||||
|
||||
|
@ -187,7 +187,7 @@ describe 'Chat Controller', type: :request do
|
|||
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
channel = DiscourseChat::Channel.all.last
|
||||
channel = DiscourseChatIntegration::Channel.all.last
|
||||
expect(channel.data).to eq("val" => "something-else")
|
||||
end
|
||||
|
||||
|
@ -204,7 +204,7 @@ describe 'Chat Controller', type: :request do
|
|||
end
|
||||
|
||||
describe 'deleting a channel' do
|
||||
let(:channel) { DiscourseChat::Channel.create(provider: 'dummy', data: {}) }
|
||||
let(:channel) { DiscourseChatIntegration::Channel.create(provider: 'dummy', data: {}) }
|
||||
|
||||
include_examples 'admin constraints', 'delete', "/admin/plugins/chat/channels/1.json"
|
||||
|
||||
|
@ -218,7 +218,7 @@ describe 'Chat Controller', type: :request do
|
|||
delete "/admin/plugins/chat/channels/#{channel.id}.json"
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
expect(DiscourseChat::Channel.all.size).to eq(0)
|
||||
expect(DiscourseChatIntegration::Channel.all.size).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -244,7 +244,7 @@ describe 'Chat Controller', type: :request do
|
|||
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
rule = DiscourseChat::Rule.all.last
|
||||
rule = DiscourseChatIntegration::Rule.all.last
|
||||
|
||||
expect(rule.channel_id).to eq(channel.id)
|
||||
expect(rule.category_id).to eq(category.id)
|
||||
|
@ -269,7 +269,7 @@ describe 'Chat Controller', type: :request do
|
|||
end
|
||||
|
||||
describe 'updating a rule' do
|
||||
let(:rule) { DiscourseChat::Rule.create(channel: channel, filter: 'follow', category_id: category.id, tags: [tag.name]) }
|
||||
let(:rule) { DiscourseChatIntegration::Rule.create(channel: channel, filter: 'follow', category_id: category.id, tags: [tag.name]) }
|
||||
|
||||
include_examples 'admin constraints', 'put', "/admin/plugins/chat/rules/1.json"
|
||||
|
||||
|
@ -291,7 +291,7 @@ describe 'Chat Controller', type: :request do
|
|||
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
rule = DiscourseChat::Rule.all.last
|
||||
rule = DiscourseChatIntegration::Rule.all.last
|
||||
expect(rule.category_id).to eq(category2.id)
|
||||
end
|
||||
|
||||
|
@ -312,7 +312,7 @@ describe 'Chat Controller', type: :request do
|
|||
|
||||
describe 'deleting a rule' do
|
||||
let(:rule) do
|
||||
DiscourseChat::Rule.create!(
|
||||
DiscourseChatIntegration::Rule.create!(
|
||||
channel_id: channel.id,
|
||||
filter: 'follow',
|
||||
category_id: category.id,
|
||||
|
@ -332,7 +332,7 @@ describe 'Chat Controller', type: :request do
|
|||
delete "/admin/plugins/chat/rules/#{rule.id}.json"
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
expect(DiscourseChat::Rule.all.size).to eq(0)
|
||||
expect(DiscourseChatIntegration::Rule.all.size).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ describe 'Public Controller', type: :request do
|
|||
describe 'loading a transcript' do
|
||||
|
||||
it 'should be able to load a transcript' do
|
||||
key = DiscourseChat::Helper.save_transcript("Some content here")
|
||||
key = DiscourseChatIntegration::Helper.save_transcript("Some content here")
|
||||
|
||||
get "/chat-transcript/#{key}.json"
|
||||
|
||||
|
|
|
@ -4,9 +4,9 @@ require 'rails_helper'
|
|||
require_dependency 'post_creator'
|
||||
require_relative '../dummy_provider'
|
||||
|
||||
RSpec.describe DiscourseChat::Manager do
|
||||
RSpec.describe DiscourseChatIntegration::Manager do
|
||||
|
||||
let(:manager) { ::DiscourseChat::Manager }
|
||||
let(:manager) { ::DiscourseChatIntegration::Manager }
|
||||
let(:category) { Fabricate(:category) }
|
||||
let(:group) { Fabricate(:group) }
|
||||
let(:group2) { Fabricate(:group) }
|
||||
|
@ -17,38 +17,38 @@ RSpec.describe DiscourseChat::Manager do
|
|||
describe '.trigger_notifications' do
|
||||
include_context "dummy provider"
|
||||
|
||||
let(:chan1) { DiscourseChat::Channel.create!(provider: 'dummy') }
|
||||
let(:chan2) { DiscourseChat::Channel.create!(provider: 'dummy') }
|
||||
let(:chan3) { DiscourseChat::Channel.create!(provider: 'dummy') }
|
||||
let(:chan1) { DiscourseChatIntegration::Channel.create!(provider: 'dummy') }
|
||||
let(:chan2) { DiscourseChatIntegration::Channel.create!(provider: 'dummy') }
|
||||
let(:chan3) { DiscourseChatIntegration::Channel.create!(provider: 'dummy') }
|
||||
|
||||
before do
|
||||
SiteSetting.chat_integration_enabled = true
|
||||
end
|
||||
|
||||
it "should fail gracefully when a provider throws an exception" do
|
||||
DiscourseChat::Rule.create!(channel: chan1, filter: 'watch', category_id: category.id)
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan1, filter: 'watch', category_id: category.id)
|
||||
|
||||
# Triggering a ProviderError should set the error_key to the error message
|
||||
provider.set_raise_exception(DiscourseChat::ProviderError.new info: { error_key: "hello" })
|
||||
provider.set_raise_exception(DiscourseChatIntegration::ProviderError.new info: { error_key: "hello" })
|
||||
manager.trigger_notifications(first_post.id)
|
||||
expect(provider.sent_to_channel_ids).to contain_exactly()
|
||||
expect(DiscourseChat::Channel.all.first.error_key).to eq('hello')
|
||||
expect(DiscourseChatIntegration::Channel.all.first.error_key).to eq('hello')
|
||||
|
||||
# Triggering a different error should set the error_key to a generic message
|
||||
provider.set_raise_exception(StandardError.new "hello")
|
||||
manager.trigger_notifications(first_post.id)
|
||||
expect(provider.sent_to_channel_ids).to contain_exactly()
|
||||
expect(DiscourseChat::Channel.all.first.error_key).to eq('chat_integration.channel_exception')
|
||||
expect(DiscourseChatIntegration::Channel.all.first.error_key).to eq('chat_integration.channel_exception')
|
||||
|
||||
provider.set_raise_exception(nil)
|
||||
|
||||
manager.trigger_notifications(first_post.id)
|
||||
expect(DiscourseChat::Channel.all.first.error_key.nil?).to be true
|
||||
expect(DiscourseChatIntegration::Channel.all.first.error_key.nil?).to be true
|
||||
end
|
||||
|
||||
it "should not send notifications when provider is disabled" do
|
||||
SiteSetting.chat_integration_enabled = false
|
||||
DiscourseChat::Rule.create!(channel: chan1, filter: 'watch', category_id: category.id)
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan1, filter: 'watch', category_id: category.id)
|
||||
|
||||
manager.trigger_notifications(first_post.id)
|
||||
|
||||
|
@ -56,9 +56,9 @@ RSpec.describe DiscourseChat::Manager do
|
|||
end
|
||||
|
||||
it "should send a notification to watched and following channels for new topic" do
|
||||
DiscourseChat::Rule.create!(channel: chan1, filter: 'watch', category_id: category.id)
|
||||
DiscourseChat::Rule.create!(channel: chan2, filter: 'follow', category_id: category.id)
|
||||
DiscourseChat::Rule.create!(channel: chan3, filter: 'mute', category_id: category.id)
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan1, filter: 'watch', category_id: category.id)
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan2, filter: 'follow', category_id: category.id)
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan3, filter: 'mute', category_id: category.id)
|
||||
|
||||
manager.trigger_notifications(first_post.id)
|
||||
|
||||
|
@ -66,9 +66,9 @@ RSpec.describe DiscourseChat::Manager do
|
|||
end
|
||||
|
||||
it "should send a notification only to watched for reply" do
|
||||
DiscourseChat::Rule.create!(channel: chan1, filter: 'watch', category_id: category.id)
|
||||
DiscourseChat::Rule.create!(channel: chan2, filter: 'follow', category_id: category.id)
|
||||
DiscourseChat::Rule.create!(channel: chan3, filter: 'mute', category_id: category.id)
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan1, filter: 'watch', category_id: category.id)
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan2, filter: 'follow', category_id: category.id)
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan3, filter: 'mute', category_id: category.id)
|
||||
|
||||
manager.trigger_notifications(second_post.id)
|
||||
|
||||
|
@ -76,7 +76,7 @@ RSpec.describe DiscourseChat::Manager do
|
|||
end
|
||||
|
||||
it "should respect wildcard category settings" do
|
||||
DiscourseChat::Rule.create!(channel: chan1, filter: 'watch', category_id: nil)
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan1, filter: 'watch', category_id: nil)
|
||||
|
||||
manager.trigger_notifications(first_post.id)
|
||||
|
||||
|
@ -84,8 +84,8 @@ RSpec.describe DiscourseChat::Manager do
|
|||
end
|
||||
|
||||
it "should respect mute over watch" do
|
||||
DiscourseChat::Rule.create!(channel: chan1, filter: 'watch', category_id: nil) # Wildcard watch
|
||||
DiscourseChat::Rule.create!(channel: chan1, filter: 'mute', category_id: category.id) # Specific mute
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan1, filter: 'watch', category_id: nil) # Wildcard watch
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan1, filter: 'mute', category_id: category.id) # Specific mute
|
||||
|
||||
manager.trigger_notifications(first_post.id)
|
||||
|
||||
|
@ -93,8 +93,8 @@ RSpec.describe DiscourseChat::Manager do
|
|||
end
|
||||
|
||||
it "should respect watch over follow" do
|
||||
DiscourseChat::Rule.create!(channel: chan1, filter: 'follow', category_id: nil) # Wildcard follow
|
||||
DiscourseChat::Rule.create!(channel: chan1, filter: 'watch', category_id: category.id) # Specific watch
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan1, filter: 'follow', category_id: nil) # Wildcard follow
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan1, filter: 'watch', category_id: category.id) # Specific watch
|
||||
|
||||
manager.trigger_notifications(second_post.id)
|
||||
|
||||
|
@ -102,8 +102,8 @@ RSpec.describe DiscourseChat::Manager do
|
|||
end
|
||||
|
||||
it "should respect thread over watch" do
|
||||
DiscourseChat::Rule.create!(channel: chan1, filter: 'watch', category_id: nil) # Wildcard watch
|
||||
DiscourseChat::Rule.create!(channel: chan1, filter: 'thread', category_id: category.id) # Specific thread
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan1, filter: 'watch', category_id: nil) # Wildcard watch
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan1, filter: 'thread', category_id: category.id) # Specific thread
|
||||
|
||||
manager.trigger_notifications(second_post.id)
|
||||
|
||||
|
@ -111,7 +111,7 @@ RSpec.describe DiscourseChat::Manager do
|
|||
end
|
||||
|
||||
it "should not notify about private messages" do
|
||||
DiscourseChat::Rule.create!(channel: chan1, filter: 'follow', category_id: nil) # Wildcard watch
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan1, filter: 'follow', category_id: nil) # Wildcard watch
|
||||
|
||||
private_post = Fabricate(:private_message_post)
|
||||
|
||||
|
@ -121,8 +121,8 @@ RSpec.describe DiscourseChat::Manager do
|
|||
end
|
||||
|
||||
it "should work for group pms" do
|
||||
DiscourseChat::Rule.create!(channel: chan1, filter: 'watch') # Wildcard watch
|
||||
DiscourseChat::Rule.create!(channel: chan2, type: 'group_message', filter: 'watch', group_id: group.id) # Group watch
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan1, filter: 'watch') # Wildcard watch
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan2, type: 'group_message', filter: 'watch', group_id: group.id) # Group watch
|
||||
|
||||
private_post = Fabricate(:private_message_post)
|
||||
private_post.topic.invite_group(Fabricate(:user), group)
|
||||
|
@ -133,8 +133,8 @@ RSpec.describe DiscourseChat::Manager do
|
|||
end
|
||||
|
||||
it "should work for pms with multiple groups" do
|
||||
DiscourseChat::Rule.create!(channel: chan1, type: 'group_message', filter: 'watch', group_id: group.id)
|
||||
DiscourseChat::Rule.create!(channel: chan2, type: 'group_message', filter: 'watch', group_id: group2.id)
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan1, type: 'group_message', filter: 'watch', group_id: group.id)
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan2, type: 'group_message', filter: 'watch', group_id: group2.id)
|
||||
|
||||
private_post = Fabricate(:private_message_post)
|
||||
private_post.topic.invite_group(Fabricate(:user), group)
|
||||
|
@ -148,9 +148,9 @@ RSpec.describe DiscourseChat::Manager do
|
|||
it "should work for group mentions" do
|
||||
third_post = Fabricate(:post, topic: topic, post_number: 3, raw: "let's mention @#{group.name}")
|
||||
|
||||
DiscourseChat::Rule.create!(channel: chan1, filter: 'watch') # Wildcard watch
|
||||
DiscourseChat::Rule.create!(channel: chan2, type: 'group_message', filter: 'watch', group_id: group.id)
|
||||
DiscourseChat::Rule.create!(channel: chan3, type: 'group_mention', filter: 'watch', group_id: group.id)
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan1, filter: 'watch') # Wildcard watch
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan2, type: 'group_message', filter: 'watch', group_id: group.id)
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan3, type: 'group_mention', filter: 'watch', group_id: group.id)
|
||||
|
||||
manager.trigger_notifications(third_post.id)
|
||||
expect(provider.sent_to_channel_ids).to contain_exactly(chan1.id, chan3.id)
|
||||
|
@ -159,20 +159,20 @@ RSpec.describe DiscourseChat::Manager do
|
|||
it "should give group rule precedence over normal rules" do
|
||||
third_post = Fabricate(:post, topic: topic, post_number: 3, raw: "let's mention @#{group.name}")
|
||||
|
||||
DiscourseChat::Rule.create!(channel: chan1, filter: 'mute', category_id: category.id) # Mute category
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan1, filter: 'mute', category_id: category.id) # Mute category
|
||||
manager.trigger_notifications(third_post.id)
|
||||
expect(provider.sent_to_channel_ids).to contain_exactly()
|
||||
|
||||
DiscourseChat::Rule.create!(channel: chan1, filter: 'watch', type: 'group_mention', group_id: group.id) # Watch mentions
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan1, filter: 'watch', type: 'group_mention', group_id: group.id) # Watch mentions
|
||||
manager.trigger_notifications(third_post.id)
|
||||
expect(provider.sent_to_channel_ids).to contain_exactly(chan1.id)
|
||||
end
|
||||
|
||||
it "should not notify about mentions in private messages" do
|
||||
# Group 1 watching for messages on channel 1
|
||||
DiscourseChat::Rule.create!(channel: chan1, filter: 'watch', type: 'group_message', group_id: group.id)
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan1, filter: 'watch', type: 'group_message', group_id: group.id)
|
||||
# Group 2 watching for mentions on channel 2
|
||||
DiscourseChat::Rule.create!(channel: chan2, filter: 'watch', type: 'group_mention', group_id: group2.id)
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan2, filter: 'watch', type: 'group_mention', group_id: group2.id)
|
||||
|
||||
# Make a private message only accessible to group 1
|
||||
private_message = Fabricate(:private_message_post)
|
||||
|
@ -187,7 +187,7 @@ RSpec.describe DiscourseChat::Manager do
|
|||
end
|
||||
|
||||
it "should not notify about posts the chat_user cannot see" do
|
||||
DiscourseChat::Rule.create!(channel: chan1, filter: 'follow', category_id: nil) # Wildcard watch
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan1, filter: 'follow', category_id: nil) # Wildcard watch
|
||||
|
||||
# Create a group & user
|
||||
group = Fabricate(:group, name: "friends")
|
||||
|
@ -230,7 +230,7 @@ RSpec.describe DiscourseChat::Manager do
|
|||
end
|
||||
|
||||
it 'should still work for rules without any tags specified' do
|
||||
DiscourseChat::Rule.create!(channel: chan1, filter: 'follow', category_id: nil) # Wildcard watch
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan1, filter: 'follow', category_id: nil) # Wildcard watch
|
||||
|
||||
manager.trigger_notifications(first_post.id)
|
||||
manager.trigger_notifications(tagged_first_post.id)
|
||||
|
@ -239,7 +239,7 @@ RSpec.describe DiscourseChat::Manager do
|
|||
end
|
||||
|
||||
it 'should only match tagged topics when rule has tags' do
|
||||
DiscourseChat::Rule.create!(channel: chan1, filter: 'follow', category_id: category.id, tags: [tag.name])
|
||||
DiscourseChatIntegration::Rule.create!(channel: chan1, filter: 'follow', category_id: category.id, tags: [tag.name])
|
||||
|
||||
manager.trigger_notifications(first_post.id)
|
||||
manager.trigger_notifications(tagged_first_post.id)
|
||||
|
|
Loading…
Reference in New Issue