pnp / cli-microsoft365

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

Bug report: `m365 spo page set` doesn't prompt for options when specifying nothing to update #5938

Closed MathijsVerbeeck closed 5 months ago

MathijsVerbeeck commented 5 months ago

Priority

(Low) Something is a little off

Description

When using the command m365 spo page set it will prompt for the required options, but not for an optional one, making it possible to run the command without specifying any property to update, so it basically just returns.

I have also noticed that, however the docs mention that the command will not return a response, the XML of the page is being logged when setting layoutType. This is most likely due to that we are calling a separate command to execute this step.

Steps to reproduce

  1. run m365 spo page set

Expected results

Prompting for atleast one property to update

Actual results

It prompts for the required ones and will then return. The code however will actually checkout the page. So it does some actions.

Diagnostics

Executing command spo page set with options {"options":{"debug":true,"output":"json","name":"Home","webUrl":"https://contoso.sharepoint.com"}} Executing command as 'App', appId: Hidden, tenantId: Hidden Request: { "url": "https://contoso.sharepoint.com/_api/contextinfo", "method": "post", "headers": { "Accept": "application/json;odata=nometadata", "user-agent": "NONISV|SharePointPnP|CLIMicrosoft365/7.5.0", "accept-encoding": "gzip, deflate", "X-ClientService-ClientTag": "M365CLI:7.5.0", "authorization": "Bearer" }, "responseType": "json", "decompress": true } Response: { "url": "https://contoso.sharepoint.com/_api/contextinfo", "status": 200, "statusText": "OK", "headers": { "cache-control": "private, max-age=0", "transfer-encoding": "chunked", "content-type": "application/json;odata=nometadata;streaming=true;charset=utf-8", "expires": "Tue, 12 Mar 2024 14:19:23 GMT", "last-modified": "Wed, 27 Mar 2024 14:19:23 GMT", "vary": "Origin,Accept-Encoding", "p3p": "CP=\"ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI\"", "x-networkstatistics": "0,525568,0,15,350767,0,198476", "x-sharepointhealthscore": "2", "x-sp-serverstate": "ReadOnly=0", "dataserviceversion": "3.0", "spclientservicerequestduration": "13", "sprequestduration": "14", "x-aspnet-version": "4.0.30319", "x-databoundary": "EU", "x-1dscollectorurl": "https://eu-mobile.events.data.microsoft.com/OneCollector/1.0/", "x-ariacollectorurl": "https://eu-mobile.events.data.microsoft.com/Collector/3.0", "sprequestguid": "472719a1-e0e8-8000-624b-7d04332514e4", "request-id": "472719a1-e0e8-8000-624b-7d04332514e4", "ms-cv": "oRknR+jgAIBiS30EMyUU5A.0", "strict-transport-security": "max-age=31536000", "x-frame-options": "SAMEORIGIN", "content-security-policy": "frame-ancestors 'self' teams.microsoft.com .teams.microsoft.com .skype.com .teams.microsoft.us local.teams.office.com .office365.com .powerapps.com .yammer.com engage.cloud.microsoft .officeapps.live.com .office.com .microsoft365.com .stream.azure-test.net .microsoftstream.com .dynamics.com .microsoft.com onedrive.live.com .onedrive.live.com securebroker.sharepointonline.com;", "x-powered-by": "ASP.NET", "microsoftsharepointteamservices": "16.0.0.24706", "x-content-type-options": "nosniff", "x-ms-invokeapp": "1; RequireReadOnly", "x-cache": "CONFIG_NOCACHE", "x-msedge-ref": "Ref A: 264F4D5D3F3941AB86534FAB17847C6B Ref B: AMS04EDGE1713 Ref C: 2024-03-27T14:19:23Z", "date": "Wed, 27 Mar 2024 14:19:22 GMT", "connection": "close" }, "data": { "FormDigestTimeoutSeconds": 1800, "FormDigestValue": "", "LibraryVersion": "16.0.24706.12008", "SiteFullUrl": "https://contoso.sharepoint.com", "SupportedSchemaVersions": [ "14.0.0.0", "15.0.0.0" ], "WebFullUrl": "https://contoso.sharepoint.com" } } "Checking out Home page..." Existing access token Request: { "url": "https://contoso.sharepoint.com/_api/sitepages/pages/GetByUrl('sitepages/Home.aspx')/checkoutpage", "method": "post", "headers": { "Accept": "application/json;odata=nometadata", "user-agent": "NONISV|SharePointPnP|CLIMicrosoft365/7.5.0", "accept-encoding": "gzip, deflate", "X-ClientService-ClientTag": "M365CLI:7.5.0", "authorization": "" }, "responseType": "json", "decompress": true } Response: { "url": "https://contoso.sharepoint.com/_api/sitepages/pages/GetByUrl('sitepages/Home.aspx')/checkoutpage", "status": 200, "statusText": "OK", "headers": { "cache-control": "private, max-age=0", "transfer-encoding": "chunked", "content-type": "application/json;odata=nometadata;streaming=true;charset=utf-8", "expires": "Tue, 12 Mar 2024 14:19:23 GMT", "last-modified": "Wed, 27 Mar 2024 14:19:23 GMT", "vary": "Origin,Accept-Encoding", "p3p": "CP=\"ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI\"", "x-networkstatistics": "0,525568,0,92,808459,0,525568", "x-sharepointhealthscore": "1", "x-sp-serverstate": "ReadOnly=0", "dataserviceversion": "3.0", "spclientservicerequestduration": "152", "sprequestduration": "153", "x-aspnet-version": "4.0.30319", "x-databoundary": "EU", "x-1dscollectorurl": "https://eu-mobile.events.data.microsoft.com/OneCollector/1.0/", "x-ariacollectorurl": "https://eu-mobile.events.data.microsoft.com/Collector/3.0", "sprequestguid": "472719a1-f0f0-8000-75bf-459f210e40da", "request-id": "472719a1-f0f0-8000-75bf-459f210e40da", "ms-cv": "oRknR/DwAIB1v0WfIQ5A2g.0", "strict-transport-security": "max-age=31536000", "x-frame-options": "SAMEORIGIN", "content-security-policy": "frame-ancestors 'self' teams.microsoft.com .teams.microsoft.com .skype.com .teams.microsoft.us local.teams.office.com .office365.com .powerapps.com .yammer.com engage.cloud.microsoft .officeapps.live.com .office.com .microsoft365.com .stream.azure-test.net .microsoftstream.com .dynamics.com .microsoft.com onedrive.live.com .onedrive.live.com securebroker.sharepointonline.com;", "x-powered-by": "ASP.NET", "microsoftsharepointteamservices": "16.0.0.24706", "x-content-type-options": "nosniff", "x-ms-invokeapp": "1; RequireReadOnly", "x-cache": "CONFIG_NOCACHE", "x-msedge-ref": "Ref A: 08E76A7B771345A18A4964E260910991 Ref B: FRA231050416011 Ref C: 2024-03-27T14:19:23Z", "date": "Wed, 27 Mar 2024 14:19:23 GMT", "connection": "close" }, "data": { "AbsoluteUrl": "https://contoso.sharepoint.com/SitePages/Home.aspx", "AuthorByline": null, "BannerImageUrl": "https://contoso.sharepoint.com/_layouts/15/getpreview.ashx?path=%2FSiteAssets%2FSitePages%2FModern-Home%2F148232813-home-header-1-resized_1711531300640.jpg&ow=1228&oh=330", "BannerThumbnailUrl": "https://contoso.sharepoint.com/_vti_bin/afdcache.ashx/authitem/SiteAssets/SitePages/Modern-Home/148232813-home-header-1-resized_1711531300640.jpg?_oat_=1711578426_90f6b8c7af06902bc1f1f81949747ff8f430860e150823d2615b606fdd5f6e2f&P1=1711553995&P2=1963766474&P3=1&P4=g%2bx6kxHcv7Dcg0jRuy2a0EB%2fu3JCpKbVOIsZK7MQHZ%2b%2b0yenbs%2fE31KtXsQspR4z1%2f84pmny5Q2h%2bn9kGopKQVy%2fyaoF0z7jpVhmZuVf47EnOdLAWKoJ5t47c%2f8fhzAYSpX34moEkocQUBkGcjweRZVx%2b0g%2bvKdCP4sl84sBJnv5KbVLr4XRIOgzBKedD%2bFSuhnLa8fIDOLzycs5xpLcQGDufzDu8Bfr1A9i%2bmHKdgz3lonr2GATueHROFPsLU1DTsFz2iwthMLEJPoq%2fMSnwX%2fai4K6VC3ru633MloMDm5%2f3%2faj%2boFiTLYT8wfQAhCaT5QkeUfpMr1neBtPNeGy2Q%3d%3d&width=400", "CallToAction": "", "Categories": null, "ContentTypeId": "0x0101009D1CB255DA76424F860D91F20E6C411800476D12F05CFD7E4B9FCD03B0B89F53FF", "Description": null, "DoesUserHaveEditPermission": true, "FileName": "Home.aspx", "FirstPublished": "0001-01-01T08:00:00Z", "Id": 32, "IsPageCheckedOutToCurrentUser": true, "IsWebWelcomePage": true, "Modified": "2024-03-27T14:13:45Z", "PageLayoutType": "Home", "Path": { "DecodedUrl": "SitePages/Home.aspx" }, "PromotedState": 0, "Title": "Home", "TopicHeader": null, "UniqueId": "2a0e7f61-10c8-439d-9f18-279686ea687d", "Url": "SitePages/Home.aspx", "Version": "11.0", "VersionInfo": null, "AlternativeUrlMap": "{\"UserPhotoAspx\":\"https://contoso.sharepoint.com/_vti_bin/afdcache.ashx/_userprofile/userphoto.jpg?_oat_=1711591706_42054882f586e9f979f8c66620cb258fc07bee134036a50a0d20c3d1bd94aa1c&P1=1711552863&P2=1963766474&P3=1&P4=ACNHcQw1K%2bTCyfEHLbpqowolEW2dKPjns9gI8lOeIwiRXygekXaRvAqIp0kNRtfCyWxA5i%2bDltbq0GPAs%2bwShfOrMPubyv0SZruDFfET1l4YCvEl0%2fcSuuifucc4giHLp8Bj65mkHDn%2bEWwizHgsbBMEZZIP98LkTP3JaJOmc6GQ03CGNF18aTAkIhetkVLeKfZgotL%2fPAOM%2f593%2b8cFOFOod94jG6QLvoimFIJLjVY3bPQwT9VZCpRbMBN5ujKBHRuPhhLa4Kepun0ceIl32ak1GVwGuIAjMuZ3qLafMLonfcJPDDJN3ruA2lvC0iTWP2YxE9jp5OKWHEGvSpOYow%3d%3d\",\"MediaTAThumbnailPathUrl\":\"https://northeurope1-mediap.svc.ms/transform/thumbnail?provider=spo&inputFormat={.fileType}&cs=UEFHRVN8U1BP&docid={.spHost}/_api/v2.0/sharePoint:{.resourceUrl}:/driveItem&w={.widthValue}&oauth_token=bearer%20{.oauthToken}\",\"MediaTAThumbnailHostUrl\":\"https://northeurope1-mediap.svc.ms\",\"AFDCDNEnabled\":\"True\",\"CurrentSiteCDNPolicy\":\"True\",\"PublicCDNEnabled\":\"True\",\"PrivateCDNEnabled\":\"True\",\"/SiteAssets/SitePages/Modern-Home/148232813-home-header-1-resized_1711531300640.jpg\":\"https://contoso.sharepoint.com/_vti_bin/afdcache.ashx/authitem/SiteAssets/SitePages/Modern-Home/148232813-home-header-1-resized_1711531300640.jpg?_oat_=1711578426_90f6b8c7af06902bc1f1f81949747ff8f430860e150823d2615b606fdd5f6e2f&P1=1711553995&P2=1963766474&P3=1&P4=g%2bx6kxHcv7Dcg0jRuy2a0EB%2fu3JCpKbVOIsZK7MQHZ%2b%2b0yenbs%2fE31KtXsQspR4z1%2f84pmny5Q2h%2bn9kGopKQVy%2fyaoF0z7jpVhmZuVf47EnOdLAWKoJ5t47c%2f8fhzAYSpX34moEkocQUBkGcjweRZVx%2b0g%2bvKdCP4sl84sBJnv5KbVLr4XRIOgzBKedD%2bFSuhnLa8fIDOLzycs5xpLcQGDufzDu8Bfr1A9i%2bmHKdgz3lonr2GATueHROFPsLU1DTsFz2iwthMLEJPoq%2fMSnwX%2fai4K6VC3ru633MloMDm5%2f3%2faj%2boFiTLYT8wfQAhCaT5QkeUfpMr1neBtPNeGy2Q%3d%3d\"}", "AuthoringMetadata": null, "CanvasContent1": "", "CoAuthState": null, "Collaborators": null, "Language": "en-us", "LayoutWebpartsContent": "[{\"id\":\"cbe7b0a9-3504-44dd-a3a3-0e5cacd07788\",\"instanceId\":\"cbe7b0a9-3504-44dd-a3a3-0e5cacd07788\",\"title\":\"Title area\",\"description\":\"Title Region Description\",\"audiences\":[],\"serverProcessedContent\":{\"htmlStrings\":{},\"searchablePlainTexts\":{},\"imageSources\":{},\"links\":{}},\"dataVersion\":\"1.4\",\"properties\":{\"title\":\"Home\",\"imageSourceType\":4,\"layoutType\":\"NoImage\",\"textAlignment\":\"Left\",\"showTopicHeader\":false,\"showPublishDate\":false,\"topicHeader\":\"\",\"enableGradientEffect\":true,\"isDecorative\":true,\"authors\":[],\"authorByline\":[],\"hasTitleBeenCommitted\":true},\"containsDynamicDataSource\":false,\"reservedHeight\":141}]", "SitePageFlags": "" } } "Page Home is now checked out" Existing access token Request: { "url": "https://contoso.sharepoint.com/_api/SitePages/Pages(32)/SavePageAsDraft", "method": "post", "headers": { "Accept": "application/json;odata=nometadata", "Content-Type": "application/json;odata=nometadata", "user-agent": "NONISV|SharePointPnP|CLIMicrosoft365/7.5.0", "accept-encoding": "gzip, deflate", "X-ClientService-ClientTag": "M365CLI:7.5.0", "authorization": "Bearer" }, "responseType": "json", "decompress": true, "data": { "Title": "Home", "BannerImageUrl": "https://contoso.sharepoint.com/_layouts/15/getpreview.ashx?path=%2FSiteAssets%2FSitePages%2FModern-Home%2F148232813-home-header-1-resized_1711531300640.jpg&ow=1228&oh=330", "CanvasContent1": "", "LayoutWebpartsContent": "[{\"id\":\"cbe7b0a9-3504-44dd-a3a3-0e5cacd07788\",\"instanceId\":\"cbe7b0a9-3504-44dd-a3a3-0e5cacd07788\",\"title\":\"Title area\",\"description\":\"Title Region Description\",\"audiences\":[],\"serverProcessedContent\":{\"htmlStrings\":{},\"searchablePlainTexts\":{},\"imageSources\":{},\"links\":{}},\"dataVersion\":\"1.4\",\"properties\":{\"title\":\"Home\",\"imageSourceType\":4,\"layoutType\":\"NoImage\",\"textAlignment\":\"Left\",\"showTopicHeader\":false,\"showPublishDate\":false,\"topicHeader\":\"\",\"enableGradientEffect\":true,\"isDecorative\":true,\"authors\":[],\"authorByline\":[],\"hasTitleBeenCommitted\":true},\"containsDynamicDataSource\":false,\"reservedHeight\":141}]" } } Response: { "url": "https://contoso.sharepoint.com/_api/SitePages/Pages(32)/SavePageAsDraft", "status": 200, "statusText": "OK", "headers": { "cache-control": "private, max-age=0", "transfer-encoding": "chunked", "content-type": "application/json;odata=nometadata;streaming=true;charset=utf-8", "expires": "Tue, 12 Mar 2024 14:19:23 GMT", "last-modified": "Wed, 27 Mar 2024 14:19:23 GMT", "vary": "Origin,Accept-Encoding", "p3p": "CP=\"ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI\"", "x-networkstatistics": "0,525568,0,0,1227661,0,269774", "x-sharepointhealthscore": "3", "x-sp-serverstate": "ReadOnly=0", "dataserviceversion": "3.0", "spclientservicerequestduration": "256", "sprequestduration": "256", "x-aspnet-version": "4.0.30319", "x-databoundary": "EU", "x-1dscollectorurl": "https://eu-mobile.events.data.microsoft.com/OneCollector/1.0/", "x-ariacollectorurl": "https://eu-mobile.events.data.microsoft.com/Collector/3.0", "sprequestguid": "482719a1-4003-8000-6aa8-358a03ac3ea6", "request-id": "482719a1-4003-8000-6aa8-358a03ac3ea6", "ms-cv": "oRknSANAAIBqqDWKA6w+pg.0", "strict-transport-security": "max-age=31536000", "x-frame-options": "SAMEORIGIN", "content-security-policy": "frame-ancestors 'self' teams.microsoft.com .teams.microsoft.com .skype.com .teams.microsoft.us local.teams.office.com .office365.com .powerapps.com .yammer.com engage.cloud.microsoft .officeapps.live.com .office.com .microsoft365.com .stream.azure-test.net .microsoftstream.com .dynamics.com .microsoft.com onedrive.live.com .onedrive.live.com securebroker.sharepointonline.com;", "x-powered-by": "ASP.NET", "microsoftsharepointteamservices": "16.0.0.24706", "x-content-type-options": "nosniff", "x-ms-invokeapp": "1; RequireReadOnly", "x-cache": "CONFIG_NOCACHE", "x-msedge-ref": "Ref A: 0E32845A3B1841BEB2044DE288727366 Ref B: AMS04EDGE2305 Ref C: 2024-03-27T14:19:23Z", "date": "Wed, 27 Mar 2024 14:19:23 GMT", "connection": "close" }, "data": { "value": false } }

