Skip to content

Commit

Permalink
Enhances spo contenttype get, spo contenttype listand `spo list c…
Browse files Browse the repository at this point in the history
…ontenttype list` commands with Parent expand. Closes #6329
  • Loading branch information
MathijsVerbeeck committed Sep 26, 2024
1 parent 2d61838 commit e21568a
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 476 deletions.
8 changes: 7 additions & 1 deletion docs/docs/cmd/spo/contenttype/contenttype-get.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ m365 spo contenttype get --webUrl https://contoso.sharepoint.com/sites/contoso-s
"NewFormTarget": 0,
"NewFormTemplateName": "ListForm",
"NewFormUrl": "",
"Parent": {
"StringId": "0x01000B1208C5D23DF",
"Name": "Item",
"Group": "List items",
"Id": { "StringId": "0x01000B1208C5D23DF" }
},
"ReadOnly": false,
"SchemaXml": "<ContentType ID=\"0x01007926A45D687BA842B947286090B8F67D\" Name=\"PnP Alert\" Group=\"PnP Content Types\" Description=\"Create a new list item.\" Version=\"0\"><Folder TargetName=\"_cts/PnP Alert\" /><Fields><Field ID=\"{c042a256-787d-4a6f-8a8a-cf6ab767f12d}\" Name=\"ContentType\" SourceID=\"http://schemas.microsoft.com/sharepoint/v3\" StaticName=\"ContentType\" Group=\"_Hidden\" Type=\"Computed\" DisplayName=\"Content Type\" Sealed=\"TRUE\" Sortable=\"FALSE\" RenderXMLUsingPattern=\"TRUE\" PITarget=\"MicrosoftWindowsSharePointServices\" PIAttribute=\"ContentTypeID\" DelayActivateTemplateBinding=\"GROUP,SPSPERS,SITEPAGEPUBLISHING\" Customization=\"\"><FieldRefs><FieldRef ID=\"{03e45e84-1992-4d42-9116-26f756012634}\" Name=\"ContentTypeId\" /></FieldRefs><DisplayPattern><MapToContentType><Column Name=\"ContentTypeId\" /></MapToContentType></DisplayPattern></Field><Field ID=\"{fa564e0f-0c70-4ab9-b863-0177e6ddd247}\" Name=\"Title\" SourceID=\"http://schemas.microsoft.com/sharepoint/v3\" StaticName=\"Title\" Group=\"_Hidden\" Type=\"Text\" DisplayName=\"Title\" Required=\"TRUE\" FromBaseType=\"TRUE\" DelayActivateTemplateBinding=\"GROUP,SPSPERS,SITEPAGEPUBLISHING\" Customization=\"\" ShowInNewForm=\"TRUE\" ShowInEditForm=\"TRUE\"></Field></Fields><XmlDocuments><XmlDocument NamespaceURI=\"http://schemas.microsoft.com/sharepoint/v3/contenttype/forms\"><FormTemplates xmlns=\"http://schemas.microsoft.com/sharepoint/v3/contenttype/forms\"><Display>ListForm</Display><Edit>ListForm</Edit><New>ListForm</New></FormTemplates></XmlDocument></XmlDocuments></ContentType>",
"Scope": "/sites/contoso-sales",
Expand Down Expand Up @@ -170,7 +176,7 @@ m365 spo contenttype get --webUrl https://contoso.sharepoint.com/sites/contoso-s

Date: 10/2/2023

## PnP Alert ([object Object])
## PnP Alert (0x01007926A45D687BA842B947286090B8F67D)

