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

Adds 'm365 spo homesite list'. Closes #6091 #6496

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2aa9bed
publish home site list
reshmee011 Nov 18, 2024
c33f76f
update homesite list
reshmee011 Nov 18, 2024
d605e6c
updates based on Milan's comments
reshmee011 Nov 20, 2024
1efc329
Update docs/docs/cmd/spo/homesite/homesite-list.mdx
reshmee011 Nov 20, 2024
b0d5aba
Update docs/docs/cmd/spo/homesite/homesite-list.mdx
reshmee011 Nov 20, 2024
a892672
Update src/m365/spo/commands/homesite/homesite-list.ts
reshmee011 Nov 20, 2024
70c06d9
update
reshmee011 Nov 20, 2024
c90115b
Merge branch 'homesitelist' of https://github.com/reshmee011/cli-micr…
reshmee011 Nov 20, 2024
756b607
Update src/m365/spo/commands/homesite/homesite-list.ts
reshmee011 Nov 20, 2024
abcdb96
Update src/m365/spo/commands/homesite/homesite-list.spec.ts
reshmee011 Nov 20, 2024
15d3652
Update docs/docs/cmd/spo/homesite/homesite-list.mdx
reshmee011 Nov 20, 2024
508b84f
Update docs/docs/cmd/spo/homesite/homesite-list.mdx
reshmee011 Nov 20, 2024
376b1b2
latest changes after Milan's review
reshmee011 Nov 20, 2024
aea2196
One line after imports
reshmee011 Nov 20, 2024
856a5ce
Update src/m365/spo/commands/homesite/homesite-list.ts
reshmee011 Nov 24, 2024
f2ddd9b
Update src/m365/spo/commands/homesite/homesite-list.ts
reshmee011 Nov 24, 2024
1a08980
Update docs/docs/cmd/spo/homesite/homesite-list.mdx
reshmee011 Nov 24, 2024
5eb45fb
changes to the md file
reshmee011 Nov 24, 2024
2568d42
Merge branch 'pnp:main' into homesitelist
reshmee011 Nov 28, 2024
cb30e6b
update to move home site list under tenant location
reshmee011 Nov 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions docs/docs/cmd/spo/tenant/tenant-homesite-list.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import Global from '/docs/cmd/_global.mdx';
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# spo homesite list

Lists all home sites

## Usage

```sh
m365 spo tenant homesite list [options]
```

## Options

<Global />

## Examples

List all home sites

```sh
m365 spo tenant homesite list
```

## Response

<Tabs>
<TabItem value="JSON">

```json
[
{
"Audiences": [
{
"Email": "[email protected]",
"Id": "978b5280-4f80-47ea-a1db-b0d1d2fb1ba4",
"Title": "ColumnSearchable Members"
}
],
"IsInDraftMode": false,
"IsVivaBackendSite": false,
"SiteId": "431d7819-4aaf-49a1-b664-b2fe9e609b63",
"TargetedLicenseType": 2,
"Title": "The Landing",
"Url": "https://contoso.sharepoint.com/sites/TheLanding",
"VivaConnectionsDefaultStart": true,
"WebId": "626c1724-8ac8-45d5-af87-c07c752fab75"
}
]
```

</TabItem>
<TabItem value="Text">

```text
Url Title
----------------------------------------------- -----------
https://contoso.sharepoint.com/sites/TheLanding The Landing
```

</TabItem>
<TabItem value="CSV">

```csv
IsInDraftMode,IsVivaBackendSite,SiteId,TargetedLicenseType,Title,Url,VivaConnectionsDefaultStart,WebId
0,0,431d7819-4aaf-49a1-b664-b2fe9e609b63,2,The Landing,https://contoso.sharepoint.com/sites/TheLanding,1,626c1724-8ac8-45d5-af87-c07c752fab75
```

</TabItem>
<TabItem value="Markdown">

```md
# spo homesite list

Date: 11/18/2024

Property | Value
---------|-------
IsInDraftMode | false
IsVivaBackendSite | false
SiteId | 431d7819-4aaf-49a1-b664-b2fe9e609b63
TargetedLicenseType | 2
Title | The Landing
Url | https://contoso.sharepoint.com/sites/TheLanding
VivaConnectionsDefaultStart | true
WebId | 626c1724-8ac8-45d5-af87-c07c752fab75
```
</TabItem>
</Tabs>

## More information

- SharePoint home sites [Viva Connections set up](https://learn.microsoft.com/en-us/viva/connections/set-up-admin-center)
5 changes: 5 additions & 0 deletions docs/src/config/sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3737,6 +3737,11 @@ const sidebars: SidebarsConfig = {
label: 'tenant commandset set',
id: 'cmd/spo/tenant/tenant-commandset-set'
},
{
type: 'doc',
label: 'homesite list',
id: 'cmd/spo/tenant/tenant-homesite-list'
},
{
type: 'doc',
label: 'tenant recyclebinitem list',
Expand Down
1 change: 1 addition & 0 deletions src/m365/spo/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ export default {
TENANT_COMMANDSET_LIST: `${prefix} tenant commandset list`,
TENANT_COMMANDSET_REMOVE: `${prefix} tenant commandset remove`,
TENANT_COMMANDSET_SET: `${prefix} tenant commandset set`,
TENANT_HOMESITE_LIST: `${prefix} tenant homesite list`,
TENANT_RECYCLEBINITEM_LIST: `${prefix} tenant recyclebinitem list`,
TENANT_RECYCLEBINITEM_REMOVE: `${prefix} tenant recyclebinitem remove`,
TENANT_RECYCLEBINITEM_RESTORE: `${prefix} tenant recyclebinitem restore`,
Expand Down
123 changes: 123 additions & 0 deletions src/m365/spo/commands/tenant/tenant-homesite-list.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import assert from 'assert';
import sinon from 'sinon';
import auth from '../../../../Auth.js';
import { Logger } from '../../../../cli/Logger.js';
import { CommandError } from '../../../../Command.js';
import request from '../../../../request.js';
import { telemetry } from '../../../../telemetry.js';
import { pid } from '../../../../utils/pid.js';
import { session } from '../../../../utils/session.js';
import { sinonUtil } from '../../../../utils/sinonUtil.js';
import commands from '../../commands.js';
import command from './tenant-homesite-list.js';

describe(commands.TENANT_HOMESITE_LIST, () => {
let log: string[];
let logger: Logger;
let loggerLogSpy: sinon.SinonSpy;
const homeSites = {
"value": [
{
"Audiences": [
{
"Email": "[email protected]",
"Id": "978b5280-4f80-47ea-a1db-b0d1d2fb1ba4",
"Title": "ColumnSearchable Members"
},
{
"Email": "[email protected]",
"Id": "21af775d-17b3-4637-94a4-2ba8625277cb",
"Title": "Contoso TeamR Members"
}
],
"IsInDraftMode": false,
"IsVivaBackendSite": false,
"SiteId": "431d7819-4aaf-49a1-b664-b2fe9e609b63",
"TargetedLicenseType": 2,
"Title": "The Landing",
"Url": "https://contoso.sharepoint.com/sites/TheLanding",
"VivaConnectionsDefaultStart": true,
"WebId": "626c1724-8ac8-45d5-af87-c07c752fab75"
},
{
"Audiences": [],
"IsInDraftMode": false,
"IsVivaBackendSite": false,
"SiteId": "45d4a135-40e4-4571-8340-61d17fdfd58a",
"TargetedLicenseType": 0,
"Title": "Contoso Electronics",
"Url": "https://contoso.sharepoint.com/sites/contosoportal",
"VivaConnectionsDefaultStart": true,
"WebId": "9418e2a1-855c-4752-8dd4-48693f43b10a"
}
]
};

before(() => {
sinon.stub(auth, 'restoreAuth').resolves();
sinon.stub(telemetry, 'trackEvent').returns();
sinon.stub(pid, 'getProcessName').returns('');
sinon.stub(session, 'getId').returns('');
auth.connection.active = true;
auth.connection.spoUrl = 'https://contoso.sharepoint.com';
});

beforeEach(() => {
log = [];
logger = {
log: async (msg: string) => {
log.push(msg);
},
logRaw: async (msg: string) => {
log.push(msg);
},
logToStderr: async (msg: string) => {
log.push(msg);
}
};
loggerLogSpy = sinon.spy(logger, 'log');
});

afterEach(() => {
sinonUtil.restore([
request.get
]);
});

after(() => {
sinon.restore();
auth.connection.active = false;
auth.connection.spoUrl = undefined;
});

it('has correct name', () => {
assert.strictEqual(command.name, commands.TENANT_HOMESITE_LIST);
});

it('has a description', () => {
assert.notStrictEqual(command.description, null);
});

it('defines correct properties for the default output', () => {
assert.deepStrictEqual(command.defaultProperties(), ['Url', 'Title']);
});

it('lists available home sites', async () => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === `https://contoso-admin.sharepoint.com/_api/SPO.Tenant/GetTargetedSitesDetails`) {
return homeSites;
}

throw opts.url;
});

await command.action(logger, { options: { verbose: true } });
assert(loggerLogSpy.calledWith(homeSites.value));
});

it('correctly handles OData error when retrieving available home sites', async () => {
sinon.stub(request, 'get').rejects({ error: { 'odata.error': { message: { value: 'An error has occurred' } } } });

await assert.rejects(command.action(logger, { options: {} } as any), new CommandError('An error has occurred'));
});
});
43 changes: 43 additions & 0 deletions src/m365/spo/commands/tenant/tenant-homesite-list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Logger } from '../../../../cli/Logger.js';
import { odata } from '../../../../utils/odata.js';
import { spo } from '../../../../utils/spo.js';
import SpoCommand from '../../../base/SpoCommand.js';
import commands from '../../commands.js';
import { CliRequestOptions } from "../../../../request.js";

class SpoTenantHomeSiteListCommand extends SpoCommand {
public get name(): string {
return commands.TENANT_HOMESITE_LIST;
}

public get description(): string {
return 'Lists all home sites';
}

public defaultProperties(): string[] | undefined {
return ['Url', 'Title'];
}

public async commandAction(logger: Logger): Promise<void> {
try {
const spoAdminUrl: string = await spo.getSpoAdminUrl(logger, this.verbose);
const requestOptions: CliRequestOptions = {
url: `${spoAdminUrl}/_api/SPO.Tenant/GetTargetedSitesDetails`,
headers: {
accept: 'application/json;odata=nometadata'
},
responseType: 'json'
};
if (this.verbose) {
await logger.logToStderr(`Retrieving all home sites...`);
}
const res = await odata.getAllItems(requestOptions);
await logger.log(res);
}
catch (err: any) {
this.handleRejectedODataJsonPromise(err);
}
}
}

export default new SpoTenantHomeSiteListCommand();