Skip to content

Commit

Permalink
Merge branch 'add/governance-plugin' of github.com:Automattic/vip-go-…
Browse files Browse the repository at this point in the history
…mu-plugins into add/governance-plugin
  • Loading branch information
ingeniumed committed Sep 29, 2023
2 parents d3e214a + ae3da86 commit 88f53e3
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 7 deletions.
49 changes: 49 additions & 0 deletions security/class-private-sites.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ public function init() {

add_filter( 'jetpack_active_modules', array( $this, 'filter_jetpack_active_modules' ) );
add_filter( 'jetpack_get_available_modules', array( $this, 'filter_jetpack_get_available_modules' ) );

// Force the blog_public option to be -1 and disable UI
add_filter( 'option_blog_public', array( $this, 'filter_restrict_blog_public' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'disable_blog_public_ui' ) );

$this->disable_core_feeds();
$this->block_unnecessary_access();
Expand All @@ -71,6 +74,52 @@ public function disable_core_feeds() {
add_action( 'do_feed_atom', array( $this, 'action_do_feed' ), -1 );
}

/**
* Disable checkbox/radio UI in Reading Settings
*/
public function disable_blog_public_ui() {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}

$screen = get_current_screen();
if ( 'options-reading' !== $screen->base ) {
return;
}

wp_register_script( 'vip-disable-blog-public-option-ui', false, array(), '0.1', true );
wp_enqueue_script( 'vip-disable-blog-public-option-ui' );
$js_code = <<<JS
function onContentLoaded(callback) {
if (document.readyState !== 'loading') {
callback();
} else {
document.addEventListener('DOMContentLoaded', callback);
}
}
onContentLoaded(function() {
function updateProperty(selector, property, value) {
const element = document.querySelector(selector);
if (element) {
element[property] = value;
}
}
var checkbox = 'tr.option-site-visibility input#blog_public[type="checkbox"]';
if (document.querySelector(checkbox)) {
updateProperty(checkbox, 'disabled', true);
} else {
updateProperty('tr.option-site-visibility input#blog-public[type="radio"]', 'disabled', true);
updateProperty('tr.option-site-visibility input#blog-norobots[type="radio"]', 'disabled', true);
}
updateProperty('tr.option-site-visibility p.description', 'textContent', '%s');
});
JS;
$description = esc_html__( 'This option is disabled when the constant VIP_JETPACK_IS_PRIVATE is enabled.', 'vip' );
$final_js_code = sprintf( $js_code, $description );
wp_add_inline_script( 'vip-disable-blog-public-option-ui', $final_js_code );
}

/*
* Block the entire site for the feedbot
*
Expand Down
8 changes: 4 additions & 4 deletions tests/search/e2e/integration/features/woocommerce.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ describe('WooCommerce Feature', { tags: '@slow' }, () => {
cy.get('.woocommerce-orders-table tbody tr').should('have.length', 1);

// VIP: Use Search Dev Tools instead of Debug Bar
// cy.searchDevToolsResponseOK('shop_order');
cy.searchDevToolsResponseOK('shop_order', 2);
cy.get('#vip-search-dev-tools-mount').click();
cy.get('h3.vip-h3').first().click();
cy.get('strong.vip-h4.wp_query').first().click();
cy.get('ol.wp_query.vip-collapse-ol').first().should('contain.text','orderby: "date"');
cy.get('h3.vip-h3').eq(2).click();
cy.get('strong.vip-h4.wp_query').eq(2).click();
cy.get('ol.wp_query.vip-collapse-ol').eq(2).should('contain.text','orderby: "date"');
cy.get('#vip-search-dev-tools-mount').click();

cy.logout();
Expand Down
7 changes: 4 additions & 3 deletions tests/search/e2e/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,11 +461,12 @@ Cypress.Commands.add('createUser', (userData) => {
});

// VIP: Check that Search Dev Tools returns a 200 status and a certain text in the response body
Cypress.Commands.add('searchDevToolsResponseOK', (bodyText) => {
// If there's more than one ES query, use the index to select the correct one
Cypress.Commands.add('searchDevToolsResponseOK', (bodyText, index = 0) => {
cy.get('#vip-search-dev-tools-mount').click();
cy.get('h3.vip-h3').first().should('contain.text','(200)');
cy.get('h3.vip-h3').eq( index ).should('contain.text','(200)');
if ( bodyText ) {
cy.get('.line-numbers').first().should('contain.text', bodyText);
cy.get('.line-numbers').eq( index ).should('contain.text', bodyText);
}
cy.get('#vip-search-dev-tools-mount').click();
});
Expand Down

0 comments on commit 88f53e3

Please sign in to comment.