diff --git a/app/models/channel.rb b/app/models/channel.rb index 007d5ef..fc17c64 100644 --- a/app/models/channel.rb +++ b/app/models/channel.rb @@ -1,6 +1,6 @@ class DiscourseChat::Channel < DiscourseChat::PluginModel # Setup ActiveRecord::Store to use the JSON field to read/write these values - store :value, accessors: [ :provider, :error_key, :data ], coder: JSON + store :value, accessors: [ :provider, :error_key, :error_info, :data ], coder: JSON scope :with_provider, ->(provider) { where("value::json->>'provider'=?", provider) } scope :with_data_value, ->(key, value) { where("(value::json->>'data')::json->>?=?", key.to_s, value.to_s) } diff --git a/app/serializers/channel_serializer.rb b/app/serializers/channel_serializer.rb index 59aeb5e..80d5795 100644 --- a/app/serializers/channel_serializer.rb +++ b/app/serializers/channel_serializer.rb @@ -1,7 +1,7 @@ require_relative './rule_serializer' class DiscourseChat::ChannelSerializer < ApplicationSerializer - attributes :id, :provider, :error_key, :data, :rules + attributes :id, :provider, :error_key, :error_info, :data, :rules def rules object.rules.order_by_precedence.map do |rule| diff --git a/app/services/manager.rb b/app/services/manager.rb index 3f4fb2d..9b72414 100644 --- a/app/services/manager.rb +++ b/app/services/manager.rb @@ -86,15 +86,16 @@ module DiscourseChat else channel.update_attribute('error_key', 'chat_integration.channel_exception') end + channel.update_attribute('error_info', JSON.pretty_generate(e.try(:info))) # Log the error - Discourse.handle_job_exception(e, - message: "Triggering notifications failed", - extra: { provider_name: provider::PROVIDER_NAME, - channel: rule.channel, - post_id: post.id, - error_info: e.class == DiscourseChat::ProviderError ? e.info : nil } - ) + # Discourse.handle_job_exception(e, + # message: "Triggering notifications failed", + # extra: { provider_name: provider::PROVIDER_NAME, + # channel: rule.channel, + # post_id: post.id, + # error_info: e.class == DiscourseChat::ProviderError ? e.info : nil } + # ) end end diff --git a/assets/javascripts/admin/components/channel-details.js.es6 b/assets/javascripts/admin/components/channel-details.js.es6 index abd24ae..2b352fa 100644 --- a/assets/javascripts/admin/components/channel-details.js.es6 +++ b/assets/javascripts/admin/components/channel-details.js.es6 @@ -1,41 +1,48 @@ -import { popupAjaxError } from 'discourse/lib/ajax-error'; +import { popupAjaxError } from "discourse/lib/ajax-error"; export default Ember.Component.extend({ - classNames: ['channel-details'], + classNames: ["channel-details"], actions: { - refresh: function(){ - this.sendAction('refresh'); + refresh: function() { + this.sendAction("refresh"); }, - delete(channel){ - bootbox.confirm(I18n.t("chat_integration.channel_delete_confirm"), I18n.t("no_value"), I18n.t("yes_value"), result => { - if (result) { - channel.destroyRecord().then(() => { - this.send('refresh'); - }).catch(popupAjaxError); + delete(channel) { + bootbox.confirm( + I18n.t("chat_integration.channel_delete_confirm"), + I18n.t("no_value"), + I18n.t("yes_value"), + result => { + if (result) { + channel + .destroyRecord() + .then(() => { + this.send("refresh"); + }) + .catch(popupAjaxError); + } } - }); + ); }, - edit(channel){ - this.sendAction('edit', channel); + edit(channel) { + this.sendAction("edit", channel); }, - test(channel){ - this.sendAction('test', channel); + test(channel) { + this.sendAction("test", channel); }, - createRule(channel){ - this.sendAction('createRule', channel); + createRule(channel) { + this.sendAction("createRule", channel); }, - editRule(rule){ - this.sendAction('editRule', rule, this.get('channel')); - }, - - showError(errorKey){ - bootbox.alert(I18n.t(errorKey)); + editRule(rule) { + this.sendAction("editRule", rule, this.get("channel")); }, + showError(channel) { + this.sendAction("showError", channel); + } } }); 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 b261603..7c0a591 100644 --- a/assets/javascripts/admin/controllers/admin-plugins-chat-provider.js.es6 +++ b/assets/javascripts/admin/controllers/admin-plugins-chat-provider.js.es6 @@ -1,14 +1,14 @@ -import showModal from 'discourse/lib/show-modal'; +import showModal from "discourse/lib/show-modal"; import computed from "ember-addons/ember-computed-decorators"; export default Ember.Controller.extend({ modalShowing: false, - @computed('model.channels') + @computed("model.channels") anyErrors(channels) { let anyErrors = false; - channels.forEach((channel) => { + channels.forEach(channel => { if (channel.error_key) { anyErrors = true; } @@ -17,57 +17,78 @@ export default Ember.Controller.extend({ return anyErrors; }, - actions:{ + actions: { createChannel() { - this.set('modalShowing', true); + this.set("modalShowing", true); const model = { - channel: this.store.createRecord('channel', { provider: this.get('model.provider.id'), data:{} }), - provider: this.get('model.provider') + 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 }); + showModal("admin-plugins-chat-edit-channel", { + model: model, + admin: true + }); }, editChannel(channel) { - this.set('modalShowing', true); + this.set("modalShowing", true); const model = { channel: channel, - provider: this.get('model.provider') + provider: this.get("model.provider") }; - showModal('admin-plugins-chat-edit-channel', { model: model, admin: true }); + showModal("admin-plugins-chat-edit-channel", { + model: model, + admin: true + }); }, testChannel(channel) { - this.set('modalShowing', true); - showModal('admin-plugins-chat-test', { model: { channel: channel }, admin: true }); + this.set("modalShowing", true); + showModal("admin-plugins-chat-test", { + model: { channel: channel }, + admin: true + }); }, - createRule(channel){ - this.set('modalShowing', true); + createRule(channel) { + this.set("modalShowing", true); const model = { - rule: this.store.createRecord('rule', { channel_id: channel.id }), + rule: this.store.createRecord("rule", { channel_id: channel.id }), channel: channel, - provider: this.get('model.provider'), - groups: this.get('model.groups') + provider: this.get("model.provider"), + groups: this.get("model.groups") }; - showModal('admin-plugins-chat-edit-rule', { model: model, admin: true }); + showModal("admin-plugins-chat-edit-rule", { model: model, admin: true }); }, - editRule(rule, channel){ - this.set('modalShowing', true); + editRule(rule, channel) { + this.set("modalShowing", true); const model = { rule: rule, channel: channel, - provider: this.get('model.provider'), - groups: this.get('model.groups') + provider: this.get("model.provider"), + groups: this.get("model.groups") }; - showModal('admin-plugins-chat-edit-rule', { model: model, admin: true }); + showModal("admin-plugins-chat-edit-rule", { model: model, admin: true }); }, + + showError(channel) { + this.set("modalShowing", true); + + showModal("admin-plugins-chat-channel-error", { + model: channel, + admin: true + }); + } } }); diff --git a/assets/javascripts/admin/templates/modal/admin-plugins-chat-channel-error.hbs b/assets/javascripts/admin/templates/modal/admin-plugins-chat-channel-error.hbs new file mode 100644 index 0000000..3c0cea7 --- /dev/null +++ b/assets/javascripts/admin/templates/modal/admin-plugins-chat-channel-error.hbs @@ -0,0 +1,4 @@ +{{#d-modal-body id="chat_integration_error_modal"}} +
{{model.error_info}}+{{/d-modal-body}} \ 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 eb7f66e..07f721a 100644 --- a/assets/javascripts/discourse/templates/admin/plugins-chat-provider.hbs +++ b/assets/javascripts/discourse/templates/admin/plugins-chat-provider.hbs @@ -14,7 +14,8 @@ edit='editChannel' test='testChannel' createRule='createRule' - editRule='editRule'}} + editRule='editRule' + showError='showError'}} {{/each}}