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

VIP Cache Manager: implement "Purge page and its assets" admin bar button #1880

Merged
merged 14 commits into from
Dec 15, 2020

Conversation

rinatkhaziev
Copy link
Contributor

@rinatkhaziev rinatkhaziev commented Nov 24, 2020

Description

This PR adds an Admin Bar button that allows a user to purge the current page and all its external (as opposed to inline) styles and scripts.

Screen Shot 2020-11-23 at 8 24 01 PM

Screen Shot 2020-11-23 at 8 24 09 PM

Checklist

Please make sure the items below have been covered before requesting a review:

  • This change works and has been tested locally (or has an appropriate fallback).
  • This change works and has been tested on a Go sandbox.
  • This change has relevant unit tests (if applicable).
  • This change has relevant documentation additions / updates (if applicable).

Steps to Test

  1. Check out PR.
  2. Make sure you're logged in.
  3. Go to any frontend page and verify the button is there and working
  4. Verify cookies are delicious.

Considerations

  • Do we also want to display the button in the admin to allow purging the assets for Dashboard requests?
  • Do we want to add a filter to allow users to adjust the needed capability? Currently, it's hardcoded for manage_options which may limit the usefulness.

@rinatkhaziev rinatkhaziev requested a review from a team as a code owner November 24, 2020 02:38
@mjangda
Copy link
Member

mjangda commented Nov 24, 2020

Nice work! Quick thought: we should add some stats for how often this is used and by which sites (probably easiest using Automattic\VIP\Stats\send_pixel().

btn.removeEventListener('click', onClickHandler);
} catch (err) {
purgeQueried = false;
btn.textContent = '❌ Cache Purge Failed';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there the option to use https://make.wordpress.org/accessibility/handbook/markup/wp-a11y-speak/ here, so that screen reader users get notified on the success / failure of the action?

@rinatkhaziev
Copy link
Contributor Author

@mjangda I've added the send_pixel in 2fa146f, do you think that's sufficient or overengineered?

…-go-cache-manager-action and vip-go-cache-manager-url-purge-by-site for unsuccessful requests
@rinatkhaziev
Copy link
Contributor Author

@mjangda I've recreated your suggestions via a separate commit.

Copy link
Member

@mjangda mjangda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this looks pretty solid. Spotted a couple of small things.

vip-cache-manager/js/admin-bar.js Outdated Show resolved Hide resolved
wp_send_json_error( [ 'error' => 'Malformed payload' ], 400 );
}

if ( ! ( current_user_can( 'manage_options' ) && isset( $req->nonce ) && wp_verify_nonce( $req->nonce, 'purge-page' ) ) ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would split these up because it's very easy to introduce a mistake with a long conditional like this. We can then also separate the deny stats into deny-permissions and deny-nonce.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, will address.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I've split the check into two, as proposed.

@@ -0,0 +1,69 @@
(async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This javascript file needs more ( nacin spacin ) :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prettier doesn't like ( nacin spacin ) but let me see what I can do short of fixing each occurrence manually :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied eslint-config-wpvip to the file (will work on adding it to the repo in a separate PR)

vip-cache-manager/js/admin-bar.js Outdated Show resolved Hide resolved
@mjangda
Copy link
Member

mjangda commented Dec 15, 2020

Props @emrikol for the initial pass at this!

Copy link
Member

@mjangda mjangda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and working great!

@netsuso netsuso merged commit 0691ba6 into master Dec 15, 2020
@netsuso netsuso deleted the add/purge-cache-page-button branch December 15, 2020 19:51
@netsuso
Copy link

netsuso commented Dec 15, 2020

stacks-r1307

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants