site-kit-wp
site-kit-wp copied to clipboard
Refresh user permissions on module recovery
Feature Description
Any time a module is recovered, the current user's permissions for that module will be elevated as a result of becoming the new module owner. As such, we should always make sure to refresh the user's permissions from the server after modules are recovered.
Without this, the recovering user will not be able to manage the sharing settings for the modules they just recovered.
Screenshots
Search Console and Analytics recoverable

Post-recovery sharing settings show managed by the current user but lacking capabilities they should have

Settings appear properly after reloading the page

Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- When one or more modules are recovered successfully, the current user's capabilities should be refreshed from the server
Implementation Brief
- In
Google\Site_Kit\Core\Permissions\Permissionsclass:- Define a new private method
get_rest_routesthat defines a API route to get users current capabilities.- Return an array from the method with a single get (
WP_REST_Server::READABLE)REST_Route.- Path:
core/user/data/permissions callbackshould return aWP_REST_Responsewith the value of$this->check_all_for_current_user().permission_callbackshould becurrent_user_can( Permissions::VIEW_SPLASH )
- Path:
- Return an array from the method with a single get (
- In the
registermethod:- Add a filter
googlesitekit_rest_routesthat adds the rest route to site kit. - See
Authenticationfor how it's done.
- Add a filter
- Define a new private method
- In
assets/js/googlesitekit/datastore/user/permissions.jsfile:- Add a new action
refreshCapabilities. - Get
dispatchfromcommonActions. - Get
newCapabilitiesby calling the newly added api usingAPI.get. API.get( 'core', 'user', 'permissions', undefined, { useCache: false } )- Update
capabilitiesby dispatchingreceiveCapabilitiesaction with thenewCapabilities.
- Add a new action
- In
assets/js/googlesitekit/modules/datastore/modules.jsfile:- Update the
recoverModulesaction:- Dispatch
refreshCapabilitiesaction to theCORE_USERstore when one (or more) module is successfully recovered.
- Dispatch
- Update the
Test Coverage
- Add PHP Unit Test for new API Route.
- Add test for
refreshCapabilitiesand update any failing tests. - Update
recoverModulestests to check for the updated permissions after a successful recovery.
QA Brief
- Enable
dashboardSharingand Sign In with first admin. - Install Sharing Settings Tester.
- In a Incognito Window, login to second admin.
- Do not connect to site kit. Instead, go to the Sharing Settings and change some roles on
PageSpeed Insights. - Back in the first admin, visit Site Kit Dashboard. You should see the Module Recovery Alert for PageSpeed Insights.
- Click on
Open Sharing Settingsin the toolbar. - See that, the
Who can viewcolumn forPageSpeed Insightsbeing unavailable with a message to contact managing user. - Close the modal and Initiate module recovery.
- Once the module has been recovered, the recovery alert will disappear. DO NOT REFRESH THE PAGE.
- Click on
Open Sharing Settingsagain in the toolbar. Who can viewfor Pagespeed Inshight should be restored and editable.
Changelog entry
- Refresh user permissions on module recovery.
IB :white_check_mark:
QA Update ✅
Verified
- Verified using tester plugin and dashboard sharing settings tester plugin.
- After initiating recovery
Who can viewfor Pagespeed Inshight gets restored and editable without refreshing again. - User is able to edit 'Who can view' access for PSI and other modules after recovery.
https://user-images.githubusercontent.com/94359491/186407303-a912ff0a-1e67-47ab-8d4c-c340173e4174.mp4