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 9, 2024
1 parent bf59841 commit fa44837
Show file tree
Hide file tree
Showing 26 changed files with 762 additions and 129 deletions.
15 changes: 12 additions & 3 deletions docs/docs/cmd/entra/m365group/m365group-conversation-list.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,29 @@ m365 aad m365group conversation list [options]
## Options

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

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

<Global />

## Examples

Lists conversations for the specified Microsoft 365 group
Lists conversations for the Microsoft 365 group specified by id.

```sh
m365 entra m365group conversation list --groupId '00000000-0000-0000-0000-000000000000'
```

Lists conversations for the Microsoft 365 group specified by displayName.

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

## Response

<Tabs>
Expand Down
13 changes: 11 additions & 2 deletions docs/docs/cmd/entra/m365group/m365group-get.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ m365 aad m365group get [options]
## Options

```md definition-list
`-i, --id <id>`
: The ID of the Microsoft 365 Group or Microsoft Teams team to retrieve information for
`-i, --id [id]`
: The ID of the Microsoft 365 Group or Microsoft Teams team to retrieve information for. Specify either `id` or `displayName`, but not both.

`-n, --displayName [displayName]`
: Display name of the Microsoft 365 Group or Microsoft Teams team to retrieve information for. Specify either `id` or `displayName`, but not both.

`--includeSiteUrl`
: Set to retrieve the site URL for the group
Expand All @@ -38,6 +41,12 @@ Get information about the Microsoft 365 Group with id _1caf7dcd-7e83-4c3a-94f7-9
m365 entra m365group get --id 1caf7dcd-7e83-4c3a-94f7-932a1299c844
```

Get information about the Microsoft 365 Group with displayName _Finance_

```sh
m365 entra m365group get --displayName Finance
```

Get information about the Microsoft 365 Group with id _1caf7dcd-7e83-4c3a-94f7-932a1299c844_ and also retrieve the URL of the corresponding SharePoint site

```sh
Expand Down
11 changes: 7 additions & 4 deletions docs/docs/cmd/entra/m365group/m365group-remove.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ m365 aad m365group remove [options]
## Options

```md definition-list
`-i, --id <id>`
: The ID of the Microsoft 365 Group to remove
`-i, --id [id]`
: The ID of the Microsoft 365 Group to remove. Specify either `id` or `displayName`, but not both.

`-n, --displayName [displayName]`
: Display name of the Microsoft 365 Group to remove. Specify either `id` or `displayName`, but not both.

`-f, --force`
: Don't prompt for confirming removing the group
Expand Down Expand Up @@ -53,10 +56,10 @@ Remove group with id _28beab62-7540-4db1-a23f-29a6018a3848_. Will prompt for con
m365 entra m365group remove --id 28beab62-7540-4db1-a23f-29a6018a3848
```

Remove group with id _28beab62-7540-4db1-a23f-29a6018a3848_ without prompting for confirmation
Remove group with displayName _Finance_ without prompting for confirmation

```sh
m365 entra m365group remove --id 28beab62-7540-4db1-a23f-29a6018a3848 --force
m365 entra m365group remove --displayName 28beab62-7540-4db1-a23f-29a6018a3848 --force
```

Remove group with id _28beab62-7540-4db1-a23f-29a6018a3848_ without prompting for confirmation and without moving it to the Recycle Bin
Expand Down
13 changes: 11 additions & 2 deletions docs/docs/cmd/entra/m365group/m365group-renew.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ m365 aad m365group renew [options]
## Options

```md definition-list
`-i, --id <id>`
: The ID of the Microsoft 365 group to renew
`-i, --id [id]`
: The ID of the Microsoft 365 group to renew. Specify either `id` or `displayName`, but not both.

`-n, --displayName [displayName]`
: Display name of the Microsoft 365 Group to renew. Specify either `id` or `displayName`, but not both.
```

<Global />
Expand All @@ -37,6 +40,12 @@ Renew the Microsoft 365 group with id _28beab62-7540-4db1-a23f-29a6018a3848_
m365 entra m365group renew --id 28beab62-7540-4db1-a23f-29a6018a3848
```

Renew the Microsoft 365 group with displayName _Finance_

```sh
m365 entra m365group renew --displayName Finance
```

## Response

The command won't return a response on success.
13 changes: 11 additions & 2 deletions docs/docs/cmd/entra/m365group/m365group-teamify.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ m365 aad m365group teamify [options]

```md definition-list
`-i, --id [id]`
: The ID of the Microsoft 365 Group to connect to Microsoft Teams. Specify either id or mailNickname but not both
: The ID of the Microsoft 365 Group to connect to Microsoft Teams. Specify either `id`, `displayName` or `mailNickname`, but not multiple.

`-n, --displayName [displayName]`
: Display name of the Microsoft 365 Group to connect to Microsoft Teams. Specify either `id`, `displayName` or `mailNickname`, but not multiple.

`--mailNickname [mailNickname]`
: The mail alias of the Microsoft 365 Group to connect to Microsoft Teams. Specify either id or mailNickname but not both
: The mail alias of the Microsoft 365 Group to connect to Microsoft Teams. Specify either `id`, `displayName` or `mailNickname`, but not multiple.
```

<Global />
Expand All @@ -36,6 +39,12 @@ Creates a new Microsoft Teams team under existing Microsoft 365 group with id _e
m365 entra m365group teamify --id e3f60f99-0bad-481f-9e9f-ff0f572fbd03
```

Creates a new Microsoft Teams team under existing Microsoft 365 group with displayName _Finance_

```sh
m365 entra m365group teamify --displayName Finance
```

Creates a new Microsoft Teams team under existing Microsoft 365 group with mailNickname _GroupName_

```sh
Expand Down
15 changes: 8 additions & 7 deletions docs/docs/cmd/entra/m365group/m365group-user-add.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,27 @@ m365 entra m365group user add [options]
m365 aad m365group user add [options]
```

## Alias

```sh
m365 teams user add
m365 teams user add [options]
```

## Options

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

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

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

`-n, --userName <userName>`
: User's UPN (user principal name, eg. [email protected])

`-r, --role [role]`
: The role to be assigned to the new user: `Owner,Member`. Default `Member`
: The role to be assigned to the new user. Allowed values: `Owner`, `Member`. Default `Member`.
```

<Global />
Expand All @@ -51,7 +52,7 @@ m365 entra m365group user add --groupId '00000000-0000-0000-0000-000000000000' -
Add a new owner to the specified Microsoft 365 Group

```sh
m365 entra m365group user add --groupId '00000000-0000-0000-0000-000000000000' --userName '[email protected]' --role Owner
m365 entra m365group user add --groupDisplayName Finance --userName '[email protected]' --role Owner
```

Add a new member to the specified Microsoft Teams team
Expand Down
13 changes: 8 additions & 5 deletions docs/docs/cmd/entra/m365group/m365group-user-remove.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@ m365 aad m365group user remove [options]
```

```sh
m365 aad teams user remove
m365 teams user remove [options]
```

## Options

```md definition-list
`-i, --groupId [groupId]`
: The ID of the Microsoft 365 Group from which to remove the user
: The ID of the Microsoft 365 Group from which to remove the user. Specify either `groupId`, `groupDisplayName` 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.

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

`-n, --userName <userName>`
: User's UPN (user principal name), eg. `[email protected]`
Expand All @@ -53,13 +56,13 @@ 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 --groupId '00000000-0000-0000-0000-000000000000' --userName '[email protected]' --force
m365 entra m365group user remove --groupDisplayName Finance --userName '[email protected]' --force
```

Removes user from the specified Microsoft Teams team

```sh
m365 entra teams user remove --teamId '00000000-0000-0000-0000-000000000000' --userName '[email protected]'
m365 teams user remove --teamId '00000000-0000-0000-0000-000000000000' --userName '[email protected]'
```

## Response
Expand Down
17 changes: 10 additions & 7 deletions docs/docs/cmd/entra/m365group/m365group-user-set.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,26 @@ m365 aad m365group user set [options]
```

```sh
m365 aad teams user set
m365 teams user set [options]
```

## Options

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

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

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

`-n, --userName <userName>`
: UPN of the user for whom to update the role (eg. [email protected])