Property | Value
---------|-------
Expand Down
8 changes: 7 additions & 1 deletion docs/docs/cmd/spo/contenttype/contenttype-list.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ m365 spo contenttype list --webUrl "https://contoso.sharepoint.com/sites/contoso
"NewFormTarget": 0,
"NewFormTemplateName": "ListForm",
"NewFormUrl": "",
"Parent": {
"StringId": "0x01000B1208C5D23DF",
"Name": "Item",
"Group": "List items",
"Id": { "StringId": "0x01000B1208C5D23DF" }
},
"ReadOnly": false,
"SchemaXml": "<ContentType ID=\"0x01007926A45D687BA842B947286090B8F67D\" Name=\"PnP Alert\" Group=\"PnP Content Types\" Description=\"Create a new list item.\" Version=\"0\"><Folder TargetName=\"_cts/PnP Alert\" /><Fields><Field ID=\"{c042a256-787d-4a6f-8a8a-cf6ab767f12d}\" Name=\"ContentType\" SourceID=\"http://schemas.microsoft.com/sharepoint/v3\" StaticName=\"ContentType\" Group=\"_Hidden\" Type=\"Computed\" DisplayName=\"Content Type\" Sealed=\"TRUE\" Sortable=\"FALSE\" RenderXMLUsingPattern=\"TRUE\" PITarget=\"MicrosoftWindowsSharePointServices\" PIAttribute=\"ContentTypeID\" DelayActivateTemplateBinding=\"GROUP,SPSPERS,SITEPAGEPUBLISHING\" Customization=\"\"><FieldRefs><FieldRef ID=\"{03e45e84-1992-4d42-9116-26f756012634}\" Name=\"ContentTypeId\" /></FieldRefs><DisplayPattern><MapToContentType><Column Name=\"ContentTypeId\" /></MapToContentType></DisplayPattern></Field><Field ID=\"{fa564e0f-0c70-4ab9-b863-0177e6ddd247}\" Name=\"Title\" SourceID=\"http://schemas.microsoft.com/sharepoint/v3\" StaticName=\"Title\" Group=\"_Hidden\" Type=\"Text\" DisplayName=\"Title\" Required=\"TRUE\" FromBaseType=\"TRUE\" DelayActivateTemplateBinding=\"GROUP,SPSPERS,SITEPAGEPUBLISHING\" Customization=\"\" ShowInNewForm=\"TRUE\" ShowInEditForm=\"TRUE\"></Field></Fields><XmlDocuments><XmlDocument NamespaceURI=\"http://schemas.microsoft.com/sharepoint/v3/contenttype/forms\"><FormTemplates xmlns=\"http://schemas.microsoft.com/sharepoint/v3/contenttype/forms\"><Display>ListForm</Display><Edit>ListForm</Edit><New>ListForm</New></FormTemplates></XmlDocument></XmlDocuments></ContentType>",
"Scope": "/sites/contoso-sales",
Expand Down Expand Up @@ -108,7 +114,7 @@ m365 spo contenttype list --webUrl "https://contoso.sharepoint.com/sites/contoso
# spo contenttype list --webUrl "https://contoso.sharepoint.com/sites/contoso-sales"

Date: 10/2/2023
## PnP Alert ([object Object])
## PnP Alert (0x01007926A45D687BA842B947286090B8F67D)

Property | Value
---------|-------
Expand Down
8 changes: 7 additions & 1 deletion docs/docs/cmd/spo/list/list-contenttype-list.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ m365 spo list contenttype list --webUrl https://contoso.sharepoint.com/sites/pro
"NewFormTarget": 0,
"NewFormTemplateName": "ListForm",
"NewFormUrl": "",
"Parent": {
"StringId": "0x01000B1208C5D23DF",
"Name": "Item",
"Group": "List items",
"Id": { "StringId": "0x01000B1208C5D23DF" }
},
"ReadOnly": false,
"SchemaXml": "<ContentType ID=\"0x01000B1208C5D23DF44B9F1AEE7373DE9D5E\" Name=\"Item\" Group=\"List Content Types\" Description=\"Create a new list item.\" Version=\"0\" FeatureId=\"{695b6570-a48b-4a8e-8ea5-26ea7fc1d162}\" FeatureIds=\"{695b6570-a48b-4a8e-8ea5-26ea7fc1d162};{c94c1702-30a7-454c-be15-5a895223428d}\"><Folder TargetName=\"Item\"/><Fields><Field ID=\"{c042a256-787d-4a6f-8a8a-cf6ab767f12d}\" Type=\"Computed\" DisplayName=\"Content Type\" Name=\"ContentType\" DisplaceOnUpgrade=\"TRUE\" RenderXMLUsingPattern=\"TRUE\" Sortable=\"FALSE\" SourceID=\"http://schemas.microsoft.com/sharepoint/v3\" StaticName=\"ContentType\" Group=\"_Hidden\" PITarget=\"MicrosoftWindowsSharePointServices\" PIAttribute=\"ContentTypeID\" FromBaseType=\"TRUE\"><FieldRefs><FieldRef Name=\"ContentTypeId\"/></FieldRefs><DisplayPattern><MapToContentType><Column Name=\"ContentTypeId\"/></MapToContentType></DisplayPattern></Field><Field ID=\"{fa564e0f-0c70-4ab9-b863-0177e6ddd247}\" Type=\"Text\" Name=\"Title\" DisplayName=\"Title\" Required=\"TRUE\" SourceID=\"http://schemas.microsoft.com/sharepoint/v3\" StaticName=\"Title\" FromBaseType=\"TRUE\" ColName=\"nvarchar1\" ShowInNewForm=\"TRUE\" ShowInEditForm=\"TRUE\"/></Fields><XmlDocuments><XmlDocument NamespaceURI=\"http://schemas.microsoft.com/sharepoint/v3/contenttype/forms\"><FormTemplates xmlns=\"http://schemas.microsoft.com/sharepoint/v3/contenttype/forms\"><Display>ListForm</Display><Edit>ListForm</Edit><New>ListForm</New></FormTemplates></XmlDocument></XmlDocuments></ContentType>",
"Scope": "/Lists/Test",
Expand Down Expand Up @@ -121,7 +127,7 @@ m365 spo list contenttype list --webUrl https://contoso.sharepoint.com/sites/pro

