From 173b3f3f843cd46286f0e49de74959357f016f3b Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Fri, 2 Sep 2016 15:23:56 -0500 Subject: [PATCH] fix: Account for system messages in flag slack alert --- test/api/v3/unit/libs/slack.js | 17 +++++++++++++++++ website/server/libs/slack.js | 9 ++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/test/api/v3/unit/libs/slack.js b/test/api/v3/unit/libs/slack.js index b133380384..3e48ade892 100644 --- a/test/api/v3/unit/libs/slack.js +++ b/test/api/v3/unit/libs/slack.js @@ -97,6 +97,23 @@ describe('slack', () => { }); }); + it('provides name for system message', () => { + message.uuid = 'system'; + delete message.user; + + slack.sendFlagNotification({ + flagger, + group, + message, + }); + + expect(IncomingWebhook.prototype.send).to.be.calledWithMatch({ + attachments: [sandbox.match({ + author_name: 'System Message', + })], + }); + }); + it('noops if no flagging url is provided', () => { sandbox.stub(nconf, 'get').withArgs('SLACK:FLAGGING_URL').returns(''); sandbox.stub(logger, 'error'); diff --git a/website/server/libs/slack.js b/website/server/libs/slack.js index 2c309ae430..14350d8a8b 100644 --- a/website/server/libs/slack.js +++ b/website/server/libs/slack.js @@ -25,6 +25,7 @@ function sendFlagNotification ({ return; } let titleLink; + let authorName; let title = `Flag in ${group.name}`; let text = `${flagger.profile.name} (${flagger.id}) flagged a message`; @@ -36,12 +37,18 @@ function sendFlagNotification ({ title += ` - (${group.privacy} ${group.type})`; } + if (!message.user && message.uuid === 'system') { + authorName = 'System Message'; + } else { + authorName = `${message.user} - ${message.uuid}`; + } + flagSlack.send({ text, attachments: [{ fallback: 'Flag Message', color: 'danger', - author_name: `${message.user} - ${message.uuid}`, + author_name: authorName, title, title_link: titleLink, text: message.text,