`-r, --role <role>`
: Role to set for the given user in the specified Microsoft 365 Group or Microsoft Teams team. Allowed values: `Owner`, `Member`
: Role to set for the given user in the specified Microsoft 365 Group or Microsoft Teams team. Allowed values: `Owner`, `Member`.
```

<Global />
Expand All @@ -53,19 +56,19 @@ m365 entra m365group user set --groupId '00000000-0000-0000-0000-000000000000' -
Demote the specified user from owner to member in the given Microsoft 365 Group

```sh
m365 entra m365group user set --groupId '00000000-0000-0000-0000-000000000000' --userName '[email protected]' --role Member
m365 entra m365group user set --groupDisplayName Finance --userName '[email protected]' --role Member
```

Promote the specified user to owner of the given Microsoft Teams team

```sh
m365 entra teams user set --teamId '00000000-0000-0000-0000-000000000000' --userName '[email protected]' --role Owner
m365 teams user set --teamId '00000000-0000-0000-0000-000000000000' --userName '[email protected]' --role Owner
```

Demote the specified user from owner to member in the given Microsoft Teams team

```sh
m365 entra teams user set --teamId '00000000-0000-0000-0000-000000000000' --userName '[email protected]' --role Member
m365 teams user set --teamId '00000000-0000-0000-0000-000000000000' --userName '[email protected]' --role Member
```

## Response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe(commands.M365GROUP_CONVERSATION_LIST, () => {
sinon.stub(pid, 'getProcessName').returns('');
sinon.stub(session, 'getId').returns('');
sinon.stub(entraGroup, 'isUnifiedGroup').resolves(true);
sinon.stub(entraGroup, 'getGroupIdByDisplayName').resolves('00000000-0000-0000-0000-000000000000');
auth.connection.active = true;
commandInfo = cli.getCommandInfo(command);
});
Expand Down Expand Up @@ -113,7 +114,7 @@ describe(commands.M365GROUP_CONVERSATION_LIST, () => {
assert.strictEqual(actual, true);
});

it('Retrieve conversations for the specified group by groupId in the tenant (verbose)', async () => {
it('Retrieve conversations for the group specified by groupId 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 @@ -130,6 +131,25 @@ describe(commands.M365GROUP_CONVERSATION_LIST, () => {
jsonOutput.value
));
});

it('Retrieve conversations for the group specified by groupDisplayName 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;
}
throw 'Invalid request';
});

await command.action(logger, {
options: {
verbose: true, groupDisplayName: "Finance"
}
});
assert(loggerLogSpy.calledWith(
jsonOutput.value
));
});

it('correctly handles error when listing conversations', async () => {
sinon.stub(request, 'get').rejects(new Error('An error has occurred'));

Expand Down
36 changes: 30 additions & 6 deletions src/m365/entra/commands/m365group/m365group-conversation-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ interface CommandArgs {
}

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

class EntraM365GroupConversationListCommand extends GraphCommand {
Expand All @@ -38,20 +39,25 @@ class EntraM365GroupConversationListCommand extends GraphCommand {

this.#initOptions();
this.#initValidators();
this.#initOptionSets();
this.#initTypes();
}

#initOptions(): void {
this.options.unshift(
{
option: '-i, --groupId <groupId>'
option: '-i, --groupId [groupId]'
},
{
option: '-n, --groupDisplayName [groupDisplayName]'
}
);
}

#initValidators(): void {
this.validators.push(
async (args: CommandArgs) => {
if (!validation.isValidGuid(args.options.groupId as string)) {
if (args.options.groupId && !validation.isValidGuid(args.options.groupId as string)) {
return `${args.options.groupId} is not a valid GUID`;
}

Expand All @@ -60,17 +66,35 @@ class EntraM365GroupConversationListCommand extends GraphCommand {
);
}

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

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

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

try {
const isUnifiedGroup = await entraGroup.isUnifiedGroup(args.options.groupId);
let groupId = args.options.groupId;

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

const isUnifiedGroup = await entraGroup.isUnifiedGroup(groupId!);

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

const conversations = await odata.getAllItems<Conversation>(`${this.resource}/v1.0/groups/${args.options.groupId}/conversations`);
const conversations = await odata.getAllItems<Conversation>(`${this.resource}/v1.0/groups/${groupId}/conversations`);
await logger.log(conversations);
}
catch (err: any) {
Expand Down
Loading

0 comments on commit fa44837

Please sign in to comment.