Skip to content

Commit 03e176e

Browse files
MartinM85milanholemans
authored andcommitted
Adds command 'viva engage role list'. Closes #6796
1 parent 68ad79a commit 03e176e

File tree

7 files changed

+273
-0
lines changed

7 files changed

+273
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import Global from '/docs/cmd/_global.mdx';
2+
import Tabs from '@theme/Tabs';
3+
import TabItem from '@theme/TabItem';
4+
5+
# viva engage role list
6+
7+
Lists all Viva Engage roles
8+
9+
## Usage
10+
11+
```sh
12+
m365 viva engage role list [options]
13+
```
14+
15+
## Options
16+
17+
<Global />
18+
19+
## Remarks
20+
21+
:::warning
22+
23+
This command is based on an API that is currently in preview and is subject to change once the API reaches general availability.
24+
25+
:::
26+
27+
## Permissions
28+
29+
<Tabs>
30+
<TabItem value="Delegated">
31+
32+
| Resource | Permissions |
33+
|-----------------|-------------------------|
34+
| Microsoft Graph | EngagementRole.Read.All |
35+
36+
</TabItem>
37+
<TabItem value="Application">
38+
39+
| Resource | Permissions |
40+
|-----------------|-------------------------|
41+
| Microsoft Graph | EngagementRole.Read.All |
42+
43+
</TabItem>
44+
</Tabs>
45+
46+
## Examples
47+
48+
List all Viva Engage roles
49+
50+
```sh
51+
m365 viva engage role list
52+
```
53+
54+
## Response
55+
56+
<Tabs>
57+
<TabItem value="JSON">
58+
59+
```json
60+
[
61+
{
62+
"id": "ec759127-089f-4f91-8dfc-03a30b51cb38",
63+
"displayName": "Network Admin"
64+
}
65+
]
66+
```
67+
68+
</TabItem>
69+
<TabItem value="Text">
70+
71+
```text
72+
id displayName
73+
------------------------------------ -------------
74+
ec759127-089f-4f91-8dfc-03a30b51cb38 Network Admin
75+
```
76+
77+
</TabItem>
78+
<TabItem value="CSV">
79+
80+
```csv
81+
id,displayName
82+
ec759127-089f-4f91-8dfc-03a30b51cb38,Network Admin
83+
```
84+
85+
</TabItem>
86+
<TabItem value="Markdown">
87+
88+
```md
89+
# viva engage role list
90+
91+
Date: 7/11/2025
92+
93+
## Network Admin (ec759127-089f-4f91-8dfc-03a30b51cb38)
94+
95+
Property | Value
96+
---------|-------
97+
id | ec759127-089f-4f91-8dfc-03a30b51cb38
98+
displayName | Network Admin
99+
```
100+
101+
</TabItem>
102+
</Tabs>