CLI for Microsoft 365 version

v7.5.0

nodejs version

20.11.0

Operating system (environment)

macOS

Shell

zsh

milanholemans commented 5 months ago

Hi @MathijsVerbeeck, thank you for reporting this.

When using the command m365 spo page set it will prompt for the required options, but not for an optional one, making it possible to run the command without specifying any property to update, so it basically just returns.

I'm afraid that a lot of commands will suffer from this. Usually, we write a validation condition that throws an error when no value is specified to update. We could do that here as well, ... or implement an interactive prompt for that. If we decide to implement it, that would mean we have to implement it for a lot of (set) commands. I don't know what our stance is for this @pnp/cli-for-microsoft-365-maintainers?

I have also noticed that, however, the docs mention that the command will not return a response, the XML of the page is being logged when setting layoutType. This is most likely due to that we are calling a separate command to execute this step.

Seems like that's because we're calling a subcommand which outputs a response. That's not really ideal and intentional, but it's actually a breaking change and something that should be resolved by completing #4531.

milanholemans commented 5 months ago

Additionally, I noticed that this page util function which is executed logs verbose messages to stdout instead of stderr, we should fix this as well.

https://github.com/pnp/cli-microsoft365/blob/fc0eacc93e7949876496e26545e30706f7a01fb6/src/m365/spo/commands/page/Page.ts#L38-L59

MathijsVerbeeck commented 5 months ago

I'm afraid that a lot of commands will suffer from this. Usually, we write a validation condition that throws an error when no value is specified to update. We could do that here as well, ... or implement an interactive prompt for that. If we decide to implement it, that would mean we have to implement it for a lot of (set) commands. I don't know what our stance is for this @pnp/cli-for-microsoft-365-maintainers?

Yes, perhaps we should look a bit deeper and check more commands for this, it's just that it is annoying for this command specifically as this will create a draft version of the page, even though we don't pass any options...

milanholemans commented 5 months ago

Yes agree, therefore we should either throw an error when no options to update are specified (like we do for most commands now). Or we do another interactive prompt, which would be the most user-friendly ofcourse.

Adam-it commented 5 months ago

I'm afraid that a lot of commands will suffer from this. Usually, we write a validation condition that throws an error when no value is specified to update. We could do that here as well, ... or implement an interactive prompt for that. If we decide to implement it, that would mean we have to implement it for a lot of (set) commands. I don't know what our stance is for this @pnp/cli-for-microsoft-365-maintainers?

As of now prompting supports only required options, so I would add validation to solve this issue. If we want to add support with prompting for optional options lets create a separate issue for that and track this suggestion there 👍

MathijsVerbeeck commented 5 months ago

As of now prompting supports only required options, so I would add validation to solve this issue.

That's also what I was thinking.

Adam-it commented 5 months ago

Ok so we agreed to add validation for missing option to resolve this issue and create support for prompting for more options in separate issue. I will open this up. @MathijsVerbeeck would you like to take the lead in this?

MathijsVerbeeck commented 5 months ago

Sure. Seems like a small fix.

Adam-it commented 5 months ago

Sure. Seems like a small fix.

Let's remember to add a test for it to prevent this from happening in the future if anything would change