pnp / cli-microsoft365

Manage Microsoft 365 and SharePoint Framework projects on any platform
https://aka.ms/cli-m365
MIT License
882 stars 312 forks source link

New command: m365 spe containertype remove #5992

Open Adam-it opened 2 months ago

Adam-it commented 2 months ago

Usage

m365 spe containertype remove [options]

Description

Remove a specific Container Type

Options

Option Description
-i, --id [id] The Id of the Container Type. Specify either id or name but not both.
-n, --name [name] The Container Type name. Specify either id or name but not both.
-f, --force Don't prompt for confirming removal

Examples

Removes Container Type by id

m365 spe containertype remove --id '4ec4aefd-4fa3-0e4a-20c3-6e68389e7138'

Removes Container Type by name

m365 spe containertype remove --name 'test container'

Removes Container Type by id and doesn't prompt for confirmation

m365 spe containertype remove --id '4ec4aefd-4fa3-0e4a-20c3-6e68389e7138' --force

Default properties

No response

Additional Info

We may use CSOM for this command passing the following

<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName="SharePoint Online PowerShell (16.0.24322.0)"
    xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009">
    <Actions>
        <ObjectPath Id="58" ObjectPathId="57" />
        <Method Name="RemoveSPOContainerType" Id="59" ObjectPathId="57">
            <Parameters>
                <Parameter TypeId="{b66ab1ca-fd51-44f9-8cfc-01f5c2a21f99}">
                    <Property Name="ContainerTypeId" Type="Guid">{4ec4aefd-4fa3-0e4a-20c3-6e68389e7138}</Property>
                </Parameter>
            </Parameters>
        </Method>
    </Actions>
    <ObjectPaths>
        <Constructor Id="57" TypeId="{268004ae-ef6b-4e9b-8425-127220d84719}" />
    </ObjectPaths>
</Request>

⚠️ Tricky part

The CSOM call does not support filtering by name only by Guid so if we want to add handling also remove the Container Type by name what we will need to do under the hood is query all Container Types and filter them by name. Also if more than one Container Type will be found (as the name does not have to be unique) CLI (when interactive mode on) should prompt to pick the correct one based on id

❗Important

We need to handle that only Trail Container Type may be removed. This should be added to the command spec

Adam-it commented 2 months ago

@andrewconnell any opinion on that 👆

milanholemans commented 2 months ago

2 remarks:

1) Only trial Container Types can be removed, does this mean that we don't have to check for the type ourselves and the API will just throw a decent error when you try to remove a standard container type?

2) Documentation quote:

To delete a trial Container Type, you must remove all Containers of the Trial Container Type first, including from the recycle bin. To remove Containers from the Trial Container Type, refer to Consuming Tenant Admin. Once all the Containers are deleted, Developer Admins can delete the Container Types using the below PowerShell cmdlet.

What will happen if we run this command when there are still containers attached? Will we remove them, or just throw an error?

Adam-it commented 2 months ago

2 remarks:

  1. Only trial Container Types can be removed, does this mean that we don't have to check for the type ourselves and the API will just throw a decent error when you try to remove a standard container type?

yes it will return something like Tenant 2942bb31-1d49-4da6-8d3d-d0f9e1141486 cannot delete Container Type 32793d51-870d-07da-113f-b586dee1c12a as it is Standard ContainerType.

Documentation quote:

To delete a trial Container Type, you must remove all Containers of the Trial Container Type first, including from the recycle bin. To remove Containers from the Trial Container Type, refer to Consuming Tenant Admin. Once all the Containers are deleted, Developer Admins can delete the Container Types using the below PowerShell cmdlet.

What will happen if we run this command when there are still containers attached? Will we remove them, or just throw an error?

I think we should throw an error.

milanholemans commented 2 months ago

Ok, thanks for clarifying. Let's open it up then.