docs/src/config/sidebars.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4936,6 +4936,11 @@ const sidebars: SidebarsConfig = {
49364936
label: 'engage report groupsactivitygroupcounts',
49374937
id: 'cmd/viva/engage/engage-report-groupsactivitygroupcounts'
49384938
},
4939+
{
4940+
type: 'doc',
4941+
label: 'engage role list',
4942+
id: 'cmd/viva/engage/engage-role-list'
4943+
},
49394944
{
49404945
type: 'doc',
49414946
label: 'engage role member list',

src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export default {
1717
'https://graph.microsoft.com/Community.ReadWrite.All',
1818
'https://graph.microsoft.com/Directory.AccessAsUser.All',
1919
'https://graph.microsoft.com/Directory.ReadWrite.All',
20+
'https://graph.microsoft.com/EngagementRole.ReadWrite.All',
2021
'https://graph.microsoft.com/ExternalConnection.ReadWrite.All',
2122
'https://graph.microsoft.com/ExternalItem.ReadWrite.All',
2223
'https://graph.microsoft.com/FileStorageContainer.Selected',

src/m365/viva/commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default {
2828
ENGAGE_REPORT_GROUPSACTIVITYCOUNTS: `${prefix} engage report groupsactivitycounts`,
2929
ENGAGE_REPORT_GROUPSACTIVITYDETAIL: `${prefix} engage report groupsactivitydetail`,
3030
ENGAGE_REPORT_GROUPSACTIVITYGROUPCOUNTS: `${prefix} engage report groupsactivitygroupcounts`,
31+
ENGAGE_ROLE_LIST: `${prefix} engage role list`,
3132
ENGAGE_ROLE_MEMBER_LIST: `${prefix} engage role member list`,
3233
ENGAGE_SEARCH: `${prefix} engage search`,
3334
ENGAGE_USER_GET: `${prefix} engage user get`,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface EngageRole {
2+
id?: string;
3+
displayName?: string;
4+
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
import assert from 'assert';
2+
import sinon from 'sinon';
3+
import auth from '../../../../Auth.js';
4+
import { Logger } from '../../../../cli/Logger.js';
5+
import { CommandError } from '../../../../Command.js';
6+
import request from '../../../../request.js';
7+
import { telemetry } from '../../../../telemetry.js';
8+
import { pid } from '../../../../utils/pid.js';
9+
import { session } from '../../../../utils/session.js';
10+
import { sinonUtil } from '../../../../utils/sinonUtil.js';
11+
import commands from '../../commands.js';
12+
import command from './engage-role-list.js';
13+
14+
describe(commands.ENGAGE_ROLE_LIST, () => {
15+
let log: string[];
16+
let logger: Logger;
17+
let loggerLogSpy: sinon.SinonSpy;
18+
19+
before(() => {
20+
sinon.stub(auth, 'restoreAuth').resolves();
21+
sinon.stub(telemetry, 'trackEvent').resolves();
22+
sinon.stub(pid, 'getProcessName').returns('');
23+
sinon.stub(session, 'getId').returns('');
24+
auth.connection.active = true;
25+
});
26+
27+
beforeEach(() => {
28+
log = [];
29+
logger = {
30+
log: async (msg: string) => {
31+
log.push(msg);
32+
},
33+
logRaw: async (msg: string) => {
34+
log.push(msg);
35+
},
36+
logToStderr: async (msg: string) => {
37+
log.push(msg);
38+
}
39+
};
40+
loggerLogSpy = sinon.spy(logger, 'log');
41+
});
42+
43+
afterEach(() => {
44+
sinonUtil.restore([
45+
request.get
46+
]);
47+
});
48+
49+
after(() => {
50+
sinon.restore();
51+
auth.connection.active = false;
52+
});
53+
54+
it('has correct name', () => {
55+
assert.strictEqual(command.name, commands.ENGAGE_ROLE_LIST);
56+
});
57+
58+
it('has a description', () => {
59+
assert.notStrictEqual(command.description, null);
60+
});
61+
62+
it('defines correct properties for the default output', () => {
63+
assert.deepStrictEqual(command.defaultProperties(), ['id', 'displayName']);
64+
});
65+
66+
it(`should get a list of Viva Engage roles`, async () => {
67+
sinon.stub(request, 'get').callsFake(async (opts) => {
68+
if (opts.url === `https://graph.microsoft.com/beta/employeeExperience/roles`) {
69+
return {
70+
"value": [
71+
{
72+
"id": "ec759127-089f-4f91-8dfc-03a30b51cb38",
73+
"displayName": "Network Admin"
74+
},
75+
{
76+
"id": "966b8ec4-6457-4f22-bd3c-5a2520e98f4a",
77+
"displayName": "Verified Admin"
78+
},
79+
{
80+
"id": "77aa47ad-96fe-4ecc-8024-fd1ac5e28f17",
81+
"displayName": "Corporate Communicator"
82+
}
83+
]
84+
};
85+
}
86+
87+
throw 'Invalid request';
88+
});
89+
90+
await command.action(logger, {
91+
options: { verbose: true }
92+
});
93+
94+
assert(
95+
loggerLogSpy.calledOnceWith([
96+
{
97+
"id": "ec759127-089f-4f91-8dfc-03a30b51cb38",
98+
"displayName": "Network Admin"
99+
},
100+
{
101+
"id": "966b8ec4-6457-4f22-bd3c-5a2520e98f4a",
102+
"displayName": "Verified Admin"
103+
},
104+
{
105+
"id": "77aa47ad-96fe-4ecc-8024-fd1ac5e28f17",
106+
"displayName": "Corporate Communicator"
107+
}
108+
])
109+
);
110+
});
111+
112+
it('handles error when retrieving Viva Engage roles failed', async () => {
113+
sinon.stub(request, 'get').callsFake(async (opts) => {
114+
if (opts.url === `https://graph.microsoft.com/beta/employeeExperience/roles`) {
115+
throw { error: { message: 'An error has occurred' } };
116+
}
117+
throw `Invalid request`;
118+
});
119+
120+
await assert.rejects(
121+
command.action(logger, { options: {} }),
122+
new CommandError('An error has occurred')
123+
);
124+
});
125+
});
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Logger } from '../../../../cli/Logger.js';
2+
import { odata } from '../../../../utils/odata.js';
3+
import GraphCommand from '../../../base/GraphCommand.js';
4+
import commands from '../../commands.js';
5+
import { EngageRole } from './EngageRole.js';
6+
7+
class VivaEngageRoleListCommand extends GraphCommand {
8+
public get name(): string {
9+
return commands.ENGAGE_ROLE_LIST;
10+
}
11+
12+
public get description(): string {
13+
return 'Lists all Viva Engage roles';
14+
}
15+
16+
public defaultProperties(): string[] | undefined {
17+
return ['id', 'displayName'];
18+
}
19+
20+
public async commandAction(logger: Logger): Promise<void> {
21+
if (this.verbose) {
22+
await logger.logToStderr('Getting all Viva Engage roles...');
23+
}
24+
25+
try {
26+
const results = await odata.getAllItems<EngageRole>(`${this.resource}/beta/employeeExperience/roles`);
27+
await logger.log(results);
28+
}
29+
catch (err: any) {
30+
this.handleRejectedODataJsonPromise(err);
31+
}
32+
}
33+
}
34+
35+
export default new VivaEngageRoleListCommand();

0 commit comments

Comments
 (0)