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

Bug report - 'aad o365group remove' - the connected SharePoint site is not removed #5224

Closed
martinlingstuyl opened this issue Jul 14, 2023 · 11 comments

Comments

@martinlingstuyl
Copy link
Contributor

martinlingstuyl commented Jul 14, 2023

As discussed in issue #5218 we have a couple of issues when removing sites and m365 groups with connected sites.

The issue for the aad o365group remove command is that it uses the Graph API to remove the Azure AD group. This means that the connected SharePoint site is left where it is.

That's not the right behavior: when using aad o365group remove, all connected resources of the group should be removed as well.

To implement this, we need to change the API that is called. The GroupSiteManager api is used by the UI in the admin center. That would be a better fit:

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

We first need to get the siteUrl for the group and then call this endpoint.
This will delete the site AND the group in one call.

@martinlingstuyl martinlingstuyl changed the title aad o365group remove - the connected SharePoint site is not removed Bug report - 'aad o365group remove' - the connected SharePoint site is not removed Jul 14, 2023
@Saurabh7019
Copy link
Contributor

Hi Martin, Can I work on it?

@Saurabh7019
Copy link
Contributor

Oh, I see you have already planned to work on this one - #5218

@milanholemans
Copy link
Contributor

I think Martin means that he could pick it up after his holiday if it hasn't been picked up by someone else yet.
That's why he added the help wanted label and didn't assign it to himself.

@Saurabh7019
Copy link
Contributor

I tried running the "m365 aad o365group remove" command to assess its behavior, and it appears to work as expected. The command successfully removes both the o365 group and its associated SharePoint site. Although the deletion process takes a few minutes, the site eventually gets deleted. Can anyone please test the command and and let us know your results?

@milanholemans
Copy link
Contributor

milanholemans commented Aug 1, 2023

Reading it again, I'm wondering if this is the desired behavior. If I'm not mistaken, if you remove an M365 group from the Azure portal, the SharePoint site will still be there. If you want to remove all connected resources, you should use the SP admin center to remove the site with its connected resources. In that case, people should use spo site remove right?

@Saurabh7019
Copy link
Contributor

If I'm not mistaken, if you remove an M365 group from the Azure portal, the SharePoint site will still be there.

Removing an M365 group from the Azure portal does remove the associated site. To me, it seems logical that resources created with the group are deleted upon the group's deletion.

@milanholemans
Copy link
Contributor

Removing an M365 group from the Azure portal does remove the associated site. To me, it seems logical that resources created with the group are deleted upon the group's deletion.

It might be logical indeed, but from my experience, if you remove the group from the Azure portal, the SP site remains there. Just tested it with a new group and had the same behavior. Group is gone, site is still there.

image

Unless I remove the site via the SP admin center and check the box to remove all associated resources, the site stays there.

@Saurabh7019
Copy link
Contributor

I just found that if you're the owner of a group and site and you delete the group, the associated site also gets deleted. If you're not an owner and you delete the group, the group itself gets removed, but the site continues to exist.

Reading more about it, Microsoft states that attempting to delete the O365 group will result in the entire site being deleted – this is by design. Therefore, if the site is not deleted because the person deleting the group is not an owner, it appears to be a bug.

Martin's suggestion seems to provide a fail-safe approach. I will try to implement that.

@milanholemans
Copy link
Contributor

I just found that if you're the owner of a group and site and you delete the group, the associated site also gets deleted. If you're not an owner and you delete the group, the group itself gets removed, but the site continues to exist.

That's weird, I just created the group displayed above. If I create it, I should be an owner, right? Strange behavior 😄

@Saurabh7019
Copy link
Contributor

Hi @martinlingstuyl, Should we remove the skipRecycleBin option from the command? If we keep this option, we can delete the group from the recycle bin using the https://graph.microsoft.com/v1.0/directory/deletedItems endpoint, but that does not remove the site from the recycle bin.

@martinlingstuyl
Copy link
Contributor Author

Hi @Saurabh7019, we should not remove the option.

Instead we can probably remove the site from the recycle bin with an extra call. Am I right?

Saurabh7019 added a commit to Saurabh7019/cli-microsoft365 that referenced this issue Aug 22, 2023
Saurabh7019 added a commit to Saurabh7019/cli-microsoft365 that referenced this issue Sep 5, 2023
Saurabh7019 added a commit to Saurabh7019/cli-microsoft365 that referenced this issue Sep 6, 2023
Saurabh7019 added a commit to Saurabh7019/cli-microsoft365 that referenced this issue Sep 18, 2023
Saurabh7019 added a commit to Saurabh7019/cli-microsoft365 that referenced this issue Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants