pnp / cli-microsoft365

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

New Command: Sync a content type from the content type hub to a site #5551

Closed martinlingstuyl closed 6 months ago

martinlingstuyl commented 12 months ago

Usage

m365 spo contenttype sync [options]

Description

Adds a published content type from the content type hub to a site or syncs its latest changes

Options

Option Description
-u, --webUrl <webUrl> The site to sync the Content Type to.
-i, --id [id] The Id of the published Content Type to sync from the Content Type Hub. Specify either id or name.
-n, --name [name] The name of the published Content Type to sync from the Content Type Hub. Specify either id or name.
--listTitle [listTitle] Title of the list. Specify either listTitle, listId or listUrl. Omit to sync as a site content type.
--listId [listId] ID of the list. Specify either listTitle, listId or listUrl. Omit to sync as a site content type.
--listUrl [listUrl] Server- or site-relative URL of the list. Specify either listTitle, listId or listUrl. Omit to sync as a site content type.

Examples

Syncs a given published content type from the hub to the specified site.

m365 spo contenttype sync —webUrl https://contoso.sharepoint.com/sites/sales --id 0x01007926A45D687BA842B947286090B8F67D

Syncs a given published content type from the hub to the specified site and adds it to the specified list.

m365 spo contenttype sync —webUrl https://contoso.sharepoint.com/sites/sales --id 0x01007926A45D687BA842B947286090B8F67D --listTitle Contacts

Response

The api response should be returned

Additional info

The id property should be added to the types.strings array, to force minimist to parse it as string!

The following endpoint should be used:

https://learn.microsoft.com/en-us/graph/api/contenttype-addcopyfromcontenttypehub?view=graph-rest-1.0&tabs=http

waldekmastykarz commented 12 months ago

Could we also allow syncing the content type by name?

waldekmastykarz commented 12 months ago

Also, since contenttype is the last noun we can shorten contentTypeId to id

waldekmastykarz commented 12 months ago

For the ID we need to force it to be treated as a string or bash will assume a hex digit because of the 0x prefix

martinlingstuyl commented 12 months ago

Could we also allow syncing the content type by name?

A, good idea!

We'd need to get it from the hub first, but that should be possible.

martinlingstuyl commented 12 months ago

Any other comments before we open this up? @pnp/cli-for-microsoft-365-maintainers

Jwaegebaert commented 12 months ago

I've got nothing else to add. Good catch on this one!

milanholemans commented 12 months ago

For the ID we need to force it to be treated as a string or bash will assume a hex digit because of the 0x prefix

As mentioned before, in fact, we should (for now) always parse all options as string. Image, for example, the option listId here, the user could provide a value like 123 as listId. Minimist will parse it as a number and the whole validation would fail because we assume the value is a string. Therefore it's best that every option that is typed as string in the interface, is typed as string in the args parser as well. Otherwise, we have no guarantee that the option is actually a string and not something else.

MathijsVerbeeck commented 6 months ago

Can I work on this?