Skip to content

Commit 35c5b87

Browse files
nicodecleyreAdam-it
authored andcommitted
Enhances spo list retentionlabel ensure. Closes pnp#4247
1 parent 7b9fc77 commit 35c5b87

File tree

4 files changed

+65
-38
lines changed

4 files changed

+65
-38
lines changed

docs/docs/cmd/spo/list/list-retentionlabel-ensure.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ m365 spo list label set [options]
1919
`-u, --webUrl <webUrl>`
2020
: The URL of the site where the list is located.
2121

22+
`--name <name>`
23+
: The label name to set on the list.
24+
2225
`--label <label>`
23-
: The label to set on the list.
26+
: (deprecated. Use `name` instead) The label name to set on the list.
2427

2528
`-t, --listTitle [listTitle]`
2629
: The title of the list on which to set the label. Specify either `listTitle`, `listId`, or `listUrl` but not multiple.
@@ -48,16 +51,16 @@ A list retention label is a default label that will be applied to all new items
4851

4952
## Examples
5053

51-
Sets retention label on the list with specified site-relative URL located in the specified site.
54+
Sets a retention label by name on a given list
5255

5356
```sh
54-
m365 spo list retentionlabel ensure --webUrl https://contoso.sharepoint.com/sites/project-x --listUrl 'Shared Documents' --label 'Some label'
57+
m365 spo list retentionlabel ensure --webUrl https://contoso.sharepoint.com/sites/project-x --listUrl 'Shared Documents' --name 'Some label'
5558
```
5659

57-
Sets retention label and disables editing and deleting items on the list and all existing items for the list with specified title located in the specified site.
60+
Sets a retention label by name and disables editing and deleting items on the list and all existing items for a given list
5861

5962
```sh
60-
m365 spo list retentionlabel ensure --webUrl https://contoso.sharepoint.com/sites/project-x --listTitle 'Documents' --label 'Some label' --blockEdit --blockDelete --syncToItems
63+
m365 spo list retentionlabel ensure --webUrl https://contoso.sharepoint.com/sites/project-x --listTitle 'Documents' --name 'Some label' --blockEdit --blockDelete --syncToItems
6164
```
6265

6366
## Response

src/m365/spo/commands/list/list-retentionlabel-ensure.spec.ts

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,12 @@ describe(commands.LIST_RETENTIONLABEL_ENSURE, () => {
117117
debug: true,
118118
webUrl: 'https://contoso.sharepoint.com/sites/team1',
119119
listTitle: 'MyLibrary',
120-
label: 'abc'
120+
name: 'abc'
121121
}
122122
} as any), new CommandError('404 - "404 FILE NOT FOUND"'));
123123
});
124124

