Skip to content

Commit

Permalink
All entra m365group commands should accept displayName option
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinM85 committed Aug 24, 2024
1 parent 262a1a1 commit 9335709
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 83 deletions.
8 changes: 4 additions & 4 deletions docs/docs/cmd/entra/m365group/m365group-conversation-list.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ m365 aad m365group conversation list [options]

```md definition-list
`-i, --groupId [groupId]`
: The ID of the Microsoft 365 Group. Specify either `groupId` or `groupDisplayName`, but not both.
: The ID of the Microsoft 365 Group. Specify either `groupId` or `groupName`, but not both.

`-n, --groupDisplayName [groupDisplayName]`
: Display name of the Microsoft 365 Group. Specify either `groupId` or `groupDisplayName`, but not both.
`-n, --groupName [groupName]`
: Display name of the Microsoft 365 Group. Specify either `groupId` or `groupName`, but not both.
```

<Global />
Expand All @@ -41,7 +41,7 @@ m365 entra m365group conversation list --groupId '00000000-0000-0000-0000-000000
Lists conversations for the Microsoft 365 group specified by displayName.

```sh
m365 entra m365group conversation list --groupDisplayName Finance
m365 entra m365group conversation list --groupName Finance
```

## Response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ m365 aad m365group conversation post list [options]

```md definition-list
`-i, --groupId [groupId]`
: The Id of the Microsoft 365 Group. You can specify the groupId or groupDisplayName, but not both.
: The Id of the Microsoft 365 Group. You can specify the groupId or groupName, but not both.

`-d, --groupDisplayName [groupDisplayName]`
: The Displayname of the Microsoft 365 Group. You can specify the groupId or groupDisplayName, but not both.
`-d, --groupName [groupName]`
: The Displayname of the Microsoft 365 Group. You can specify the groupId or groupName, but not both.

`-t, --threadId <threadId>`
: The ID of the thread to retrieve details for
Expand All @@ -41,10 +41,10 @@ Lists the posts of the specific conversation of Microsoft 365 group by groupId
m365 entra m365group conversation post list --groupId '00000000-0000-0000-0000-000000000000' --threadId 'AAQkADkwN2Q2NDg1LWQ3ZGYtNDViZi1iNGRiLTVhYjJmN2Q5NDkxZQAQAOnRAfDf71lIvrdK85FAn5E='
```

Lists the posts of the specific conversation of Microsoft 365 group by groupDisplayName
Lists the posts of the specific conversation of Microsoft 365 group by groupName

```sh
m365 entra m365group conversation post list --groupDisplayName 'MyGroup' --threadId 'AAQkADkwN2Q2NDg1LWQ3ZGYtNDViZi1iNGRiLTVhYjJmN2Q5NDkxZQAQAOnRAfDf71lIvrdK85FAn5E='
m365 entra m365group conversation post list --groupName 'MyGroup' --threadId 'AAQkADkwN2Q2NDg1LWQ3ZGYtNDViZi1iNGRiLTVhYjJmN2Q5NDkxZQAQAOnRAfDf71lIvrdK85FAn5E='
```

## Response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ m365 aad m365group recyclebinitem list [options]
## Options

```md definition-list
`-d, --groupDisplayName [groupDisplayName]`
`-d, --groupName [groupName]`
: Lists groups with DisplayName starting with the specified value

`-m, --groupMailNickname [groupMailNickname]`
Expand All @@ -41,7 +41,7 @@ m365 entra m365group recyclebinitem list
List deleted Microsoft 365 Groups with display name starting with _Project_

```sh
m365 entra m365group recyclebinitem list --groupDisplayName Project
m365 entra m365group recyclebinitem list --groupName Project
```

List deleted Microsoft 365 Groups mail nick name starting with _team_
Expand All @@ -53,7 +53,7 @@ m365 entra m365group recyclebinitem list --groupMailNickname team
List deleted Microsoft 365 Groups mail nick name starting with _team_ and with display name starting with _Project_

```sh
m365 entra m365group recyclebinitem list --groupMailNickname team --groupDisplayName Project
m365 entra m365group recyclebinitem list --groupMailNickname team --groupName Project
```

## Response
Expand Down
10 changes: 5 additions & 5 deletions docs/docs/cmd/entra/m365group/m365group-user-list.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ m365 aad m365group user list [options]

```md definition-list
`-i, --groupId [groupId]`
: The ID of the Microsoft 365 group. Specify `groupId` or `groupDisplayName` but not both.
: The ID of the Microsoft 365 group. Specify `groupId` or `groupName` but not both.

`-n, --groupDisplayName [groupDisplayName]`
: The display name of the Microsoft 365 group. Specify `groupId` or `groupDisplayName` but not both.
`-n, --groupName [groupName]`
: The display name of the Microsoft 365 group. Specify `groupId` or `groupName` but not both.

