Skip to content

Commit b2330dc

Browse files
Saurabh7019milanholemans
authored andcommitted
Extends 'spo file version' commands with ExpirationDate property. Closes #6773
1 parent 98bc073 commit b2330dc

File tree

6 files changed

+32
-17
lines changed

6 files changed

+32
-17
lines changed

docs/docs/cmd/spo/file/file-version-get.mdx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ m365 spo file version get --webUrl https://contoso.sharepoint.com --label "1.0"
5353
{
5454
"CheckInComment": "",
5555
"Created": "2022-10-30T12:03:06Z",
56+
"ExpirationDate": "2026-01-31T08:23:43.0000000Z",
5657
"ID": 512,
5758
"IsCurrentVersion": false,
5859
"Length": "18898",
@@ -68,6 +69,7 @@ m365 spo file version get --webUrl https://contoso.sharepoint.com --label "1.0"
6869
```text
6970
CheckInComment :
7071
Created : 2022-10-30T12:03:06Z
72+
ExpirationDate : 2026-01-31T08:23:43.0000000Z
7173
ID : 512
7274
IsCurrentVersion: false
7375
Length : 18898
@@ -80,8 +82,8 @@ m365 spo file version get --webUrl https://contoso.sharepoint.com --label "1.0"
8082
<TabItem value="CSV">
8183

8284
```csv
83-
CheckInComment,Created,ID,IsCurrentVersion,Length,Size,Url,VersionLabel
84-
,2022-10-30T12:03:06Z,512,,18898,18898,_vti_history/512/Shared Documents/Document.docx,1.0
85+
CheckInComment,Created,ExpirationDate,ID,IsCurrentVersion,Length,Size,Url,VersionLabel
86+
,2022-10-30T12:03:06Z,2026-01-31T08:23:43.0000000Z,512,0,18898,18898,_vti_history/512/Shared Documents/Document.docx,1.0
8587
```
8688

8789
</TabItem>
@@ -98,6 +100,7 @@ m365 spo file version get --webUrl https://contoso.sharepoint.com --label "1.0"
98100
---------|-------
99101
CheckInComment |
100102
Created | 2022-10-30T12:03:06Z
103+
ExpirationDate | 2026-01-31T08:23:43.0000000Z
101104
ID | 512
102105
IsCurrentVersion | false
103106
Length | 18898

docs/docs/cmd/spo/file/file-version-list.mdx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ m365 spo file version list --webUrl https://contoso.sharepoint.com/sites/project
5757
{
5858
"CheckInComment": "",
5959
"Created": "2022-10-30T12:03:06Z",
60+
"ExpirationDate": "2026-01-31T08:23:43.0000000Z",
6061
"ID": 512,
6162
"IsCurrentVersion": false,
6263
"Length": "18898",
@@ -71,17 +72,17 @@ m365 spo file version list --webUrl https://contoso.sharepoint.com/sites/project
7172
<TabItem value="Text">
7273

7374
```text
74-
Created ID IsCurrentVersion VersionLabel
75-
-------------------- ---- ---------------- ------------
76-
2022-10-30T12:03:06Z 512 false 1.0
75+
Created ID IsCurrentVersion VersionLabel ExpirationDate
76+
-------------------- ---- ---------------- ------------ ----------------------------
77+
2022-10-30T12:03:06Z 512 false 1.0 2026-01-31T08:23:43.0000000Z
7778
```
7879

7980
</TabItem>
8081
<TabItem value="CSV">
8182

8283
```csv
83-
Created,ID,IsCurrentVersion,VersionLabel
84-
2022-10-30T12:03:06Z,512,false,1.0
84+
CheckInComment,Created,ExpirationDate,ID,IsCurrentVersion,Length,Size,Url,VersionLabel
85+
,2022-10-30T12:03:06Z,2026-01-31T08:23:43.0000000Z,512,0,18898,18898,_vti_history/512/Shared Documents/Document.docx,1.0
8586
```
8687

8788
</TabItem>
@@ -98,6 +99,7 @@ m365 spo file version list --webUrl https://contoso.sharepoint.com/sites/project
9899
---------|-------
99100
CheckInComment |
100101
Created | 2022-10-30T12:03:06Z
102+
ExpirationDate | 2026-01-31T08:23:43.0000000Z
101103
ID | 512
102104
IsCurrentVersion | false
103105
Length | 18898

src/m365/spo/commands/file/file-version-get.spec.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ describe(commands.FILE_VERSION_GET, () => {
2828
{
2929
"CheckInComment": "",
3030
"Created": "2022-10-30T12:03:06Z",
31+
"ExpirationDate": "2026-01-31T08:23:43.0000000Z",
3132
"ID": 512,
3233
"IsCurrentVersion": false,
3334
"Length": "18898",
@@ -37,6 +38,7 @@ describe(commands.FILE_VERSION_GET, () => {
3738
}
3839
]
3940
};
41+
const selectQueryString = "$select=*,ExpirationDate";
4042

4143
before(() => {
4244
sinon.stub(auth, 'restoreAuth').resolves();
@@ -110,7 +112,7 @@ describe(commands.FILE_VERSION_GET, () => {
110112

111113
it('retrieves version from a file with the fileUrl options', async () => {
112114
sinon.stub(request, 'get').callsFake(async (opts) => {
113-
if (opts.url === `${validWebUrl}/_api/web/GetFileByServerRelativePath(DecodedUrl='${formatting.encodeQueryParameter(validFileUrl)}')/versions/?$filter=VersionLabel eq '${validLabel}'`) {
115+
if (opts.url === `${validWebUrl}/_api/web/GetFileByServerRelativePath(DecodedUrl='${formatting.encodeQueryParameter(validFileUrl)}')/versions/?$filter=VersionLabel eq '${validLabel}'&${selectQueryString}`) {
114116
return fileVersionResponse;
115117
}
116118
throw 'Invalid request';
@@ -129,7 +131,7 @@ describe(commands.FILE_VERSION_GET, () => {
129131

130132
it('retrieves version from a file with the fileId options', async () => {
131133
sinon.stub(request, 'get').callsFake(async (opts) => {
132-
if (opts.url === `${validWebUrl}/_api/web/GetFileById('${validFileId}')/versions/?$filter=VersionLabel eq '${validLabel}'`) {
134+
if (opts.url === `${validWebUrl}/_api/web/GetFileById('${validFileId}')/versions/?$filter=VersionLabel eq '${validLabel}'&${selectQueryString}`) {
133135
return fileVersionResponse;
134136
}
135137
throw 'Invalid request';
@@ -148,10 +150,11 @@ describe(commands.FILE_VERSION_GET, () => {
148150

149151
it('properly escapes single quotes in fileUrl', async () => {
150152
sinon.stub(request, 'get').callsFake(async (opts) => {
151-
if (opts.url = `${validWebUrl}/_api/web/GetFileByServerRelativePath(DecodedUrl='Shared%20Documents%2FFo''lde''r')/versions/?$filter=VersionLabel eq '${validLabel}'`) {
153+
if (opts.url === `${validWebUrl}/_api/web/GetFileByServerRelativePath(DecodedUrl='%2FShared%20Documents%2FFo''lde''r')/versions/?$filter=VersionLabel eq '${validLabel}'&${selectQueryString}`) {
152154
return fileVersionResponse;
153155
}
154-
throw 'Invalid request';
156+
157+
throw 'Invalid GET request ' + opts.url;
155158
});
156159

157160
await command.action(logger, {

src/m365/spo/commands/file/file-version-get.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ class SpoFileVersionGetCommand extends SpoCommand {
106106
else {
107107
requestUrl += `GetFileById('${args.options.fileId}')/versions/?$filter=VersionLabel eq '${args.options.label}'`;
108108
}
109+
110+
requestUrl += `&$select=*,ExpirationDate`;
111+
109112
const requestOptions: CliRequestOptions = {
110113
url: requestUrl,
111114
headers: {

src/m365/spo/commands/file/file-version-list.spec.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ describe(commands.FILE_VERSION_LIST, () => {
2727
{
2828
"CheckInComment": "",
2929
"Created": "2022-10-30T12:03:06Z",
30+
"ExpirationDate": "2026-01-31T08:23:43.0000000Z",
3031
"ID": 512,
3132
"IsCurrentVersion": false,
3233
"Length": "18898",
@@ -37,6 +38,7 @@ describe(commands.FILE_VERSION_LIST, () => {
3738
{
3839
"CheckInComment": "",
3940
"Created": "2022-10-30T12:06:13Z",
41+
"ExpirationDate": null,
4042
"ID": 1024,
4143
"IsCurrentVersion": false,
4244
"Length": "21098",
@@ -46,6 +48,7 @@ describe(commands.FILE_VERSION_LIST, () => {
4648
}
4749
]
4850
};
51+
const queryString = "$select=*,ExpirationDate";
4952

5053
before(() => {
5154
sinon.stub(auth, 'restoreAuth').resolves();
@@ -92,7 +95,7 @@ describe(commands.FILE_VERSION_LIST, () => {
9295
});
9396

9497
it('defines correct properties for the default output', () => {
95-
assert.deepStrictEqual(command.defaultProperties(), ['Created', 'ID', 'IsCurrentVersion', 'VersionLabel']);
98+
assert.deepStrictEqual(command.defaultProperties(), ['Created', 'ID', 'IsCurrentVersion', 'VersionLabel', 'ExpirationDate']);
9699
});
97100

98101
it('fails validation if fileId is not a valid guid', async () => {
@@ -122,7 +125,7 @@ describe(commands.FILE_VERSION_LIST, () => {
122125

123126
it('retrieves versions from a file with the fileUrl option', async () => {
124127
sinon.stub(request, 'get').callsFake(async (opts) => {
125-
if (opts.url === `${validWebUrl}/_api/web/GetFileByServerRelativePath(DecodedUrl='${formatting.encodeQueryParameter(validFileUrl)}')/versions`) {
128+
if (opts.url === `${validWebUrl}/_api/web/GetFileByServerRelativePath(DecodedUrl='${formatting.encodeQueryParameter(validFileUrl)}')/versions?${queryString}`) {
126129
return fileVersionResponse;
127130
}
128131
throw 'Invalid request';
@@ -140,7 +143,7 @@ describe(commands.FILE_VERSION_LIST, () => {
140143

141144
it('retrieves versions from a file with the fileId option', async () => {
142145
sinon.stub(request, 'get').callsFake(async (opts) => {
143-
if (opts.url === `${validWebUrl}/_api/web/GetFileById('${validFileId}')/versions`) {
146+
if (opts.url === `${validWebUrl}/_api/web/GetFileById('${validFileId}')/versions?${queryString}`) {
144147
return fileVersionResponse;
145148
}
146149
throw 'Invalid request';
@@ -159,7 +162,7 @@ describe(commands.FILE_VERSION_LIST, () => {
159162
it('handles a random API error correctly', async () => {
160163
const err = 'Invalid versions request';
161164
sinon.stub(request, 'get').callsFake((opts) => {
162-
if (opts.url === `${validWebUrl}/_api/web/GetFileById('${validFileId}')/versions`) {
165+
if (opts.url === `${validWebUrl}/_api/web/GetFileById('${validFileId}')/versions?${queryString}`) {
163166
throw { error: { 'odata.error': { message: { value: err } } } };
164167
}
165168

src/m365/spo/commands/file/file-version-list.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class SpoFileVersionListCommand extends SpoCommand {
2727
}
2828

2929
public defaultProperties(): string[] | undefined {
30-
return ['Created', 'ID', 'IsCurrentVersion', 'VersionLabel'];
30+
return ['Created', 'ID', 'IsCurrentVersion', 'VersionLabel', 'ExpirationDate'];
3131
}
3232

3333
constructor() {
@@ -97,7 +97,8 @@ class SpoFileVersionListCommand extends SpoCommand {
9797
else {
9898
requestUrl += `/GetFileById('${args.options.fileId}')`;
9999
}
100-
requestUrl += `/versions`;
100+
101+
requestUrl += `/versions?$select=*,ExpirationDate`;
101102

102103
const response = await odata.getAllItems<any>(requestUrl);
103104
await logger.log(response);

0 commit comments

Comments
 (0)