0
Fork 0
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:
Sag 2023-11-29 09:48:05 -03:00 committed by GitHub
parent babbca1c19
commit f8ad5fb2ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 116 additions and 43 deletions

View file

@ -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;
}
};

View file

@ -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,51 +284,101 @@ describe('Helpers - ', () => {
});
describe('getSupportAddress -', () => {
test('returns expected support address for non sub domain', () => {
let site = {
members_support_address: 'jamie@example.com'
};
const supportAddress = getSupportAddress({site});
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('jamie@example.com');
expect(supportAddress).toBe('support@example.com');
});
});
test('returns expected support address for non www sub domain', () => {
let site = {
members_support_address: 'jamie@blog.example.com'
};
const supportAddress = getSupportAddress({site});
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'
};
const supportAddress = getSupportAddress({site});
expect(supportAddress).toBe('jamie@blog.example.com');
expect(supportAddress).toBe('jamie@example.com');
});
test('returns expected support address for non www sub domain', () => {
let site = {
members_support_address: 'jamie@blog.example.com'
};
const supportAddress = getSupportAddress({site});
expect(supportAddress).toBe('jamie@blog.example.com');
});
test('returns expected support address for www domain', () => {
let site = {
members_support_address: 'jamie@www.example.com'
};
const supportAddress = getSupportAddress({site});
expect(supportAddress).toBe('jamie@example.com');
});
test('returns expected support address for default noreply value', () => {
let site = {
members_support_address: 'noreply',
url: 'https://www.example.com'
};
const supportAddress = getSupportAddress({site});
expect(supportAddress).toBe('noreply@example.com');
});
test('returns empty string for missing support address', () => {
let site = {
members_support_address: null,
url: 'https://www.example.com'
};
const supportAddress = getSupportAddress({site});
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('returns expected support address for www domain', () => {
test('otherwise, fallbacks to the calculated default_email_address when available', () => {
let site = {
members_support_address: 'jamie@www.example.com'
default_email_address: 'default@example.com',
url: 'https://example.com'
};
const supportAddress = getSupportAddress({site});
const defaultAddress = getDefaultNewsletterSender({site});
expect(supportAddress).toBe('jamie@example.com');
expect(defaultAddress).toBe('default@example.com');
});
test('returns expected support address for default noreply value', () => {
test('otherwise, fallbacks to noreply@sitedomain.com', () => {
let site = {
members_support_address: 'noreply',
url: 'https://www.example.com'
url: 'https://example.com'
};
const supportAddress = getSupportAddress({site});
const defaultAddress = getDefaultNewsletterSender({site});
expect(supportAddress).toBe('noreply@example.com');
});
test('returns empty string for missing support address', () => {
let site = {
members_support_address: null,
url: 'https://www.example.com'
};
const supportAddress = getSupportAddress({site});
expect(supportAddress).toBe('');
expect(defaultAddress).toBe('noreply@example.com');
});
});

View file

@ -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'
};

View file

@ -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",

View file

@ -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",