Skip to content

Commit

Permalink
Revert "Merge pull request #13160 from Automattic/update/site-is-cust…
Browse files Browse the repository at this point in the history
…omizable"

This reverts commit d180acc, reversing
changes made to 78d8f29.
  • Loading branch information
mcsf committed Apr 26, 2017
1 parent 8018fc4 commit d8434b5
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 168 deletions.
6 changes: 6 additions & 0 deletions client/lib/site/computed-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,11 @@ export default function( site ) {
isHttps( attributes.options.unmapped_url )
);

//TODO:(ehg) Replace instances with canCurrentUser selector when my-sites/sidebar is connected
attributes.is_customizable = !! (
site.capabilities &&
site.capabilities.edit_theme_options
);

return attributes;
}
4 changes: 4 additions & 0 deletions client/lib/site/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,8 @@ Site.prototype.isUpgradeable = function() {
return this.capabilities && this.capabilities.manage_options;
};

Site.prototype.isCustomizable = function() {
return !! ( this.capabilities && this.capabilities.edit_theme_options );
};

module.exports = Site;
1 change: 0 additions & 1 deletion client/state/selectors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ export isSendingBillingReceiptEmail from './is-sending-billing-receipt-email';
export isSharingButtonsSaveSuccessful from './is-sharing-buttons-save-successful';
export isSiteAutomatedTransfer from './is-site-automated-transfer';
export isSiteBlocked from './is-site-blocked';
export isSiteCustomizable from './is-site-customizable';
export isSiteOnFreePlan from './is-site-on-free-plan';
export isSiteSupportingImageEditor from './is-site-supporting-image-editor';
export isSiteUpgradeable from './is-site-upgradeable';
Expand Down
24 changes: 0 additions & 24 deletions client/state/selectors/is-site-customizable.js

This file was deleted.

1 change: 1 addition & 0 deletions client/state/selectors/test/get-visible-sites.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ describe( 'getVisibleSites()', () => {
domain: 'example.com',
slug: 'example.com',
hasConflict: false,
is_customizable: false,
is_previewable: false,
options: {
default_post_format: 'standard',
Expand Down
58 changes: 0 additions & 58 deletions client/state/selectors/test/is-site-customizable.js

This file was deleted.

27 changes: 3 additions & 24 deletions client/state/sites/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { isHttps, withoutHttp, addQueryArgs, urlToSlug } from 'lib/url';
import createSelector from 'lib/create-selector';
import { fromApi as seoTitleFromApi } from 'components/seo/meta-title-editor/mappings';
import versionCompare from 'lib/version-compare';
import getComputedAttributes from 'lib/site/computed-attributes';
import { getCustomizerFocus } from 'my-sites/customize/panels';

/**
Expand Down Expand Up @@ -81,40 +82,18 @@ export const getSite = createSelector(

return {
...site,
...getComputedAttributes( site ),
...getJetpackComputedAttributes( state, siteId ),
hasConflict: isSiteConflicting( state, siteId ),
title: getSiteTitle( state, siteId ),
slug: getSiteSlug( state, siteId ),
domain: getSiteDomain( state, siteId ),
is_previewable: isSitePreviewable( state, siteId ),
options: computeSiteOptions( state, siteId ),
is_previewable: isSitePreviewable( state, siteId )
};
},
( state ) => state.sites.items
);

export function computeSiteOptions( state, siteId ) {
const site = getRawSite( state, siteId );
if ( ! site ) {
return null;
}

const isWpcomMappedDomain = getSiteOption( state, siteId, 'is_mapped_domain' ) && ! isJetpackSite( state, siteId );
const wpcomUrl = withoutHttp( getSiteOption( state, siteId, 'unmapped_url' ) );

// The 'standard' post format is saved as an option of '0'
let defaultPostFormat = getSiteOption( state, siteId, 'default_post_format' );
if ( ! defaultPostFormat || defaultPostFormat === '0' ) {
defaultPostFormat = 'standard';
}

return {
...site.options,
...isWpcomMappedDomain && { wpcom_url: wpcomUrl },
default_post_format: defaultPostFormat
};
}

export function getJetpackComputedAttributes( state, siteId ) {
if ( ! isJetpackSite( state, siteId ) ) {
return {};
Expand Down
60 changes: 1 addition & 59 deletions client/state/sites/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import config from 'config';
import { useSandbox } from 'test/helpers/use-sinon';
import {
getSite,
computeSiteOptions,
getSiteCollisions,
isSiteConflicting,
isSingleUserSite,
Expand Down Expand Up @@ -105,6 +104,7 @@ describe( 'selectors', () => {
domain: 'example.com',
slug: 'example.com',
hasConflict: false,
is_customizable: false,
is_previewable: true,
options: {
default_post_format: 'standard',
Expand All @@ -114,64 +114,6 @@ describe( 'selectors', () => {
} );
} );

describe( '#computeSiteOptions()', () => {
it( 'should return null if the site is not known', () => {
const siteOptions = computeSiteOptions( {
sites: {
items: {}
}
}, 2916284 );

expect( siteOptions ).to.be.null;
} );

it( 'should return a the site options along with the computed option wpcom_url', () => {
const siteOptions = computeSiteOptions( {
sites: {
items: {
2916284: {
ID: 2916284,
URL: 'https://example.com',
options: {
unmapped_url: 'https://example.wordpress.com',
is_mapped_domain: true
}
}
}
}
}, 2916284 );

expect( siteOptions ).to.eql( {
default_post_format: 'standard',
unmapped_url: 'https://example.wordpress.com',
is_mapped_domain: true,
wpcom_url: 'example.wordpress.com'
} );
} );

it( 'should fix `default_post_format` if it is equal to \'0\'', () => {
const siteOptions = computeSiteOptions( {
sites: {
items: {
2916284: {
ID: 2916284,
URL: 'https://example.com',
options: {
default_post_format: '0',
unmapped_url: 'https://example.wordpress.com'
}
}
}
}
}, 2916284 );

expect( siteOptions ).to.eql( {
default_post_format: 'standard',
unmapped_url: 'https://example.wordpress.com'
} );
} );
} );

describe( '#getSiteCollisions', () => {
it( 'should not consider distinct URLs as conflicting', () => {
const collisions = getSiteCollisions( {
Expand Down
4 changes: 2 additions & 2 deletions client/state/ui/guided-tours/contexts.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from 'state/ui/selectors';
import { getLastAction } from 'state/ui/action-log/selectors';
import { getCurrentUser } from 'state/current-user/selectors';
import { canCurrentUser, isSiteCustomizable } from 'state/selectors';
import { canCurrentUser } from 'state/selectors';
import {
hasDefaultSiteTitle,
isCurrentPlanPaid,
Expand Down Expand Up @@ -122,7 +122,7 @@ export const isSelectedSitePreviewable = state =>
* @return {Boolean} True if user can run customizer, false otherwise.
*/
export const isSelectedSiteCustomizable = state =>
isSiteCustomizable( state, getSelectedSiteId( state ) );
getSelectedSite( state ) && getSelectedSite( state ).is_customizable;

/**
* Returns a selector that tests whether an A/B test is in a given variant.
Expand Down
1 change: 1 addition & 0 deletions client/state/ui/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe( 'selectors', () => {
URL: 'https://example.com',
domain: 'example.com',
hasConflict: false,
is_customizable: false,
is_previewable: false,
options: {
default_post_format: 'standard',
Expand Down

0 comments on commit d8434b5

Please sign in to comment.