Skip to content

New command: m365 viva engage role list. Closes #6796 #6798

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
102 changes: 102 additions & 0 deletions docs/docs/cmd/viva/engage/engage-role-list.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import Global from '/docs/cmd/_global.mdx';
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# viva engage role list

Lists all Viva Engage roles

## Usage

```sh
m365 viva engage role list [options]
```

## Options

<Global />

## Remarks

:::warning

This command is based on an API that is currently in preview and is subject to change once the API reaches general availability.

:::

## Permissions

<Tabs>
<TabItem value="Delegated">

| Resource | Permissions |
|-----------------|-------------------------|
| Microsoft Graph | EngagementRole.Read.All |

</TabItem>
<TabItem value="Application">

| Resource | Permissions |
|-----------------|-------------------------|
| Microsoft Graph | EngagementRole.Read.All |

</TabItem>
</Tabs>

## Examples

List all Viva Engage roles

```sh
m365 viva engage role list
```

## Response

<Tabs>
<TabItem value="JSON">

```json
[
{
"id": "ec759127-089f-4f91-8dfc-03a30b51cb38",
"displayName": "Network Admin"
}
]
```

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

```text
id displayName
------------------------------------ -------------
ec759127-089f-4f91-8dfc-03a30b51cb38 Network Admin
```

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

```csv
id,displayName
ec759127-089f-4f91-8dfc-03a30b51cb38,Network Admin
```

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

```md
# viva engage role list

Date: 7/11/2025

## Network Admin (ec759127-089f-4f91-8dfc-03a30b51cb38)

Property | Value
---------|-------
id | ec759127-089f-4f91-8dfc-03a30b51cb38
displayName | Network Admin
```

</TabItem>
</Tabs>
5 changes: 5 additions & 0 deletions docs/src/config/sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4907,6 +4907,11 @@ const sidebars: SidebarsConfig = {
label: 'engage report groupsactivitygroupcounts',
id: 'cmd/viva/engage/engage-report-groupsactivitygroupcounts'
},
{
type: 'doc',
label: 'engage role list',
id: 'cmd/viva/engage/engage-role-list'
},
{
type: 'doc',
label: 'engage user get',
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default {
'https://graph.microsoft.com/Community.ReadWrite.All',
'https://graph.microsoft.com/Directory.AccessAsUser.All',
'https://graph.microsoft.com/Directory.ReadWrite.All',
'https://graph.microsoft.com/EngagementRole.ReadWrite.All',
'https://graph.microsoft.com/ExternalConnection.ReadWrite.All',
'https://graph.microsoft.com/ExternalItem.ReadWrite.All',
'https://graph.microsoft.com/FileStorageContainer.Selected',
Expand Down
1 change: 1 addition & 0 deletions src/m365/viva/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default {
ENGAGE_REPORT_GROUPSACTIVITYCOUNTS: `${prefix} engage report groupsactivitycounts`,
ENGAGE_REPORT_GROUPSACTIVITYDETAIL: `${prefix} engage report groupsactivitydetail`,
ENGAGE_REPORT_GROUPSACTIVITYGROUPCOUNTS: `${prefix} engage report groupsactivitygroupcounts`,
ENGAGE_ROLE_LIST: `${prefix} engage role list`,
ENGAGE_SEARCH: `${prefix} engage search`,
ENGAGE_USER_GET: `${prefix} engage user get`,
ENGAGE_USER_LIST: `${prefix} engage user list`
Expand Down
4 changes: 4 additions & 0 deletions src/m365/viva/commands/engage/EngageRole.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface EngageRole {
id?: string;
displayName?: string;
}
125 changes: 125 additions & 0 deletions src/m365/viva/commands/engage/engage-role-list.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
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 './engage-role-list.js';

describe(commands.ENGAGE_ROLE_LIST, () => {
let log: string[];
let logger: Logger;
let loggerLogSpy: sinon.SinonSpy;

before(() => {
sinon.stub(auth, 'restoreAuth').resolves();
sinon.stub(telemetry, 'trackEvent').resolves();
sinon.stub(pid, 'getProcessName').returns('');
sinon.stub(session, 'getId').returns('');
auth.connection.active = true;
});

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;
});

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

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

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

it(`should get a list of Viva Engage roles`, async () => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === `https://graph.microsoft.com/beta/employeeExperience/roles`) {
return {
"value": [
{
"id": "ec759127-089f-4f91-8dfc-03a30b51cb38",
"displayName": "Network Admin"
},
{
"id": "966b8ec4-6457-4f22-bd3c-5a2520e98f4a",
"displayName": "Verified Admin"
},
{
"id": "77aa47ad-96fe-4ecc-8024-fd1ac5e28f17",
"displayName": "Corporate Communicator"
}
]
};
}

throw 'Invalid request';
});

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

assert(
loggerLogSpy.calledOnceWith([
{
"id": "ec759127-089f-4f91-8dfc-03a30b51cb38",
"displayName": "Network Admin"
},
{
"id": "966b8ec4-6457-4f22-bd3c-5a2520e98f4a",
"displayName": "Verified Admin"
},
{
"id": "77aa47ad-96fe-4ecc-8024-fd1ac5e28f17",
"displayName": "Corporate Communicator"
}
])
);
});

it('handles error when retrieving Viva Engage roles failed', async () => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === `https://graph.microsoft.com/beta/employeeExperience/roles`) {
throw { error: { message: 'An error has occurred' } };
}
throw `Invalid request`;
});

await assert.rejects(
command.action(logger, { options: {} }),
new CommandError('An error has occurred')
);
});
});
35 changes: 35 additions & 0 deletions src/m365/viva/commands/engage/engage-role-list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Logger } from '../../../../cli/Logger.js';
import { odata } from '../../../../utils/odata.js';
import GraphCommand from '../../../base/GraphCommand.js';
import commands from '../../commands.js';
import { EngageRole } from './EngageRole.js';

class VivaEngageRoleListCommand extends GraphCommand {
public get name(): string {
return commands.ENGAGE_ROLE_LIST;
}

public get description(): string {
return 'Lists all Viva Engage roles';
}

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

public async commandAction(logger: Logger): Promise<void> {
if (this.verbose) {
await logger.logToStderr('Getting all Viva Engage roles...');
}

try {
const results = await odata.getAllItems<EngageRole>(`${this.resource}/beta/employeeExperience/roles`);
await logger.log(results);
}
catch (err: any) {
this.handleRejectedODataJsonPromise(err);
}
}
}

export default new VivaEngageRoleListCommand();
Loading