这是indexloc提供的服务,不要输入任何密码
Skip to content

Add getAdminScreenURL and getAdminReauthURL selectors to base module store #1559

@felixarntz

Description

@felixarntz

Feature Description

stores created by createModuleStore should include new selectors for module-specific admin URLs. These can be built on top of the enhanced version of getAdminURL from the core/site store, which was implemented as part of #1500.


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

Acceptance criteria

  • The core/user/data/authentication REST route should also return needsReauthentication, which uses Authentication::need_reauthenticate() (will be migrated to OAuth_Client class via Request write scopes only when needed #1566, just fyi - depending on timeline this may overlap).
  • The core/user store should receive an additional selector needsReauthentication() that exposes the above.
  • createModuleStore should receive a new options argument adminPage. The default should be "googlesitekit-dashboard". Modules with their own screens (Search Console, Analytics, AdSense) need to be amended so that they provide the slugs for their own screens when calling createModuleStore.
  • createModuleStore should receive a new options argument requiresSetup. The default should be a boolean true. Modules that do not require setup (only PageSpeed Insights for now) need to be amended so that they provide false for this argument.
  • Store objects returned by createModuleStore should have two additional selectors:
    • getAdminScreenURL( queryArgs ): Should use getAdminURL from core/site passing adminPage as the selector's page parameter, and queryArgs can be passed through.
    • getAdminReauthURL(): Should mirror the exact behavior of the legacy getReAuthURL utility function, based on getAdminScreenURL, whether the module requiresSetup, and whether the user needs to re-authenticate (requested scopes and granted scopes are available via core/user score, let's introduce a new selector to simplify this check, see below).
  • Refactored module code based on the datastore that currently still relies on one of the old utility functions (e.g. getReAuthURL, used at least by refactored AdSense code) should be modified to use the new selectors.

Implementation Brief

  • Update the core/user/data/authentication REST endpoint in includes/Core/Authentication/Authentication.php to also return needsReauthentication which will get its value from the OAuth_Client::needs_reauthentication() function.

  • Add needsReauthentication() selector to assets/js/googlesitekit/datastore/user/authentication.js which connects to the needsReauthentication value returned from the above endpoint.

  • Add these arguments to options in createModuleStore() in assets/js/googlesitekit/modules/create-module-store.js

    • adminPage (string) default value of googlesitekit-dashboard
    • requiresSetup (boolean) default value of true
  • For modules with their own screens, add the adminPage argument with the appropriate page name (ie: googlesitekit-module-analytics for the analytics module) when createModuleStore() is called for them.

    • assets/js/modules/search-console/datastore/index.js
    • assets/js/modules/analytics/datastore/index.js
    • assets/js/modules/adsense/datastore/index.js
  • For PageSpeed Insights module, pass false as the options.requiresSetup argument for createModuleStore() at assets/js/modules/pagespeed-insights/datastore/index.js

  • Create a new file assets/js/googlesitekit/modules/datastore/info.js that creates a store with selectors for getAdminScreenURL() and getAdminReauthURL() which will use getAdminURL() from the core/site store with the proper adminPage parameter which is passed to createModuleStore().

  • Ensure the above info store is combined with the other stores in assets/js/googlesitekit/modules/create-module-store.js to add to the base module store.

  • Write tests in assets/js/googlesitekit/modules/datastore/info.js to ensure the selectors properly call getAdminURL() with the correct parameters.

  • Update tests in assets/js/googlesitekit/modules/create-module-store.test.js to ensure the new selectors are included.

  • Refactor code in modules to use the new selector instead of utilities like getReAuthURL, for example:

QA Brief

Changelog entry

  • Add selectors to get module-specific admin screen URLs to every module datastore.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Good First IssueGood first issue for new engineersP0High priorityQA: EngRequires specialized QA by an engineerType: EnhancementImprovement of an existing feature

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions