Skip to content

Commit a81f464

Browse files
committed
New command: spo page default get. Closes #6493
1 parent 63210ca commit a81f464

File tree

5 files changed

+385
-0
lines changed

5 files changed

+385
-0
lines changed
+179
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
import Global from '/docs/cmd/_global.mdx';
2+
import Tabs from '@theme/Tabs';
3+
import TabItem from '@theme/TabItem';
4+
5+
# spo page default get
6+
7+
Gets the home page for a specific site
8+
9+
## Usage
10+
11+
```sh
12+
m365 spo page default get [options]
13+
```
14+
15+
## Options
16+
17+
```md definition-list
18+
`-u, --siteUrl <siteUrl>`
19+
: URL of the SharePoint site.
20+
```
21+
22+
<Global />
23+
24+
## Examples
25+
26+
Get the home page of a specific site
27+
28+
```sh
29+
m365 spo page default get --siteUrl https://contoso.sharepoint.com/sites/Marketing
30+
```
31+
32+
## Response
33+
34+
<Tabs>
35+
<TabItem value="JSON">
36+
37+
```json
38+
{
39+
"ListItemAllFields": {
40+
"CommentsDisabled": true,
41+
"FileSystemObjectType": 0,
42+
"Id": 1,
43+
"ServerRedirectedEmbedUri": null,
44+
"ServerRedirectedEmbedUrl": "",
45+
"ContentTypeId": "0x0101009D1CB255DA76424F860D91F20E6C411800DE13AFD7BD1A9847A5DEB2C981024CB6",
46+
"OData__ColorTag": null,
47+
"ComplianceAssetId": null,
48+
"WikiField": null,
49+
"Title": "Home",
50+
"ClientSideApplicationId": "b6917cb1-93a0-4b97-a84d-7cf49975d4ec",
51+
"PageLayoutType": "Home",
52+
"CanvasContent1": null,
53+
"BannerImageUrl": null,
54+
"Description": null,
55+
"PromotedState": null,
56+
"FirstPublishedDate": null,
57+
"LayoutWebpartsContent": null,
58+
"OData__AuthorBylineId": null,
59+
"_AuthorBylineStringId": null,
60+
"OData__TopicHeader": null,
61+
"OData__SPSitePageFlags": null,
62+
"OData__SPCallToAction": null,
63+
"OData__OriginalSourceUrl": null,
64+
"OData__OriginalSourceSiteId": null,
65+
"OData__OriginalSourceWebId": null,
66+
"OData__OriginalSourceListId": null,
67+
"OData__OriginalSourceItemId": null,
68+
"ID": 1,
69+
"Created": "2023-05-20T17:37:33",
70+
"AuthorId": 1073741823,
71+
"Modified": "2023-05-20T17:37:33",
72+
"EditorId": 1073741823,
73+
"OData__CopySource": null,
74+
"CheckoutUserId": null,
75+
"OData__UIVersionString": "1.0",
76+
"GUID": "25af1202-addb-4f3a-ab69-f14d5630796a"
77+
},
78+
"CheckInComment": "",
79+
"CheckOutType": 2,
80+
"ContentTag": "{2F6CF80C-E4CC-4FCC-A424-8D36770AC481},4,1",
81+
"CustomizedPageStatus": 1,
82+
"ETag": "\"{2F6CF80C-E4CC-4FCC-A424-8D36770AC481},4\"",
83+
"Exists": true,
84+
"ExistsAllowThrowForPolicyFailures": true,
85+
"ExistsWithException": true,
86+
"IrmEnabled": false,
87+
"Length": "805",
88+
"Level": 1,
89+
"LinkingUri": null,
90+
"LinkingUrl": "",
91+
"MajorVersion": 1,
92+
"MinorVersion": 0,
93+
"Name": "Home.aspx",
94+
"ServerRelativeUrl": "/teams/Marketing/SitePages/Home.aspx",
95+
"TimeCreated": "2023-05-21T00:37:33Z",
96+
"TimeLastModified": "2023-05-21T00:37:33Z",
97+
"Title": "Home",
98+
"UIVersion": 512,
99+
"UIVersionLabel": "1.0",
100+
"UniqueId": "2f6cf80c-e4cc-4fcc-a424-8d36770ac481"
101+
}
102+
```
103+
104+
</TabItem>
105+
<TabItem value="Text">
106+
107+
```text
108+
CheckInComment :
109+
CheckOutType : 2
110+
ContentTag : {2F6CF80C-E4CC-4FCC-A424-8D36770AC481},4,1
111+
CustomizedPageStatus : 1
112+
ETag : "{2F6CF80C-E4CC-4FCC-A424-8D36770AC481},4"
113+
Exists : true
114+
ExistsAllowThrowForPolicyFailures: true
115+
ExistsWithException : true
116+
IrmEnabled : false
117+
Length : 805
118+
Level : 1
119+
LinkingUri : null
120+
LinkingUrl :
121+
ListItemAllFields : {"CommentsDisabled":true,"FileSystemObjectType":0,"Id":1,"ServerRedirectedEmbedUri":null,"ServerRedirectedEmbedUrl":"","ContentTypeId":"0x0101009D1CB255DA76424F860D91F20E6C411800DE13AFD7BD1A9847A5DEB2C981024CB6","OData__ColorTag":null,"ComplianceAssetId":null,"WikiField":null,"Title":"Home","ClientSideApplicationId":"b6917cb1-93a0-4b97-a84d-7cf49975d4ec","PageLayoutType":"Home","CanvasContent1":null,"BannerImageUrl":null,"Description":null,"PromotedState":null,"FirstPublishedDate":null,"LayoutWebpartsContent":null,"OData__AuthorBylineId":null,"_AuthorBylineStringId":null,"OData__TopicHeader":null,"OData__SPSitePageFlags":null,"OData__SPCallToAction":null,"OData__OriginalSourceUrl":null,"OData__OriginalSourceSiteId":null,"OData__OriginalSourceWebId":null,"OData__OriginalSourceListId":null,"OData__OriginalSourceItemId":null,"ID":1,"Created":"2023-05-20T17:37:33","AuthorId":1073741823,"Modified":"2023-05-20T17:37:33","EditorId":1073741823,"OData__CopySource":null,"CheckoutUserId":null,"OData__UIVersionString":"1.0","GUID":"25af1202-addb-4f3a-ab69-f14d5630796a"}
122+
MajorVersion : 1
123+
MinorVersion : 0
124+
Name : Home.aspx
125+
ServerRelativeUrl : /teams/Marketing/SitePages/Home.aspx
126+
TimeCreated : 2023-05-21T00:37:33Z
127+
TimeLastModified : 2023-05-21T00:37:33Z
128+
Title : Home
129+
UIVersion : 512
130+
UIVersionLabel : 1.0
131+
UniqueId : 2f6cf80c-e4cc-4fcc-a424-8d36770ac481
132+
```
133+
134+
</TabItem>
135+
<TabItem value="CSV">
136+
137+
```csv
138+
CheckInComment,CheckOutType,ContentTag,CustomizedPageStatus,ETag,Exists,ExistsAllowThrowForPolicyFailures,ExistsWithException,IrmEnabled,Length,Level,LinkingUri,LinkingUrl,MajorVersion,MinorVersion,Name,ServerRelativeUrl,TimeCreated,TimeLastModified,Title,UIVersion,UIVersionLabel,UniqueId
139+
,2,"{2F6CF80C-E4CC-4FCC-A424-8D36770AC481},4,1",1,"""{2F6CF80C-E4CC-4FCC-A424-8D36770AC481},4""",1,1,1,0,805,1,,,1,0,Home.aspx,/teams/Marketing/SitePages/Home.aspx,2023-05-21T00:37:33Z,2023-05-21T00:37:33Z,Home,512,1.0,2f6cf80c-e4cc-4fcc-a424-8d36770ac481
140+
```
141+
142+
</TabItem>
143+
<TabItem value="Markdown">
144+
145+
```md
146+
# spo page default get --debug "false" --verbose "false" --siteUrl "https://contoso.sharepoint.com/teams/Marketing"
147+
148+
Date: 28/11/2024
149+
150+
## Home (2f6cf80c-e4cc-4fcc-a424-8d36770ac481)
151+
152+
Property | Value
153+
---------|-------
154+
CheckInComment |
155+
CheckOutType | 2
156+
ContentTag | {2F6CF80C-E4CC-4FCC-A424-8D36770AC481},4,1
157+
CustomizedPageStatus | 1
158+
ETag | "{2F6CF80C-E4CC-4FCC-A424-8D36770AC481},4"
159+
Exists | true
160+
ExistsAllowThrowForPolicyFailures | true
161+
ExistsWithException | true
162+
IrmEnabled | false
163+
Length | 805
164+
Level | 1
165+
LinkingUrl |
166+
MajorVersion | 1
167+
MinorVersion | 0
168+
Name | Home.aspx
169+
ServerRelativeUrl | /teams/Marketing/SitePages/Home.aspx
170+
TimeCreated | 2023-05-21T00:37:33Z
171+
TimeLastModified | 2023-05-21T00:37:33Z
172+
Title | Home
173+
UIVersion | 512
174+
UIVersionLabel | 1.0
175+
UniqueId | 2f6cf80c-e4cc-4fcc-a424-8d36770ac481
176+
```
177+
178+
</TabItem>
179+
</Tabs>

docs/src/config/sidebars.ts

+5
Original file line numberDiff line numberDiff line change
@@ -3221,6 +3221,11 @@ const sidebars: SidebarsConfig = {
32213221
label: 'page control set',
32223222
id: 'cmd/spo/page/page-control-set'
32233223
},
3224+
{
3225+
type: 'doc',
3226+
label: 'page default get',
3227+
id: 'cmd/spo/page/page-default-get'
3228+
},
32243229
{
32253230
type: 'doc',
32263231
label: 'page header set',

src/m365/spo/commands.ts

+1
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ export default {
213213
PAGE_CONTROL_GET: `${prefix} page control get`,
214214
PAGE_CONTROL_LIST: `${prefix} page control list`,
215215
PAGE_CONTROL_SET: `${prefix} page control set`,
216+
PAGE_DEFAULT_GET: `${prefix} page default get`,
216217
PAGE_HEADER_SET: `${prefix} page header set`,
217218
PAGE_SECTION_ADD: `${prefix} page section add`,
218219
PAGE_SECTION_GET: `${prefix} page section get`,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
import assert from 'assert';
2+
import sinon from 'sinon';
3+
import { z } from 'zod';
4+
import auth from '../../../../Auth.js';
5+
import { cli } from '../../../../cli/cli.js';
6+
import { CommandInfo } from '../../../../cli/CommandInfo.js';
7+
import { Logger } from '../../../../cli/Logger.js';
8+
import { CommandError } from '../../../../Command.js';
9+
import request from '../../../../request.js';
10+
import { telemetry } from '../../../../telemetry.js';
11+
import { pid } from '../../../../utils/pid.js';
12+
import { session } from '../../../../utils/session.js';
13+
import { sinonUtil } from '../../../../utils/sinonUtil.js';
14+
import commands from '../../commands.js';
15+
import command from './page-default-get.js';
16+
import { urlUtil } from '../../../../utils/urlUtil.js';
17+
import { formatting } from '../../../../utils/formatting.js';
18+
import { pageListItemMock } from './page-get.mock.js';
19+
20+
describe(commands.PAGE_DEFAULT_GET, () => {
21+
let log: string[];
22+
let logger: Logger;
23+
let loggerLogSpy: sinon.SinonSpy;
24+
let commandInfo: CommandInfo;
25+
let commandOptionsSchema: z.ZodTypeAny;
26+
27+
const siteUrl = 'https://contoso.sharepoint.com/sites/Marketing';
28+
const serverRelativeUrl = urlUtil.getServerRelativeSiteUrl(siteUrl);
29+
const page = {
30+
WelcomePage: '/SitePages/Home.aspx'
31+
};
32+
33+
before(() => {
34+
sinon.stub(auth, 'restoreAuth').resolves();
35+
sinon.stub(telemetry, 'trackEvent').returns();
36+
sinon.stub(pid, 'getProcessName').returns('');
37+
sinon.stub(session, 'getId').returns('');
38+
auth.connection.active = true;
39+
commandInfo = cli.getCommandInfo(command);
40+
commandOptionsSchema = commandInfo.command.getSchemaToParse()!;
41+
});
42+
43+
beforeEach(() => {
44+
log = [];
45+
logger = {
46+
log: async (msg: string) => {
47+
log.push(msg);
48+
},
49+
logRaw: async (msg: string) => {
50+
log.push(msg);
51+
},
52+
logToStderr: async (msg: string) => {
53+
log.push(msg);
54+
}
55+
};
56+
loggerLogSpy = sinon.spy(logger, 'log');
57+
});
58+
59+
afterEach(() => {
60+
sinonUtil.restore([
61+
request.get
62+
]);
63+
});
64+
65+
after(() => {
66+
sinon.restore();
67+
auth.connection.active = false;
68+
});
69+
70+
it('has correct name', () => {
71+
assert.strictEqual(command.name, commands.PAGE_DEFAULT_GET);
72+
});
73+
74+
it('has a description', () => {
75+
assert.notStrictEqual(command.description, null);
76+
});
77+
78+
it('fails validation if siteUrl is not a valid SharePoint URL', async () => {
79+
const actual = commandOptionsSchema.safeParse({ siteUrl: 'foo' });
80+
assert.strictEqual(actual.success, false);
81+
});
82+
83+
it('passes validation when the siteUrl is a valid SharePoint URL and name is specified', async () => {
84+
const actual = commandOptionsSchema.safeParse({ siteUrl: siteUrl });
85+
assert.strictEqual(actual.success, true);
86+
});
87+
88+
it('gets the home page details for a specific site', async () => {
89+
sinon.stub(request, 'get').callsFake(async (opts) => {
90+
if (opts.url === `${siteUrl}/_api/Web/RootFolder?$select=WelcomePage`) {
91+
return page;
92+
}
93+
94+
if (opts.url === `${siteUrl}/_api/web/GetFileByServerRelativePath(DecodedUrl='${serverRelativeUrl}/${formatting.encodeQueryParameter(page.WelcomePage)}')?$expand=ListItemAllFields/ClientSideApplicationId,ListItemAllFields/PageLayoutType,ListItemAllFields/CommentsDisabled`) {
95+
return pageListItemMock;
96+
}
97+
98+
throw 'Invalid request';
99+
});
100+
101+
await command.action(logger, { options: { siteUrl: siteUrl, verbose: true } });
102+
assert(loggerLogSpy.calledWith({ ...pageListItemMock }));
103+
});
104+
105+
it('correctly handles API error', async () => {
106+
const errorMessage = 'The file /sites/Marketing/SitePages/Welcome.aspx does not exist.';
107+
108+
sinon.stub(request, 'get').rejects({
109+
error: {
110+
'odata.error': {
111+
message: {
112+
lang: 'en-US',
113+
value: errorMessage
114+
}
115+
}
116+
}
117+
});
118+
119+
await assert.rejects(command.action(logger, { options: { siteUrl: siteUrl } }),
120+
new CommandError(errorMessage));
121+
});
122+
});

0 commit comments

Comments
 (0)