From e21568ae24342811050028a980b11c1a58b242b4 Mon Sep 17 00:00:00 2001 From: Mathijs Verbeeck Date: Thu, 26 Sep 2024 10:07:27 +0200 Subject: [PATCH] Enhances `spo contenttype get`, `spo contenttype list`and `spo list contenttype list` commands with Parent expand. Closes #6329 --- .../cmd/spo/contenttype/contenttype-get.mdx | 8 +- .../cmd/spo/contenttype/contenttype-list.mdx | 8 +- .../cmd/spo/list/list-contenttype-list.mdx | 8 +- src/Command.ts | 2 +- .../contenttype/contenttype-get.spec.ts | 26 +- .../commands/contenttype/contenttype-get.ts | 4 +- .../contenttype/contenttype-list.spec.ts | 529 +++--------------- .../commands/contenttype/contenttype-list.ts | 9 +- .../list/list-contenttype-list.spec.ts | 22 +- .../commands/list/list-contenttype-list.ts | 7 +- 10 files changed, 147 insertions(+), 476 deletions(-) diff --git a/docs/docs/cmd/spo/contenttype/contenttype-get.mdx b/docs/docs/cmd/spo/contenttype/contenttype-get.mdx index 6a6ff026de6..c8bf91effc1 100644 --- a/docs/docs/cmd/spo/contenttype/contenttype-get.mdx +++ b/docs/docs/cmd/spo/contenttype/contenttype-get.mdx @@ -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": "ListFormListFormListForm", "Scope": "/sites/contoso-sales", @@ -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 ---------|------- diff --git a/docs/docs/cmd/spo/contenttype/contenttype-list.mdx b/docs/docs/cmd/spo/contenttype/contenttype-list.mdx index 4e35cd377e0..b2964a64679 100644 --- a/docs/docs/cmd/spo/contenttype/contenttype-list.mdx +++ b/docs/docs/cmd/spo/contenttype/contenttype-list.mdx @@ -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": "ListFormListFormListForm", "Scope": "/sites/contoso-sales", @@ -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 ---------|------- diff --git a/docs/docs/cmd/spo/list/list-contenttype-list.mdx b/docs/docs/cmd/spo/list/list-contenttype-list.mdx index f0db7ff4106..71cced4d53e 100644 --- a/docs/docs/cmd/spo/list/list-contenttype-list.mdx +++ b/docs/docs/cmd/spo/list/list-contenttype-list.mdx @@ -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": "ListFormListFormListForm", "Scope": "/Lists/Test", @@ -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 ---------|------- diff --git a/src/Command.ts b/src/Command.ts index 54c28bcd8e6..21a579905b6 100644 --- a/src/Command.ts +++ b/src/Command.ts @@ -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; diff --git a/src/m365/spo/commands/contenttype/contenttype-get.spec.ts b/src/m365/spo/commands/contenttype/contenttype-get.spec.ts index 2969ff88213..b4b7f7b0368 100644 --- a/src/m365/spo/commands/contenttype/contenttype-get.spec.ts +++ b/src/m365/spo/commands/contenttype/contenttype-get.spec.ts @@ -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; } @@ -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; } @@ -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; } @@ -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; } @@ -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; } @@ -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; } @@ -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; } @@ -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; } @@ -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 }; } @@ -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 }; } @@ -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": [] }; } @@ -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 }; } @@ -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": { diff --git a/src/m365/spo/commands/contenttype/contenttype-get.ts b/src/m365/spo/commands/contenttype/contenttype-get.ts index e419a5da2f0..0ab5a9b9e8c 100644 --- a/src/m365/spo/commands/contenttype/contenttype-get.ts +++ b/src/m365/spo/commands/contenttype/contenttype-get.ts @@ -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 = { diff --git a/src/m365/spo/commands/contenttype/contenttype-list.spec.ts b/src/m365/spo/commands/contenttype/contenttype-list.spec.ts index 54f06af0f9f..9b733922831 100644 --- a/src/m365/spo/commands/contenttype/contenttype-list.spec.ts +++ b/src/m365/spo/commands/contenttype/contenttype-list.spec.ts @@ -14,6 +14,75 @@ import commands from '../../commands.js'; import command from './contenttype-list.js'; describe(commands.CONTENTTYPE_LIST, () => { + const ctResponse = { + "value": [ + { + "Parent": { + "StringId": "0x01000B1208C5D23DF", + "Name": "Item", + "Group": "List items", + "Id": { "StringId": "0x01000B1208C5D23DF" } + }, + "Description": "Create a new document.", + "DisplayFormTemplateName": "DocumentLibraryForm", + "DisplayFormUrl": "", + "DocumentTemplate": "/Shared Documents/Forms/template.dotx", + "DocumentTemplateUrl": "/Shared Documents/Forms/template.dotx", + "EditFormTemplateName": "DocumentLibraryForm", + "EditFormUrl": "", + "Group": "Document Content Types", + "Hidden": false, + "Id": { + "StringValue": "0x010100260C61709CD8E548948F9BF605F8F54F" + }, + "JSLink": "", + "MobileDisplayFormUrl": "", + "MobileEditFormUrl": "", + "MobileNewFormUrl": "", + "Name": "Document", + "NewFormTemplateName": "DocumentLibraryForm", + "NewFormUrl": "", + "ReadOnly": false, + "SchemaXml": "DocumentLibraryFormDocumentLibraryFormDocumentLibraryForm", + "Scope": "/Shared Documents", + "Sealed": false, + "StringId": "0x010100260C61709CD8E548948F9BF605F8F54F" + }, + { + "Parent": { + "StringId": "0x01000B1208C5D23DF", + "Name": "Item", + "Group": "List items", + "Id": { "StringId": "0x01000B1208C5D23DF" } + }, + "Description": "Create a new folder.", + "DisplayFormTemplateName": "ListForm", + "DisplayFormUrl": "", + "DocumentTemplate": "", + "DocumentTemplateUrl": "", + "EditFormTemplateName": "ListForm", + "EditFormUrl": "", + "Group": "Folder Content Types", + "Hidden": false, + "Id": { + "StringValue": "0x0120000EAD53EDAD7C6647B0D976EEC953F99E" + }, + "JSLink": "", + "MobileDisplayFormUrl": "", + "MobileEditFormUrl": "", + "MobileNewFormUrl": "", + "Name": "Folder", + "NewFormTemplateName": "ListForm", + "NewFormUrl": "", + "ReadOnly": false, + "SchemaXml": "ListFormListFormListForm", + "Scope": "/Shared Documents", + "Sealed": true, + "StringId": "0x0120000EAD53EDAD7C6647B0D976EEC953F99E" + } + ] + }; + let log: any[]; let logger: Logger; let loggerLogSpy: sinon.SinonSpy; @@ -83,9 +152,9 @@ describe(commands.CONTENTTYPE_LIST, () => { }); it('command correctly handles reject request', async () => { - const err = 'Invalid request'; + const err = 'Error occured...'; sinon.stub(request, 'get').callsFake(async (opts) => { - if ((opts.url as string).indexOf('/_api/web/ContentTypes') > -1) { + if (opts.url === 'https://contoso.sharepoint.com/_api/web/ContentTypes?$expand=Parent') { throw err; } @@ -102,66 +171,11 @@ describe(commands.CONTENTTYPE_LIST, () => { it('retrieves all content types (debug)', async () => { sinon.stub(request, 'get').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`https://contoso.sharepoint.com/sites/test/_api/web/ContentTypes`) > -1) { + if (opts.url === 'https://contoso.sharepoint.com/sites/test/_api/web/ContentTypes?$expand=Parent') { if (opts.headers && opts.headers.accept && (opts.headers.accept as string).indexOf('application/json') === 0) { - return { - "value": [ - { - "Description": "Create a new document.", - "DisplayFormTemplateName": "DocumentLibraryForm", - "DisplayFormUrl": "", - "DocumentTemplate": "/Shared Documents/Forms/template.dotx", - "DocumentTemplateUrl": "/Shared Documents/Forms/template.dotx", - "EditFormTemplateName": "DocumentLibraryForm", - "EditFormUrl": "", - "Group": "Document Content Types", - "Hidden": false, - "Id": { - "StringValue": "0x010100260C61709CD8E548948F9BF605F8F54F" - }, - "JSLink": "", - "MobileDisplayFormUrl": "", - "MobileEditFormUrl": "", - "MobileNewFormUrl": "", - "Name": "Document", - "NewFormTemplateName": "DocumentLibraryForm", - "NewFormUrl": "", - "ReadOnly": false, - "SchemaXml": "DocumentLibraryFormDocumentLibraryFormDocumentLibraryForm", - "Scope": "/Shared Documents", - "Sealed": false, - "StringId": "0x010100260C61709CD8E548948F9BF605F8F54F" - }, - { - "Description": "Create a new folder.", - "DisplayFormTemplateName": "ListForm", - "DisplayFormUrl": "", - "DocumentTemplate": "", - "DocumentTemplateUrl": "", - "EditFormTemplateName": "ListForm", - "EditFormUrl": "", - "Group": "Folder Content Types", - "Hidden": false, - "Id": { - "StringValue": "0x0120000EAD53EDAD7C6647B0D976EEC953F99E" - }, - "JSLink": "", - "MobileDisplayFormUrl": "", - "MobileEditFormUrl": "", - "MobileNewFormUrl": "", - "Name": "Folder", - "NewFormTemplateName": "ListForm", - "NewFormUrl": "", - "ReadOnly": false, - "SchemaXml": "ListFormListFormListForm", - "Scope": "/Shared Documents", - "Sealed": true, - "StringId": "0x0120000EAD53EDAD7C6647B0D976EEC953F99E" - } - ] - }; + return ctResponse; } } @@ -174,124 +188,16 @@ describe(commands.CONTENTTYPE_LIST, () => { webUrl: 'https://contoso.sharepoint.com/sites/test' } }); - assert(loggerLogSpy.calledWith([ - { - "Description": "Create a new document.", - "DisplayFormTemplateName": "DocumentLibraryForm", - "DisplayFormUrl": "", - "DocumentTemplate": "/Shared Documents/Forms/template.dotx", - "DocumentTemplateUrl": "/Shared Documents/Forms/template.dotx", - "EditFormTemplateName": "DocumentLibraryForm", - "EditFormUrl": "", - "Group": "Document Content Types", - "Hidden": false, - "Id": { - "StringValue": "0x010100260C61709CD8E548948F9BF605F8F54F" - }, - "JSLink": "", - "MobileDisplayFormUrl": "", - "MobileEditFormUrl": "", - "MobileNewFormUrl": "", - "Name": "Document", - "NewFormTemplateName": "DocumentLibraryForm", - "NewFormUrl": "", - "ReadOnly": false, - "SchemaXml": "DocumentLibraryFormDocumentLibraryFormDocumentLibraryForm", - "Scope": "/Shared Documents", - "Sealed": false, - "StringId": "0x010100260C61709CD8E548948F9BF605F8F54F" - }, - { - "Description": "Create a new folder.", - "DisplayFormTemplateName": "ListForm", - "DisplayFormUrl": "", - "DocumentTemplate": "", - "DocumentTemplateUrl": "", - "EditFormTemplateName": "ListForm", - "EditFormUrl": "", - "Group": "Folder Content Types", - "Hidden": false, - "Id": { - "StringValue": "0x0120000EAD53EDAD7C6647B0D976EEC953F99E" - }, - "JSLink": "", - "MobileDisplayFormUrl": "", - "MobileEditFormUrl": "", - "MobileNewFormUrl": "", - "Name": "Folder", - "NewFormTemplateName": "ListForm", - "NewFormUrl": "", - "ReadOnly": false, - "SchemaXml": "ListFormListFormListForm", - "Scope": "/Shared Documents", - "Sealed": true, - "StringId": "0x0120000EAD53EDAD7C6647B0D976EEC953F99E" - } - ])); + assert(loggerLogSpy.calledWith(ctResponse.value)); }); it('retrieves all content types', async () => { sinon.stub(request, 'get').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`https://contoso.sharepoint.com/sites/test/_api/web/ContentTypes`) > -1) { + if (opts.url === `https://contoso.sharepoint.com/sites/test/_api/web/ContentTypes?$expand=Parent`) { if (opts.headers && opts.headers.accept && (opts.headers.accept as string).indexOf('application/json') === 0) { - return { - "value": [ - { - "Description": "Create a new document.", - "DisplayFormTemplateName": "DocumentLibraryForm", - "DisplayFormUrl": "", - "DocumentTemplate": "/Shared Documents/Forms/template.dotx", - "DocumentTemplateUrl": "/Shared Documents/Forms/template.dotx", - "EditFormTemplateName": "DocumentLibraryForm", - "EditFormUrl": "", - "Group": "Document Content Types", - "Hidden": false, - "Id": { - "StringValue": "0x010100260C61709CD8E548948F9BF605F8F54F" - }, - "JSLink": "", - "MobileDisplayFormUrl": "", - "MobileEditFormUrl": "", - "MobileNewFormUrl": "", - "Name": "Document", - "NewFormTemplateName": "DocumentLibraryForm", - "NewFormUrl": "", - "ReadOnly": false, - "SchemaXml": "DocumentLibraryFormDocumentLibraryFormDocumentLibraryForm", - "Scope": "/Shared Documents", - "Sealed": false, - "StringId": "0x010100260C61709CD8E548948F9BF605F8F54F" - }, - { - "Description": "Create a new folder.", - "DisplayFormTemplateName": "ListForm", - "DisplayFormUrl": "", - "DocumentTemplate": "", - "DocumentTemplateUrl": "", - "EditFormTemplateName": "ListForm", - "EditFormUrl": "", - "Group": "Folder Content Types", - "Hidden": false, - "Id": { - "StringValue": "0x0120000EAD53EDAD7C6647B0D976EEC953F99E" - }, - "JSLink": "", - "MobileDisplayFormUrl": "", - "MobileEditFormUrl": "", - "MobileNewFormUrl": "", - "Name": "Folder", - "NewFormTemplateName": "ListForm", - "NewFormUrl": "", - "ReadOnly": false, - "SchemaXml": "ListFormListFormListForm", - "Scope": "/Shared Documents", - "Sealed": true, - "StringId": "0x0120000EAD53EDAD7C6647B0D976EEC953F99E" - } - ] - }; + return ctResponse; } } @@ -303,124 +209,16 @@ describe(commands.CONTENTTYPE_LIST, () => { webUrl: 'https://contoso.sharepoint.com/sites/test' } }); - assert(loggerLogSpy.calledWith([ - { - "Description": "Create a new document.", - "DisplayFormTemplateName": "DocumentLibraryForm", - "DisplayFormUrl": "", - "DocumentTemplate": "/Shared Documents/Forms/template.dotx", - "DocumentTemplateUrl": "/Shared Documents/Forms/template.dotx", - "EditFormTemplateName": "DocumentLibraryForm", - "EditFormUrl": "", - "Group": "Document Content Types", - "Hidden": false, - "Id": { - "StringValue": "0x010100260C61709CD8E548948F9BF605F8F54F" - }, - "JSLink": "", - "MobileDisplayFormUrl": "", - "MobileEditFormUrl": "", - "MobileNewFormUrl": "", - "Name": "Document", - "NewFormTemplateName": "DocumentLibraryForm", - "NewFormUrl": "", - "ReadOnly": false, - "SchemaXml": "DocumentLibraryFormDocumentLibraryFormDocumentLibraryForm", - "Scope": "/Shared Documents", - "Sealed": false, - "StringId": "0x010100260C61709CD8E548948F9BF605F8F54F" - }, - { - "Description": "Create a new folder.", - "DisplayFormTemplateName": "ListForm", - "DisplayFormUrl": "", - "DocumentTemplate": "", - "DocumentTemplateUrl": "", - "EditFormTemplateName": "ListForm", - "EditFormUrl": "", - "Group": "Folder Content Types", - "Hidden": false, - "Id": { - "StringValue": "0x0120000EAD53EDAD7C6647B0D976EEC953F99E" - }, - "JSLink": "", - "MobileDisplayFormUrl": "", - "MobileEditFormUrl": "", - "MobileNewFormUrl": "", - "Name": "Folder", - "NewFormTemplateName": "ListForm", - "NewFormUrl": "", - "ReadOnly": false, - "SchemaXml": "ListFormListFormListForm", - "Scope": "/Shared Documents", - "Sealed": true, - "StringId": "0x0120000EAD53EDAD7C6647B0D976EEC953F99E" - } - ])); + assert(loggerLogSpy.calledWith(ctResponse.value)); }); it('retrieves all content types by category (debug)', async () => { sinon.stub(request, 'get').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`https://contoso.sharepoint.com/sites/test/_api/web/ContentTypes?$filter=Group eq 'List%20Content%20Types'`) > -1) { + if (opts.url === `https://contoso.sharepoint.com/sites/test/_api/web/ContentTypes?$expand=Parent&$filter=Group eq 'List%20Content%20Types'`) { if (opts.headers && opts.headers.accept && (opts.headers.accept as string).indexOf('application/json') === 0) { - return { - "value": [ - { - "Description": "Create a new document.", - "DisplayFormTemplateName": "DocumentLibraryForm", - "DisplayFormUrl": "", - "DocumentTemplate": "/Shared Documents/Forms/template.dotx", - "DocumentTemplateUrl": "/Shared Documents/Forms/template.dotx", - "EditFormTemplateName": "DocumentLibraryForm", - "EditFormUrl": "", - "Group": "Document Content Types", - "Hidden": false, - "Id": { - "StringValue": "0x010100260C61709CD8E548948F9BF605F8F54F" - }, - "JSLink": "", - "MobileDisplayFormUrl": "", - "MobileEditFormUrl": "", - "MobileNewFormUrl": "", - "Name": "Document", - "NewFormTemplateName": "DocumentLibraryForm", - "NewFormUrl": "", - "ReadOnly": false, - "SchemaXml": "DocumentLibraryFormDocumentLibraryFormDocumentLibraryForm", - "Scope": "/Shared Documents", - "Sealed": false, - "StringId": "0x010100260C61709CD8E548948F9BF605F8F54F" - }, - { - "Description": "Create a new folder.", - "DisplayFormTemplateName": "ListForm", - "DisplayFormUrl": "", - "DocumentTemplate": "", - "DocumentTemplateUrl": "", - "EditFormTemplateName": "ListForm", - "EditFormUrl": "", - "Group": "Folder Content Types", - "Hidden": false, - "Id": { - "StringValue": "0x0120000EAD53EDAD7C6647B0D976EEC953F99E" - }, - "JSLink": "", - "MobileDisplayFormUrl": "", - "MobileEditFormUrl": "", - "MobileNewFormUrl": "", - "Name": "Folder", - "NewFormTemplateName": "ListForm", - "NewFormUrl": "", - "ReadOnly": false, - "SchemaXml": "ListFormListFormListForm", - "Scope": "/Shared Documents", - "Sealed": true, - "StringId": "0x0120000EAD53EDAD7C6647B0D976EEC953F99E" - } - ] - }; + return ctResponse; } } @@ -434,124 +232,16 @@ describe(commands.CONTENTTYPE_LIST, () => { webUrl: 'https://contoso.sharepoint.com/sites/test' } }); - assert(loggerLogSpy.calledWith([ - { - "Description": "Create a new document.", - "DisplayFormTemplateName": "DocumentLibraryForm", - "DisplayFormUrl": "", - "DocumentTemplate": "/Shared Documents/Forms/template.dotx", - "DocumentTemplateUrl": "/Shared Documents/Forms/template.dotx", - "EditFormTemplateName": "DocumentLibraryForm", - "EditFormUrl": "", - "Group": "Document Content Types", - "Hidden": false, - "Id": { - "StringValue": "0x010100260C61709CD8E548948F9BF605F8F54F" - }, - "JSLink": "", - "MobileDisplayFormUrl": "", - "MobileEditFormUrl": "", - "MobileNewFormUrl": "", - "Name": "Document", - "NewFormTemplateName": "DocumentLibraryForm", - "NewFormUrl": "", - "ReadOnly": false, - "SchemaXml": "DocumentLibraryFormDocumentLibraryFormDocumentLibraryForm", - "Scope": "/Shared Documents", - "Sealed": false, - "StringId": "0x010100260C61709CD8E548948F9BF605F8F54F" - }, - { - "Description": "Create a new folder.", - "DisplayFormTemplateName": "ListForm", - "DisplayFormUrl": "", - "DocumentTemplate": "", - "DocumentTemplateUrl": "", - "EditFormTemplateName": "ListForm", - "EditFormUrl": "", - "Group": "Folder Content Types", - "Hidden": false, - "Id": { - "StringValue": "0x0120000EAD53EDAD7C6647B0D976EEC953F99E" - }, - "JSLink": "", - "MobileDisplayFormUrl": "", - "MobileEditFormUrl": "", - "MobileNewFormUrl": "", - "Name": "Folder", - "NewFormTemplateName": "ListForm", - "NewFormUrl": "", - "ReadOnly": false, - "SchemaXml": "ListFormListFormListForm", - "Scope": "/Shared Documents", - "Sealed": true, - "StringId": "0x0120000EAD53EDAD7C6647B0D976EEC953F99E" - } - ])); + assert(loggerLogSpy.calledWith(ctResponse.value)); }); it('retrieves all content types by category', async () => { sinon.stub(request, 'get').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`https://contoso.sharepoint.com/sites/test/_api/web/ContentTypes?$filter=Group eq 'List%20Content%20Types'`) > -1) { + if (opts.url === `https://contoso.sharepoint.com/sites/test/_api/web/ContentTypes?$expand=Parent&$filter=Group eq 'List%20Content%20Types'`) { if (opts.headers && opts.headers.accept && (opts.headers.accept as string).indexOf('application/json') === 0) { - return { - "value": [ - { - "Description": "Create a new document.", - "DisplayFormTemplateName": "DocumentLibraryForm", - "DisplayFormUrl": "", - "DocumentTemplate": "/Shared Documents/Forms/template.dotx", - "DocumentTemplateUrl": "/Shared Documents/Forms/template.dotx", - "EditFormTemplateName": "DocumentLibraryForm", - "EditFormUrl": "", - "Group": "Document Content Types", - "Hidden": false, - "Id": { - "StringValue": "0x010100260C61709CD8E548948F9BF605F8F54F" - }, - "JSLink": "", - "MobileDisplayFormUrl": "", - "MobileEditFormUrl": "", - "MobileNewFormUrl": "", - "Name": "Document", - "NewFormTemplateName": "DocumentLibraryForm", - "NewFormUrl": "", - "ReadOnly": false, - "SchemaXml": "DocumentLibraryFormDocumentLibraryFormDocumentLibraryForm", - "Scope": "/Shared Documents", - "Sealed": false, - "StringId": "0x010100260C61709CD8E548948F9BF605F8F54F" - }, - { - "Description": "Create a new folder.", - "DisplayFormTemplateName": "ListForm", - "DisplayFormUrl": "", - "DocumentTemplate": "", - "DocumentTemplateUrl": "", - "EditFormTemplateName": "ListForm", - "EditFormUrl": "", - "Group": "Folder Content Types", - "Hidden": false, - "Id": { - "StringValue": "0x0120000EAD53EDAD7C6647B0D976EEC953F99E" - }, - "JSLink": "", - "MobileDisplayFormUrl": "", - "MobileEditFormUrl": "", - "MobileNewFormUrl": "", - "Name": "Folder", - "NewFormTemplateName": "ListForm", - "NewFormUrl": "", - "ReadOnly": false, - "SchemaXml": "ListFormListFormListForm", - "Scope": "/Shared Documents", - "Sealed": true, - "StringId": "0x0120000EAD53EDAD7C6647B0D976EEC953F99E" - } - ] - }; + return ctResponse; } } @@ -564,59 +254,6 @@ describe(commands.CONTENTTYPE_LIST, () => { webUrl: 'https://contoso.sharepoint.com/sites/test' } }); - assert(loggerLogSpy.calledWith([ - { - "Description": "Create a new document.", - "DisplayFormTemplateName": "DocumentLibraryForm", - "DisplayFormUrl": "", - "DocumentTemplate": "/Shared Documents/Forms/template.dotx", - "DocumentTemplateUrl": "/Shared Documents/Forms/template.dotx", - "EditFormTemplateName": "DocumentLibraryForm", - "EditFormUrl": "", - "Group": "Document Content Types", - "Hidden": false, - "Id": { - "StringValue": "0x010100260C61709CD8E548948F9BF605F8F54F" - }, - "JSLink": "", - "MobileDisplayFormUrl": "", - "MobileEditFormUrl": "", - "MobileNewFormUrl": "", - "Name": "Document", - "NewFormTemplateName": "DocumentLibraryForm", - "NewFormUrl": "", - "ReadOnly": false, - "SchemaXml": "DocumentLibraryFormDocumentLibraryFormDocumentLibraryForm", - "Scope": "/Shared Documents", - "Sealed": false, - "StringId": "0x010100260C61709CD8E548948F9BF605F8F54F" - }, - { - "Description": "Create a new folder.", - "DisplayFormTemplateName": "ListForm", - "DisplayFormUrl": "", - "DocumentTemplate": "", - "DocumentTemplateUrl": "", - "EditFormTemplateName": "ListForm", - "EditFormUrl": "", - "Group": "Folder Content Types", - "Hidden": false, - "Id": { - "StringValue": "0x0120000EAD53EDAD7C6647B0D976EEC953F99E" - }, - "JSLink": "", - "MobileDisplayFormUrl": "", - "MobileEditFormUrl": "", - "MobileNewFormUrl": "", - "Name": "Folder", - "NewFormTemplateName": "ListForm", - "NewFormUrl": "", - "ReadOnly": false, - "SchemaXml": "ListFormListFormListForm", - "Scope": "/Shared Documents", - "Sealed": true, - "StringId": "0x0120000EAD53EDAD7C6647B0D976EEC953F99E" - } - ])); + assert(loggerLogSpy.calledWith(ctResponse.value)); }); }); diff --git a/src/m365/spo/commands/contenttype/contenttype-list.ts b/src/m365/spo/commands/contenttype/contenttype-list.ts index 8c0aaf6fe38..e09ca57352d 100644 --- a/src/m365/spo/commands/contenttype/contenttype-list.ts +++ b/src/m365/spo/commands/contenttype/contenttype-list.ts @@ -34,6 +34,7 @@ class SpoContentTypeListCommand extends SpoCommand { this.#initTelemetry(); this.#initOptions(); this.#initValidators(); + this.#initTypes(); } #initTelemetry(): void { @@ -61,12 +62,16 @@ class SpoContentTypeListCommand extends SpoCommand { ); } + #initTypes(): void { + this.types.string.push('webUrl', 'category'); + } + public async commandAction(logger: Logger, args: CommandArgs): Promise { try { - let requestUrl: string = `${args.options.webUrl}/_api/web/ContentTypes`; + let requestUrl: string = `${args.options.webUrl}/_api/web/ContentTypes?$expand=Parent`; if (args.options.category) { - requestUrl += `?$filter=Group eq '${formatting.encodeQueryParameter(args.options.category as string)}'`; + requestUrl += `&$filter=Group eq '${formatting.encodeQueryParameter(args.options.category as string)}'`; } const res = await odata.getAllItems(requestUrl); diff --git a/src/m365/spo/commands/list/list-contenttype-list.spec.ts b/src/m365/spo/commands/list/list-contenttype-list.spec.ts index cc827b4c4fc..831f4de7d5e 100644 --- a/src/m365/spo/commands/list/list-contenttype-list.spec.ts +++ b/src/m365/spo/commands/list/list-contenttype-list.spec.ts @@ -18,6 +18,12 @@ describe(commands.LIST_CONTENTTYPE_LIST, () => { const contentTypeResponse = { "value": [ { + "Parent": { + "StringId": "0x01000B1208C5D23DF", + "Name": "Item", + "Group": "List items", + "Id": { "StringId": "0x01000B1208C5D23DF" } + }, "Description": "Create a new document.", "DisplayFormTemplateName": "DocumentLibraryForm", "DisplayFormUrl": "", @@ -127,7 +133,7 @@ describe(commands.LIST_CONTENTTYPE_LIST, () => { it('retrieves all content types of the specific list if listTitle option is passed (debug)', async () => { sinon.stub(request, 'get').callsFake(async (opts) => { - if (opts.url === `https://contoso.sharepoint.com/sites/ninja/_api/web/lists/getByTitle('Documents')/ContentTypes`) { + if (opts.url === `https://contoso.sharepoint.com/sites/ninja/_api/web/lists/getByTitle('Documents')/ContentTypes?$expand=Parent`) { if (opts.headers && opts.headers.accept && (opts.headers.accept as string).indexOf('application/json') === 0) { @@ -150,7 +156,7 @@ describe(commands.LIST_CONTENTTYPE_LIST, () => { it('retrieves all content types of the specific list if listTitle option is passed', async () => { sinon.stub(request, 'get').callsFake(async (opts) => { - if (opts.url === `https://contoso.sharepoint.com/sites/ninja/_api/web/lists/getByTitle('Documents')/ContentTypes`) { + if (opts.url === `https://contoso.sharepoint.com/sites/ninja/_api/web/lists/getByTitle('Documents')/ContentTypes?$expand=Parent`) { if (opts.headers && opts.headers.accept && (opts.headers.accept as string).indexOf('application/json') === 0) { @@ -172,7 +178,7 @@ describe(commands.LIST_CONTENTTYPE_LIST, () => { it('retrieves all content types of the specific list if listId option is passed (debug)', async () => { sinon.stub(request, 'get').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`https://contoso.sharepoint.com/sites/ninja/_api/web/lists(guid'dfddade1-4729-428d-881e-7fedf3cae50d')/ContentTypes`) > -1) { + if ((opts.url as string).indexOf(`https://contoso.sharepoint.com/sites/ninja/_api/web/lists(guid'dfddade1-4729-428d-881e-7fedf3cae50d')/ContentTypes?$expand=Parent`) > -1) { if (opts.headers && opts.headers.accept && (opts.headers.accept as string).indexOf('application/json') === 0) { @@ -195,7 +201,7 @@ describe(commands.LIST_CONTENTTYPE_LIST, () => { it('retrieves all content types of the specific list if listUrl option is passed', async () => { sinon.stub(request, 'get').callsFake(async (opts) => { - if (opts.url === 'https://contoso.sharepoint.com/_api/web/GetList(\'%2Fsites%2Fdocuments\')/ContentTypes') { + if (opts.url === 'https://contoso.sharepoint.com/_api/web/GetList(\'%2Fsites%2Fdocuments\')/ContentTypes?$expand=Parent') { if (opts.headers && opts.headers.accept && (opts.headers.accept as string).indexOf('application/json') === 0) { @@ -217,7 +223,7 @@ describe(commands.LIST_CONTENTTYPE_LIST, () => { it('retrieves all content types of the specific list if listUrl option is passed (debug)', async () => { sinon.stub(request, 'get').callsFake(async (opts) => { - if (opts.url === 'https://contoso.sharepoint.com/_api/web/GetList(\'%2Fsites%2Fdocuments\')/ContentTypes') { + if (opts.url === 'https://contoso.sharepoint.com/_api/web/GetList(\'%2Fsites%2Fdocuments\')/ContentTypes?$expand=Parent') { if (opts.headers && opts.headers.accept && (opts.headers.accept as string).indexOf('application/json') === 0) { @@ -240,7 +246,7 @@ describe(commands.LIST_CONTENTTYPE_LIST, () => { it('retrieves all content types of the specific list if listId option is passed', async () => { sinon.stub(request, 'get').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`https://contoso.sharepoint.com/sites/ninja/_api/web/lists(guid'dfddade1-4729-428d-881e-7fedf3cae50d')/ContentTypes`) > -1) { + if ((opts.url as string).indexOf(`https://contoso.sharepoint.com/sites/ninja/_api/web/lists(guid'dfddade1-4729-428d-881e-7fedf3cae50d')/ContentTypes?$expand=Parent`) > -1) { if (opts.headers && opts.headers.accept && (opts.headers.accept as string).indexOf('application/json') === 0) { @@ -263,7 +269,7 @@ describe(commands.LIST_CONTENTTYPE_LIST, () => { it('outputs all properties when output is JSON', async () => { sinon.stub(request, 'get').callsFake(async (opts) => { - if (opts.url === `https://contoso.sharepoint.com/sites/ninja/_api/web/lists(guid'dfddade1-4729-428d-881e-7fedf3cae50d')/ContentTypes`) { + if (opts.url === `https://contoso.sharepoint.com/sites/ninja/_api/web/lists(guid'dfddade1-4729-428d-881e-7fedf3cae50d')/ContentTypes?$expand=Parent`) { if (opts.headers && opts.headers.accept && (opts.headers.accept as string).indexOf('application/json') === 0) { @@ -287,7 +293,7 @@ describe(commands.LIST_CONTENTTYPE_LIST, () => { it('command correctly handles list get reject request', async () => { const err = 'list retrieve error'; sinon.stub(request, 'get').callsFake(async (opts) => { - if (opts.url === `https://contoso.sharepoint.com/_api/web/lists/getByTitle('Documents')/ContentTypes`) { + if (opts.url === `https://contoso.sharepoint.com/_api/web/lists/getByTitle('Documents')/ContentTypes?$expand=Parent`) { throw err; } diff --git a/src/m365/spo/commands/list/list-contenttype-list.ts b/src/m365/spo/commands/list/list-contenttype-list.ts index 58da790b470..b034fecfedb 100644 --- a/src/m365/spo/commands/list/list-contenttype-list.ts +++ b/src/m365/spo/commands/list/list-contenttype-list.ts @@ -38,6 +38,7 @@ class SpoListContentTypeListCommand extends SpoCommand { this.#initOptions(); this.#initValidators(); this.#initOptionSets(); + this.#initTypes(); } #initTelemetry(): void { @@ -90,6 +91,10 @@ class SpoListContentTypeListCommand extends SpoCommand { this.optionSets.push({ options: ['listId', 'listTitle', 'listUrl'] }); } + #initTypes(): void { + this.types.string.push('webUrl', 'listId', 'listTitle', 'listUrl'); + } + public async commandAction(logger: Logger, args: CommandArgs): Promise { if (this.verbose) { const list: string = (args.options.listId ? args.options.listId : args.options.listTitle ? args.options.listTitle : args.options.listUrl) as string; @@ -109,7 +114,7 @@ class SpoListContentTypeListCommand extends SpoCommand { } try { - const res = await odata.getAllItems(`${requestUrl}/ContentTypes`); + const res = await odata.getAllItems(`${requestUrl}/ContentTypes?$expand=Parent`); await logger.log(res); } catch (err: any) {