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

Enhance mechanism for dashboard sharing request context #5780

Closed
aaemnnosttv opened this issue Sep 1, 2022 · 7 comments
Closed

Enhance mechanism for dashboard sharing request context #5780

aaemnnosttv opened this issue Sep 1, 2022 · 7 comments
Labels
P1 Medium priority PHP Type: Enhancement Improvement of an existing feature

Comments

@aaemnnosttv
Copy link
Collaborator

aaemnnosttv commented Sep 1, 2022

Feature Description

In #5711 we added a new is_using_shared_credentials property to the Module class for storing state to enable logic that should be conditionally applied for a request that is made on behalf of a module owner rather than the current user via dashboard sharing.

This approach works but should ideally be a bit more reliable to avoid logic being potentially applied improperly due to this property getting out of sync. See #5711 (comment)


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • Sharing request context (i.e. whether a given request will use shared credentials or not) and behavior based on it should be determined using the Data_Request and not stored in a way which is not specific to the request
    • Said another way, any behavior related to whether a request is made as a shared one or not should be derived from the current user together with the Data_Request
  • The Data_Request class should not be changed

Implementation Brief

  • Extract the logic in Module::execute_data_request that is used to determine if a request should use shared credentials into a new protected method is_shared_data_request( Data_Request ) : bool (perhaps final as well)
    • Refactor execute_data_request to use the new method (this introduces some duplicate calls but that should be acceptable – if that's a concern, we could consider caching the result by the given Data_Request. Ideally we could use a Weak_Map for this but that doesn't exist until PHP 8, so we'd need to use something like SplObjectStorage)
  • Rework usage of Module::$is_using_shared_credentials to use the new Module::is_shared_data_request method instead
    • The only usage of this property is in create_data_request -> validate_report_metrics | validate_report_dimensions for Analytics(_4) and AdSense modules
    • This can be reworked by renaming validate_report_* to validate_shared_report_* (which is more accurate to what it does as well) and conditionally calling that if is_shared_data_request from the calling create_data_request where the current Data_Request is in scope
  • Remove Module::$is_using_shared_credentials property

Test Coverage

  • Add more robust PHPUnit coverage of data requests that covers shared requests
    • Current module owner with/without sharing with their role
    • Non-module owner with/without sharing with their role

QA Brief

  • Perform a regression test of the Dashboard Sharing feature for shared AdSense and Analytics widgets, verifying they still display as expected with shared data.
  • On the Shared Dashboard, check that the AdSense and Analytics report metrics and dimensions are still validated correctly.
    • Make some requests with invalid AdSense report metrics and dimensions and verify that they return a 400 error with an error message in the format Unsupported (metric|dimension)/s requested: SOME_(METRIC|DIMENSION).
    • In order to make the requests, invoke as follows in the JS Console.
      • Note the valid metrics are: ESTIMATED_EARNINGS, IMPRESSIONS, PAGE_VIEWS_CTR, PAGE_VIEWS_RPM
      • And the only valid dimension is: DATE
googlesitekit.api.get("modules", "adsense", "report", {
  startDate: "2022-07-26",
  endDate: "2022-08-22",
  metrics: ["FOO", "BAR"],
  dimensions: ["BAZ"],
});
  • Perform similar checks for Analytics.
    • Note the valid metrics are:
      • ga:sessions
      • ga:users
      • ga:pageviews
      • ga:uniquePageviews
      • ga:bounceRate
      • ga:avgSessionDuration
      • ga:adsenseRevenue
      • ga:adsenseECPM
      • ga:adsensePageImpressions
      • ga:goalCompletionsAll
    • And the valid dimensions:
      • ga:date
      • ga:pagePath
      • ga:pageTitle
      • ga:channelGrouping
      • ga:country
      • ga:deviceCategory
      • ga:hostname
googlesitekit.api.get("modules", "analytics", "report", {
  startDate: "2022-07-26",
  endDate: "2022-08-22",
  metrics: ["FOO", "BAR"],
  dimensions: ["BAZ"],
});

Changelog entry

  • Enhance mechanism for dashboard sharing request context.
@aaemnnosttv aaemnnosttv self-assigned this Sep 1, 2022
@aaemnnosttv aaemnnosttv added P1 Medium priority Type: Enhancement Improvement of an existing feature labels Sep 2, 2022
@FlicHollis
Copy link
Collaborator

@aaemnnosttv if you are not actively working on this, can this be unassigned so another team member can pick this up? Thanks!

@mxbclang
Copy link

mxbclang commented Jan 3, 2023

@aaemnnosttv Following up on this one – can this be unassigned so another team member can pick up, or do you want to move it forward? Thanks!

@aaemnnosttv
Copy link
Collaborator Author

Updated with AC + IB. @techanvil @eugene-manuilov I'd be interested to get your thoughts on this one. Once this is approved, this is one I'd like to work on.

@eugene-manuilov
Copy link
Collaborator

@aaemnnosttv IB looks good to me. I'll let Tom to take a look as well.

@eugene-manuilov eugene-manuilov removed their assignment Jan 9, 2023
@techanvil
Copy link
Collaborator

@aaemnnosttv, LGTM to me too. The only change I would consider is possibly making is_shared_data_request a property/accessor on Data_Request itself, seeing as the value is relevant to that specific instance. This would solve the caching problem, and allow Data_Request to be passed to an external utility if necessary including that piece of information.

The logic to set it would still need to reside in Module, though, so might look a little unwieldy.

Please see what you think - if you'd prefer to keep as-is, then consider the IB approved from me too.

@techanvil techanvil assigned aaemnnosttv and unassigned techanvil Jan 11, 2023
@aaemnnosttv
Copy link
Collaborator Author

The only change I would consider is possibly making is_shared_data_request a property/accessor on Data_Request itself, seeing as the value is relevant to that specific instance. This would solve the caching problem, and allow Data_Request to be passed to an external utility if necessary including that piece of information.

@techanvil that's something I had considered as well, although I don't think this state fits well into Data_Request as its intended to be immutable and represents the request itself whereas the "is shareable" state is entirely contingent on internal conditions involving the current user, sharing settings, etc.

The ability to pass the object off elsewhere isn't a real need yet but we can always modify things later if it did. It would be nice to have it available on the object itself, but it isn't too different to get the same data using the object as the key for getting it especially as the Module class would need to be involved there anyways.

Even the performance concern should be more/less a non-issue since these requests are always async and only handle one at a time.

I'll move this forward for implementation now – thanks both for your thoughts. Feel free to raise anything else if you think of it 👍

@aaemnnosttv aaemnnosttv removed their assignment Feb 15, 2023
@techanvil techanvil self-assigned this Mar 2, 2023
@techanvil techanvil removed their assignment Mar 6, 2023
@eugene-manuilov eugene-manuilov removed their assignment Mar 10, 2023
@mohitwp mohitwp self-assigned this Mar 13, 2023
@mohitwp
Copy link
Collaborator

mohitwp commented Mar 20, 2023

QA Update ✅

  • Tested on dev.
  • Done regression testing of Dashboard sharing.
  • Verified AdSense and Analytics shared widget on View only dashboard.
  • Verified AdSense and Analytics shared widget For another admin.
  • Ran code in console and validated analytics and AdSense metrics and dimensions,
  • Tested different combinations of valid and invalid metrics and dimensions.

image

image

Valid metrics and invalid dimensions-

image

Invalid metrics and valid dimensions-

image

Analytics

image

Valid metrics and dimensions-

image

Invalid metrics and valid dimensions-

image

Valid metrics and invalid dimension-

image

@mohitwp mohitwp removed their assignment Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 Medium priority PHP Type: Enhancement Improvement of an existing feature
Projects
None yet
Development

No branches or pull requests

6 participants