google / site-kit-wp

Site Kit is a one-stop solution for WordPress users to use everything Google has to offer to make them successful on the web.
https://sitekit.withgoogle.com
Apache License 2.0
1.25k stars 290 forks source link

Update `hasCapability` selector to support meta capabilities #4804

Closed aaemnnosttv closed 2 years ago

aaemnnosttv commented 2 years ago

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 like current_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

Implementation Brief

Test Coverage

QA Brief

QA:Eng

Changelog entry

tofumatt commented 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 🙂

jimmymadon commented 2 years ago

QA:Eng

  • 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. Screenshot 2022-03-06 at 11 54 46

  • As a extra mile testing, call the hasCapability selector and pass googlesitekit_manage_module_sharing_options as the capability and search-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

Screenshot 2022-03-06 at 12 22 08 Screenshot 2022-03-06 at 12 22 38