125-
it('should set label for list (debug)', async () => {
125+
it('should set label for list with deprecated label', async () => {
126126
const postStub = sinon.stub(request, 'post').callsFake((opts) => {
127127
if ((opts.url as string).indexOf(`https://contoso.sharepoint.com/sites/team1/_api/SP_CompliancePolicy_SPPolicyStoreProxy_SetListComplianceTag`) > -1) {
128128
return Promise.resolve();
@@ -156,6 +156,40 @@ describe(commands.LIST_RETENTIONLABEL_ENSURE, () => {
156156
assert.strictEqual(lastCall.data.syncToItems, false);
157157
});
158158

159+
it('should set label for list (debug)', async () => {
160+
const postStub = sinon.stub(request, 'post').callsFake((opts) => {
161+
if ((opts.url as string).indexOf(`https://contoso.sharepoint.com/sites/team1/_api/SP_CompliancePolicy_SPPolicyStoreProxy_SetListComplianceTag`) > -1) {
162+
return Promise.resolve();
163+
}
164+
165+
return Promise.reject('Invalid request');
166+
});
167+
168+
sinon.stub(request, 'get').callsFake((opts) => {
169+
if (opts.url === `https://contoso.sharepoint.com/sites/team1/_api/web/lists/getByTitle('MyLibrary')/?$expand=RootFolder&$select=RootFolder`) {
170+
return Promise.resolve({ "RootFolder": { "Exists": true, "IsWOPIEnabled": false, "ItemCount": 0, "Name": "MyLibrary", "ProgID": null, "ServerRelativeUrl": "/sites/team1/MyLibrary", "TimeCreated": "2019-01-11T10:03:19Z", "TimeLastModified": "2019-01-11T10:03:20Z", "UniqueId": "faaa6af2-0157-4e9a-a352-6165195923c8", "WelcomePage": "" } }
171+
);
172+
}
173+
174+
return Promise.reject('Invalid request');
175+
});
176+
177+
await command.action(logger, {
178+
options: {
179+
debug: true,
180+
webUrl: 'https://contoso.sharepoint.com/sites/team1',
181+
listTitle: 'MyLibrary',
182+
name: 'abc'
183+
}
184+
});
185+
const lastCall = postStub.lastCall.args[0];
186+
assert.strictEqual(lastCall.data.listUrl, 'https://contoso.sharepoint.com/sites/team1/MyLibrary');
187+
assert.strictEqual(lastCall.data.complianceTagValue, 'abc');
188+
assert.strictEqual(lastCall.data.blockDelete, false);
189+
assert.strictEqual(lastCall.data.blockEdit, false);
190+
assert.strictEqual(lastCall.data.syncToItems, false);
191+
});
192+
159193
it('should set label for list using listId (debug)', async () => {
160194
const postStub = sinon.stub(request, 'post').callsFake((opts) => {
161195
if ((opts.url as string).indexOf(`https://contoso.sharepoint.com/sites/team1/_api/SP_CompliancePolicy_SPPolicyStoreProxy_SetListComplianceTag`) > -1) {
@@ -178,7 +212,7 @@ describe(commands.LIST_RETENTIONLABEL_ENSURE, () => {
178212
options: {
179213
webUrl: 'https://contoso.sharepoint.com/sites/team1',
180214
listId: '4d535433-2a7b-40b0-9dad-8f0f8f3b3841',
181-
label: 'abc'
215+
name: 'abc'
182216
}
183217
});
184218
const lastCall = postStub.lastCall.args[0];
@@ -202,7 +236,7 @@ describe(commands.LIST_RETENTIONLABEL_ENSURE, () => {
202236
options: {
203237
webUrl: 'https://contoso.sharepoint.com/sites/team1',
204238
listUrl: 'MyLibrary',
205-
label: 'abc',
239+
name: 'abc',
206240
blockDelete: true,
207241
blockEdit: true,
208242
syncToItems: true
@@ -222,33 +256,22 @@ describe(commands.LIST_RETENTIONLABEL_ENSURE, () => {
222256
});
223257

224258
it('passes validation if the url option is a valid SharePoint site URL', async () => {
225-
const actual = await command.validate({ options: { webUrl: 'https://contoso.sharepoint.com', label: 'abc', listId: '0CD891EF-AFCE-4E55-B836-FCE03286CCCF' } }, commandInfo);
259+
const actual = await command.validate({ options: { webUrl: 'https://contoso.sharepoint.com', name: 'abc', listId: '0CD891EF-AFCE-4E55-B836-FCE03286CCCF' } }, commandInfo);
226260
assert(actual);
227261
});
228262

229263
it('fails validation if the listid option is not a valid GUID', async () => {
230-
const actual = await command.validate({ options: { webUrl: 'https://contoso.sharepoint.com', label: 'abc', listId: 'XXXXX' } }, commandInfo);
264+
const actual = await command.validate({ options: { webUrl: 'https://contoso.sharepoint.com', name: 'abc', listId: 'XXXXX' } }, commandInfo);
231265
assert.notStrictEqual(actual, true);
232266
});
233267

234268
it('passes validation if the listid option is a valid GUID', async () => {
235-
const actual = await command.validate({ options: { webUrl: 'https://contoso.sharepoint.com', label: 'abc', listId: 'cc27a922-8224-4296-90a5-ebbc54da2e85' } }, commandInfo);
269+
const actual = await command.validate({ options: { webUrl: 'https://contoso.sharepoint.com', name: 'abc', listId: 'cc27a922-8224-4296-90a5-ebbc54da2e85' } }, commandInfo);
236270
assert(actual);
237271
});
238272

239273
it('fails validation if listId, listUrl and listTitle options are not passed', async () => {
240-
const actual = await command.validate({ options: { webUrl: 'https://contoso.sharepoint.com', label: 'abc' } }, commandInfo);
274+
const actual = await command.validate({ options: { webUrl: 'https://contoso.sharepoint.com', name: 'abc' } }, commandInfo);
241275
assert.notStrictEqual(actual, true);
242276
});
243-
244-
it('supports debug mode', () => {
245-
const options = command.options;
246-
let containsDebugOption = false;
247-
options.forEach(o => {
248-
if (o.option === '--debug') {
249-
containsDebugOption = true;
250-
}
251-
});
252-
assert(containsDebugOption);
253-
});
254277
});

src/m365/spo/commands/list/list-retentionlabel-ensure.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ interface CommandArgs {
1414

1515
interface Options extends GlobalOptions {
1616
webUrl: string;
17-
label: string;
17+
name?: string;
18+
label?: string;
1819
listId?: string;
1920
listTitle?: string;
2021
listUrl?: string;
@@ -48,6 +49,8 @@ class SpoListRetentionLabelEnsureCommand extends SpoCommand {
4849
#initTelemetry(): void {
4950
this.telemetry.push((args: CommandArgs) => {
5051
Object.assign(this.telemetryProperties, {
52+
name: (!(!args.options.name)).toString(),
53+
label: (!(!args.options.label)).toString(),
5154
listId: (!(!args.options.listId)).toString(),
5255
listTitle: (!(!args.options.listTitle)).toString(),
5356
listUrl: (!(!args.options.listUrl)).toString(),
@@ -64,7 +67,10 @@ class SpoListRetentionLabelEnsureCommand extends SpoCommand {
6467
option: '-u, --webUrl <webUrl>'
6568
},
6669
{
67-
option: '--label <label>'
70+
option: '--name [name]'
71+
},
72+
{
73+
option: '--label [label]'
6874
},
6975
{
7076
option: '-t, --listTitle [listTitle]'
@@ -106,6 +112,12 @@ class SpoListRetentionLabelEnsureCommand extends SpoCommand {
106112
public async commandAction(logger: Logger, args: CommandArgs): Promise<void> {
107113
this.showDeprecationWarning(logger, commands.LIST_LABEL_SET, commands.LIST_RETENTIONLABEL_ENSURE);
108114

115+
if (args.options.label) {
116+
args.options.name = args.options.label;
117+
118+
this.warn(logger, `Option 'label' is deprecated. Please use 'name' instead`);
119+
}
120+
109121
if (args.options.blockDelete) {
110122
this.warn(logger, `Option 'blockDelete' is deprecated.`);
111123
}
@@ -152,7 +164,7 @@ class SpoListRetentionLabelEnsureCommand extends SpoCommand {
152164
},
153165
data: {
154166
listUrl: listAbsoluteUrl,
155-
complianceTagValue: args.options.label,
167+
complianceTagValue: args.options.name,
156168
blockDelete: args.options.blockDelete || false,
157169
blockEdit: args.options.blockEdit || false,
158170
syncToItems: args.options.syncToItems || false

src/m365/spo/commands/web/web-retentionlabel-list.spec.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,4 @@ describe(commands.WEB_RETENTIONLABEL_LIST, () => {
151151
}
152152
} as any), new CommandError('An error has occurred'));
153153
});
154-
155-
it('supports debug mode', () => {
156-
const options = command.options;
157-
let containsDebugOption = false;
158-
options.forEach(o => {
159-
if (o.option === '--debug') {
160-
containsDebugOption = true;
161-
}
162-
});
163-
assert(containsDebugOption);
164-
});
165154
});

0 commit comments

Comments
 (0)