mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Updated Portal to use calculated support and default email addresses (#19163)
fixes GRO-72 - added "default_email_address" and "support_email_address" to the public settings - when available, use these addresses in Portal. Otherwise, fallback to current logic
This commit is contained in:
parent
babbca1c19
commit
f8ad5fb2ea
5 changed files with 116 additions and 43 deletions
|
@ -700,27 +700,42 @@ export const getMemberName = ({member}) => {
|
|||
};
|
||||
|
||||
export const getSupportAddress = ({site}) => {
|
||||
const {members_support_address: supportAddress} = site || {};
|
||||
const {members_support_address: oldSupportAddress, support_email_address: supportAddress} = site || {};
|
||||
|
||||
if (supportAddress?.indexOf('@') < 0) {
|
||||
const siteDomain = getSiteDomain({site});
|
||||
const updatedDomain = siteDomain?.replace(/^(www)\.(?=[^/]*\..{2,5})/, '') || '';
|
||||
return `${supportAddress}@${updatedDomain}`;
|
||||
// If available, use the calculated setting support_email_address
|
||||
if (supportAddress) {
|
||||
return supportAddress;
|
||||
}
|
||||
|
||||
if (supportAddress?.split('@')?.length > 1) {
|
||||
const [recipient, domain] = supportAddress.split('@');
|
||||
// Deprecated: use the saved setting members_support_address
|
||||
if (oldSupportAddress?.indexOf('@') < 0) {
|
||||
const siteDomain = getSiteDomain({site});
|
||||
const updatedDomain = siteDomain?.replace(/^(www)\.(?=[^/]*\..{2,5})/, '') || '';
|
||||
return `${oldSupportAddress}@${updatedDomain}`;
|
||||
}
|
||||
|
||||
if (oldSupportAddress?.split('@')?.length > 1) {
|
||||
const [recipient, domain] = oldSupportAddress.split('@');
|
||||
const updatedDomain = domain?.replace(/^(www)\.(?=[^/]*\..{2,5})/, '') || '';
|
||||
return `${recipient}@${updatedDomain}`;
|
||||
}
|
||||
return supportAddress || '';
|
||||
|
||||
return oldSupportAddress || '';
|
||||
};
|
||||
|
||||
export const getDefaultNewsletterSender = ({site}) => {
|
||||
const {default_email_address: defaultEmailAddress} = site || {};
|
||||
|
||||
// If available, use the calculated setting default_email_address as default
|
||||
const defaultAddress = defaultEmailAddress || `noreply@${getSiteDomain({site})}`;
|
||||
|
||||
const newsletters = getSiteNewsletters({site});
|
||||
const defaultNewsletter = newsletters?.[0];
|
||||
if (defaultNewsletter) {
|
||||
return defaultNewsletter.sender_email || `noreply@${getSiteDomain({site})}`;
|
||||
|
||||
if (defaultNewsletter && defaultNewsletter.sender_email) {
|
||||
return defaultNewsletter.sender_email;
|
||||
} else {
|
||||
return defaultAddress;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {getAllProductsForSite, getAvailableProducts, getCurrencySymbol, getFreeProduct, getMemberName, getMemberSubscription, getPriceFromSubscription, getPriceIdFromPageQuery, getSupportAddress, getUrlHistory, hasMultipleProducts, isActiveOffer, isInviteOnlySite, isPaidMember, isSameCurrency, transformApiTiersData, isSigninAllowed, isSignupAllowed, getCompExpiry, isInThePast} from './helpers';
|
||||
import {getAllProductsForSite, getAvailableProducts, getCurrencySymbol, getFreeProduct, getMemberName, getMemberSubscription, getPriceFromSubscription, getPriceIdFromPageQuery, getSupportAddress, getDefaultNewsletterSender, getUrlHistory, hasMultipleProducts, isActiveOffer, isInviteOnlySite, isPaidMember, isSameCurrency, transformApiTiersData, isSigninAllowed, isSignupAllowed, getCompExpiry, isInThePast} from './helpers';
|
||||
import * as Fixtures from './fixtures-generator';
|
||||
import {site as FixturesSite, member as FixtureMember, offer as FixtureOffer, transformTierFixture as TransformFixtureTiers} from '../utils/test-fixtures';
|
||||
import {isComplimentaryMember} from '../utils/helpers';
|
||||
|
@ -284,6 +284,19 @@ describe('Helpers - ', () => {
|
|||
});
|
||||
|
||||
describe('getSupportAddress -', () => {
|
||||
describe('when the calculated support address is available', () => {
|
||||
test('returns the calculated support email address, if available', () => {
|
||||
let site = {
|
||||
support_email_address: 'support@example.com',
|
||||
members_support_address: 'noreply@example.com'
|
||||
};
|
||||
const supportAddress = getSupportAddress({site});
|
||||
|
||||
expect(supportAddress).toBe('support@example.com');
|
||||
});
|
||||
});
|
||||
|
||||
describe('[Deprecated] when the calculated support address is not available', () => {
|
||||
test('returns expected support address for non sub domain', () => {
|
||||
let site = {
|
||||
members_support_address: 'jamie@example.com'
|
||||
|
@ -331,6 +344,43 @@ describe('Helpers - ', () => {
|
|||
expect(supportAddress).toBe('');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('getDefaultNewsletterSender - ', () => {
|
||||
test('returns the sender_email from the first newsletter when available', () => {
|
||||
let site = {
|
||||
default_email_address: 'default@example.com',
|
||||
url: 'https://example.com',
|
||||
newsletters: [
|
||||
{
|
||||
sender_email: 'sender_email@example.com'
|
||||
}
|
||||
]
|
||||
};
|
||||
const defaultAddress = getDefaultNewsletterSender({site});
|
||||
|
||||
expect(defaultAddress).toBe('sender_email@example.com');
|
||||
});
|
||||
|
||||
test('otherwise, fallbacks to the calculated default_email_address when available', () => {
|
||||
let site = {
|
||||
default_email_address: 'default@example.com',
|
||||
url: 'https://example.com'
|
||||
};
|
||||
const defaultAddress = getDefaultNewsletterSender({site});
|
||||
|
||||
expect(defaultAddress).toBe('default@example.com');
|
||||
});
|
||||
|
||||
test('otherwise, fallbacks to noreply@sitedomain.com', () => {
|
||||
let site = {
|
||||
url: 'https://example.com'
|
||||
};
|
||||
const defaultAddress = getDefaultNewsletterSender({site});
|
||||
|
||||
expect(defaultAddress).toBe('noreply@example.com');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getPriceIdFromPageQuery - ', () => {
|
||||
test('can correctly fetch price id from page query ', () => {
|
||||
|
|
|
@ -42,5 +42,7 @@ module.exports = {
|
|||
portal_button: 'portal_button',
|
||||
comments_enabled: 'comments_enabled',
|
||||
recommendations_enabled: 'recommendations_enabled',
|
||||
outbound_link_tagging: 'outbound_link_tagging'
|
||||
outbound_link_tagging: 'outbound_link_tagging',
|
||||
default_email_address: 'default_email_address',
|
||||
support_email_address: 'support_email_address'
|
||||
};
|
||||
|
|
|
@ -10,6 +10,7 @@ Object {
|
|||
"codeinjection_head": null,
|
||||
"comments_enabled": "off",
|
||||
"cover_image": "https://static.ghost.org/v5.0.0/images/publication-cover.jpg",
|
||||
"default_email_address": "noreply@127.0.0.1",
|
||||
"description": "Thoughts, stories and ideas",
|
||||
"facebook": "ghost",
|
||||
"firstpromoter_account": null,
|
||||
|
@ -74,6 +75,7 @@ Object {
|
|||
"url": "/contribute/",
|
||||
},
|
||||
],
|
||||
"support_email_address": "noreply@127.0.0.1",
|
||||
"timezone": "Etc/UTC",
|
||||
"title": "Ghost",
|
||||
"twitter": "@ghost",
|
||||
|
|
|
@ -1362,6 +1362,7 @@ Object {
|
|||
"codeinjection_head": null,
|
||||
"comments_enabled": "off",
|
||||
"cover_image": "https://static.ghost.org/v5.0.0/images/publication-cover.jpg",
|
||||
"default_email_address": "noreply@127.0.0.1",
|
||||
"description": "Thoughts, stories and ideas",
|
||||
"facebook": "ghost",
|
||||
"firstpromoter_account": null,
|
||||
|
@ -1426,6 +1427,7 @@ Object {
|
|||
"url": "/contribute/",
|
||||
},
|
||||
],
|
||||
"support_email_address": "noreply@127.0.0.1",
|
||||
"timezone": "Etc/UTC",
|
||||
"title": "Ghost",
|
||||
"twitter": "@ghost",
|
||||
|
@ -1461,6 +1463,7 @@ Object {
|
|||
"codeinjection_head": null,
|
||||
"comments_enabled": "off",
|
||||
"cover_image": "https://static.ghost.org/v5.0.0/images/publication-cover.jpg",
|
||||
"default_email_address": "noreply@127.0.0.1",
|
||||
"description": "Thoughts, stories and ideas",
|
||||
"facebook": "ghost",
|
||||
"firstpromoter_account": null,
|
||||
|
@ -1525,6 +1528,7 @@ Object {
|
|||
"url": "/contribute/",
|
||||
},
|
||||
],
|
||||
"support_email_address": "noreply@127.0.0.1",
|
||||
"timezone": "Etc/UTC",
|
||||
"title": "Ghost",
|
||||
"twitter": "@ghost",
|
||||
|
|
Loading…
Reference in a new issue