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

Prevent module activation when plan doesn't support them #8983

Merged
merged 8 commits into from
Mar 7, 2018

Conversation

gravityrail
Copy link
Contributor

@gravityrail gravityrail commented Mar 5, 2018

Fixes #7867

Some plans support different modules. This change declares plan support in the module header, and checks for that support when rendering the "active plan" information.

This allows us to easily render inactive rows in the jetpack_modules page and elsewhere, so that users know which modules are truly available.

This change also adds some basic checking in WP-cli and elsewhere for whether plan activation was successful.

Changes proposed in this Pull Request:

  • Declare modules with a Plan: business, premium, personal (default is free) attribute
  • Render full list of supported modules and plugins (in the case of vaultpress/akismet) in the Jetpack::get_active_plan() response
  • Render rows as inactive in the jetpack_modules list if they are not supported by the current plan

The goal is NOT to prevent users from being able to hack the code to enable modules they shouldn't (since that is impossible anyway) but to help users understand what features their plan supports, and prevent them from accidentally enabling features that it doesn't.

Further work:

  • Allow users to click to upgrade to a supporting plan from within the jetpack_modules page.

Testing instructions:

  • On a site with a free plan:
    • Go to /wp-admin/admin.php?page=jetpack_modules
    • Ads, Data Backups, Google Analytics, SEO Tools, Search and VideoPress should be greyed out. Only Data Backups should be clickable, with a Configure link.
    • Go to /settings/traffic/{site_domain} in Calypso
      • Attempt to enable SEO tools using the Enable link next to SEO Tools module is disabled in Jetpack.
      • You should see a message There was a problem saving your changes. Please try again. (TODO: a better error message - in the network response you will see the actual error is {error: "not_supported", message: "The requested Jetpack module is not supported by your plan."})
  • On a site with a Premium plan
    • VideoPress should become available
  • On a site with a Professional plan
    • SEO Tools, Google Analytics and Search should become available

Proposed changelog entry for your changes:

  • Show correct available status in Jetpack modules list
  • Return error in wp-cli if activating a module that is unsupported by your plan

