cli-microsoft365: Bug report - 'spo site remove' - Removing sites and groupified sites does not work correctly

Priority

(Medium) I’m annoyed but I’ll live

Description

Removing sites and groupified sites does not work correctly

Issues 1

If I try to delete a groupified site, this does not work correctly:

image

What happens is that it removes the group using the Graph, and then tries to remove the site using the sharepoint API. The only problem is that the site cannot be removed because it’s connected to the group. Thus it throws an exception, but the exception is caught by a try-catch that interprets it as something different.

Long story short, this code is bad. It does not do what you’d expect it to do.

The result is that the group is deleted, but the site is not deleted at all.

Issue 2

I can use --fromRecycleBin when deleting a site that is not in the recycle bin. SharePoint will delete the site for you. I find this questionable. It should throw an error if it’s not in the recycle bin.

Issue 3

I can use --fromRecycleBin on groupified sites. This deletes the site (and skips the recycle bin), but leaves the group as is. It’s not even deleted

Issue 4

The command claims that you cannot use --skipRecycleBin on groupified sites. however, this functionality IS available on aad o365group remove, so I guess we should implement it here as well.

Steps to reproduce

just try it out

Expected results

sites and groups correctly deleted or moved to the recycle bin

Actual results

odd results…

Additional Info

Part of the solution is to start using the GroupManager API for groupified sites:

https://contoso-admin.sharepoint.com/_api/GroupSiteManager/Delete
{
"siteUrl": "https://contoso.sharepoint.com/sites/sales"
}

This will delete the site AND the group in one call. This API is already implemented for deleting orphaned sites. But it should be used in any m365 group deletion call.

For --skipRecycleBin, the implementation on aad o365group remove can serve for inspiration

Implementation

The issue will be solved if the following points have been implemented:

  • spo site remove - the GroupManager API is used for groupified sites.

  • spo site remove - the --skipRecycleBin flag can be used for groupified sites as well.

  • spo site remove - for non-groupified sites, --fromRecycleBin checks if a site is actually in the recycle bin before deleting it. It will throw an error if not.

  • spo site remove - for groupified sites --fromRecycleBin checks if a group is a deleted group using the graph API and removes it if it is.

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Comments: 23 (23 by maintainers)

Most upvoted comments

I can pick this up after my holiday.

I have now however noticed that, when we use the REST-API Endpoints provided by SharePoint, we do no longer have to capability to poll for a response, so this would mean that the --wait option will be no longer used.

Regarding your other question. So you’re saying that the response is always instantaneous, even if an exception occurs? Do you know if this works the same for Classic sites? Other than that I’d say it would be fine to leave the --wait option in while marking it as deprecated, and remove all references to it from the command code, making it obsolete practically.

Other ideas on this @pnp/cli-for-microsoft-365-maintainers ??

Ive moved the second command to a separate issue 👍

I have now however noticed that, when we use the REST-API Endpoints provided by SharePoint, we do no longer have to capability to poll for a response, so this would mean that the --wait option will be no longer used.

Regarding your other question. So you’re saying that the response is always instantaneous, even if an exception occurs? Do you know if this works the same for Classic sites? Other than that I’d say it would be fine to leave the --wait option in while marking it as deprecated, and remove all references to it from the command code, making it obsolete practically.

Other ideas on this @pnp/cli-for-microsoft-365-maintainers ??

Sounds like another v8 issue indeed.

As far as I’m concerned let’s keep the option for now, marked as deprecated, and remove all references.

I have now however noticed that, when we use the REST-API Endpoints provided by SharePoint, we do no longer have to capability to poll for a response, so this would mean that the --wait option will be no longer used.

Regarding your other question. So you’re saying that the response is always instantaneous, even if an exception occurs? Do you know if this works the same for Classic sites? Other than that I’d say it would be fine to leave the --wait option in while marking it as deprecated, and remove all references to it from the command code, making it obsolete practically.

I have tested it with both classic and communication sites, and it works for both.

Nice @MathijsVerbeeck! That would be great, this bug has gone on too long.

I could give this a shot.

Hey @martinlingstuyl, coming back to this issue, it’s hard to understand what’s wrong exactly. Could you please clarify what’s not working vs. what’s expected with clear repro steps? If you see multiple issues, let’s keep them separate to avoid making the fixes too hard.

Hi @waldekmastykarz, the command implementation is just bad on multiple counts. I believe that much is clear from the issue specs, right? I think it’s best if I just pick this up myself and fix it. I’ll add some repro-steps to aid the reviewer.

It’s actually two commands… we could move the second to a separate issue indeed.

Great suggestion @martinlingstuyl. Let’s do this. Let’s open it up, since it’s a bug, but if no one picks it up, it’s all yours when you get back 🙂

Maybe it was a bit shorter if you wrote down what does work of the command 😂