0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Added createUnsubscribeUrl fn to mega

no-issue
This commit is contained in:
Fabien O'Carroll 2019-11-06 17:46:30 +07:00
parent 4db260f17e
commit 00db1d385c

View file

@ -6,6 +6,7 @@ const membersService = require('../members');
const bulkEmailService = require('../bulk-email'); const bulkEmailService = require('../bulk-email');
const models = require('../../models'); const models = require('../../models');
const postEmailSerializer = require('./post-email-serializer'); const postEmailSerializer = require('./post-email-serializer');
const urlUtils = require('../../lib/url-utils');
const sendEmail = async (post, members) => { const sendEmail = async (post, members) => {
const emailTmpl = postEmailSerializer.serialize(post); const emailTmpl = postEmailSerializer.serialize(post);
@ -39,6 +40,23 @@ const serialize = async (model) => {
return frame.response[docName][0]; return frame.response[docName][0];
}; };
/**
* createUnsubscribeUrl
*
* Takes a member and returns the url that should be used to unsubscribe
*
* @param {object} member
* @param {string} member.uuid
*/
function createUnsubscribeUrl(member) {
const siteUrl = urlUtils.getSiteUrl();
const unsubscribeUrl = new URL(siteUrl);
unsubscribeUrl.searchParams.set('action', 'unsubscribe');
unsubscribeUrl.searchParams.set('unsubscribe', member.uuid);
return unsubscribeUrl.href;
}
/** /**
* handleUnsubscribeRequest * handleUnsubscribeRequest
* *
@ -151,5 +169,6 @@ function listen() {
module.exports = { module.exports = {
listen, listen,
sendTestEmail, sendTestEmail,
handleUnsubscribeRequest handleUnsubscribeRequest,
createUnsubscribeUrl
}; };