@gravityrail gravityrail requested a review from a team as a code owner March 5, 2018 21:48
@gravityrail gravityrail self-assigned this Mar 5, 2018
@gravityrail gravityrail added this to the 6.0 milestone Mar 5, 2018
@gravityrail gravityrail added Admin Page React-powered dashboard under the Jetpack menu Plans [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Mar 5, 2018
@@ -231,8 +220,10 @@ function single_row( $item ) {
if ( ! empty( $item['activated'] ) )
$row_class .= ' active';

if ( ! $this->is_module_available( $item ) )
if ( ! Jetpack_Admin::is_module_available( $item ) ) {
error_log($item['module']." is NOT available");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -4033,7 +4051,9 @@ function admin_page_load() {
$module = stripslashes( $_GET['module'] );
check_admin_referer( "jetpack_activate-$module" );
Jetpack::log( 'activate', $module );
Jetpack::activate_module( $module );
if ( ! Jetpack::activate_module( $module ) ) {
Jetpack::state( 'error', sprintf( __( 'Could not activated %s', 'jetpack' ), $module ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: Could not activate

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

'akismet',
'vaultpress',
'wordads',
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to remove videopress and wordads from here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - they are modules, the others are plugins. Modules are automatically added to the list based on metadata.

'google-analytics',
'wordads',
'search',
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, did you mean to remove some items from this list?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above - yes ;)

@beaulebens
Copy link
Member

beaulebens commented Mar 5, 2018

On a Free plan
Not a blocker, but noticed that all of the paid options are added to the bottom of the list, vs being in amongst the other items (in alpha order).

I don't have any configuration options on "Data Backups" (on Free plan), although maybe that's correct? I'm not sure what I'd actually configure at this point.

screen shot 2018-03-05 at 4 26 22 pm

I don't get the

SEO Tools module is disabled in Jetpack.

banner in Calypso (correctly), so can't test that bit. I just get a banner asking me to upgrade to get access to that feature.

On Personal
No apparent differences compared to Free.

I'd expect Data Backups to be available, but it doesn't appear to be.

On Premium
Backups, Google Analytics, SEO and Search remain unavailable (VideoPress becomes available, as expected)

screen shot 2018-03-05 at 4 56 55 pm

On Professional
Everything was "available" except "Data Backups". I could see the "Configure" link when I hovered, but the module was still "disabled" in the list and could not be Activated via link or checkbox.

screen shot 2018-03-05 at 4 45 24 pm

@gravityrail
Copy link
Contributor Author

gravityrail commented Mar 6, 2018

@beaulebens - thanks for the detailed feedback.

Not a blocker, but noticed that all of the paid options are added to the bottom of the list, vs being in amongst the other items (in alpha order).

That appears to be a deliberate feature that was added to the modules list at some point - not a thing I added.

I don't have any configuration options on "Data Backups" (on Free plan), although maybe that's correct? I'm not sure what I'd actually configure at this point.

I'd expect Data Backups to be available, but it doesn't appear to be.

Everything was "available" except "Data Backups". I could see the "Configure" link when I hovered, but the module was still "disabled" in the list and could not be Activated via link or checkbox.

These are existing bugs unrelated to my changes, and should be handled in a separate PR. They also probably need some design/UX work to figure out how things need to behave.

Having now dealt with the code for this change, I actually recommend throwing away the whole modules list code and either just doing without it, or replacing it with a cleanroom implementation. In its current form it is very hard to understand what's going on. Case in point: The HTML implementation that is rendered out as a table appears to be completely replaced in the DOM by a Javascript implementation using JS templates at load time - all the data is being rendered twice, and it is impossible to tell why your changes are having no effect until you realise this is what's going on.

I would encourage you, if you could, to confirm that the Data Backups behaviour is actually identical in master and then either approve this PR as-is, or add fixing that bug as a requirement for this branch. From a cursory look at the code, it appears to be a wholly different kettle of fish.

@beaulebens
Copy link
Member

Gotcha -- I hadn't realized that "Data Backups" was already in the list; I figured you'd added it as part of this. I've just tested master and am seeing it there as well, with all the same issues as mentioned above.

I've just gone through with that in mind and done some more testing, and this seems to handle things much better and more explicitly than the current master.

@@ -1452,6 +1452,13 @@ public static function refresh_active_plan_from_wpcom() {
* @return array Active Jetpack plan details
*/
public static function get_active_plan() {
global $active_plan_cache;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any better way to do this than introducing another global?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately I couldn't think of one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clear: We could refactor the whole way that we list out modules, and then we'd only need to call this one - but that requires a lot more time than "hack week" necessarily allows.

if ( ! isset( $plan['supports'] ) ) {
$plan['supports'] = array();
// get available features
foreach( self::get_available_modules() as $module_slug ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spacing -- foreach (

Copy link
Member

@beaulebens beaulebens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does seem to work in all of my testing, so I'm going to go ahead and approve. I agree that this entire module-listing UI probably needs to be gutted and simplified at some point.

@jeherve
Copy link
Member

jeherve commented Mar 12, 2018

Related: #9033

oskosk added a commit that referenced this pull request Mar 23, 2018
dereksmart pushed a commit that referenced this pull request Mar 27, 2018
* Changelog 6.0: create base for changelog.

* Add #8938 to changelog

* Add #8962 to changelog

* Add #8974 to changelog

* Add #8975 to changelog

* Add #8978 to changelog

* Add #8867 to changelog

* Add #8937 to changelog

* Add #8961 to changelog

* Add #8855 to changelog

* Add #8944 to changelog

* Add #8973 to changelog

* Add #8977 to changelog

* Add #8979 to changelog

* Add #8980 to changelog

* Add #8982 to changelog

* Add #8983 to changelog

* Add #8984 to changelog

* Add #8986 to changelog

* Add #9005 to changelog

* Add #9010 to changelog

* Add #9012 to changelog

* Add #9021 to changelog

* Add #9022 to changelog

* Add #9056 to changelog

* Add #9061 to changelog

* Add #9079 to changelog

* Add #9080 to changelog

* Add #9088 to changelog

* Add #9096 to changelog

* Add #9097 to changelog

* Add #9100 to changelog

* Add #9107 to changelog

* Add #8969 to changelog

* Add #8993 to changelog

* Add #9003 to changelog

* Add #9031 to changelog

* Add #8945 to changelog

* Add #9052 to changelog

* Add #9058 to changelog

* Add #9066 to changelog

* Add #9076 to changelog

* Add #9053 to changelog

* Add #9108 to changelog

* Add #9135 to changelog

* Add #9148 to changelog

* Add #9125 to changelog

* Add #9137 to changelog

* Added testing instructions for 6.0.

* Added IS testing instructions, huge props to @tiagonoronha.

* Added #8498 to changelog.

* Added #8954 to changelog.

* Added #8985 to changelog.

* add #9027

* add #9112 to changelog

* add #9136 to changelog

* add #9102 to changelog

* add #9093 to changelog

* add #9062 to changelog

* add #9172 to changelog
@kraftbj kraftbj removed the [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. label Sep 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Admin Page React-powered dashboard under the Jetpack menu [Focus] FixTheFlows Plans
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SEO Tools can be enabled from module list
6 participants