diff --git a/app/controllers/chat_controller.rb b/app/controllers/chat_controller.rb index 2b2863e..787e00e 100644 --- a/app/controllers/chat_controller.rb +++ b/app/controllers/chat_controller.rb @@ -26,7 +26,7 @@ class DiscourseChat::ChatController < ApplicationController provider = ::DiscourseChat::Provider.get_by_name(channel.provider) - if not ::DiscourseChat::Provider.is_enabled(provider) + if !DiscourseChat::Provider.is_enabled(provider) raise Discourse::NotFound end @@ -48,16 +48,12 @@ class DiscourseChat::ChatController < ApplicationController end def list_channels - providers = ::DiscourseChat::Provider.enabled_providers.map { |x| x::PROVIDER_NAME } - + providers = ::DiscourseChat::Provider.enabled_provider_names requested_provider = params[:provider] - if not providers.include? requested_provider - raise Discourse::NotFound - end + raise Discourse::InvalidParameters if !providers.include?(requested_provider) channels = DiscourseChat::Channel.with_provider(requested_provider) - render_serialized channels, DiscourseChat::ChannelSerializer, root: 'channels' end @@ -65,13 +61,13 @@ class DiscourseChat::ChatController < ApplicationController begin providers = ::DiscourseChat::Provider.enabled_providers.map { |x| x::PROVIDER_NAME } - if (not defined? params[:channel]) && defined? params[:channel][:provider] + if !defined?(params[:channel]) && defined?(params[:channel][:provider]) raise Discourse::InvalidParameters, 'Provider is not valid' end requested_provider = params[:channel][:provider] - if not providers.include? requested_provider + if !providers.include?(requested_provider) raise Discourse::InvalidParameters, 'Provider is not valid' end @@ -81,7 +77,7 @@ class DiscourseChat::ChatController < ApplicationController channel = DiscourseChat::Channel.new(hash) - if not channel.save(hash) + if !channel.save(hash) raise Discourse::InvalidParameters, 'Channel is not valid' end @@ -100,7 +96,7 @@ class DiscourseChat::ChatController < ApplicationController hash = params.require(:channel).permit(data: allowed_keys) - if not channel.update(hash) + if !channel.update(hash) raise Discourse::InvalidParameters, 'Channel is not valid' end @@ -111,9 +107,9 @@ class DiscourseChat::ChatController < ApplicationController end def destroy_channel - rule = DiscourseChat::Channel.find(params[:id].to_i) - - rule.destroy + rule = DiscourseChat::Channel.find_by(id: params[:id]) + raise Discourse::InvalidParameters unless rule + rule.destroy! render json: success_json end @@ -121,10 +117,9 @@ class DiscourseChat::ChatController < ApplicationController def create_rule begin hash = params.require(:rule).permit(:channel_id, :type, :filter, :group_id, :category_id, tags: []) - rule = DiscourseChat::Rule.new(hash) - if not rule.save(hash) + if !rule.save(hash) raise Discourse::InvalidParameters, 'Rule is not valid' end @@ -139,7 +134,7 @@ class DiscourseChat::ChatController < ApplicationController rule = DiscourseChat::Rule.find(params[:id].to_i) hash = params.require(:rule).permit(:type, :filter, :group_id, :category_id, tags: []) - if not rule.update(hash) + if !rule.update(hash) raise Discourse::InvalidParameters, 'Rule is not valid' end @@ -150,9 +145,9 @@ class DiscourseChat::ChatController < ApplicationController end def destroy_rule - rule = DiscourseChat::Rule.find(params[:id].to_i) - - rule.destroy + rule = DiscourseChat::Rule.find_by(id: params[:id]) + raise Discourse::InvalidParameters.new unless rule + rule.destroy! render json: success_json end diff --git a/app/controllers/public_controller.rb b/app/controllers/public_controller.rb index 233aa3a..c3ad7b0 100644 --- a/app/controllers/public_controller.rb +++ b/app/controllers/public_controller.rb @@ -4,15 +4,13 @@ class DiscourseChat::PublicController < ApplicationController def post_transcript params.require(:secret) - redis_key = "chat_integration:transcript:" + params[:secret] + redis_key = "chat_integration:transcript:#{params[:secret]}" content = $redis.get(redis_key) if content render json: { content: content } - return + else + raise Discourse::NotFound end - - raise Discourse::NotFound - end end diff --git a/app/helpers/helper.rb b/app/helpers/helper.rb index 1d03461..d4a0586 100644 --- a/app/helpers/helper.rb +++ b/app/helpers/helper.rb @@ -33,11 +33,12 @@ module DiscourseChat if token.start_with?('tag:') tag_name = token.sub(/^tag:/, '') else - return error_text # Abort and send help text + return error_text end tag = Tag.find_by(name: tag_name) - unless tag # If tag doesn't exist, abort + + unless tag return I18n.t("chat_integration.provider.#{provider}.not_found.tag", name: tag_name) end tags.push(tag.name) @@ -46,11 +47,11 @@ module DiscourseChat category_id = category.nil? ? nil : category.id case DiscourseChat::Helper.smart_create_rule(channel: channel, filter: cmd, category_id: category_id, tags: tags) when :created - return I18n.t("chat_integration.provider.#{provider}.create.created") + I18n.t("chat_integration.provider.#{provider}.create.created") when :updated - return I18n.t("chat_integration.provider.#{provider}.create.updated") + I18n.t("chat_integration.provider.#{provider}.create.updated") else - return I18n.t("chat_integration.provider.#{provider}.create.error") + I18n.t("chat_integration.provider.#{provider}.create.error") end when "remove" return error_text unless tokens.size == 1 @@ -59,16 +60,16 @@ module DiscourseChat 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) - return I18n.t("chat_integration.provider.#{provider}.delete.success") + I18n.t("chat_integration.provider.#{provider}.delete.success") else - return I18n.t("chat_integration.provider.#{provider}.delete.error") + I18n.t("chat_integration.provider.#{provider}.delete.error") end when "status" return DiscourseChat::Helper.status_for_channel(channel) when "help" - return I18n.t("chat_integration.provider.#{provider}.help") + I18n.t("chat_integration.provider.#{provider}.help") else - return error_text + error_text end end @@ -105,12 +106,12 @@ module DiscourseChat end text << I18n.t("chat_integration.provider.#{provider}.status.rule_string", - index: i, - filter: rule.filter, - category: category_name - ) + index: i, + filter: rule.filter, + category: category_name + ) - if SiteSetting.tagging_enabled && (not rule.tags.nil?) + if SiteSetting.tagging_enabled && (!rule.tags.nil?) text << I18n.t("chat_integration.provider.#{provider}.status.rule_string_tags_suffix", tags: rule.tags.join(', ')) end @@ -121,16 +122,15 @@ module DiscourseChat if rules.size == 0 text << I18n.t("chat_integration.provider.#{provider}.status.no_rules") end - return text + + text end # Delete a rule based on its (1 based) index as seen in the # status_for_channel function def self.delete_by_index(channel, index) rules = channel.rules.order_by_precedence - return false if index < (1) || index > (rules.size) - return :deleted if rules[index - 1].destroy end @@ -184,17 +184,14 @@ module DiscourseChat # This rule is unique! Create a new one: return :created if Rule.new(channel: channel, filter: filter, category_id: category_id, tags: tags).save - - return false # Error - + false end def self.save_transcript(transcript) secret = SecureRandom.hex - redis_key = "chat_integration:transcript:" + secret - $redis.set(redis_key, transcript, ex: 3600) # Expire in 1 hour - - return secret + redis_key = "chat_integration:transcript:#{secret}" + $redis.setex(redis_key, 3600, transcript) + secret end end diff --git a/app/initializers/discourse_chat.rb b/app/initializers/discourse_chat.rb index 67567d6..22031e8 100644 --- a/app/initializers/discourse_chat.rb +++ b/app/initializers/discourse_chat.rb @@ -2,12 +2,12 @@ module ::DiscourseChat PLUGIN_NAME = "discourse-chat-integration".freeze class AdminEngine < ::Rails::Engine - engine_name DiscourseChat::PLUGIN_NAME + "-admin" + engine_name "#{DiscourseChat::PLUGIN_NAME}-admin" isolate_namespace DiscourseChat end class PublicEngine < ::Rails::Engine - engine_name DiscourseChat::PLUGIN_NAME + "-public" + engine_name "#{DiscourseChat::PLUGIN_NAME}-public" isolate_namespace DiscourseChat end diff --git a/app/jobs/regular/notify_chats.rb b/app/jobs/regular/notify_chats.rb index 0b0f282..8ed597e 100644 --- a/app/jobs/regular/notify_chats.rb +++ b/app/jobs/regular/notify_chats.rb @@ -1,9 +1,9 @@ module Jobs class NotifyChats < Jobs::Base - sidekiq_options retry: false # Don't retry, could result in duplicate notifications for some providers - def execute(args) - return if not SiteSetting.chat_integration_enabled? # Plugin may have been disabled since job triggered + sidekiq_options retry: false + def execute(args) + return if !SiteSetting.chat_integration_enabled? ::DiscourseChat::Manager.trigger_notifications(args[:post_id]) end end diff --git a/app/models/channel.rb b/app/models/channel.rb index d2f545b..c43200a 100644 --- a/app/models/channel.rb +++ b/app/models/channel.rb @@ -29,10 +29,8 @@ class DiscourseChat::Channel < DiscourseChat::PluginModel end def provider_valid? - # Validate provider - if not ::DiscourseChat::Provider.provider_names.include? provider + if !DiscourseChat::Provider.provider_names.include?(provider) errors.add(:provider, "#{provider} is not a valid provider") - return end end @@ -66,6 +64,5 @@ class DiscourseChat::Channel < DiscourseChat::PluginModel if check_unique && matching_channels.exists? errors.add(:data, "matches an existing channel") end - end end diff --git a/app/services/manager.rb b/app/services/manager.rb index 8e646b3..b46620b 100644 --- a/app/services/manager.rb +++ b/app/services/manager.rb @@ -17,8 +17,6 @@ module DiscourseChat return if post.blank? || post.post_type != Post.types[:regular] topic = post.topic - - # Abort if topic is blank... this should never be the case return if topic.blank? # If it's a private message, filter rules by groups, otherwise filter rules by category @@ -66,7 +64,7 @@ module DiscourseChat matching_rules = matching_rules.select { |rule| rule.filter != "mute" } # If this is not the first post, discard all "follow" rules - if not post.is_first_post? + if !post.is_first_post? matching_rules = matching_rules.select { |rule| rule.filter != "follow" } end diff --git a/assets/javascripts/admin/adapters/channel.js.es6 b/assets/javascripts/admin/adapters/channel.js.es6 index 4b0cbd4..ae28a13 100644 --- a/assets/javascripts/admin/adapters/channel.js.es6 +++ b/assets/javascripts/admin/adapters/channel.js.es6 @@ -1,6 +1,3 @@ import buildPluginAdapter from 'admin/adapters/build-plugin'; -export default buildPluginAdapter('chat').extend({ - - -}); \ No newline at end of file +export default buildPluginAdapter('chat'); diff --git a/assets/javascripts/admin/adapters/provider.js.es6 b/assets/javascripts/admin/adapters/provider.js.es6 index c55aab7..ae28a13 100644 --- a/assets/javascripts/admin/adapters/provider.js.es6 +++ b/assets/javascripts/admin/adapters/provider.js.es6 @@ -1,5 +1,3 @@ import buildPluginAdapter from 'admin/adapters/build-plugin'; -export default buildPluginAdapter('chat').extend({ - -}); \ No newline at end of file +export default buildPluginAdapter('chat'); diff --git a/assets/javascripts/admin/adapters/rule.js.es6 b/assets/javascripts/admin/adapters/rule.js.es6 index c55aab7..ae28a13 100644 --- a/assets/javascripts/admin/adapters/rule.js.es6 +++ b/assets/javascripts/admin/adapters/rule.js.es6 @@ -1,5 +1,3 @@ import buildPluginAdapter from 'admin/adapters/build-plugin'; -export default buildPluginAdapter('chat').extend({ - -}); \ No newline at end of file +export default buildPluginAdapter('chat'); diff --git a/assets/javascripts/admin/components/channel-details.js.es6 b/assets/javascripts/admin/components/channel-details.js.es6 index 7cc2b6c..abd24ae 100644 --- a/assets/javascripts/admin/components/channel-details.js.es6 +++ b/assets/javascripts/admin/components/channel-details.js.es6 @@ -33,9 +33,9 @@ export default Ember.Component.extend({ this.sendAction('editRule', rule, this.get('channel')); }, - showError(error_key){ - bootbox.alert(I18n.t(error_key)); + showError(errorKey){ + bootbox.alert(I18n.t(errorKey)); }, } -}); \ No newline at end of file +}); diff --git a/assets/javascripts/admin/components/rule-row.js.es6 b/assets/javascripts/admin/components/rule-row.js.es6 index 63c9df7..3d3cc38 100644 --- a/assets/javascripts/admin/components/rule-row.js.es6 +++ b/assets/javascripts/admin/components/rule-row.js.es6 @@ -1,32 +1,37 @@ import { popupAjaxError } from 'discourse/lib/ajax-error'; +import computed from 'ember-addons/ember-computed-decorators'; export default Ember.Component.extend({ tagName: 'tr', - isCategory: function(){ - return this.get('rule.type') === 'normal'; - }.property('rule.type'), + @computed('rule.type') + isCategory(type) { + return type === 'normal'; + }, - isMessage: function(){ - return this.get('rule.type') === 'group_message'; - }.property('rule.type'), + @computed('rule.type') + isMessage(type) { + return type === 'group_message'; + }, - isMention: function(){ - return this.get('rule.type') === 'group_mention'; - }.property('rule.type'), + @computed('rule.type') + isMention(type) { + return type === 'group_mention'; + }, actions: { - edit: function(){ + edit() { this.sendAction('edit', this.get('rule')); }, - delete(rule){ + + delete(rule) { rule.destroyRecord().then(() => { this.send('refresh'); }).catch(popupAjaxError); }, - refresh: function(){ + + refresh() { this.sendAction('refresh'); } - } -}); \ No newline at end of file +}); diff --git a/assets/javascripts/admin/controllers/admin-plugins-chat-provider.js.es6 b/assets/javascripts/admin/controllers/admin-plugins-chat-provider.js.es6 index 0843463..b261603 100644 --- a/assets/javascripts/admin/controllers/admin-plugins-chat-provider.js.es6 +++ b/assets/javascripts/admin/controllers/admin-plugins-chat-provider.js.es6 @@ -1,46 +1,73 @@ import showModal from 'discourse/lib/show-modal'; +import computed from "ember-addons/ember-computed-decorators"; export default Ember.Controller.extend({ modalShowing: false, - anyErrors: function(){ - var anyErrors = false; - this.get('model.channels').forEach(function(channel){ - if(channel.error_key){ + @computed('model.channels') + anyErrors(channels) { + let anyErrors = false; + + channels.forEach((channel) => { + if (channel.error_key) { anyErrors = true; } }); + return anyErrors; - }.property('model.channels'), + }, actions:{ - createChannel(){ + createChannel() { this.set('modalShowing', true); - var model = {channel: this.store.createRecord('channel',{provider: this.get('model.provider').id, data:{}},), provider:this.get('model.provider')}; + + const model = { + channel: this.store.createRecord('channel', { provider: this.get('model.provider.id'), data:{} }), + provider: this.get('model.provider') + }; + showModal('admin-plugins-chat-edit-channel', { model: model, admin: true }); }, - editChannel(channel){ + + editChannel(channel) { this.set('modalShowing', true); - var model = {channel: channel, provider: this.get('model.provider')}; + + const model = { + channel: channel, + provider: this.get('model.provider') + }; + showModal('admin-plugins-chat-edit-channel', { model: model, admin: true }); }, - testChannel(channel){ + + testChannel(channel) { this.set('modalShowing', true); - var model = {channel:channel}; - showModal('admin-plugins-chat-test', { model: model, admin: true }); + showModal('admin-plugins-chat-test', { model: { channel: channel }, admin: true }); }, createRule(channel){ this.set('modalShowing', true); - var model = {rule: this.store.createRecord('rule',{channel_id: channel.id}), channel:channel, provider:this.get('model.provider'), groups:this.get('model.groups')}; + + const model = { + rule: this.store.createRecord('rule', { channel_id: channel.id }), + channel: channel, + provider: this.get('model.provider'), + groups: this.get('model.groups') + }; + showModal('admin-plugins-chat-edit-rule', { model: model, admin: true }); }, editRule(rule, channel){ this.set('modalShowing', true); - var model = {rule: rule, channel:channel, provider:this.get('model.provider'), groups:this.get('model.groups')}; + + const model = { + rule: rule, + channel: channel, + provider: this.get('model.provider'), + groups: this.get('model.groups') + }; + showModal('admin-plugins-chat-edit-rule', { model: model, admin: true }); }, - } - -}); \ No newline at end of file +}); diff --git a/assets/javascripts/admin/controllers/modals/admin-plugins-chat-edit-channel.js.es6 b/assets/javascripts/admin/controllers/modals/admin-plugins-chat-edit-channel.js.es6 index d360bca..5e3822b 100644 --- a/assets/javascripts/admin/controllers/modals/admin-plugins-chat-edit-channel.js.es6 +++ b/assets/javascripts/admin/controllers/modals/admin-plugins-chat-edit-channel.js.es6 @@ -1,10 +1,11 @@ import ModalFunctionality from 'discourse/mixins/modal-functionality'; -import { extractError } from 'discourse/lib/ajax-error'; +import { popupAjaxError } from 'discourse/lib/ajax-error'; import InputValidation from 'discourse/models/input-validation'; +import { default as computed, observes } from 'ember-addons/ember-computed-decorators'; export default Ember.Controller.extend(ModalFunctionality, { - setupKeydown: function() { + setupKeydown() { Ember.run.schedule('afterRender', () => { $('#chat_integration_edit_channel_modal').keydown(e => { if (e.keyCode === 13) { @@ -15,36 +16,37 @@ export default Ember.Controller.extend(ModalFunctionality, { }.on('init'), // The validation property must be defined at runtime since the possible parameters vary by provider - setupValidations: function(){ + @observes('model') + setupValidations() { if(this.get('model.provider')){ - var theKeys = this.get('model.provider.channel_parameters').map( ( param ) => param['key'] ); - Ember.defineProperty(this,'paramValidation',Ember.computed('model.channel.data.{' + theKeys.join(',') + '}',this._paramValidation)); + const theKeys = this.get('model.provider.channel_parameters').map( ( param ) => param['key'] ); + Ember.defineProperty(this,'paramValidation', Ember.computed(`model.channel.data.{${theKeys.join(',')}},this._paramValidation`)); } - }.observes('model'), + }, - validate(parameter){ - var regString = parameter.regex; - var regex = new RegExp(regString); - var val = this.get('model.channel.data.'+parameter.key); + validate(parameter) { + const regString = parameter.regex; + const regex = new RegExp(regString); + let val = this.get(`model.channel.data.${parameter.key}`); - if(val===undefined){ + if (val === undefined) { val = ""; } - if(val === ""){ // Fail silently if field blank + if (val === "") { // Fail silently if field blank return InputValidation.create({ failed: true, }); - }else if(!regString){ // Pass silently if no regex available for provider + } else if (!regString) { // Pass silently if no regex available for provider return InputValidation.create({ ok: true, }); - }else if(regex.test(val)){ // Test against regex + } else if (regex.test(val)) { // Test against regex return InputValidation.create({ ok: true, reason: I18n.t('chat_integration.edit_channel_modal.channel_validation.ok') }); - }else{ // Failed regex + } else { // Failed regex return InputValidation.create({ failed: true, reason: I18n.t('chat_integration.edit_channel_modal.channel_validation.fail') @@ -53,50 +55,47 @@ export default Ember.Controller.extend(ModalFunctionality, { }, - _paramValidation: function(){ - var response = {}; - var parameters = this.get('model.provider.channel_parameters'); + _paramValidation() { + const response = {}; + const parameters = this.get('model.provider.channel_parameters'); + parameters.forEach(parameter => { response[parameter.key] = this.validate(parameter); }); + return response; }, - saveDisabled: function(){ - var validations = this.get('paramValidation'); + @computed('paramValidation') + saveDisabled(paramValidation) { + if (!paramValidation) return true; - if(!validations){ return true; } + let invalid = false; - var invalid = false; - - Object.keys(validations).forEach(key =>{ - if(!validations[key]){ + Object.keys(paramValidation).forEach(key =>{ + if (!validations[key]) { invalid = true; } - if(!validations[key]['ok']){ + + if (!validations[key]['ok']) { invalid = true; } }); return invalid; - }.property('paramValidation'), + }, actions: { - cancel: function(){ + cancel() { this.send('closeModal'); }, - save: function(){ - if(this.get('saveDisabled')){return;}; - - const self = this; - - this.get('model.channel').save().then(function() { - self.send('closeModal'); - }).catch(function(error) { - self.flash(extractError(error), 'error'); - }); + save() { + if (this.get('saveDisabled')) return; + this.get('model.channel').save().then(() => { + this.send('closeModal'); + }).catch(popupAjaxError); } } -}); \ No newline at end of file +}); diff --git a/assets/javascripts/admin/controllers/modals/admin-plugins-chat-edit-rule.js.es6 b/assets/javascripts/admin/controllers/modals/admin-plugins-chat-edit-rule.js.es6 index 0ae39e0..ea103a8 100644 --- a/assets/javascripts/admin/controllers/modals/admin-plugins-chat-edit-rule.js.es6 +++ b/assets/javascripts/admin/controllers/modals/admin-plugins-chat-edit-rule.js.es6 @@ -1,9 +1,11 @@ import ModalFunctionality from 'discourse/mixins/modal-functionality'; -import { extractError } from 'discourse/lib/ajax-error'; +import { popupAjaxError } from 'discourse/lib/ajax-error'; import computed from "ember-addons/ember-computed-decorators"; export default Ember.Controller.extend(ModalFunctionality, { - setupKeydown: function() { + saveDisabled: false, + + setupKeydown() { Ember.run.schedule('afterRender', () => { $('#chat_integration_edit_channel_modal').keydown(e => { if (e.keyCode === 13) { @@ -13,31 +15,22 @@ export default Ember.Controller.extend(ModalFunctionality, { }); }.on('init'), - saveDisabled: function(){ - return false; - }.property(), - @computed('model.rule.type') - showCategory: function(type){ - return (type === "normal"); + showCategory(type) { + return type === "normal"; }, actions: { - cancel: function(){ + cancel() { this.send('closeModal'); }, - save: function(){ - if(this.get('saveDisabled')){return;}; - - const self = this; - - this.get('model.rule').save().then(function() { - self.send('closeModal'); - }).catch(function(error) { - self.flash(extractError(error), 'error'); - }); + save() { + if (this.get('saveDisabled')) return; + this.get('model.rule').save().then(() => { + this.send('closeModal'); + }).catch(popupAjaxError); } } -}); \ No newline at end of file +}); diff --git a/assets/javascripts/admin/controllers/modals/admin-plugins-chat-test.js.es6 b/assets/javascripts/admin/controllers/modals/admin-plugins-chat-test.js.es6 index 81a5f46..6fcb3e8 100644 --- a/assets/javascripts/admin/controllers/modals/admin-plugins-chat-test.js.es6 +++ b/assets/javascripts/admin/controllers/modals/admin-plugins-chat-test.js.es6 @@ -1,8 +1,9 @@ import ModalFunctionality from 'discourse/mixins/modal-functionality'; import { ajax } from 'discourse/lib/ajax'; +import computed from "ember-addons/ember-computed-decorators"; export default Ember.Controller.extend(ModalFunctionality, { - setupKeydown: function() { + setupKeydown() { Ember.run.schedule('afterRender', () => { $('#chat_integration_test_modal').keydown(e => { if (e.keyCode === 13) { @@ -12,42 +13,26 @@ export default Ember.Controller.extend(ModalFunctionality, { }); }.on('init'), - sendDisabled: function(){ - if(this.get('model').topic_id){ - return false; - } - return true; - }.property('model.topic_id'), + @computed('model.topic_id') + sendDisabled(topicId) { + return !topicId; + }, actions: { + send() { + if (this.get('sendDisabled')) return; - send: function(){ - if(this.get('sendDisabled')){return;}; - self = this; this.set('loading', true); ajax("/admin/plugins/chat/test", { - data: { channel_id: this.get('model.channel.id'), - topic_id: this.get('model.topic_id') - }, + data: { + channel_id: this.get('model.channel.id'), + topic_id: this.get('model.topic_id') + }, type: 'POST' - }).then(function () { - self.set('loading', false); - self.flash(I18n.t('chat_integration.test_modal.success'), 'success'); - }, function(e) { - self.set('loading', false); - - var response = e.jqXHR.responseJSON; - var error_key = 'chat_integration.test_modal.error'; - - if(response['error_key']){ - error_key = response['error_key']; - } - self.flash(I18n.t(error_key), 'error'); - - }); + }).then(() => { + this.set('loading', false); + this.flash(I18n.t('chat_integration.test_modal.success'), 'success'); + }.catch(popupAjaxError); } - } - - -}); \ No newline at end of file +}); diff --git a/assets/javascripts/admin/models/channel.js.es6 b/assets/javascripts/admin/models/channel.js.es6 index b21399c..4d32062 100644 --- a/assets/javascripts/admin/models/channel.js.es6 +++ b/assets/javascripts/admin/models/channel.js.es6 @@ -1,14 +1,11 @@ import RestModel from 'discourse/models/rest'; export default RestModel.extend({ - updateProperties() { - var prop_names = ['data']; - return this.getProperties(prop_names); + return this.getProperties(['data']); }, createProperties() { - var prop_names = ['provider','data']; - return this.getProperties(prop_names); + return this.getProperties(['provider','data']); } }); diff --git a/assets/javascripts/admin/models/rule.js.es6 b/assets/javascripts/admin/models/rule.js.es6 index cf4b798..9773417 100644 --- a/assets/javascripts/admin/models/rule.js.es6 +++ b/assets/javascripts/admin/models/rule.js.es6 @@ -1,6 +1,6 @@ import RestModel from 'discourse/models/rest'; import Category from 'discourse/models/category'; -import computed from "ember-addons/ember-computed-decorators"; +import { default as computed, observes } from "ember-addons/ember-computed-decorators"; export default RestModel.extend({ available_filters: [ @@ -22,21 +22,22 @@ export default RestModel.extend({ type: 'normal', error_key: null, + @observes('type') + removeUnneededInfo() { + const type = this.get('type'); - removeUnneededInfo: function(){ - const type=this.get('type'); - if(type==='normal'){ + if (type === 'normal') { this.set('group_id', null); - }else{ + } else { this.set('category_id', null); } - }.observes('type'), + }, @computed('category_id') category(categoryId) { if (categoryId){ return Category.findById(categoryId); - }else { + } else { return false; } }, @@ -47,13 +48,10 @@ export default RestModel.extend({ }, updateProperties() { - var prop_names = ['type','category_id','group_id','tags','filter']; - return this.getProperties(prop_names); + return this.getProperties(['type','category_id','group_id','tags','filter']); }, createProperties() { - var prop_names = ['type','channel_id', 'category_id','group_id','tags','filter']; - return this.getProperties(prop_names); + return this.getProperties(['type','channel_id', 'category_id','group_id','tags','filter']); } - }); diff --git a/assets/javascripts/admin/routes/admin-plugins-chat-index.js.es6 b/assets/javascripts/admin/routes/admin-plugins-chat-index.js.es6 index 03fd012..0a09c33 100644 --- a/assets/javascripts/admin/routes/admin-plugins-chat-index.js.es6 +++ b/assets/javascripts/admin/routes/admin-plugins-chat-index.js.es6 @@ -1,8 +1,7 @@ export default Discourse.Route.extend({ - afterModel(model) { - - if(model.totalRows > 0){ - this.transitionTo('adminPlugins.chat.provider', model.get('firstObject').name); - } + afterModel(model) { + if (model.totalRows > 0) { + this.transitionTo('adminPlugins.chat.provider', model.get('firstObject').name); + } } }); diff --git a/assets/javascripts/admin/routes/admin-plugins-chat-provider.js.es6 b/assets/javascripts/admin/routes/admin-plugins-chat-provider.js.es6 index eefbe83..6992b11 100644 --- a/assets/javascripts/admin/routes/admin-plugins-chat-provider.js.es6 +++ b/assets/javascripts/admin/routes/admin-plugins-chat-provider.js.es6 @@ -17,17 +17,18 @@ export default Discourse.Route.extend({ return rule; })); }); + return value; }); }, - serialize: function(model) { - return { provider: model['provider'].get('id')}; + serialize(model) { + return { provider: model['provider'].get('id') }; }, actions: { - closeModal: function(){ - if(this.get('controller.modalShowing')){ + closeModal() { + if (this.get('controller.modalShowing')) { this.refresh(); this.set('controller.modalShowing', false); } @@ -35,9 +36,8 @@ export default Discourse.Route.extend({ return true; // Continue bubbling up, so the modal actually closes }, - refresh: function(){ + refresh() { this.refresh(); } - } }); diff --git a/assets/javascripts/admin/routes/admin-plugins-chat.js.es6 b/assets/javascripts/admin/routes/admin-plugins-chat.js.es6 index 7975516..26ea770 100644 --- a/assets/javascripts/admin/routes/admin-plugins-chat.js.es6 +++ b/assets/javascripts/admin/routes/admin-plugins-chat.js.es6 @@ -1,13 +1,13 @@ export default Discourse.Route.extend({ - model() { + model() { return this.store.findAll('provider'); }, actions: { - showSettings: function(){ - this.transitionTo('adminSiteSettingsCategory', 'plugins', { - queryParams: { filter: 'chat_integration'} - }); - } - } + showSettings() { + this.transitionTo('adminSiteSettingsCategory', 'plugins', { + queryParams: { filter: 'chat_integration'} + }); + } + } }); diff --git a/assets/javascripts/admin/templates/modal/admin-plugins-chat-edit-channel.hbs b/assets/javascripts/admin/templates/modal/admin-plugins-chat-edit-channel.hbs index bc6562b..cf44e5d 100644 --- a/assets/javascripts/admin/templates/modal/admin-plugins-chat-edit-channel.hbs +++ b/assets/javascripts/admin/templates/modal/admin-plugins-chat-edit-channel.hbs @@ -3,10 +3,10 @@
- + @@ -14,13 +14,13 @@ - {{# each model.provider.channel_parameters as |param|}} + {{#each model.provider.channel_parameters as |param|}}
- {{i18n (concat 'chat_integration.provider.' model.channel.provider '.title')}} + {{i18n (concat 'chat_integration.provider.' model.channel.provider '.title')}}
- {{text-field - name=(concat 'param-' param.key) - value=(mut (get model.channel.data param.key)) + {{text-field + name=(concat 'param-' param.key) + value=(mut (get model.channel.data param.key)) }}   @@ -37,13 +37,19 @@
- + {{/d-modal-body}} \ No newline at end of file + {{d-button class="btn-large" + action="cancel" + title="chat_integration.edit_channel_modal.cancel" + label="chat_integration.edit_channel_modal.cancel"}} + diff --git a/assets/javascripts/admin/templates/modal/admin-plugins-chat-edit-rule.hbs b/assets/javascripts/admin/templates/modal/admin-plugins-chat-edit-rule.hbs index 3e00e36..30cee6a 100644 --- a/assets/javascripts/admin/templates/modal/admin-plugins-chat-edit-rule.hbs +++ b/assets/javascripts/admin/templates/modal/admin-plugins-chat-edit-rule.hbs @@ -3,10 +3,10 @@
- + @@ -57,7 +57,7 @@ rootNoneLabel="chat_integration.all_categories" rootNone=true overrideWidths=false - }} + }} @@ -95,13 +95,19 @@
- {{i18n (concat 'chat_integration.provider.' model.channel.provider '.title')}} + {{i18n (concat 'chat_integration.provider.' model.channel.provider '.title')}}
- + {{/d-modal-body}} \ No newline at end of file + {{d-button class="btn-large" + action="cancel" + title="chat_integration.edit_rule_modal.cancel" + label="chat_integration.edit_rule_modal.cancel"}} + diff --git a/assets/javascripts/discourse/public-route-map.js.es6 b/assets/javascripts/discourse/public-route-map.js.es6 index acff9f8..fd4b9dd 100644 --- a/assets/javascripts/discourse/public-route-map.js.es6 +++ b/assets/javascripts/discourse/public-route-map.js.es6 @@ -1,3 +1,3 @@ export default function() { - this.route('transcript', {path: '/chat-transcript/:secret'}); -}; \ No newline at end of file + this.route('transcript', { path: '/chat-transcript/:secret' }); +}; diff --git a/assets/javascripts/discourse/routes/transcript.js.es6 b/assets/javascripts/discourse/routes/transcript.js.es6 index c4cdee2..ac2e803 100644 --- a/assets/javascripts/discourse/routes/transcript.js.es6 +++ b/assets/javascripts/discourse/routes/transcript.js.es6 @@ -2,25 +2,22 @@ import { ajax } from 'discourse/lib/ajax'; import { popupAjaxError } from 'discourse/lib/ajax-error'; export default Discourse.Route.extend({ - beforeModel: function(transition) { + beforeModel(transition) { + if (this.currentUser) { + const secret = transition.params.transcript.secret; - if (Discourse.User.current()) { - var secret = transition.params.transcript.secret; - // User is logged in this.replaceWith('discovery.latest').then(e => { if (this.controllerFor('navigation/default').get('canCreateTopic')) { - // User can create topic Ember.run.next(() => { - ajax("/chat-transcript/"+secret).then(result => { + ajax(`chat-transcript/${secret}`).then(result => { e.send('createNewTopicViaParams', null, result['content'], null, null, null); }, popupAjaxError); }); } }); } else { - // User is not logged in this.session.set("shouldRedirectToUrl", window.location.href); this.replaceWith('login'); } } -}); \ No newline at end of file +}); diff --git a/assets/javascripts/discourse/templates/admin/plugins-chat-provider.hbs b/assets/javascripts/discourse/templates/admin/plugins-chat-provider.hbs index ee1d6bc..eb7f66e 100644 --- a/assets/javascripts/discourse/templates/admin/plugins-chat-provider.hbs +++ b/assets/javascripts/discourse/templates/admin/plugins-chat-provider.hbs @@ -1,27 +1,29 @@ +{{#if anyErrors}} +
+ + {{i18n "chat_integration.channels_with_errors"}} +
+{{/if}} - {{#if anyErrors}} -
- - {{i18n "chat_integration.channels_with_errors"}} -
- {{/if}} +{{#each model.channels as |channel|}} + {{channel-details + channel=channel + provider=model.provider + store=store + refresh='refresh' + edit='editChannel' + test='testChannel' + createRule='createRule' + editRule='editRule'}} +{{/each}} - {{# each model.channels as |channel|}} - {{channel-details - channel=channel - provider=model.provider - store=store - refresh='refresh' - edit='editChannel' - test='testChannel' - createRule='createRule' - editRule='editRule' - }} - - {{/each}} - - \ No newline at end of file + diff --git a/assets/javascripts/discourse/templates/admin/plugins-chat.hbs b/assets/javascripts/discourse/templates/admin/plugins-chat.hbs index 8b1aec5..14a8fab 100644 --- a/assets/javascripts/discourse/templates/admin/plugins-chat.hbs +++ b/assets/javascripts/discourse/templates/admin/plugins-chat.hbs @@ -1,27 +1,25 @@
- -
-
- -
-
- {{#d-button - action="showSettings" - icon="gear" - title="chat_integration.settings" - label="chat_integration.settings"}} - {{/d-button}} -
-
- {{#if model.totalRows}} - {{else}} - {{i18n "chat_integration.no_providers"}} - {{/if}} - - {{outlet}} +
+
+ +
+ +
+ {{#d-button + action="showSettings" + icon="gear" + title="chat_integration.settings" + label="chat_integration.settings"}} +
+
+ + {{#unless model.totalRows}} + {{i18n "chat_integration.no_providers"}} + {{/unless}} + + {{outlet}}
- \ No newline at end of file diff --git a/assets/javascripts/discourse/templates/components/channel-data.hbs b/assets/javascripts/discourse/templates/components/channel-data.hbs index bdcdfbc..975db8c 100644 --- a/assets/javascripts/discourse/templates/components/channel-data.hbs +++ b/assets/javascripts/discourse/templates/components/channel-data.hbs @@ -1,7 +1,7 @@ -{{# each provider.channel_parameters as |param|}} - {{#if param.hidden}}{{else}} +{{#each provider.channel_parameters as |param|}} + {{#unless param.hidden}} {{i18n (concat 'chat_integration.provider.' channel.provider '.param.' param.key '.title')}}: - {{get channel.data param.key}} + {{get channel.data param.key}}
- {{/if}} -{{/each}} \ No newline at end of file + {{/unless}} +{{/each}} diff --git a/assets/javascripts/discourse/templates/components/channel-details.hbs b/assets/javascripts/discourse/templates/components/channel-details.hbs index b50b5a9..c47831b 100644 --- a/assets/javascripts/discourse/templates/components/channel-details.hbs +++ b/assets/javascripts/discourse/templates/components/channel-details.hbs @@ -6,44 +6,41 @@ {{d-button class='cancel' action="delete" actionParam=channel icon="trash" title="chat_integration.delete_channel" label="chat_integration.delete_channel"}} + {{#if channel.error_key}} {{d-button action="showError" actionParam=channel.error_key class="delete btn-danger" icon="exclamation-triangle"}} {{/if}} - {{channel-data provider=provider channel=channel}} - - +
- - - {{!-- --}} - +
{{i18n "chat_integration.rule_table.filter"}}
+ + + - + {{#if siteSettings.tagging_enabled}} + + {{/if}} - {{#if siteSettings.tagging_enabled}} - - {{/if}} + + - - - - - - - {{#each channel.rules as |rule|}} - {{rule-row rule=rule edit='editRule' refresh='refresh'}} - - {{/each}} - -
{{i18n "chat_integration.rule_table.filter"}}{{i18n "chat_integration.rule_table.category"}}{{i18n "chat_integration.rule_table.category"}}{{i18n "chat_integration.rule_table.tags"}}{{i18n "chat_integration.rule_table.tags"}}
+ {{#each channel.rules as |rule|}} + {{rule-row rule=rule edit='editRule' refresh='refresh'}} + {{/each}} +
+ \ No newline at end of file + diff --git a/assets/javascripts/discourse/templates/components/rule-row.hbs b/assets/javascripts/discourse/templates/components/rule-row.hbs index 12202e5..2db7ca9 100644 --- a/assets/javascripts/discourse/templates/components/rule-row.hbs +++ b/assets/javascripts/discourse/templates/components/rule-row.hbs @@ -1,8 +1,7 @@ - {{rule.filterName}} - + {{#if isCategory}} {{#if rule.category}} @@ -31,5 +30,4 @@ {{d-button action="edit" actionParam=rule icon="pencil" class="edit" title="chat_integration.rule_table.edit_rule"}} {{d-button action="delete" actionParam=rule icon="trash-o" class="delete" title="chat_integration.rule_table.delete_rule"}} - diff --git a/assets/stylesheets/chat-integration-admin.scss b/assets/stylesheets/chat-integration-admin.scss index fda4780..ff78251 100644 --- a/assets/stylesheets/chat-integration-admin.scss +++ b/assets/stylesheets/chat-integration-admin.scss @@ -1,97 +1,96 @@ -#admin-plugin-chat{ +#admin-plugin-chat { - table{ - margin-top:0; - td:last-child{ - white-space:nowrap; - } - td:not(:last-child){ - width: 30%; - } - } + table { + margin-top:0; - div.table-footer{ - margin: 10px; - } + td:last-child { + white-space:nowrap; + } - div.error { - font-size: 1.1em; - font-weight:bold; - max-width: 100%; + td:not(:last-child) { + width: 30%; + } + } + + div.table-footer { + margin: 10px; + } + + div.error { + font-size: 1.1em; + font-weight:bold; + max-width: 100%; margin-top: 10px; margin-bottom: 10px; background-color: $danger-low; padding: 15px; } - div.channel-details{ - margin: 20px 10px; - - border: 1px solid $primary-low; + div.channel-details { + margin: 20px 10px; + border: 1px solid $primary-low; - div.channel-header{ - background: $primary-low; - padding: 10px; - overflow:auto; + div.channel-header { + background: $primary-low; + padding: 10px; + overflow:auto; - .channel-title{ + .channel-title { font-size: 1.3em; - .field-name{ - font-weight: bold; + + .field-name { + font-weight: bold; } - - } - - - } - - div.channel-footer{ - overflow:auto; - } - } - - -} - -#chat_integration_edit_channel_modal, #chat_integration_test_modal, #chat_integration_edit_rule_modal{ - table{ - width:100%; - - tr.input td{ - padding-top: 10px; - - &.label{ - width: 100px; - label{ - margin-bottom: 0px; - font-weight: bold; - } - } - } - - tr.instructions label{ - color: $primary-medium; - } - - - } - - #channel-field{ - width: 200px; - margin-bottom: 0px; - box-shadow: none; - } - .tag-chooser{ - ul.select2-choices{ - border: none; - background:none; - } - margin-bottom: 0px; - margin-top: 0px; - } - - .field-name{ - font-weight: bold; + } } - } + div.channel-footer { + overflow:auto; + } + } +} + +#chat_integration_edit_channel_modal, +#chat_integration_test_modal, +#chat_integration_edit_rule_modal { + table { + width:100%; + + tr.input td { + padding-top: 10px; + + &.label { + width: 100px; + + label { + margin-bottom: 0px; + font-weight: bold; + } + } + } + + tr.instructions label { + color: $primary-medium; + } + } + + #channel-field { + width: 200px; + margin-bottom: 0px; + box-shadow: none; + } + + .tag-chooser { + ul.select2-choices { + border: none; + background:none; + } + + margin-bottom: 0px; + margin-top: 0px; + } + + .field-name { + font-weight: bold; + } +} diff --git a/lib/discourse_chat/provider.rb b/lib/discourse_chat/provider.rb index 45df620..5f62823 100644 --- a/lib/discourse_chat/provider.rb +++ b/lib/discourse_chat/provider.rb @@ -22,11 +22,11 @@ module DiscourseChat end def self.provider_names - self.providers.map { |x| x::PROVIDER_NAME } + self.providers.map! { |x| x::PROVIDER_NAME } end def self.enabled_provider_names - self.enabled_providers.map { |x| x::PROVIDER_NAME } + self.enabled_providers.map! { |x| x::PROVIDER_NAME } end def self.get_by_name(name) @@ -71,7 +71,7 @@ module DiscourseChat engines = [] DiscourseChat::Provider.providers.each do |provider| engine = provider.constants.select do |constant| - constant.to_s =~ (/Engine$/) && (not constant.to_s == "HookEngine") + constant.to_s =~ (/Engine$/) && (constant.to_s != "HookEngine") end.map(&provider.method(:const_get)).first if engine diff --git a/lib/discourse_chat/provider/discord/discord_provider.rb b/lib/discourse_chat/provider/discord/discord_provider.rb index bb8ff20..94faebc 100644 --- a/lib/discourse_chat/provider/discord/discord_provider.rb +++ b/lib/discourse_chat/provider/discord/discord_provider.rb @@ -3,10 +3,11 @@ module DiscourseChat module DiscordProvider PROVIDER_NAME = "discord".freeze PROVIDER_ENABLED_SETTING = :chat_integration_discord_enabled + CHANNEL_PARAMETERS = [ - { key: "name", regex: '^\S+' }, - { key: "webhook_url", regex: '^https:\/\/discordapp\.com\/api\/webhooks\/', unique: true, hidden: true } - ] + { key: "name", regex: '^\S+' }, + { key: "webhook_url", regex: '^https:\/\/discordapp\.com\/api\/webhooks\/', unique: true, hidden: true } + ].freeze def self.send_message(url, message) http = Net::HTTP.new("discordapp.com", 443) @@ -18,12 +19,12 @@ module DiscourseChat req.body = message.to_json response = http.request(req) - return response + response end def self.ensure_protocol(url) - return url if not url.start_with?('//') - return 'http:' + url + return url if !url.start_with?('//') + "http:#{url}" end def self.generate_discord_message(post) @@ -49,22 +50,20 @@ module DiscourseChat }] } - return message + message end def self.trigger_notification(post, channel) # Adding ?wait=true means that we actually get a success/failure response, rather than returning asynchronously - webhook_url = channel.data['webhook_url'] + '?wait=true' - + webhook_url = "#{channel.data['webhook_url']}?wait=true" message = generate_discord_message(post) - response = send_message(webhook_url, message) - if not response.kind_of? Net::HTTPSuccess - error_key = nil - raise ::DiscourseChat::ProviderError.new info: { error_key: error_key, message: message, response_body: response.body } + if !response.kind_of?(Net::HTTPSuccess) + raise ::DiscourseChat::ProviderError.new(info: { + error_key: nil, message: message, response_body: response.body + }) end - end end diff --git a/lib/discourse_chat/provider/hipchat/hipchat_provider.rb b/lib/discourse_chat/provider/hipchat/hipchat_provider.rb index c4a4899..890b39a 100644 --- a/lib/discourse_chat/provider/hipchat/hipchat_provider.rb +++ b/lib/discourse_chat/provider/hipchat/hipchat_provider.rb @@ -81,7 +81,7 @@ module DiscourseChat response = send_message(webhook_url, message) - if not response.kind_of? Net::HTTPSuccess + if !response.kind_of?(Net::HTTPSuccess) error_key = nil raise ::DiscourseChat::ProviderError.new info: { error_key: error_key, message: message, response_body: response.body } end diff --git a/lib/discourse_chat/provider/matrix/matrix_provider.rb b/lib/discourse_chat/provider/matrix/matrix_provider.rb index ea335de..5e77ec0 100644 --- a/lib/discourse_chat/provider/matrix/matrix_provider.rb +++ b/lib/discourse_chat/provider/matrix/matrix_provider.rb @@ -59,7 +59,7 @@ module DiscourseChat response = send_message(channel.data['room_id'], message) - if not response.kind_of? Net::HTTPSuccess + if !response.kind_of?(Net::HTTPSuccess) error_key = nil begin responseData = JSON.parse(response.body) diff --git a/lib/discourse_chat/provider/telegram/telegram_provider.rb b/lib/discourse_chat/provider/telegram/telegram_provider.rb index 917e205..9d5afd1 100644 --- a/lib/discourse_chat/provider/telegram/telegram_provider.rb +++ b/lib/discourse_chat/provider/telegram/telegram_provider.rb @@ -18,7 +18,7 @@ module DiscourseChat response = self.do_api_request('setWebhook', message) - if not response['ok'] == true + if response['ok'] != true # If setting up webhook failed, disable provider SiteSetting.chat_integration_telegram_enabled = false Rails.logger.error("Failed to setup telegram webhook. Message data= " + message.to_json + " response=" + response.to_json) @@ -89,7 +89,7 @@ module DiscourseChat response = sendMessage(message) - if not response['ok'] == true + if response['ok'] != true error_key = nil if response['description'].include? 'chat not found' error_key = 'chat_integration.provider.telegram.errors.channel_not_found' diff --git a/lib/discourse_chat/provider/zulip/zulip_provider.rb b/lib/discourse_chat/provider/zulip/zulip_provider.rb index 2679a08..c6a7646 100644 --- a/lib/discourse_chat/provider/zulip/zulip_provider.rb +++ b/lib/discourse_chat/provider/zulip/zulip_provider.rb @@ -53,7 +53,7 @@ module DiscourseChat response = send_message(message) - if not response.kind_of? Net::HTTPSuccess + 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 } diff --git a/spec/controllers/chat_controller_spec.rb b/spec/controllers/chat_controller_spec.rb index 1157144..4322a3f 100644 --- a/spec/controllers/chat_controller_spec.rb +++ b/spec/controllers/chat_controller_spec.rb @@ -114,9 +114,9 @@ describe 'Chat Controller', type: :request do end it 'should fail for invalid provider' do - get '/admin/plugins/chat/channels.json', params: { provider: 'someprovider' } - - expect(response).not_to be_success + expect do + get '/admin/plugins/chat/channels.json', params: { provider: 'someprovider' } + end.to raise_error(Discourse::InvalidParameters) end end diff --git a/spec/dummy_provider.rb b/spec/dummy_provider.rb index c1e80d4..a4d0fec 100644 --- a/spec/dummy_provider.rb +++ b/spec/dummy_provider.rb @@ -13,6 +13,7 @@ RSpec.shared_context "dummy provider" do if @@raise_exception raise @@raise_exception end + @@sent_messages.push(post: post.id, channel: channel) end diff --git a/test/javascripts/acceptance/chat-integration-test.js.es6 b/test/javascripts/acceptance/chat-integration-test.js.es6 index bfc41f3..e9ef089 100644 --- a/test/javascripts/acceptance/chat-integration-test.js.es6 +++ b/test/javascripts/acceptance/chat-integration-test.js.es6 @@ -10,41 +10,49 @@ acceptance("Chat Integration", { object ]; }; + server.get('/admin/plugins/chat/providers', () => { // eslint-disable-line no-undef return response({ providers: [{name: 'dummy', id:'dummy',channel_parameters:[{key:'somekey', regex:"^\\S+$"}]}] }); }); + server.get('/admin/plugins/chat/channels', () => { // eslint-disable-line no-undef return response({"channels":[{"id":97,"provider":"dummy","data":{somekey:"#general"},"rules":[ {"id":98,"channel_id":97,"category_id":null,"team_id":null,"type":"normal","tags":[],"filter":"watch","error_key":null} ]}]}); }); + server.post('/admin/plugins/chat/channels', () => { // eslint-disable-line no-undef return response({ }); }); + server.put('/admin/plugins/chat/channels/:id', () => { // eslint-disable-line no-undef return response({ }); }); + server.delete('/admin/plugins/chat/channels/:id', () => { // eslint-disable-line no-undef return response({ }); }); + server.post('/admin/plugins/chat/rules', () => { // eslint-disable-line no-undef return response({ }); }); + server.put('/admin/plugins/chat/rules/:id', () => { // eslint-disable-line no-undef return response({ }); }); + server.delete('/admin/plugins/chat/rules/:id', () => { // eslint-disable-line no-undef return response({ }); }); + server.post('/admin/plugins/chat/test', () => { // eslint-disable-line no-undef return response({ }); }); + server.get('/groups/search.json', () => { // eslint-disable-line no-undef return response([]); }); - } - }); test("Rules load successfully", assert => { @@ -60,21 +68,21 @@ test("Create channel works", assert => { visit("/admin/plugins/chat"); andThen(() => { - click('#create_channel'); + click('#create-channel'); }); andThen(() => { assert.ok(exists('#chat_integration_edit_channel_modal'), 'it displays the modal'); - assert.ok(find('#save_channel').prop('disabled'), 'it disables the save button'); + assert.ok(find('#save-channel').prop('disabled'), 'it disables the save button'); fillIn('#chat_integration_edit_channel_modal input', '#general'); }); andThen(() => { - assert.ok(find('#save_channel').prop('disabled') === false, 'it enables the save button'); + assert.ok(find('#save-channel').prop('disabled') === false, 'it enables the save button'); }); andThen(() => { - click('#save_channel'); + click('#save-channel'); }); andThen(() => { @@ -92,12 +100,12 @@ test("Edit channel works", assert => { andThen(() => { assert.ok(exists('#chat_integration_edit_channel_modal'), 'it displays the modal'); - assert.ok(!find('#save_channel').prop('disabled'), 'save is enabled'); + assert.ok(!find('#save-channel').prop('disabled'), 'save is enabled'); fillIn('#chat_integration_edit_channel_modal input', ' general'); }); andThen(() => { - assert.ok(find('#save_channel').prop('disabled'), 'it disables the save button'); + assert.ok(find('#save-channel').prop('disabled'), 'it disables the save button'); }); andThen(() => { @@ -125,10 +133,10 @@ test("Create rule works", assert => { andThen(() => { assert.ok(exists('#chat_integration_edit_rule_modal'), 'modal opens on edit'); - assert.ok(find('#save_rule').prop('disabled') === false, 'save is enabled'); + assert.ok(find('#save-rule').prop('disabled') === false, 'save is enabled'); }); - click('#save_rule'); + click('#save-rule'); andThen(() => { assert.ok(!exists('#chat_integration_edit_rule_modal'), 'modal closes on save'); @@ -146,10 +154,10 @@ test("Edit rule works", assert => { andThen(() => { assert.ok(exists('#chat_integration_edit_rule_modal'), 'modal opens on edit'); - assert.ok(find('#save_rule').prop('disabled') === false, 'it enables the save button'); + assert.ok(find('#save-rule').prop('disabled') === false, 'it enables the save button'); }); - click('#save_rule'); + click('#save-rule'); andThen(() => { assert.ok(!exists('#chat_integration_edit_rule_modal'), 'modal closes on save'); @@ -213,4 +221,4 @@ test("Test channel works", assert => { assert.ok(exists('#modal-alert.alert-success'), 'success message displayed'); }); -}); \ No newline at end of file +});