Closed aaemnnosttv closed 2 years ago
It's not 100% clear from the ACs that we should be converting args
into JSON.stringify( args )
, but that's certainly what I'm reading into this as well.
IB ✅ from me. ~but I've pinged @aaemnnosttv just to clarify that's the intent.~ Actually, from json_args
that must be the intent, okay! Moving to the backlog 🙂
- Verify the changes meet AC and IB
✅ LGTM
- Verify the new unit test cases for
hasCapability
selector are good enough and are passing
✅ LGTM - base and meta capabilities covered.
- As a extra mile testing, call the
hasCapability
selector and passgooglesitekit_manage_module_sharing_options
as thecapability
andsearch-console
as next...args
- Open the dev tools console and execute
window._googlesitekitUserData.permissions
- Verify the selector's return value with
googlesitekit_manage_module_sharing_options::['search-console']
value from the console
✅ LGTM
Feature Description
With dashboard sharing, Site Kit's permission management on the client needs to be extended to support "meta capabilities", in this case – capabilities that are specific to a given module.
We already have a
hasCapability( capability )
selector which works much likecurrent_user_can()
on the backend. This issue will extend the syntax of this selector to work closer to the way it works on the backend by adding support for specific meta capabilities, with the ability to support more in the future automatically.The capabilities are already available to the client as of https://github.com/google/site-kit-wp/issues/4523, this is only about extending the selector.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
hasCapability
selector on thecore/user
store should be updated to be variadic in its definition, such that all arguments after the first (capability
) are packed into a single "args
" argument (i.e....args
)args
has a non-zero length, the capability key used for the permission look-up should be used instead:{ capability }::{ json_args }
hasCapability( 'foo', 'bar' )
would look up the following capabilityfoo::["bar"]
(a string literal) from the object of all capabilities for the current user (returned bygetCapabilities
)hasCapability
should continue to work as todayhasCapability
should be updated to cover this functionalityImplementation Brief
assets/js/googlesitekit/datastore/permissions.js
, modify the logic of thehasCapability
selector:...args
to the selector function in addition to thestate
andcapability
params.args
is not 0, convert it to a JSON string and append it to the capability being checked:Do this before checking if the capability exists in the capabilities array.
Test Coverage
assets/js/googlesitekit/datastore/permissions.test.js
:hasCapability
selector.QA Brief
QA:Eng
hasCapability
selector are good enough and are passinghasCapability
selector and passgooglesitekit_manage_module_sharing_options
as thecapability
andsearch-console
as next...args
window._googlesitekitUserData.permissions
googlesitekit_manage_module_sharing_options::['search-console']
value from the consoleChangelog entry