Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Domains: Prevent email from being purchased for Gravatar domains #96085

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/lib/emails/email-provider-constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export const EMAIL_WARNING_SLUG_UNVERIFIED_FORWARDS = 'unverified_forwards';
export const EMAIL_WARNING_CODE_OTHER_USER_OWNS_DOMAIN_SUBSCRIPTION =
'other-user-owns-subscription';
export const EMAIL_WARNING_CODE_OTHER_USER_OWNS_EMAIL = 'other-user-owns-email';
export const EMAIL_WARNING_CODE_GRAVATAR_DOMAIN = 'domain-gravatar-domain';
53 changes: 36 additions & 17 deletions client/my-sites/email/email-forwards-add/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import QueryProductsList from 'calypso/components/data/query-products-list';
import QuerySiteDomains from 'calypso/components/data/query-site-domains';
import HeaderCake from 'calypso/components/header-cake';
import Main from 'calypso/components/main';
import Notice from 'calypso/components/notice';
import SectionHeader from 'calypso/components/section-header';
import { getCurrentUserCannotAddEmailReason, getSelectedDomain } from 'calypso/lib/domains';
import { EMAIL_WARNING_CODE_GRAVATAR_DOMAIN } from 'calypso/lib/emails/email-provider-constants';
import EmailForwardingAddNewCompactList from 'calypso/my-sites/email/email-forwarding/email-forwarding-add-new-compact-list';
import EmailHeader from 'calypso/my-sites/email/email-header';
import {
Expand All @@ -17,6 +20,7 @@ import {
import { useSelector } from 'calypso/state';
import getCurrentRoute from 'calypso/state/selectors/get-current-route';
import {
getDomainsBySiteId,
hasLoadedSiteDomains,
isRequestingSiteDomains,
} from 'calypso/state/sites/domains/selectors';
Expand Down Expand Up @@ -46,6 +50,11 @@ const EmailForwardsAdd = ( { selectedDomainName, source }: EmailForwardsAddProps

const translate = useTranslate();

const domains = useSelector( ( state ) => getDomainsBySiteId( state, selectedSite?.ID ) );
const selectedDomain = getSelectedDomain( { domains, selectedDomainName } );
const cannotAddEmailWarningReason = getCurrentUserCannotAddEmailReason( selectedDomain );
const isGravatarDomain = cannotAddEmailWarningReason?.code === EMAIL_WARNING_CODE_GRAVATAR_DOMAIN;

const goToEmail = useCallback( (): void => {
if ( ! selectedSite ) {
return;
Expand All @@ -67,6 +76,32 @@ const EmailForwardsAdd = ( { selectedDomainName, source }: EmailForwardsAddProps
page( getEmailManagementPath( selectedSite.slug, selectedDomainName, currentRoute ) );
}, [ currentRoute, selectedDomainName, selectedSite ] );

const content = isGravatarDomain ? (
<Notice showDismiss={ false } className="email-forwards-add__notice">
{ translate(
'This domain is associated with a Gravatar profile and cannot be used for email services at this time.'
) }
</Notice>
) : (
<Card>
{ areDomainsLoading && (
<div className="email-forwards-add__placeholder">
<p />
<p />
<Button disabled />
</div>
) }

{ ! areDomainsLoading && (
<EmailForwardingAddNewCompactList
onAddedEmailForwards={ onAddedEmailForwards }
onBeforeAddEmailForwards={ noop }
selectedDomainName={ selectedDomainName }
/>
) }
</Card>
);

return (
<div className="email-forwards-add">
<QueryProductsList />
Expand All @@ -84,23 +119,7 @@ const EmailForwardsAdd = ( { selectedDomainName, source }: EmailForwardsAddProps

<SectionHeader label={ translate( 'Add New Email Forwards' ) } />

<Card>
{ areDomainsLoading && (
<div className="email-forwards-add__placeholder">
<p />
<p />
<Button disabled />
</div>
) }

{ ! areDomainsLoading && (
<EmailForwardingAddNewCompactList
onAddedEmailForwards={ onAddedEmailForwards }
onBeforeAddEmailForwards={ noop }
selectedDomainName={ selectedDomainName }
/>
) }
</Card>
{ content }
</Main>
</div>
);
Expand Down
4 changes: 4 additions & 0 deletions client/my-sites/email/email-forwards-add/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@
margin-top: 3em;
}
}

.email-forwards-add__notice {
margin-top: 24px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from 'calypso/lib/domains';
import { ResponseDomain } from 'calypso/lib/domains/types';
import {
EMAIL_WARNING_CODE_GRAVATAR_DOMAIN,
EMAIL_WARNING_CODE_OTHER_USER_OWNS_DOMAIN_SUBSCRIPTION,
EMAIL_WARNING_CODE_OTHER_USER_OWNS_EMAIL,
} from 'calypso/lib/emails/email-provider-constants';
Expand All @@ -20,16 +21,26 @@ type EmailPlanWarningNoticeProps = {
export const EmailPlanWarningNotice = ( props: EmailPlanWarningNoticeProps ) => {
const { domain, selectedSite } = props;

const cannotAddEmailWarningReason = getCurrentUserCannotAddEmailReason( domain );
const cannotAddEmailWarningMessage = cannotAddEmailWarningReason?.message ?? '';
const cannotAddEmailWarningCode = cannotAddEmailWarningReason?.code ?? null;

if ( cannotAddEmailWarningCode === EMAIL_WARNING_CODE_GRAVATAR_DOMAIN ) {
return (
<div className="email-plan-warning-notice__warning">
<div className="email-plan-warning-notice__message">
<span>{ cannotAddEmailWarningMessage }</span>
</div>
</div>
);
}

// If email and domain are owned by different users, none of the users will be able to make a purchase and the only way to resolve this
// is to reach out to support. Therefore, we should surface a different message to address this scenario.
if ( ! isDomainAndEmailSubscriptionsOwnedByDifferentUsers( domain ) ) {
return <EmailDifferentDomainOwnerMessage />;
}

const cannotAddEmailWarningReason = getCurrentUserCannotAddEmailReason( domain );
const cannotAddEmailWarningMessage = cannotAddEmailWarningReason?.message ?? '';
const cannotAddEmailWarningCode = cannotAddEmailWarningReason?.code ?? null;

switch ( cannotAddEmailWarningCode ) {
case EMAIL_WARNING_CODE_OTHER_USER_OWNS_EMAIL:
return (
Expand Down
20 changes: 19 additions & 1 deletion client/my-sites/email/email-management/home/utils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { translate } from 'i18n-calypso';
import { recordTracksEvent } from 'calypso/lib/analytics/tracks';
import { canCurrentUserAddEmail } from 'calypso/lib/domains';
import { canCurrentUserAddEmail, getCurrentUserCannotAddEmailReason } from 'calypso/lib/domains';
import { getEmailForwardsCount, hasEmailForwards } from 'calypso/lib/domains/email-forwarding';
import { isRecentlyRegistered } from 'calypso/lib/domains/utils';
import {
hasGoogleAccountTOSWarning,
hasUnusedMailboxWarning,
hasUnverifiedEmailForward,
} from 'calypso/lib/emails';
import { EMAIL_WARNING_CODE_GRAVATAR_DOMAIN } from 'calypso/lib/emails/email-provider-constants';
import {
getGSuiteMailboxCount,
getGSuiteSubscriptionId,
Expand Down Expand Up @@ -133,6 +134,23 @@ export function resolveEmailPlanStatus(
} ),
};

const gravatarDomainStatus = {
statusClass: 'warning',
icon: 'info',
text: translate( 'Gravatar domain', {
comment: 'Current user is not allowed to purchase new email subscriptions',
} ),
};

// Some Gravatar domains already had email purchased for them before we disabled it.
// These domains have a specific warning message.
if (
! canCurrentUserAddEmail( domain ) &&
getCurrentUserCannotAddEmailReason( domain )?.code === EMAIL_WARNING_CODE_GRAVATAR_DOMAIN
) {
return gravatarDomainStatus;
}

if ( hasGSuiteWithUs( domain ) ) {
if ( ! canCurrentUserAddEmail( domain ) ) {
return cannotManageStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@ import QueryProductsList from 'calypso/components/data/query-products-list';
import QuerySiteDomains from 'calypso/components/data/query-site-domains';
import { hasDiscount } from 'calypso/components/gsuite/gsuite-price';
import Main from 'calypso/components/main';
import Notice from 'calypso/components/notice';
import TrackComponentView from 'calypso/lib/analytics/track-component-view';
import { getSelectedDomain, canCurrentUserAddEmail } from 'calypso/lib/domains';
import {
getSelectedDomain,
canCurrentUserAddEmail,
getCurrentUserCannotAddEmailReason,
} from 'calypso/lib/domains';
import {
hasEmailForwards,
getDomainsWithEmailForwards,
} from 'calypso/lib/domains/email-forwarding';
import { EMAIL_WARNING_CODE_GRAVATAR_DOMAIN } from 'calypso/lib/emails/email-provider-constants';
import { hasGSuiteSupportedDomain } from 'calypso/lib/gsuite';
import { GOOGLE_WORKSPACE_PRODUCT_TYPE } from 'calypso/lib/gsuite/constants';
import { domainAddNew } from 'calypso/my-sites/domains/paths';
Expand Down Expand Up @@ -93,6 +99,8 @@ const EmailProvidersStackedComparison = ( {

const currentUserCanAddEmail = canCurrentUserAddEmail( domain );
const showNonOwnerMessage = ! currentUserCanAddEmail && ! isDomainInCart;
const cannotAddEmailWarningReason = getCurrentUserCannotAddEmailReason( domain );
const isGravatarDomain = cannotAddEmailWarningReason?.code === EMAIL_WARNING_CODE_GRAVATAR_DOMAIN;

const isGSuiteSupported =
domain && canPurchaseGSuite && ( isDomainInCart || hasGSuiteSupportedDomain( [ domain ] ) );
Expand Down Expand Up @@ -292,13 +300,20 @@ const EmailProvidersStackedComparison = ( {
{ ! isDomainInCart && domain && <EmailExistingPaidServiceNotice domain={ domain } /> }

<>
{ showNonOwnerMessage && (
{ showNonOwnerMessage && ! isGravatarDomain && (
<EmailNonDomainOwnerMessage
domain={ domain }
selectedSite={ selectedSite }
source="email-comparison"
/>
) }
{ isGravatarDomain && (
<Notice showDismiss={ false } className="email-providers-stacked-comparison__notice">
{ translate(
'This domain is associated with a Gravatar profile and cannot be used for email services at this time.'
) }
</Notice>
) }
{ shouldPromoteGoogleWorkspace ? [ ...emailProviderCards ].reverse() : emailProviderCards }
</>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@
margin: 10px auto;
}
}

.email-providers-stacked-comparison__notice {
margin-top: 24px;
}
Loading