Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extends 'spo list get' command with support for retrieving any default list in a given site #6447

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
6 changes: 6 additions & 0 deletions docs/docs/cmd/spo/list/list-get.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ When the `properties` option includes values with a `/`, for example: `ListItemA

## Examples

Get the default document library located in the specified site.

```sh
m365 spo list get --webUrl https://contoso.sharepoint.com/sites/project-x
```

Get information about a list with specified ID located in the specified site.

```sh
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
"Levert, Sebastien <[email protected]>",
"Lingstuyl, Martin <[email protected]>",
"Macháček, Martin <[email protected]>",
"Maestrini Tobias <tobias@bee365.ch>",
"Maestrini, Tobias <tobias[email protected]>",
"Maillot, Michaël <[email protected]>",
"Mastykarz, Waldek <[email protected]>",
"McDonnell, Kevin <[email protected]>",
Expand Down
43 changes: 42 additions & 1 deletion src/m365/spo/commands/list/list-get.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1281,4 +1281,45 @@ describe(commands.LIST_GET, () => {
const actual = await command.validate({ options: { webUrl: 'https://contoso.sharepoint.com', id: '0CD891EF-AFCE-4E55-B836-FCE03286CCCF' } }, commandInfo);
assert(actual);
});
});

it('retrieves the default list in the specified site by providing a webUrl', async () => {
const webUrl = 'https://contoso.sharepoint.com';
const mockListResponse = {
AllowContentTypes: true,
BaseTemplate: 100,
BaseType: 1,
ContentTypesEnabled: false,
Created: "2023-07-02T00:03:51Z",
DefaultItemOpenUseListSetting: false,
Description: "",
EnableVersioning: true,
EntityTypeName: "Shared_x0020_Documents",
Id: "cf07fe11-8b85-424c-972f-5f84fba5157c",
ItemCount: 20,
ListItemEntityTypeFullName: "SP.Data.Shared_x0020_DocumentsItem",
MajorVersionLimit: 500,
ParentWebUrl: "/",
Title: "Documents",
VersionPolicies: {
DefaultTrimMode: 1,
MinorVersionLimit: 0,
MajorVersionLimit: 500
}
};

sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === `${webUrl}/_api/web/DefaultDocumentLibrary`) {
return mockListResponse;
}
throw 'Invalid request';
});

await command.action(logger, {
options: {
webUrl: webUrl
}
});

assert(loggerLogSpy.calledWith(mockListResponse));
});
});
10 changes: 4 additions & 6 deletions src/m365/spo/commands/list/list-get.ts
tmaestrini marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class SpoListGetCommand extends SpoCommand {
}

public get description(): string {
return 'Gets information about the specific list';
return 'Gets information about the specific list or returns information about the default list in a site';
tmaestrini marked this conversation as resolved.
Show resolved Hide resolved
}

constructor() {
Expand All @@ -44,7 +44,6 @@ class SpoListGetCommand extends SpoCommand {
this.#initTelemetry();
this.#initOptions();
this.#initValidators();
this.#initOptionSets();
}

#initTelemetry(): void {
Expand Down Expand Up @@ -101,10 +100,6 @@ class SpoListGetCommand extends SpoCommand {
);
}

#initOptionSets(): void {
this.optionSets.push({ options: ['id', 'title', 'url'] });
}

public async commandAction(logger: Logger, args: CommandArgs): Promise<void> {
if (this.verbose) {
await logger.logToStderr(`Retrieving information for list in site at ${args.options.webUrl}...`);
Expand All @@ -122,6 +117,9 @@ class SpoListGetCommand extends SpoCommand {
const listServerRelativeUrl: string = urlUtil.getServerRelativePath(args.options.webUrl, args.options.url);
requestUrl += `GetList('${formatting.encodeQueryParameter(listServerRelativeUrl)}')`;
}
else {
requestUrl += `DefaultDocumentLibrary`;
}

const fieldsProperties: Properties = this.formatSelectProperties(args.options.properties, args.options.withPermissions);
const queryParams: string[] = [];
Expand Down