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

Site Settings: Make it impossible for users to delete a site with active subscriptions #1246

Merged
merged 4 commits into from
Dec 4, 2015

Conversation

drewblaisdell
Copy link
Contributor

Fixes #1110.

Currently, it is possible to delete a site that has active subscriptions by either:

  • Visiting /settings/general/:site and clicking the 'Delete Site' link from DeleteSiteOptions before the purchases have been fetched from the API.
  • Visiting /settings/delete-site/:site directly.

This PR addresses this by:

  • Not rendering DeleteSiteOptions until the purchases have been loaded from the API (this is how this component used to behave).
  • Returning an error from the site deletion endpoint if there are active subscriptions for the given site.
  • Updating NoticesList so that it renders even when passed an empty array of notices, ensuring that DeleteSiteNotices is rendered (this is how the this component used to behave).

@johnHackworth I believe the inverse change of this commit was added by you a couple months ago. Do you know of any issues with removing that check in NoticesList?

Testing

  • Apply the patch.
  • Checkout this branch.
  • Navigate to /settings/general/:site for a site with an active subscription (e.g. a premium plan).
  • Assert that clicking the 'Delete Site' link at the bottom of the page brings up a dialog prompting you to remove your active subscription.
  • Navigate to /settings/delete-site/:site for a site with an active subscription.
  • Assert that an error notice appears when you attempt to delete a site.

@drewblaisdell drewblaisdell added [Type] Bug [Feature] Site Settings All other general site settings. [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Dec 3, 2015
@drewblaisdell drewblaisdell self-assigned this Dec 3, 2015
@drewblaisdell drewblaisdell added this to the Purchases: v1 milestone Dec 3, 2015
@drewblaisdell drewblaisdell force-pushed the update/site-deletion-subscriptions branch 2 times, most recently from 48050a2 to c7c7189 Compare December 3, 2015 20:17
@scruffian
Copy link
Member

This looks good to me. It works as advertised and I don't have any comments on the code. I'm happy for you to merge, but I'll look more in detail tomorrow if you'd rather.

@drewblaisdell
Copy link
Contributor Author

@scruffian Thanks for taking a look. Either works for me.

@scruffian
Copy link
Member

Not rendering DeleteSiteOptions until the purchases have been loaded from the API (this is how this component used to behave).

Would a placeholder be better?

@scruffian scruffian added [Status] Needs Author Reply and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Dec 4, 2015
@scruffian
Copy link
Member

Code looks good, and the server side patch can be deployed. My only concern is that by not showing the delete section until the endpoint has loaded, so users might get confused.

@johnHackworth
Copy link
Contributor

        if ( ! noticesRaw.length ) {
            return null;
        }

To be honest, I don't remember why I needed that ... I guess I added it when I did all the pinned notices stuff, but I've just tested your branch and everything seems to be working as usual

/shrug

Dispatcher.handleViewAction( {
type: 'DELETE_SITE',
site: site
} );

debug( 'Deleting site', site );
wpcom.deleteSite( site.ID, SitesListActions.receiveDeletedSite );

wpcom.deleteSite( site.ID, function( error, data ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be so nice if we could do all this wpcom methods to return promises someday :/

@johnHackworth
Copy link
Contributor

I left a minor comment, but codewise looks good to me too

@drewblaisdell drewblaisdell force-pushed the update/site-deletion-subscriptions branch from c7c7189 to f3c01be Compare December 4, 2015 18:15
@drewblaisdell
Copy link
Contributor Author

Would a placeholder be better?

Yes, but that is out of scope for this PR, which just fixes the existing behavior. There are multiple settings on that page that "pop in" after a response from the API. I'll open an issue for it after this is merged if one doesn't already exist.

@drewblaisdell drewblaisdell added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] Needs Author Reply labels Dec 4, 2015
@scruffian
Copy link
Member

Ok sounds good. In that case 🚢

@scruffian scruffian added [Status] Ready to Merge and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Dec 4, 2015
…d from the API

This was the original behavior of `DeleteSite`, and prevents users from deleting
sites with active subscriptions.
Otherwise, `<DeleteSiteNotices />` isn't rendered.
@drewblaisdell drewblaisdell force-pushed the update/site-deletion-subscriptions branch from f3c01be to 6d4711d Compare December 4, 2015 22:10
drewblaisdell added a commit that referenced this pull request Dec 4, 2015
…ptions

Site Settings: Make it impossible for users to delete a site with active subscriptions
@drewblaisdell drewblaisdell merged commit dcc3794 into master Dec 4, 2015
@drewblaisdell drewblaisdell deleted the update/site-deletion-subscriptions branch December 4, 2015 22:19
@scruffian
Copy link
Member

I'll open an issue for it after this is merged if one doesn't already exist.

Did you do this?

@drewblaisdell
Copy link
Contributor Author

Whoops, here it is: #1291

Also, I discovered that this PR fixed another issue: #158

@scruffian
Copy link
Member

Also, I discovered that this PR fixed another issue: #158

Nice! Good work @drewblaisdell!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Site Settings All other general site settings. [Type] Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants