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

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
22 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
1181f3a
Update docs/docs/cmd/spo/tenant/tenant-homesite-list.mdx
reshmee011 Dec 15, 2024
f80fc37
Update docs/src/config/sidebars.ts
reshmee011 Dec 15, 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
104 changes: 104 additions & 0 deletions docs/docs/cmd/spo/homesite/homesite-list.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
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 homesite list [options]
```

## Options

<Global />

## Examples

List all the home sites
reshmee011 marked this conversation as resolved.
Show resolved Hide resolved

```sh
m365 spo homesite list
```

## Response
reshmee011 marked this conversation as resolved.
Show resolved Hide resolved

<Tabs>
<TabItem value="JSON">

```json
{
reshmee011 marked this conversation as resolved.
Show resolved Hide resolved
"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"
}
reshmee011 marked this conversation as resolved.
Show resolved Hide resolved
],
"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"
}
]
}
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's update this with the new output (just an array of objects).


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

```text
Url Title
--------------------------------------------------------------- -------------------
https://contoso.sharepoint.com/sites/TheLanding The Landing
```
reshmee011 marked this conversation as resolved.
Show resolved Hide resolved

</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
reshmee011 marked this conversation as resolved.
Show resolved Hide resolved
```

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

```md
m365 spo homesite list --output md
reshmee011 marked this conversation as resolved.
Show resolved Hide resolved
# 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
```
reshmee011 marked this conversation as resolved.
Show resolved Hide resolved

</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 @@ -2710,6 +2710,11 @@ const sidebars: SidebarsConfig = {
label: 'homesite get',
id: 'cmd/spo/homesite/homesite-get'
},
{
type: 'doc',
label: 'homesite list',
id: 'cmd/spo/homesite/homesite-list'
},
{
type: 'doc',
label: 'homesite remove',
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 @@ -118,6 +118,7 @@ export default {
HIDEDEFAULTTHEMES_GET: `${prefix} hidedefaultthemes get`,
HIDEDEFAULTTHEMES_SET: `${prefix} hidedefaultthemes set`,
HOMESITE_GET: `${prefix} homesite get`,
HOMESITE_LIST: `${prefix} homesite list`,
HOMESITE_REMOVE: `${prefix} homesite remove`,
HOMESITE_SET: `${prefix} homesite set`,
HUBSITE_CONNECT: `${prefix} hubsite connect`,
Expand Down
123 changes: 123 additions & 0 deletions src/m365/spo/commands/homesite/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 './homesite-list.js';

describe(commands.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.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 (debug)', async () => {
reshmee011 marked this conversation as resolved.
Show resolved Hide resolved
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: { debug: true, output: 'json' } });
assert(loggerLogSpy.calledWith(homeSites.value));
});
reshmee011 marked this conversation as resolved.
Show resolved Hide resolved

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'));
});
});
38 changes: 38 additions & 0 deletions src/m365/spo/commands/homesite/homesite-list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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';
class SpoHomeSiteListCommand extends SpoCommand {
reshmee011 marked this conversation as resolved.
Show resolved Hide resolved
public get name(): string {
return commands.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.debug);
reshmee011 marked this conversation as resolved.
Show resolved Hide resolved
reshmee011 marked this conversation as resolved.
Show resolved Hide resolved
const requestOptions: any = {
reshmee011 marked this conversation as resolved.
Show resolved Hide resolved
reshmee011 marked this conversation as resolved.
Show resolved Hide resolved
url: `${spoAdminUrl}/_api/SPO.Tenant/GetTargetedSitesDetails`,
headers: {
accept: 'application/json;odata=nometadata'
},
responseType: 'json'
};
const res = await odata.getAllItems(requestOptions);
await logger.log(res);
}
catch (err: any) {
this.handleRejectedODataJsonPromise(err);
}
}
}

export default new SpoHomeSiteListCommand();