From d028b5a5b96cc60376c0cebcdb17bc8721eba7d2 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Thu, 16 Nov 2017 12:36:17 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Allow=20any=20Slack-compatible?= =?UTF-8?q?=20webhook=20URLs=20in=20Slack=20app?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes https://github.com/TryGhost/Ghost/issues/9246, closes https://github.com/TryGhost/Ghost/issues/7856 - allow any valid URL in the slack webhook input - update slack app description to mention Slack-compatible services including Discord and Mattermost --- ghost/admin/app/templates/settings/apps/slack.hbs | 2 +- ghost/admin/app/validators/slack-integration.js | 6 +++--- ghost/admin/tests/unit/validators/slack-integration-test.js | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ghost/admin/app/templates/settings/apps/slack.hbs b/ghost/admin/app/templates/settings/apps/slack.hbs index be44e6bcf2..729e4bdc93 100644 --- a/ghost/admin/app/templates/settings/apps/slack.hbs +++ b/ghost/admin/app/templates/settings/apps/slack.hbs @@ -34,7 +34,7 @@
Webhook URL
-
Automatically send newly published posts to a channel in Slack
+
Automatically send newly published posts to a channel in Slack or any Slack-compatible service like Discord or Mattermost.
{{#gh-form-group errors=model.errors hasValidated=model.hasValidated property="url"}} {{gh-input model.url name="slack[url]" update=(action "updateURL") onenter=(action "save") focusOut=(action "triggerDirtyState") placeholder="https://hooks.slack.com/services/..." data-test-slack-url-input=true}} diff --git a/ghost/admin/app/validators/slack-integration.js b/ghost/admin/app/validators/slack-integration.js index 272cf035d2..b4af707916 100644 --- a/ghost/admin/app/validators/slack-integration.js +++ b/ghost/admin/app/validators/slack-integration.js @@ -1,4 +1,5 @@ import BaseValidator from './base'; +import {isBlank} from '@ember/utils'; export default BaseValidator.create({ properties: ['url'], @@ -7,9 +8,8 @@ export default BaseValidator.create({ let url = model.get('url'); let hasValidated = model.get('hasValidated'); - let urlRegex = new RegExp(/(^https:\/\/hooks\.slack\.com\/services\/)(\S+)/); - - if (!validator.empty(url) && !url.match(urlRegex)) { + // eslint-disable-next-line camelcase + if (!isBlank(url) && !validator.isURL(url, {require_protocol: true})) { model.get('errors').add( 'url', 'The URL must be in a format like https://hooks.slack.com/services/' diff --git a/ghost/admin/tests/unit/validators/slack-integration-test.js b/ghost/admin/tests/unit/validators/slack-integration-test.js index 3e813483d4..99018d5a77 100644 --- a/ghost/admin/tests/unit/validators/slack-integration-test.js +++ b/ghost/admin/tests/unit/validators/slack-integration-test.js @@ -47,7 +47,8 @@ describe('Unit: Validator: slack-integration', function () { let validUrls = [ 'https://hooks.slack.com/services/;alskdjf', 'https://hooks.slack.com/services/123445678', - 'https://hooks.slack.com/services/some_webhook' + 'https://hooks.slack.com/services/some_webhook', + 'https://discordapp.com/api/webhooks/380692408364433418/mGLHSRyEoUaTvY91Te16WOT8Obn-BrJoiTNoxeUqhb6klKERb9xaZkUBYC5AeduwYCCy/slack' ]; validUrls.forEach(function (url) {