`-r, --role [role]`
: Filter the results to only users with the given role. Allowed values: `Owner`, `Member`, or (Deprecated) `Guest`.
Expand Down Expand Up @@ -54,7 +54,7 @@ m365 entra m365group user list --groupId '00000000-0000-0000-0000-000000000000'
List all owners from Microsoft 365 group specified by display name.

```sh
m365 entra m365group user list --groupDisplayName Developers --role Owner
m365 entra m365group user list --groupName Developers --role Owner
```

List specific properties for all group users from a group specified by ID.
Expand All @@ -66,7 +66,7 @@ m365 entra m365group user list --groupId 03cba9da-3974-46c1-afaf-79caa2e45bbe --
List all group members that are guest users.

```sh
m365 entra m365group user list --groupDisplayName Developers --filter "userType eq 'Guest'"
m365 entra m365group user list --groupName Developers --filter "userType eq 'Guest'"
```

## Response
Expand Down
10 changes: 5 additions & 5 deletions docs/docs/cmd/entra/m365group/m365group-user-remove.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ m365 teams user remove [options]

```md definition-list
`-i, --groupId [groupId]`
: The ID of the Microsoft 365 Group from which to remove the user. Specify either `groupId`, `groupDisplayName` or `teamId`, but not multiple.
: The ID of the Microsoft 365 Group from which to remove the user. Specify either `groupId`, `groupName` or `teamId`, but not multiple.

`--groupDisplayName [groupDisplayName]`
: Display name of the Microsoft 365 Group for which to remove the user. Specify either `groupId`, `groupDisplayName` or `teamId`, but not multiple.
`--groupName [groupName]`
: Display name of the Microsoft 365 Group for which to remove the user. Specify either `groupId`, `groupName` or `teamId`, but not multiple.

`--teamId [teamId]`
: The ID of the Microsoft Teams team from which to remove the user. Specify either `groupId`, `groupDisplayName` or `teamId`, but not multiple.
: The ID of the Microsoft Teams team from which to remove the user. Specify either `groupId`, `groupName` or `teamId`, but not multiple.

`-n, --userName <userName>`
: User's UPN (user principal name), eg. `[email protected]`
Expand All @@ -56,7 +56,7 @@ m365 entra m365group user remove --groupId '00000000-0000-0000-0000-000000000000
Removes user from the specified Microsoft 365 Group without confirmation

```sh
m365 entra m365group user remove --groupDisplayName Finance --userName '[email protected]' --force
m365 entra m365group user remove --groupName Finance --userName '[email protected]' --force
```

Removes user from the specified Microsoft Teams team
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ describe(commands.M365GROUP_CONVERSATION_LIST, () => {
));
});

it('Retrieve conversations for the group specified by groupDisplayName in the tenant (verbose)', async () => {
it('Retrieve conversations for the group specified by groupName in the tenant (verbose)', async () => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === `https://graph.microsoft.com/v1.0/groups/00000000-0000-0000-0000-000000000000/conversations`) {
return jsonOutput;
Expand All @@ -142,7 +142,7 @@ describe(commands.M365GROUP_CONVERSATION_LIST, () => {

await command.action(logger, {
options: {
verbose: true, groupDisplayName: "Finance"
verbose: true, groupName: "Finance"
}
});
assert(loggerLogSpy.calledWith(
Expand Down
14 changes: 7 additions & 7 deletions src/m365/entra/commands/m365group/m365group-conversation-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface CommandArgs {

interface Options extends GlobalOptions {
groupId?: string;
groupDisplayName?: string;
groupName?: string;
}

class EntraM365GroupConversationListCommand extends GraphCommand {
Expand Down Expand Up @@ -49,7 +49,7 @@ class EntraM365GroupConversationListCommand extends GraphCommand {
option: '-i, --groupId [groupId]'
},
{
option: '-n, --groupDisplayName [groupDisplayName]'
option: '-n, --groupName [groupName]'
}
);
}
Expand All @@ -67,25 +67,25 @@ class EntraM365GroupConversationListCommand extends GraphCommand {
}

#initOptionSets(): void {
this.optionSets.push({ options: ['groupId', 'groupDisplayName'] });
this.optionSets.push({ options: ['groupId', 'groupName'] });
}

#initTypes(): void {
this.types.string.push('groupId', 'groupDisplayName');
this.types.string.push('groupId', 'groupName');
}

public async commandAction(logger: Logger, args: CommandArgs): Promise<void> {
await this.showDeprecationWarning(logger, aadCommands.M365GROUP_CONVERSATION_LIST, commands.M365GROUP_CONVERSATION_LIST);

if (this.verbose) {
await logger.logToStderr(`Retrieving conversations for Microsoft 365 Group: ${args.options.groupId || args.options.groupDisplayName}...`);
await logger.logToStderr(`Retrieving conversations for Microsoft 365 Group: ${args.options.groupId || args.options.groupName}...`);
}

try {
let groupId = args.options.groupId;

if (args.options.groupDisplayName) {
groupId = await entraGroup.getGroupIdByDisplayName(args.options.groupDisplayName);
if (args.options.groupName) {
groupId = await entraGroup.getGroupIdByDisplayName(args.options.groupName);
}

const isUnifiedGroup = await entraGroup.isUnifiedGroup(groupId!);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ describe(commands.M365GROUP_CONVERSATION_POST_LIST, () => {
it('defines correct properties for the default output', () => {
assert.deepStrictEqual(command.defaultProperties(), ['receivedDateTime', 'id']);
});
it('fails validation if groupId and groupDisplayName specified', async () => {
it('fails validation if groupId and groupName specified', async () => {
sinon.stub(cli, 'getSettingWithDefaultValue').callsFake((settingName, defaultValue) => {
if (settingName === settingsNames.prompt) {
return false;
Expand All @@ -144,10 +144,10 @@ describe(commands.M365GROUP_CONVERSATION_POST_LIST, () => {
return defaultValue;
});

const actual = await command.validate({ options: { groupId: '1caf7dcd-7e83-4c3a-94f7-932a1299c844', groupDisplayName: 'MyGroup', threadId: '123' } }, commandInfo);
const actual = await command.validate({ options: { groupId: '1caf7dcd-7e83-4c3a-94f7-932a1299c844', groupName: 'MyGroup', threadId: '123' } }, commandInfo);
assert.notStrictEqual(actual, true);
});
it('fails validation if neither groupId nor groupDisplayName specified', async () => {
it('fails validation if neither groupId nor groupName specified', async () => {
sinon.stub(cli, 'getSettingWithDefaultValue').callsFake((settingName, defaultValue) => {
if (settingName === settingsNames.prompt) {
return false;
Expand Down Expand Up @@ -187,7 +187,7 @@ describe(commands.M365GROUP_CONVERSATION_POST_LIST, () => {
jsonOutput.value
));
});
it('Retrieve posts for the specified conversation threadId of m365 group groupDisplayName in the tenant (verbose)', async () => {
it('Retrieve posts for the specified conversation threadId of m365 group groupName in the tenant (verbose)', async () => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if ((opts.url as string).indexOf('/groups?$filter=displayName') > -1) {
return {
Expand All @@ -208,7 +208,7 @@ describe(commands.M365GROUP_CONVERSATION_POST_LIST, () => {
await command.action(logger, {
options: {
verbose: true,
groupDisplayName: "MyGroup",
groupName: "MyGroup",
threadId: "AAQkADkwN2Q2NDg1LWQ3ZGYtNDViZi1iNGRiLTVhYjJmN2Q5NDkxZQAQAOnRAfDf71lIvrdK85FAn5E="
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface CommandArgs {

interface Options extends GlobalOptions {
groupId?: string;
groupDisplayName?: string;
groupName?: string;
threadId: string;
}

Expand Down Expand Up @@ -45,7 +45,7 @@ class EntraM365GroupConversationPostListCommand extends GraphCommand {
this.telemetry.push((args: CommandArgs) => {
Object.assign(this.telemetryProperties, {
groupId: typeof args.options.groupId !== 'undefined',
groupDisplayName: typeof args.options.groupDisplayName !== 'undefined'
groupName: typeof args.options.groupName !== 'undefined'
});
});
}
Expand All @@ -56,7 +56,7 @@ class EntraM365GroupConversationPostListCommand extends GraphCommand {
option: '-i, --groupId [groupId]'
},
{
option: '-d, --groupDisplayName [groupDisplayName]'
option: '-d, --groupName [groupName]'
},
{
option: '-t, --threadId <threadId>'
Expand All @@ -77,7 +77,7 @@ class EntraM365GroupConversationPostListCommand extends GraphCommand {
}

#initOptionSets(): void {
this.optionSets.push({ options: ['groupId', 'groupDisplayName'] });
this.optionSets.push({ options: ['groupId', 'groupName'] });
}

public defaultProperties(): string[] | undefined {
Expand Down Expand Up @@ -108,7 +108,7 @@ class EntraM365GroupConversationPostListCommand extends GraphCommand {
return formatting.encodeQueryParameter(args.options.groupId);
}

const group = await entraGroup.getGroupByDisplayName(args.options.groupDisplayName!);
const group = await entraGroup.getGroupByDisplayName(args.options.groupName!);
return group.id!;
}
}
Expand Down
13 changes: 1 addition & 12 deletions src/m365/entra/commands/m365group/m365group-user-add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ interface Options extends GlobalOptions {
teamId?: string;
teamName?: string;
role?: string;
groupDisplayName?: string;
}

class EntraM365GroupUserAddCommand extends GraphCommand {
Expand Down Expand Up @@ -151,18 +150,8 @@ class EntraM365GroupUserAddCommand extends GraphCommand {
const providedGroupId: string = await this.getGroupId(logger, args);
const isUnifiedGroup = await entraGroup.isUnifiedGroup(providedGroupId);

let groupId = args.options.groupId;

if (args.options.groupDisplayName) {
groupId = await entraGroup.getGroupIdByDisplayName(args.options.groupDisplayName);
}
else if (args.options.teamId) {
groupId = args.options.teamId;
}
const isUnifiedGroup = await entraGroup.isUnifiedGroup(groupId!);

if (!isUnifiedGroup) {
throw Error(`Specified group with id '${groupId}' is not a Microsoft 365 group.`);
throw Error(`Specified group with id '${providedGroupId}' is not a Microsoft 365 group.`);
}

const userIds: string[] = await this.getUserIds(logger, args.options.ids, userNames);
Expand Down
8 changes: 4 additions & 4 deletions src/m365/entra/commands/m365group/m365group-user-list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ describe(commands.M365GROUP_USER_LIST, () => {
throw 'Invalid request';
});

await command.action(logger, { options: { verbose: true, groupDisplayName: "CLI Test Group" } });
await command.action(logger, { options: { verbose: true, groupName: "CLI Test Group" } });
assert(loggerLogSpy.calledOnceWithExactly([
{
"id": "00000000-0000-0000-0000-000000000000",
Expand Down Expand Up @@ -449,12 +449,12 @@ describe(commands.M365GROUP_USER_LIST, () => {
});

it('throws error when the group by name is not a unified group', async () => {
const groupDisplayName = 'CLI Test Group';
const groupName = 'CLI Test Group';

sinonUtil.restore(entraGroup.isUnifiedGroup);
sinon.stub(entraGroup, 'isUnifiedGroup').resolves(false);

await assert.rejects(command.action(logger, { options: { verbose: true, groupDisplayName: groupDisplayName } } as any),
new CommandError(`Specified group '${groupDisplayName}' is not a Microsoft 365 group.`));
await assert.rejects(command.action(logger, { options: { verbose: true, groupName: groupName } } as any),
new CommandError(`Specified group '${groupName}' is not a Microsoft 365 group.`));
});
});
12 changes: 6 additions & 6 deletions src/m365/entra/commands/m365group/m365group-user-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface CommandArgs {
interface Options extends GlobalOptions {
filter?: string;
groupId?: string;
groupDisplayName?: string;
groupName?: string;
properties?: string;
role?: string;
}
Expand Down Expand Up @@ -51,7 +51,7 @@ class EntraM365GroupUserListCommand extends GraphCommand {
this.telemetry.push((args: CommandArgs) => {
Object.assign(this.telemetryProperties, {
groupId: typeof args.options.groupId !== 'undefined',
groupDisplayName: typeof args.options.groupDisplayName !== 'undefined',
groupName: typeof args.options.groupName !== 'undefined',
role: typeof args.options.role !== 'undefined',
properties: typeof args.options.properties !== 'undefined',
filter: typeof args.options.filter !== 'undefined'
Expand All @@ -65,7 +65,7 @@ class EntraM365GroupUserListCommand extends GraphCommand {
option: "-i, --groupId [groupId]"
},
{
option: "-n, --groupDisplayName [groupDisplayName]"
option: "-n, --groupName [groupName]"
},
{
option: "-r, --role [type]",
Expand All @@ -83,7 +83,7 @@ class EntraM365GroupUserListCommand extends GraphCommand {
#initOptionSets(): void {
this.optionSets.push(
{
options: ['groupId', 'groupDisplayName']
options: ['groupId', 'groupName']
}
);
}
Expand Down Expand Up @@ -118,7 +118,7 @@ class EntraM365GroupUserListCommand extends GraphCommand {
const isUnifiedGroup = await entraGroup.isUnifiedGroup(groupId);

if (!isUnifiedGroup) {
throw Error(`Specified group '${args.options.groupId || args.options.groupDisplayName}' is not a Microsoft 365 group.`);
throw Error(`Specified group '${args.options.groupId || args.options.groupName}' is not a Microsoft 365 group.`);
}

let users: ExtendedUser[] = [];
Expand Down Expand Up @@ -162,7 +162,7 @@ class EntraM365GroupUserListCommand extends GraphCommand {
await logger.logToStderr('Retrieving Group Id...');
}

return await entraGroup.getGroupIdByDisplayName(options.groupDisplayName!);
return await entraGroup.getGroupIdByDisplayName(options.groupName!);
}

private async getUsers(options: Options, role: string, groupId: string, logger: Logger): Promise<ExtendedUser[]> {
Expand Down
Loading

0 comments on commit 9335709

Please sign in to comment.