diff --git a/ghost/core/test/e2e-api/webmentions/webmentions.test.js b/ghost/core/test/e2e-api/webmentions/webmentions.test.js index 978272af3c..1a5cab0667 100644 --- a/ghost/core/test/e2e-api/webmentions/webmentions.test.js +++ b/ghost/core/test/e2e-api/webmentions/webmentions.test.js @@ -19,7 +19,6 @@ async function allSettled() { describe('Webmentions (receiving)', function () { let agent; - let emailMockReceiver; before(async function () { agent = await agentProvider.getWebmentionsAPIAgent(); @@ -31,7 +30,6 @@ describe('Webmentions (receiving)', function () { mockManager.disableNetwork(); mockManager.mockLabsEnabled('webmentions'); mockManager.mockLabsEnabled('webmentionEmails'); - emailMockReceiver = mockManager.mockMail(); }); afterEach(async function () { @@ -251,152 +249,6 @@ describe('Webmentions (receiving)', function () { assert.equal(mention.get('payload'), JSON.stringify({})); }); - it('can send an email notification for a new webmention', async function () { - const targetUrl = new URL('integrations/', urlUtils.getSiteUrl()); - const sourceUrl = new URL('http://testpage.com/external-article-123-email-test/'); - const html = ` - Test Page - `; - - nock(targetUrl.origin) - .head(targetUrl.pathname) - .reply(200); - - nock(sourceUrl.origin) - .get(sourceUrl.pathname) - .reply(200, html, {'Content-Type': 'text/html'}); - - await agent.post('/receive/') - .body({ - source: sourceUrl.href, - target: targetUrl.href - }) - .expectStatus(202); - - await allSettled(); - - const users = await models.User.getEmailAlertUsers('mention-received'); - for (const user of users) { - await mockManager.assert.sentEmail({ - subject: /New mention from/, - to: user.email - }); - } - emailMockReceiver.sentEmailCount(users.length); - }); - - it('can display post title in notification email', async function () { - const targetUrl = new URL('integrations/', urlUtils.getSiteUrl()); - const sourceUrl = new URL('http://testpage.com/external-article-1234-email-test/'); - const html = ` - Test Page - `; - - nock(targetUrl.origin).persist() - .head(targetUrl.pathname) - .reply(200); - - nock(sourceUrl.origin).persist() - .get(sourceUrl.pathname) - .reply(200, html, {'Content-Type': 'text/html'}); - - await agent.post('/receive/') - .body({ - source: sourceUrl.href, - target: targetUrl.href - }) - .expectStatus(202); - - await allSettled(); - - emailMockReceiver.matchHTMLSnapshot(); - }); - - it('can display page title in notification email', async function () { - const targetUrl = new URL('about/', urlUtils.getSiteUrl()); - const sourceUrl = new URL('http://testpage.com/external-article-12345-email-test/'); - const html = ` - Test Page - `; - - nock(targetUrl.origin).persist() - .head(targetUrl.pathname) - .reply(200); - - nock(sourceUrl.origin).persist() - .get(sourceUrl.pathname) - .reply(200, html, {'Content-Type': 'text/html'}); - - await agent.post('/receive/') - .body({ - source: sourceUrl.href, - target: targetUrl.href - }) - .expectStatus(202); - - await allSettled(); - - emailMockReceiver.matchHTMLSnapshot(); - }); - - it('does not send notification with flag disabled', async function () { - mockManager.mockLabsDisabled('webmentions'); - - const targetUrl = new URL('integrations/', urlUtils.getSiteUrl()); - const sourceUrl = new URL('http://testpage.com/external-article-123-email-test/'); - const html = ` - Test Page - `; - - nock(targetUrl.origin) - .head(targetUrl.pathname) - .reply(200); - - nock(sourceUrl.origin) - .get(sourceUrl.pathname) - .reply(200, html, {'Content-Type': 'text/html'}); - - await agent.post('/receive/') - .body({ - source: sourceUrl.href, - target: targetUrl.href - }) - .expectStatus(202); - - await allSettled(); - - emailMockReceiver.sentEmailCount(0); - }); - - it('does not send notification with email flag disabled', async function () { - mockManager.mockLabsDisabled('webmentionEmails'); - - const targetUrl = new URL('integrations/', urlUtils.getSiteUrl()); - const sourceUrl = new URL('http://testpage.com/external-article-123-email-test-2/'); - const html = ` - Test Page - `; - - nock(targetUrl.origin) - .head(targetUrl.pathname) - .reply(200); - - nock(sourceUrl.origin) - .get(sourceUrl.pathname) - .reply(200, html, {'Content-Type': 'text/html'}); - - await agent.post('/receive/') - .body({ - source: sourceUrl.href, - target: targetUrl.href - }) - .expectStatus(202); - - await allSettled(); - - emailMockReceiver.sentEmailCount(0); - }); - it('can verify a webmention link', async function () { const targetUrl = new URL(urlUtils.getSiteUrl()); const sourceUrl = new URL('http://testpage.com/external-article-2/'); diff --git a/ghost/staff-service/lib/email-templates/new-mention-received.hbs b/ghost/staff-service/lib/email-templates/new-mention-received.hbs deleted file mode 100644 index 9f4e569f3f..0000000000 --- a/ghost/staff-service/lib/email-templates/new-mention-received.hbs +++ /dev/null @@ -1,136 +0,0 @@ - - - - - - πŸ’Œ New mention from:{{#if sourceSiteTitle}}{{sourceSiteTitle}}{{else}}{{sourceUrl}}{{/if}} - {{> styles}} - - - - - - - - - -
  -
- - - - - - - - - - -
- - - - - - - - - - - - - - -
-

Hey there,

-

Your {{#if resource.type}} {{resource.type}} {{else}} page {{/if}} {{#if resource.name}}{{resource.name}}{{else}}{{targetUrl}}{{/if}} was mentioned in:

- - -
- -
-
{{sourceTitle}}
-
{{sourceExcerpt}}
-
- {{#if sourceFavicon}}{{/if}} - {{#if sourceSiteTitle}}{{sourceSiteTitle}}{{/if}} - {{#if sourceAuthor}} • {{sourceAuthor}}{{/if}} -
-
- {{#if sourceFeaturedImage}} -
- -
- {{/if}} -
-
- - - - - - - - - - -
- - - - - - -
View mentions
-
-
-

You can also copy & paste this URL into your browser:

- -
-

This message was sent from {{siteDomain}} to {{toEmail}}

-
-

Don’t want to receive these emails? Manage your preferences here.

-
-
- - - -
-
 
- - diff --git a/ghost/staff-service/lib/email-templates/new-mention-received.txt.js b/ghost/staff-service/lib/email-templates/new-mention-received.txt.js deleted file mode 100644 index 042bb0666d..0000000000 --- a/ghost/staff-service/lib/email-templates/new-mention-received.txt.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = function (data) { - // Be careful when you indent the email, because whitespaces are visible in emails! - return ` - You have been mentioned by ${data.sourceUrl}. - ---- - -Sent to ${data.toEmail} from ${data.siteDomain}. -If you would no longer like to receive these notifications you can adjust your settings at ${data.staffUrl}. - `; -}; diff --git a/ghost/staff-service/lib/emails.js b/ghost/staff-service/lib/emails.js index 4fe62a44a4..2aaefc6148 100644 --- a/ghost/staff-service/lib/emails.js +++ b/ghost/staff-service/lib/emails.js @@ -162,58 +162,6 @@ class StaffServiceEmails { } } - async notifyMentionReceived({mention}) { - const users = await this.models.User.getEmailAlertUsers('mention-received'); - let resource = null; - if (mention.resourceId) { - try { - const postModel = await this.models.Post.findOne({id: mention.resourceId.toString()}); - // console.log(postModel.toJSON()); - if (postModel) { - resource = { - id: postModel.id, - name: postModel.get('title'), - type: postModel.get('type') || 'post' - }; - } - } catch (err) { - this.logging.error(err); - } - } - for (const user of users) { - const to = user.email; - const subject = `πŸ’Œ New mention from: ${mention.sourceSiteTitle}`; - - const templateData = { - targetUrl: mention.target, - sourceUrl: mention.source, - sourceTitle: mention.sourceTitle, - sourceExcerpt: mention.sourceExcerpt, - sourceSiteTitle: mention.sourceSiteTitle, - sourceFavicon: mention.sourceFavicon, - sourceAuthor: mention.sourceAuthor, - sourceFeaturedImage: mention.sourceFeaturedImage, - resource, - siteTitle: this.settingsCache.get('title'), - siteUrl: this.urlUtils.getSiteUrl(), - siteDomain: this.siteDomain, - accentColor: this.settingsCache.get('accent_color'), - fromEmail: this.fromEmailAddress, - toEmail: to, - staffUrl: this.urlUtils.urlJoin(this.urlUtils.urlFor('admin', true), '#', `/settings/staff/${user.slug}`) - }; - - const {html, text} = await this.renderEmailTemplate('new-mention-received', templateData); - - await this.sendMail({ - to, - subject, - html, - text - }); - } - } - /** * * @param {object} eventData diff --git a/ghost/staff-service/lib/staff-service.js b/ghost/staff-service/lib/staff-service.js index 8502a24d61..8614350585 100644 --- a/ghost/staff-service/lib/staff-service.js +++ b/ghost/staff-service/lib/staff-service.js @@ -1,5 +1,4 @@ const {MemberCreatedEvent, SubscriptionCancelledEvent, SubscriptionActivatedEvent} = require('@tryghost/member-events'); -const {MentionCreatedEvent} = require('@tryghost/webmentions'); const {MilestoneCreatedEvent} = require('@tryghost/milestones'); // @NOTE: 'StaffService' is a vague name that does not describe what it's actually doing. @@ -79,10 +78,6 @@ class StaffService { /** @private */ async handleEvent(type, event) { - if (type === MentionCreatedEvent && event.data.mention && this.labs.isSet('webmentions') && this.labs.isSet('webmentionEmails')) { - return await this.emails.notifyMentionReceived(event.data); - } - if (type === MilestoneCreatedEvent && event.data.milestone && this.labs.isSet('milestoneEmails')) { await this.emails.notifyMilestoneReceived(event.data); } @@ -161,15 +156,6 @@ class StaffService { } }); - // Trigger email when a new webmention is received - this.DomainEvents.subscribe(MentionCreatedEvent, async (event) => { - try { - await this.handleEvent(MentionCreatedEvent, event); - } catch (e) { - this.logging.error(e, `Failed to notify webmention`); - } - }); - // Trigger email when a new milestone is reached this.DomainEvents.subscribe(MilestoneCreatedEvent, async (event) => { try { diff --git a/ghost/staff-service/test/staff-service.test.js b/ghost/staff-service/test/staff-service.test.js index 4a312a9e4e..4b61a44b21 100644 --- a/ghost/staff-service/test/staff-service.test.js +++ b/ghost/staff-service/test/staff-service.test.js @@ -2,7 +2,6 @@ // const testUtils = require('./utils'); const sinon = require('sinon'); const {MemberCreatedEvent, SubscriptionCancelledEvent, SubscriptionActivatedEvent} = require('@tryghost/member-events'); -const {MentionCreatedEvent} = require('@tryghost/webmentions'); const {MilestoneCreatedEvent} = require('@tryghost/milestones'); require('./utils'); @@ -186,11 +185,10 @@ describe('StaffService', function () { describe('subscribeEvents', function () { it('subscribes to events', async function () { service.subscribeEvents(); - subscribeStub.callCount.should.eql(5); + subscribeStub.callCount.should.eql(4); subscribeStub.calledWith(SubscriptionActivatedEvent).should.be.true(); subscribeStub.calledWith(SubscriptionCancelledEvent).should.be.true(); subscribeStub.calledWith(MemberCreatedEvent).should.be.true(); - subscribeStub.calledWith(MentionCreatedEvent).should.be.true(); subscribeStub.calledWith(MilestoneCreatedEvent).should.be.true(); }); }); @@ -336,21 +334,6 @@ describe('StaffService', function () { ).should.be.true(); }); - it('handles new mention notification', async function () { - await service.handleEvent(MentionCreatedEvent, { - data: { - mention: { - source: 'https://exmaple.com/some-post', - target: 'https://exmaple.com/some-mentioned-post', - sourceSiteTitle: 'Exmaple' - } - } - }); - mailStub.calledWith( - sinon.match({subject: `πŸ’Œ New mention from: Exmaple`}) - ).should.be.true(); - }); - it('handles milestone created event', async function () { await service.handleEvent(MilestoneCreatedEvent, { data: {