From a73f5da114d6d7adfac53bdd58b7f45a4e3ac31a Mon Sep 17 00:00:00 2001 From: Mark VanLandingham Date: Tue, 13 Jul 2021 14:36:16 -0500 Subject: [PATCH] Rename DiscourseChat to DiscourseChatIntegration (#82) --- app/controllers/chat_controller.rb | 46 ++-- app/controllers/public_controller.rb | 4 +- app/helpers/helper.rb | 12 +- ..._chat.rb => discourse_chat_integration.rb} | 16 +- app/jobs/onceoff/add_type_field.rb | 2 +- .../onceoff/migrate_from_slack_official.rb | 8 +- app/jobs/regular/notify_chats.rb | 2 +- app/models/channel.rb | 12 +- app/models/plugin_model.rb | 2 +- app/models/rule.rb | 6 +- app/routes/discourse.rb | 8 +- ..._chat.rb => discourse_chat_integration.rb} | 2 +- app/serializers/channel_serializer.rb | 4 +- app/serializers/rule_serializer.rb | 2 +- app/services/manager.rb | 18 +- .../provider.rb | 12 +- .../provider/discord/discord_provider.rb | 4 +- .../provider/flowdock/flowdock_provider.rb | 4 +- .../provider/gitter/gitter_provider.rb | 4 +- .../provider/google/google_provider.rb | 4 +- .../provider/groupme/groupme_provider.rb | 4 +- .../provider/matrix/matrix_provider.rb | 4 +- .../mattermost_command_controller.rb | 18 +- .../mattermost/mattermost_provider.rb | 4 +- .../rocketchat/rocketchat_provider.rb | 4 +- .../slack/slack_command_controller.rb | 22 +- .../slack/slack_enabled_setting_validator.rb | 0 .../provider/slack/slack_message.rb | 2 +- .../provider/slack/slack_message_formatter.rb | 2 +- .../provider/slack/slack_provider.rb | 14 +- .../provider/slack/slack_transcript.rb | 10 +- .../provider/teams/teams_provider.rb | 4 +- .../telegram/telegram_command_controller.rb | 20 +- .../provider/telegram/telegram_initializer.rb | 2 +- .../provider/telegram/telegram_provider.rb | 4 +- .../provider/webex/webex_provider.rb | 10 +- .../provider/zulip/zulip_provider.rb | 4 +- plugin.rb | 8 +- spec/dummy_provider.rb | 10 +- spec/helpers/helper_spec.rb | 200 +++++++++--------- .../migrate_from_slack_official_spec.rb | 22 +- .../provider/discord/discord_provider_spec.rb | 6 +- .../flowdock/flowdock_provider_spec.rb | 6 +- .../provider/gitter/gitter_provider_spec.rb | 6 +- .../provider/google/google_provider_spec.rb | 6 +- .../groupme/groupme_provider_spect.rb | 6 +- .../provider/matrix/matrix_provider_spec.rb | 6 +- .../mattermost_command_controller_spec.rb | 6 +- .../mattermost/mattermost_provider_spec.rb | 6 +- .../rocketchat/rocketchat_provider_spec.rb | 6 +- .../slack/slack_command_controller_spec.rb | 6 +- .../slack/slack_message_formatter_spec.rb | 2 +- .../provider/slack/slack_provider_spec.rb | 14 +- .../provider/slack/slack_transcript_spec.rb | 16 +- .../provider/teams/teams_provider_spec.rb | 6 +- .../telegram_command_controller_spec.rb | 10 +- .../telegram/telegram_provider_spec.rb | 6 +- .../provider/webex/webex_provider_spec.rb | 6 +- .../provider/zulip/zulip_provider_spec.rb | 6 +- spec/models/channel_spec.rb | 64 +++--- spec/models/rule_spec.rb | 130 ++++++------ spec/requests/chat_controller_spec.rb | 24 +-- spec/requests/public_controller_spec.rb | 2 +- spec/services/manager_spec.rb | 78 +++---- 64 files changed, 482 insertions(+), 482 deletions(-) rename app/initializers/{discourse_chat.rb => discourse_chat_integration.rb} (71%) rename app/routes/{discourse_chat.rb => discourse_chat_integration.rb} (95%) rename lib/{discourse_chat => discourse_chat_integration}/provider.rb (88%) rename lib/{discourse_chat => discourse_chat_integration}/provider/discord/discord_provider.rb (96%) rename lib/{discourse_chat => discourse_chat_integration}/provider/flowdock/flowdock_provider.rb (90%) rename lib/{discourse_chat => discourse_chat_integration}/provider/gitter/gitter_provider.rb (86%) rename lib/{discourse_chat => discourse_chat_integration}/provider/google/google_provider.rb (93%) rename lib/{discourse_chat => discourse_chat_integration}/provider/groupme/groupme_provider.rb (95%) rename lib/{discourse_chat => discourse_chat_integration}/provider/matrix/matrix_provider.rb (95%) rename lib/{discourse_chat => discourse_chat_integration}/provider/mattermost/mattermost_command_controller.rb (62%) rename lib/{discourse_chat => discourse_chat_integration}/provider/mattermost/mattermost_provider.rb (93%) rename lib/{discourse_chat => discourse_chat_integration}/provider/rocketchat/rocketchat_provider.rb (91%) rename lib/{discourse_chat => discourse_chat_integration}/provider/slack/slack_command_controller.rb (91%) rename lib/{discourse_chat => discourse_chat_integration}/provider/slack/slack_enabled_setting_validator.rb (100%) rename lib/{discourse_chat => discourse_chat_integration}/provider/slack/slack_message.rb (98%) rename lib/{discourse_chat => discourse_chat_integration}/provider/slack/slack_message_formatter.rb (95%) rename lib/{discourse_chat => discourse_chat_integration}/provider/slack/slack_provider.rb (87%) rename lib/{discourse_chat => discourse_chat_integration}/provider/slack/slack_transcript.rb (96%) rename lib/{discourse_chat => discourse_chat_integration}/provider/teams/teams_provider.rb (89%) rename lib/{discourse_chat => discourse_chat_integration}/provider/telegram/telegram_command_controller.rb (75%) rename lib/{discourse_chat => discourse_chat_integration}/provider/telegram/telegram_initializer.rb (88%) rename lib/{discourse_chat => discourse_chat_integration}/provider/telegram/telegram_provider.rb (95%) rename lib/{discourse_chat => discourse_chat_integration}/provider/webex/webex_provider.rb (81%) rename lib/{discourse_chat => discourse_chat_integration}/provider/zulip/zulip_provider.rb (92%) rename spec/lib/{discourse_chat => discourse_chat_integration}/provider/discord/discord_provider_spec.rb (79%) rename spec/lib/{discourse_chat => discourse_chat_integration}/provider/flowdock/flowdock_provider_spec.rb (73%) rename spec/lib/{discourse_chat => discourse_chat_integration}/provider/gitter/gitter_provider_spec.rb (71%) rename spec/lib/{discourse_chat => discourse_chat_integration}/provider/google/google_provider_spec.rb (71%) rename spec/lib/{discourse_chat => discourse_chat_integration}/provider/groupme/groupme_provider_spect.rb (76%) rename spec/lib/{discourse_chat => discourse_chat_integration}/provider/matrix/matrix_provider_spec.rb (77%) rename spec/lib/{discourse_chat => discourse_chat_integration}/provider/mattermost/mattermost_command_controller_spec.rb (92%) rename spec/lib/{discourse_chat => discourse_chat_integration}/provider/mattermost/mattermost_provider_spec.rb (85%) rename spec/lib/{discourse_chat => discourse_chat_integration}/provider/rocketchat/rocketchat_provider_spec.rb (76%) rename spec/lib/{discourse_chat => discourse_chat_integration}/provider/slack/slack_command_controller_spec.rb (97%) rename spec/lib/{discourse_chat => discourse_chat_integration}/provider/slack/slack_message_formatter_spec.rb (91%) rename spec/lib/{discourse_chat => discourse_chat_integration}/provider/slack/slack_provider_spec.rb (89%) rename spec/lib/{discourse_chat => discourse_chat_integration}/provider/slack/slack_transcript_spec.rb (95%) rename spec/lib/{discourse_chat => discourse_chat_integration}/provider/teams/teams_provider_spec.rb (62%) rename spec/lib/{discourse_chat => discourse_chat_integration}/provider/telegram/telegram_command_controller_spec.rb (91%) rename spec/lib/{discourse_chat => discourse_chat_integration}/provider/telegram/telegram_provider_spec.rb (80%) rename spec/lib/{discourse_chat => discourse_chat_integration}/provider/webex/webex_provider_spec.rb (66%) rename spec/lib/{discourse_chat => discourse_chat_integration}/provider/zulip/zulip_provider_spec.rb (78%) diff --git a/app/controllers/chat_controller.rb b/app/controllers/chat_controller.rb index ca294956..fa1201d7 100644 --- a/app/controllers/chat_controller.rb +++ b/app/controllers/chat_controller.rb @@ -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 @@ def test 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 @@ def test 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 @@ def test 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 @@ def create_channel 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 @@ def create_channel 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 @@ def update_channel 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 @@ def destroy_channel 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 @@ def create_rule 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! diff --git a/app/controllers/public_controller.rb b/app/controllers/public_controller.rb index d5a645d7..1f782141 100644 --- a/app/controllers/public_controller.rb +++ b/app/controllers/public_controller.rb @@ -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) diff --git a/app/helpers/helper.rb b/app/helpers/helper.rb index 3625ffb4..3062df75 100644 --- a/app/helpers/helper.rb +++ b/app/helpers/helper.rb @@ -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 @@ def self.process_command(channel, tokens) 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 @@ def self.process_command(channel, tokens) 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 @@ def self.delete_by_index(channel, index) # :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 } diff --git a/app/initializers/discourse_chat.rb b/app/initializers/discourse_chat_integration.rb similarity index 71% rename from app/initializers/discourse_chat.rb rename to app/initializers/discourse_chat_integration.rb index ec173fcc..eb1056e3 100644 --- a/app/initializers/discourse_chat.rb +++ b/app/initializers/discourse_chat_integration.rb @@ -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 @@ def self.pstore_delete(key) 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 @@ def self.pstore_delete(key) 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" diff --git a/app/jobs/onceoff/add_type_field.rb b/app/jobs/onceoff/add_type_field.rb index c6969b6d..a66e3d15 100644 --- a/app/jobs/onceoff/add_type_field.rb +++ b/app/jobs/onceoff/add_type_field.rb @@ -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 diff --git a/app/jobs/onceoff/migrate_from_slack_official.rb b/app/jobs/onceoff/migrate_from_slack_official.rb index 5eaa29db..e3eeda1e 100644 --- a/app/jobs/onceoff/migrate_from_slack_official.rb +++ b/app/jobs/onceoff/migrate_from_slack_official.rb @@ -6,7 +6,7 @@ def execute_onceoff(args) 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 @@ def migrate_data 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 @@ def migrate_data 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 diff --git a/app/jobs/regular/notify_chats.rb b/app/jobs/regular/notify_chats.rb index 9795b35b..fe7bbeee 100644 --- a/app/jobs/regular/notify_chats.rb +++ b/app/jobs/regular/notify_chats.rb @@ -6,7 +6,7 @@ class NotifyChats < ::Jobs::Base 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 diff --git a/app/models/channel.rb b/app/models/channel.rb index febe3046..312fd1ab 100644 --- a/app/models/channel.rb +++ b/app/models/channel.rb @@ -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 @@ def self.key_prefix 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 @@ def destroy_rules 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 @@ def data_valid? 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] diff --git a/app/models/plugin_model.rb b/app/models/plugin_model.rb index f2b89ca7..93e13de7 100644 --- a/app/models/plugin_model.rb +++ b/app/models/plugin_model.rb @@ -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 } diff --git a/app/models/rule.rb b/app/models/rule.rb index cb22cd8e..72e9fb59 100644 --- a/app/models/rule.rb +++ b/app/models/rule.rb @@ -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 @@ def tags=(array) # 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 @@ def channel=(val) 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 diff --git a/app/routes/discourse.rb b/app/routes/discourse.rb index 0a9ae874..0e3214f8 100644 --- a/app/routes/discourse.rb +++ b/app/routes/discourse.rb @@ -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 diff --git a/app/routes/discourse_chat.rb b/app/routes/discourse_chat_integration.rb similarity index 95% rename from app/routes/discourse_chat.rb rename to app/routes/discourse_chat_integration.rb index 810bab31..c21e5615 100644 --- a/app/routes/discourse_chat.rb +++ b/app/routes/discourse_chat_integration.rb @@ -2,7 +2,7 @@ require_dependency 'admin_constraint' -module DiscourseChat +module ::DiscourseChatIntegration AdminEngine.routes.draw do get "" => "chat#respond" get '/providers' => "chat#list_providers" diff --git a/app/serializers/channel_serializer.rb b/app/serializers/channel_serializer.rb index 1ab0a8be..e8e71139 100644 --- a/app/serializers/channel_serializer.rb +++ b/app/serializers/channel_serializer.rb @@ -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 diff --git a/app/serializers/rule_serializer.rb b/app/serializers/rule_serializer.rb index 6ace3c57..25e00865 100644 --- a/app/serializers/rule_serializer.rb +++ b/app/serializers/rule_serializer.rb @@ -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 diff --git a/app/services/manager.rb b/app/services/manager.rb index f398fe67..caf500df 100644 --- a/app/services/manager.rb +++ b/app/services/manager.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module DiscourseChat +module DiscourseChatIntegration module Manager def self.guardian @@ -23,11 +23,11 @@ def self.trigger_notifications(post_id) 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 @@ def self.trigger_notifications(post_id) 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 @@ def self.trigger_notifications(post_id) 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 @@ def self.trigger_notifications(post_id) # 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 diff --git a/lib/discourse_chat/provider.rb b/lib/discourse_chat_integration/provider.rb similarity index 88% rename from lib/discourse_chat/provider.rb rename to lib/discourse_chat_integration/provider.rb index 60a8c9e0..22720148 100644 --- a/lib/discourse_chat/provider.rb +++ b/lib/discourse_chat_integration/provider.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module DiscourseChat +module DiscourseChatIntegration class ProviderError < StandardError attr_accessor :info @@ -44,12 +44,12 @@ def self.is_enabled(provider) 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 @@ def respond # 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 @@ def self.mount_engines 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 diff --git a/lib/discourse_chat/provider/discord/discord_provider.rb b/lib/discourse_chat_integration/provider/discord/discord_provider.rb similarity index 96% rename from lib/discourse_chat/provider/discord/discord_provider.rb rename to lib/discourse_chat_integration/provider/discord/discord_provider.rb index 1f68fa9d..6f8d2d11 100644 --- a/lib/discourse_chat/provider/discord/discord_provider.rb +++ b/lib/discourse_chat_integration/provider/discord/discord_provider.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module DiscourseChat +module DiscourseChatIntegration module Provider module DiscordProvider PROVIDER_NAME = "discord".freeze @@ -70,7 +70,7 @@ def self.trigger_notification(post, channel, rule) 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 diff --git a/lib/discourse_chat/provider/flowdock/flowdock_provider.rb b/lib/discourse_chat_integration/provider/flowdock/flowdock_provider.rb similarity index 90% rename from lib/discourse_chat/provider/flowdock/flowdock_provider.rb rename to lib/discourse_chat_integration/provider/flowdock/flowdock_provider.rb index 89a50052..e0a7d3ca 100644 --- a/lib/discourse_chat/provider/flowdock/flowdock_provider.rb +++ b/lib/discourse_chat_integration/provider/flowdock/flowdock_provider.rb @@ -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 @@ def self.trigger_notification(post, channel, rule) 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 diff --git a/lib/discourse_chat/provider/gitter/gitter_provider.rb b/lib/discourse_chat_integration/provider/gitter/gitter_provider.rb similarity index 86% rename from lib/discourse_chat/provider/gitter/gitter_provider.rb rename to lib/discourse_chat_integration/provider/gitter/gitter_provider.rb index 50293f23..cf2cbc74 100644 --- a/lib/discourse_chat/provider/gitter/gitter_provider.rb +++ b/lib/discourse_chat_integration/provider/gitter/gitter_provider.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module DiscourseChat +module DiscourseChatIntegration module Provider module GitterProvider PROVIDER_NAME = 'gitter'.freeze @@ -15,7 +15,7 @@ def self.trigger_notification(post, channel, rule) 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 diff --git a/lib/discourse_chat/provider/google/google_provider.rb b/lib/discourse_chat_integration/provider/google/google_provider.rb similarity index 93% rename from lib/discourse_chat/provider/google/google_provider.rb rename to lib/discourse_chat_integration/provider/google/google_provider.rb index aca76841..9002f945 100644 --- a/lib/discourse_chat/provider/google/google_provider.rb +++ b/lib/discourse_chat_integration/provider/google/google_provider.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module DiscourseChat +module DiscourseChatIntegration module Provider module GoogleProvider PROVIDER_NAME = 'google'.freeze @@ -22,7 +22,7 @@ def self.trigger_notification(post, channel, rule) 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 diff --git a/lib/discourse_chat/provider/groupme/groupme_provider.rb b/lib/discourse_chat_integration/provider/groupme/groupme_provider.rb similarity index 95% rename from lib/discourse_chat/provider/groupme/groupme_provider.rb rename to lib/discourse_chat_integration/provider/groupme/groupme_provider.rb index a8491750..83c4a5d0 100644 --- a/lib/discourse_chat/provider/groupme/groupme_provider.rb +++ b/lib/discourse_chat_integration/provider/groupme/groupme_provider.rb @@ -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 @@ def self.send_via_webhook(message, channel) 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 diff --git a/lib/discourse_chat/provider/matrix/matrix_provider.rb b/lib/discourse_chat_integration/provider/matrix/matrix_provider.rb similarity index 95% rename from lib/discourse_chat/provider/matrix/matrix_provider.rb rename to lib/discourse_chat_integration/provider/matrix/matrix_provider.rb index c70af257..d2fbdbf7 100644 --- a/lib/discourse_chat/provider/matrix/matrix_provider.rb +++ b/lib/discourse_chat_integration/provider/matrix/matrix_provider.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module DiscourseChat +module DiscourseChatIntegration module Provider module MatrixProvider PROVIDER_NAME = "matrix".freeze @@ -71,7 +71,7 @@ def self.trigger_notification(post, channel, rule) 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 diff --git a/lib/discourse_chat/provider/mattermost/mattermost_command_controller.rb b/lib/discourse_chat_integration/provider/mattermost/mattermost_command_controller.rb similarity index 62% rename from lib/discourse_chat/provider/mattermost/mattermost_command_controller.rb rename to lib/discourse_chat_integration/provider/mattermost/mattermost_command_controller.rb index d16c8218..307632f2 100644 --- a/lib/discourse_chat/provider/mattermost/mattermost_command_controller.rb +++ b/lib/discourse_chat_integration/provider/mattermost/mattermost_command_controller.rb @@ -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 @@ def process_command(params) "##{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 @@ def mattermost_token_valid? 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 diff --git a/lib/discourse_chat/provider/mattermost/mattermost_provider.rb b/lib/discourse_chat_integration/provider/mattermost/mattermost_provider.rb similarity index 93% rename from lib/discourse_chat/provider/mattermost/mattermost_provider.rb rename to lib/discourse_chat_integration/provider/mattermost/mattermost_provider.rb index 07c65a30..1b4575be 100644 --- a/lib/discourse_chat/provider/mattermost/mattermost_provider.rb +++ b/lib/discourse_chat_integration/provider/mattermost/mattermost_provider.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module DiscourseChat +module DiscourseChatIntegration module Provider module MattermostProvider PROVIDER_NAME = "mattermost".freeze @@ -25,7 +25,7 @@ def self.send_via_webhook(message) 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 diff --git a/lib/discourse_chat/provider/rocketchat/rocketchat_provider.rb b/lib/discourse_chat_integration/provider/rocketchat/rocketchat_provider.rb similarity index 91% rename from lib/discourse_chat/provider/rocketchat/rocketchat_provider.rb rename to lib/discourse_chat_integration/provider/rocketchat/rocketchat_provider.rb index 3c7abcf1..d7bc7137 100644 --- a/lib/discourse_chat/provider/rocketchat/rocketchat_provider.rb +++ b/lib/discourse_chat_integration/provider/rocketchat/rocketchat_provider.rb @@ -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 @@ def self.send_via_webhook(message) 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 diff --git a/lib/discourse_chat/provider/slack/slack_command_controller.rb b/lib/discourse_chat_integration/provider/slack/slack_command_controller.rb similarity index 91% rename from lib/discourse_chat/provider/slack/slack_command_controller.rb rename to lib/discourse_chat_integration/provider/slack/slack_command_controller.rb index e0f8d885..feabee0e 100644 --- a/lib/discourse_chat/provider/slack/slack_command_controller.rb +++ b/lib/discourse_chat_integration/provider/slack/slack_command_controller.rb @@ -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 @@ def process_command(params) "##{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 @@ def process_command(params) 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 @@ def process_post_request(channel, tokens, slack_channel_id, channel_name, respon 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 @@ def build_post_request_response(channel, tokens, slack_channel_id, channel_name, 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 @@ def slack_payload_token_valid? 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 diff --git a/lib/discourse_chat/provider/slack/slack_enabled_setting_validator.rb b/lib/discourse_chat_integration/provider/slack/slack_enabled_setting_validator.rb similarity index 100% rename from lib/discourse_chat/provider/slack/slack_enabled_setting_validator.rb rename to lib/discourse_chat_integration/provider/slack/slack_enabled_setting_validator.rb diff --git a/lib/discourse_chat/provider/slack/slack_message.rb b/lib/discourse_chat_integration/provider/slack/slack_message.rb similarity index 98% rename from lib/discourse_chat/provider/slack/slack_message.rb rename to lib/discourse_chat_integration/provider/slack/slack_message.rb index 7b0cbac3..b6a92714 100644 --- a/lib/discourse_chat/provider/slack/slack_message.rb +++ b/lib/discourse_chat_integration/provider/slack/slack_message.rb @@ -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 diff --git a/lib/discourse_chat/provider/slack/slack_message_formatter.rb b/lib/discourse_chat_integration/provider/slack/slack_message_formatter.rb similarity index 95% rename from lib/discourse_chat/provider/slack/slack_message_formatter.rb rename to lib/discourse_chat_integration/provider/slack/slack_message_formatter.rb index 1b0d29d5..6d8f626a 100644 --- a/lib/discourse_chat/provider/slack/slack_message_formatter.rb +++ b/lib/discourse_chat_integration/provider/slack/slack_message_formatter.rb @@ -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 diff --git a/lib/discourse_chat/provider/slack/slack_provider.rb b/lib/discourse_chat_integration/provider/slack/slack_provider.rb similarity index 87% rename from lib/discourse_chat/provider/slack/slack_provider.rb rename to lib/discourse_chat_integration/provider/slack/slack_provider.rb index 8b451fd7..d38a41ac 100644 --- a/lib/discourse_chat/provider/slack/slack_provider.rb +++ b/lib/discourse_chat_integration/provider/slack/slack_provider.rb @@ -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 @@ def self.send_via_api(post, channel, message) 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 @@ def self.send_via_api(post, channel, message) 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 @@ def self.send_via_webhook(message) 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 diff --git a/lib/discourse_chat/provider/slack/slack_transcript.rb b/lib/discourse_chat_integration/provider/slack/slack_transcript.rb similarity index 96% rename from lib/discourse_chat/provider/slack/slack_transcript.rb rename to lib/discourse_chat_integration/provider/slack/slack_transcript.rb index beff4e90..cdbd135e 100644 --- a/lib/discourse_chat/provider/slack/slack_transcript.rb +++ b/lib/discourse_chat_integration/provider/slack/slack_transcript.rb @@ -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 @@ def build_modal_ui 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 @@ def build_modal_ui 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 @@ def build_slack_ui 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 @@ def load_user_data 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" diff --git a/lib/discourse_chat/provider/teams/teams_provider.rb b/lib/discourse_chat_integration/provider/teams/teams_provider.rb similarity index 89% rename from lib/discourse_chat/provider/teams/teams_provider.rb rename to lib/discourse_chat_integration/provider/teams/teams_provider.rb index d1824f49..9561d669 100644 --- a/lib/discourse_chat/provider/teams/teams_provider.rb +++ b/lib/discourse_chat_integration/provider/teams/teams_provider.rb @@ -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 @@ def self.trigger_notification(post, channel, rule) 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 diff --git a/lib/discourse_chat/provider/telegram/telegram_command_controller.rb b/lib/discourse_chat_integration/provider/telegram/telegram_command_controller.rb similarity index 75% rename from lib/discourse_chat/provider/telegram/telegram_command_controller.rb rename to lib/discourse_chat_integration/provider/telegram/telegram_command_controller.rb index 96c31d3b..13da20fb 100644 --- a/lib/discourse_chat/provider/telegram/telegram_command_controller.rb +++ b/lib/discourse_chat_integration/provider/telegram/telegram_command_controller.rb @@ -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 @@ def command 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 @@ def command 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 @@ def command 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 @@ def process_command(message) 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 @@ def telegram_token_valid? 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 diff --git a/lib/discourse_chat/provider/telegram/telegram_initializer.rb b/lib/discourse_chat_integration/provider/telegram/telegram_initializer.rb similarity index 88% rename from lib/discourse_chat/provider/telegram/telegram_initializer.rb rename to lib/discourse_chat_integration/provider/telegram/telegram_initializer.rb index 07519cfd..f28500cd 100644 --- a/lib/discourse_chat/provider/telegram/telegram_initializer.rb +++ b/lib/discourse_chat_integration/provider/telegram/telegram_initializer.rb @@ -9,7 +9,7 @@ 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 diff --git a/lib/discourse_chat/provider/telegram/telegram_provider.rb b/lib/discourse_chat_integration/provider/telegram/telegram_provider.rb similarity index 95% rename from lib/discourse_chat/provider/telegram/telegram_provider.rb rename to lib/discourse_chat_integration/provider/telegram/telegram_provider.rb index c8d4d7e9..a38097a2 100644 --- a/lib/discourse_chat/provider/telegram/telegram_provider.rb +++ b/lib/discourse_chat_integration/provider/telegram/telegram_provider.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module DiscourseChat +module DiscourseChatIntegration module Provider module TelegramProvider PROVIDER_NAME = "telegram".freeze @@ -98,7 +98,7 @@ def self.trigger_notification(post, channel, rule) 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 diff --git a/lib/discourse_chat/provider/webex/webex_provider.rb b/lib/discourse_chat_integration/provider/webex/webex_provider.rb similarity index 81% rename from lib/discourse_chat/provider/webex/webex_provider.rb rename to lib/discourse_chat_integration/provider/webex/webex_provider.rb index cdd36b16..d83e665a 100644 --- a/lib/discourse_chat/provider/webex/webex_provider.rb +++ b/lib/discourse_chat_integration/provider/webex/webex_provider.rb @@ -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 @@ def self.trigger_notification(post, channel, rule) 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 diff --git a/lib/discourse_chat/provider/zulip/zulip_provider.rb b/lib/discourse_chat_integration/provider/zulip/zulip_provider.rb similarity index 92% rename from lib/discourse_chat/provider/zulip/zulip_provider.rb rename to lib/discourse_chat_integration/provider/zulip/zulip_provider.rb index 877584dc..e608c39a 100644 --- a/lib/discourse_chat/provider/zulip/zulip_provider.rb +++ b/lib/discourse_chat_integration/provider/zulip/zulip_provider.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module DiscourseChat +module DiscourseChatIntegration module Provider module ZulipProvider PROVIDER_NAME = "zulip".freeze @@ -58,7 +58,7 @@ def self.trigger_notification(post, channel, rule) 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 diff --git a/plugin.rb b/plugin.rb index 780e557a..e7765554 100644 --- a/plugin.rb +++ b/plugin.rb @@ -14,10 +14,10 @@ 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 @@ 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 @@ end end - DiscourseChat::Provider.mount_engines + DiscourseChatIntegration::Provider.mount_engines end diff --git a/spec/dummy_provider.rb b/spec/dummy_provider.rb index 1b6c1d50..fdb6442d 100644 --- a/spec/dummy_provider.rb +++ b/spec/dummy_provider.rb @@ -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 @@ def self.set_raise_exception(bool) 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 @@ def self.sent_messages end after(:each) do - ::DiscourseChat::Provider.send(:remove_const, :Dummy2Provider) + ::DiscourseChatIntegration::Provider.send(:remove_const, :Dummy2Provider) end end diff --git a/spec/helpers/helper_spec.rb b/spec/helpers/helper_spec.rb index 57eaa4c0..fddbd5f6 100644 --- a/spec/helpers/helper_spec.rb +++ b/spec/helpers/helper_spec.rb @@ -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 @@ # 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ # 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 @@ 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 @@ 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 @@ 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") diff --git a/spec/jobs/onceoff/migrate_from_slack_official_spec.rb b/spec/jobs/onceoff/migrate_from_slack_official_spec.rb index 9da4cd05..8acf7fc7 100644 --- a/spec/jobs/onceoff/migrate_from_slack_official_spec.rb +++ b/spec/jobs/onceoff/migrate_from_slack_official_spec.rb @@ -71,26 +71,26 @@ 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 @@ 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 @@ 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 @@ 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 diff --git a/spec/lib/discourse_chat/provider/discord/discord_provider_spec.rb b/spec/lib/discourse_chat_integration/provider/discord/discord_provider_spec.rb similarity index 79% rename from spec/lib/discourse_chat/provider/discord/discord_provider_spec.rb rename to spec/lib/discourse_chat_integration/provider/discord/discord_provider_spec.rb index 909fbda3..97292605 100644 --- a/spec/lib/discourse_chat/provider/discord/discord_provider_spec.rb +++ b/spec/lib/discourse_chat_integration/provider/discord/discord_provider_spec.rb @@ -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 @@ 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 @@ 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 diff --git a/spec/lib/discourse_chat/provider/flowdock/flowdock_provider_spec.rb b/spec/lib/discourse_chat_integration/provider/flowdock/flowdock_provider_spec.rb similarity index 73% rename from spec/lib/discourse_chat/provider/flowdock/flowdock_provider_spec.rb rename to spec/lib/discourse_chat_integration/provider/flowdock/flowdock_provider_spec.rb index c87b073b..8edd0e01 100644 --- a/spec/lib/discourse_chat/provider/flowdock/flowdock_provider_spec.rb +++ b/spec/lib/discourse_chat_integration/provider/flowdock/flowdock_provider_spec.rb @@ -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 @@ 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 @@ 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 diff --git a/spec/lib/discourse_chat/provider/gitter/gitter_provider_spec.rb b/spec/lib/discourse_chat_integration/provider/gitter/gitter_provider_spec.rb similarity index 71% rename from spec/lib/discourse_chat/provider/gitter/gitter_provider_spec.rb rename to spec/lib/discourse_chat_integration/provider/gitter/gitter_provider_spec.rb index a7e84d25..e27acd50 100644 --- a/spec/lib/discourse_chat/provider/gitter/gitter_provider_spec.rb +++ b/spec/lib/discourse_chat_integration/provider/gitter/gitter_provider_spec.rb @@ -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 @@ 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 @@ 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 diff --git a/spec/lib/discourse_chat/provider/google/google_provider_spec.rb b/spec/lib/discourse_chat_integration/provider/google/google_provider_spec.rb similarity index 71% rename from spec/lib/discourse_chat/provider/google/google_provider_spec.rb rename to spec/lib/discourse_chat_integration/provider/google/google_provider_spec.rb index 28246768..e3f54b51 100644 --- a/spec/lib/discourse_chat/provider/google/google_provider_spec.rb +++ b/spec/lib/discourse_chat_integration/provider/google/google_provider_spec.rb @@ -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 @@ 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 @@ 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 diff --git a/spec/lib/discourse_chat/provider/groupme/groupme_provider_spect.rb b/spec/lib/discourse_chat_integration/provider/groupme/groupme_provider_spect.rb similarity index 76% rename from spec/lib/discourse_chat/provider/groupme/groupme_provider_spect.rb rename to spec/lib/discourse_chat_integration/provider/groupme/groupme_provider_spect.rb index 44db8784..333450ae 100644 --- a/spec/lib/discourse_chat/provider/groupme/groupme_provider_spect.rb +++ b/spec/lib/discourse_chat_integration/provider/groupme/groupme_provider_spect.rb @@ -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 @@ 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 @@ 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 diff --git a/spec/lib/discourse_chat/provider/matrix/matrix_provider_spec.rb b/spec/lib/discourse_chat_integration/provider/matrix/matrix_provider_spec.rb similarity index 77% rename from spec/lib/discourse_chat/provider/matrix/matrix_provider_spec.rb rename to spec/lib/discourse_chat_integration/provider/matrix/matrix_provider_spec.rb index 85d53513..0a052886 100644 --- a/spec/lib/discourse_chat/provider/matrix/matrix_provider_spec.rb +++ b/spec/lib/discourse_chat_integration/provider/matrix/matrix_provider_spec.rb @@ -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 @@ 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 @@ 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 diff --git a/spec/lib/discourse_chat/provider/mattermost/mattermost_command_controller_spec.rb b/spec/lib/discourse_chat_integration/provider/mattermost/mattermost_command_controller_spec.rb similarity index 92% rename from spec/lib/discourse_chat/provider/mattermost/mattermost_command_controller_spec.rb rename to spec/lib/discourse_chat_integration/provider/mattermost/mattermost_command_controller_spec.rb index 54241550..8275dce6 100644 --- a/spec/lib/discourse_chat/provider/mattermost/mattermost_command_controller_spec.rb +++ b/spec/lib/discourse_chat_integration/provider/mattermost/mattermost_command_controller_spec.rb @@ -6,7 +6,7 @@ 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 @@ 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 @@ 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 diff --git a/spec/lib/discourse_chat/provider/mattermost/mattermost_provider_spec.rb b/spec/lib/discourse_chat_integration/provider/mattermost/mattermost_provider_spec.rb similarity index 85% rename from spec/lib/discourse_chat/provider/mattermost/mattermost_provider_spec.rb rename to spec/lib/discourse_chat_integration/provider/mattermost/mattermost_provider_spec.rb index 2c2419b1..5797e5c4 100644 --- a/spec/lib/discourse_chat/provider/mattermost/mattermost_provider_spec.rb +++ b/spec/lib/discourse_chat_integration/provider/mattermost/mattermost_provider_spec.rb @@ -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 @@ 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 @@ 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 diff --git a/spec/lib/discourse_chat/provider/rocketchat/rocketchat_provider_spec.rb b/spec/lib/discourse_chat_integration/provider/rocketchat/rocketchat_provider_spec.rb similarity index 76% rename from spec/lib/discourse_chat/provider/rocketchat/rocketchat_provider_spec.rb rename to spec/lib/discourse_chat_integration/provider/rocketchat/rocketchat_provider_spec.rb index 42ecf31a..7f32fbf7 100644 --- a/spec/lib/discourse_chat/provider/rocketchat/rocketchat_provider_spec.rb +++ b/spec/lib/discourse_chat_integration/provider/rocketchat/rocketchat_provider_spec.rb @@ -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 @@ 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 @@ 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 diff --git a/spec/lib/discourse_chat/provider/slack/slack_command_controller_spec.rb b/spec/lib/discourse_chat_integration/provider/slack/slack_command_controller_spec.rb similarity index 97% rename from spec/lib/discourse_chat/provider/slack/slack_command_controller_spec.rb rename to spec/lib/discourse_chat_integration/provider/slack/slack_command_controller_spec.rb index b6e72479..de90ed63 100644 --- a/spec/lib/discourse_chat/provider/slack/slack_command_controller_spec.rb +++ b/spec/lib/discourse_chat_integration/provider/slack/slack_command_controller_spec.rb @@ -6,7 +6,7 @@ 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 @@ 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 @@ 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 diff --git a/spec/lib/discourse_chat/provider/slack/slack_message_formatter_spec.rb b/spec/lib/discourse_chat_integration/provider/slack/slack_message_formatter_spec.rb similarity index 91% rename from spec/lib/discourse_chat/provider/slack/slack_message_formatter_spec.rb rename to spec/lib/discourse_chat_integration/provider/slack/slack_message_formatter_spec.rb index 47c3eaaf..374dd06b 100644 --- a/spec/lib/discourse_chat/provider/slack/slack_message_formatter_spec.rb +++ b/spec/lib/discourse_chat_integration/provider/slack/slack_message_formatter_spec.rb @@ -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 diff --git a/spec/lib/discourse_chat/provider/slack/slack_provider_spec.rb b/spec/lib/discourse_chat_integration/provider/slack/slack_provider_spec.rb similarity index 89% rename from spec/lib/discourse_chat/provider/slack/slack_provider_spec.rb rename to spec/lib/discourse_chat_integration/provider/slack/slack_provider_spec.rb index 17e20368..792fbbf2 100644 --- a/spec/lib/discourse_chat/provider/slack/slack_provider_spec.rb +++ b/spec/lib/discourse_chat_integration/provider/slack/slack_provider_spec.rb @@ -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 @@ 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 @@ 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 @@ @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 @@ 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 @@ 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 @@ 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 diff --git a/spec/lib/discourse_chat/provider/slack/slack_transcript_spec.rb b/spec/lib/discourse_chat_integration/provider/slack/slack_transcript_spec.rb similarity index 95% rename from spec/lib/discourse_chat/provider/slack/slack_transcript_spec.rb rename to spec/lib/discourse_chat_integration/provider/slack/slack_transcript_spec.rb index fb5f89f8..b90f3769 100644 --- a/spec/lib/discourse_chat/provider/slack/slack_transcript_spec.rb +++ b/spec/lib/discourse_chat_integration/provider/slack/slack_transcript_spec.rb @@ -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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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", diff --git a/spec/lib/discourse_chat/provider/teams/teams_provider_spec.rb b/spec/lib/discourse_chat_integration/provider/teams/teams_provider_spec.rb similarity index 62% rename from spec/lib/discourse_chat/provider/teams/teams_provider_spec.rb rename to spec/lib/discourse_chat_integration/provider/teams/teams_provider_spec.rb index 3501540f..4ea45e47 100644 --- a/spec/lib/discourse_chat/provider/teams/teams_provider_spec.rb +++ b/spec/lib/discourse_chat_integration/provider/teams/teams_provider_spec.rb @@ -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 @@ 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 @@ 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 diff --git a/spec/lib/discourse_chat/provider/telegram/telegram_command_controller_spec.rb b/spec/lib/discourse_chat_integration/provider/telegram/telegram_command_controller_spec.rb similarity index 91% rename from spec/lib/discourse_chat/provider/telegram/telegram_command_controller_spec.rb rename to spec/lib/discourse_chat_integration/provider/telegram/telegram_command_controller_spec.rb index c823f06b..e4124df3 100644 --- a/spec/lib/discourse_chat/provider/telegram/telegram_command_controller_spec.rb +++ b/spec/lib/discourse_chat_integration/provider/telegram/telegram_command_controller_spec.rb @@ -4,7 +4,7 @@ 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 @@ 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 @@ 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 @@ 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 diff --git a/spec/lib/discourse_chat/provider/telegram/telegram_provider_spec.rb b/spec/lib/discourse_chat_integration/provider/telegram/telegram_provider_spec.rb similarity index 80% rename from spec/lib/discourse_chat/provider/telegram/telegram_provider_spec.rb rename to spec/lib/discourse_chat_integration/provider/telegram/telegram_provider_spec.rb index 6ce75eff..8e6f1406 100644 --- a/spec/lib/discourse_chat/provider/telegram/telegram_provider_spec.rb +++ b/spec/lib/discourse_chat_integration/provider/telegram/telegram_provider_spec.rb @@ -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 @@ 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 @@ 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 diff --git a/spec/lib/discourse_chat/provider/webex/webex_provider_spec.rb b/spec/lib/discourse_chat_integration/provider/webex/webex_provider_spec.rb similarity index 66% rename from spec/lib/discourse_chat/provider/webex/webex_provider_spec.rb rename to spec/lib/discourse_chat_integration/provider/webex/webex_provider_spec.rb index 682348a2..2940702b 100644 --- a/spec/lib/discourse_chat/provider/webex/webex_provider_spec.rb +++ b/spec/lib/discourse_chat_integration/provider/webex/webex_provider_spec.rb @@ -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 @@ 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 @@ 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 diff --git a/spec/lib/discourse_chat/provider/zulip/zulip_provider_spec.rb b/spec/lib/discourse_chat_integration/provider/zulip/zulip_provider_spec.rb similarity index 78% rename from spec/lib/discourse_chat/provider/zulip/zulip_provider_spec.rb rename to spec/lib/discourse_chat_integration/provider/zulip/zulip_provider_spec.rb index c8b2f2ba..e162c37b 100644 --- a/spec/lib/discourse_chat/provider/zulip/zulip_provider_spec.rb +++ b/spec/lib/discourse_chat_integration/provider/zulip/zulip_provider_spec.rb @@ -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 @@ 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 @@ 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 diff --git a/spec/models/channel_spec.rb b/spec/models/channel_spec.rb index 8ddfeedd..2092b0a5 100644 --- a/spec/models/channel_spec.rb +++ b/spec/models/channel_spec.rb @@ -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) diff --git a/spec/models/rule_spec.rb b/spec/models/rule_spec.rb index 633948e0..bd4833b7 100644 --- a/spec/models/rule_spec.rb +++ b/spec/models/rule_spec.rb @@ -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 @@ 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 diff --git a/spec/requests/chat_controller_spec.rb b/spec/requests/chat_controller_spec.rb index e19e38ac..8c2b2149 100644 --- a/spec/requests/chat_controller_spec.rb +++ b/spec/requests/chat_controller_spec.rb @@ -10,7 +10,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 '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 @@ 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 diff --git a/spec/requests/public_controller_spec.rb b/spec/requests/public_controller_spec.rb index 8fe9bf19..f20e03aa 100644 --- a/spec/requests/public_controller_spec.rb +++ b/spec/requests/public_controller_spec.rb @@ -11,7 +11,7 @@ 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" diff --git a/spec/services/manager_spec.rb b/spec/services/manager_spec.rb index ac9125a6..1d973f7e 100644 --- a/spec/services/manager_spec.rb +++ b/spec/services/manager_spec.rb @@ -4,9 +4,9 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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)