Date: 2/20/2023

## Document ([object Object])
## Document (0x01000B1208C5D23DF44B9F1AEE7373DE9D5E)

Property | Value
---------|-------
Expand Down
2 changes: 1 addition & 1 deletion src/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ export default abstract class Command {
}

private getLogItemId(logItem: any): string | undefined {
return logItem.id ?? logItem.Id ?? logItem.ID ??
return logItem.id ?? logItem.Id?.StringValue ?? logItem.Id ?? logItem.ID ??
logItem.uniqueId ?? logItem.UniqueId ??
logItem.objectId ?? logItem.ObjectId ??
logItem.url ?? logItem.Url ?? logItem.URL;
Expand Down
26 changes: 13 additions & 13 deletions src/m365/spo/commands/contenttype/contenttype-get.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe(commands.CONTENTTYPE_GET, () => {

it('gets information about a site content type by id', async () => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/contenttypes('0x0100558D85B7216F6A489A499DB361E1AE2F')`) {
if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/contenttypes('0x0100558D85B7216F6A489A499DB361E1AE2F')?$expand=Parent`) {
return contentTypeByIdResponse;
}

Expand All @@ -82,7 +82,7 @@ describe(commands.CONTENTTYPE_GET, () => {

it('gets information about a site content type by name', async () => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if ((opts.url as string).indexOf(`/_api/web/contenttypes?$filter=Name eq 'PnP%20Alert'`) > -1) {
if ((opts.url as string).indexOf(`/_api/web/contenttypes?$filter=Name eq 'PnP%20Alert'&$expand=Parent`) > -1) {
return contentTypeByNameResponse;
}

Expand All @@ -95,7 +95,7 @@ describe(commands.CONTENTTYPE_GET, () => {

it('gets information about a list content type by id', async () => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/lists/getByTitle('Events')/contenttypes('0x010200973548ACFFDA0948BE80AF607C4E28F9')`) {
if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/lists/getByTitle('Events')/contenttypes('0x010200973548ACFFDA0948BE80AF607C4E28F9')?$expand=Parent`) {
return contentTypeByIdResponse;
}

Expand All @@ -108,7 +108,7 @@ describe(commands.CONTENTTYPE_GET, () => {

it('gets information about a list retrieved by its title and the content type by id', async () => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/lists(guid'9153a1f5-22f7-49e8-a854-06bb4477c2a2')/contenttypes('0x010200973548ACFFDA0948BE80AF607C4E28F9')`) {
if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/lists(guid'9153a1f5-22f7-49e8-a854-06bb4477c2a2')/contenttypes('0x010200973548ACFFDA0948BE80AF607C4E28F9')?$expand=Parent`) {
return contentTypeByIdResponse;
}

Expand All @@ -121,7 +121,7 @@ describe(commands.CONTENTTYPE_GET, () => {

it('gets information about a list retrieved by its url and the content type by id', async () => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/GetList('%2Fsites%2Fportal%2Fdocuments')/contenttypes('0x010200973548ACFFDA0948BE80AF607C4E28F9')`) {
if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/GetList('%2Fsites%2Fportal%2Fdocuments')/contenttypes('0x010200973548ACFFDA0948BE80AF607C4E28F9')?$expand=Parent`) {
return contentTypeByIdResponse;
}

Expand All @@ -134,7 +134,7 @@ describe(commands.CONTENTTYPE_GET, () => {

it('gets information about a list retrieved by its title and the content type by name', async () => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/lists/getByTitle('Events')/contenttypes?$filter=Name eq 'Event'`) {
if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/lists/getByTitle('Events')/contenttypes?$filter=Name eq 'Event'&$expand=Parent`) {
return contentTypeByNameResponse;
}

Expand All @@ -147,7 +147,7 @@ describe(commands.CONTENTTYPE_GET, () => {

it('gets information about a list retrieved by its id and the content type by name', async () => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/lists(guid'9153a1f5-22f7-49e8-a854-06bb4477c2a2')/contenttypes?$filter=Name eq 'Event'`) {
if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/lists(guid'9153a1f5-22f7-49e8-a854-06bb4477c2a2')/contenttypes?$filter=Name eq 'Event'&$expand=Parent`) {
return contentTypeByNameResponse;
}

Expand All @@ -160,7 +160,7 @@ describe(commands.CONTENTTYPE_GET, () => {

it('gets information about a list retrieved by its url and the content type by name', async () => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/GetList('%2Fsites%2Fportal%2Fdocuments')/contenttypes?$filter=Name eq 'Event'`) {
if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/GetList('%2Fsites%2Fportal%2Fdocuments')/contenttypes?$filter=Name eq 'Event'&$expand=Parent`) {
return contentTypeByNameResponse;
}

Expand All @@ -173,7 +173,7 @@ describe(commands.CONTENTTYPE_GET, () => {

it('correctly escapes special characters in the content type id', async () => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/contenttypes('0%3D0100558D85B7216F6A489A499DB361E1AE2F')`) {
if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/contenttypes('0%3D0100558D85B7216F6A489A499DB361E1AE2F')?$expand=Parent`) {
return { "odata.null": true };
}

Expand All @@ -186,7 +186,7 @@ describe(commands.CONTENTTYPE_GET, () => {

it('correctly handles site content type not found by id', async () => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/contenttypes('0x0100558D85B7216F6A489A499DB361E1AE2F')`) {
if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/contenttypes('0x0100558D85B7216F6A489A499DB361E1AE2F')?$expand=Parent`) {
return { "odata.null": true };
}

Expand All @@ -199,7 +199,7 @@ describe(commands.CONTENTTYPE_GET, () => {

it('correctly handles site content type not found by content type name', async () => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/contenttypes?$filter=Name eq 'PnP%20Alert'`) {
if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/contenttypes?$filter=Name eq 'PnP%20Alert'&$expand=Parent`) {
return { "value": [] };
}

Expand All @@ -212,7 +212,7 @@ describe(commands.CONTENTTYPE_GET, () => {

it('correctly handles list content type not found', async () => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/lists/getByTitle('Documents')/contenttypes('0x0100558D85B7216F6A489A499DB361E1AE2F')`) {
if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/lists/getByTitle('Documents')/contenttypes('0x0100558D85B7216F6A489A499DB361E1AE2F')?$expand=Parent`) {
return { "odata.null": true };
}

Expand All @@ -225,7 +225,7 @@ describe(commands.CONTENTTYPE_GET, () => {

it('correctly handles list not found', async () => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/lists/getByTitle('Documents')/contenttypes('0x0100558D85B7216F6A489A499DB361E1AE2F')`) {
if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web/lists/getByTitle('Documents')/contenttypes('0x0100558D85B7216F6A489A499DB361E1AE2F')?$expand=Parent`) {
throw {
error: {
"odata.error": {
Expand Down
4 changes: 2 additions & 2 deletions src/m365/spo/commands/contenttype/contenttype-get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ class SpoContentTypeGetCommand extends SpoCommand {
requestUrl += "/contenttypes";

if (args.options.id) {
requestUrl += `('${formatting.encodeQueryParameter(args.options.id)}')`;
requestUrl += `('${formatting.encodeQueryParameter(args.options.id)}')?$expand=Parent`;
}
else if (args.options.name) {
requestUrl += `?$filter=Name eq '${formatting.encodeQueryParameter(args.options.name)}'`;
requestUrl += `?$filter=Name eq '${formatting.encodeQueryParameter(args.options.name)}'&$expand=Parent`;
}

const requestOptions: CliRequestOptions = {
Expand Down
Loading

0 comments on commit e21568a

Please sign in to comment.