Skip to content

Commit

Permalink
Remove aad options
Browse files Browse the repository at this point in the history
  • Loading branch information
nanddeepn committed Sep 6, 2024
1 parent a868b81 commit a5a3a46
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 283 deletions.
22 changes: 8 additions & 14 deletions docs/docs/cmd/spo/group/group-member-add.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,26 @@ m365 spo group member add [options]
: Name of the SharePoint Group to which the user needs to be added. Specify either `groupId` or `groupName`.

`--userNames [userNames]`
: User's UPN (user principal name, eg. [email protected]). If multiple users need to be added, they have to be comma-separated (e.g. [email protected],[email protected]). Specify either `userIds`, `userNames`, `emails`, `aadGroupIds` or `aadGroupNames`.
: User's UPN (user principal name, eg. [email protected]). If multiple users need to be added, they have to be comma-separated (e.g. [email protected],[email protected]). Specify either `userIds`, `userNames`, `emails`, `entraGroupIds` or `entraGroupNames`.

`--emails [emails]`
: User's email (eg. [email protected]). If multiple users need to be added, they have to be comma-separated (e.g. [email protected],[email protected]). Specify either `userIds`, `userNames`, `emails`, `aadGroupIds` or `aadGroupNames`.
: User's email (eg. [email protected]). If multiple users need to be added, they have to be comma-separated (e.g. [email protected],[email protected]). Specify either `userIds`, `userNames`, `emails`, `entraGroupIds` or `entraGroupNames`.

`--userIds [userIds]`
: The user Id of the user to add as a member. (Id of the site user, for example: 14) If multiple users need to be added, the Ids have to be comma-separated. Specify either `userIds`, `userNames`, `emails`, `aadGroupIds` or `aadGroupNames`.
: The user Id of the user to add as a member. (Id of the site user, for example: 14). If multiple users need to be added, the Ids have to be comma-separated. Specify either `userIds`, `userNames`, `emails`, `entraGroupIds` or `entraGroupNames`.

`--entraGroupIds [entraGroupIds]`
: The object Id of the Entra group to add as a member. If multiple groups need to be added, the Ids have to be comma-separated. Specify either `userIds`, `userNames`, `emails`, `aadGroupIds`, `entraGroupIds`, `aadGroupNames`, or `entraGroupNames`.

`--aadGroupIds [aadGroupIds]`
: (deprecated. Use `entraGroupIds` instead) The object ID of the Microsoft Entra group to add as a member. If multiple groups need to be added, the Ids have to be comma-separated. Specify either `userIds`, `userNames`, `emails`, `aadGroupIds`, `entraGroupIds`, `aadGroupNames`, or `entraGroupNames`.
: The object Id of the Entra group to add as a member. If multiple groups need to be added, the Ids have to be comma-separated. Specify either `userIds`, `userNames`, `emails`, `entraGroupIds`or `entraGroupNames`.

`--entraGroupNames [entraGroupNames]`
: The name of the Entra group to add as a member. If multiple groups need to be added, they have to be comma-separated. Specify either `userIds`, `userNames`, `emails`, `aadGroupIds`, `entraGroupIds`, `aadGroupNames`, or `entraGroupNames`.

`--aadGroupNames [aadGroupNames]`
: (deprecated. Use `entraGroupNames` instead) The name of the Microsoft Entra group to add as a member. If multiple groups need to be added, they have to be comma-separated. Specify either `userIds`, `userNames`, `emails`, `aadGroupIds`, `entraGroupIds`, `aadGroupNames`, or `entraGroupNames`.
: The name of the Entra group to add as a member. If multiple groups need to be added, they have to be comma-separated. Specify either `userIds`, `userNames`, `emails`, `entraGroupIds` or `entraGroupNames`.
```

<Global />

## Remarks

For the `userIds`, `userNames`, `emails`, `aadGroupIds`, `entraGroupIds`, `aadGroupNames`, or `entraGroupNames` options you can specify multiple values by separating them with a comma. If one of the specified entries is not valid, the command will fail with an error message showing the list of invalid values.
For the `userIds`, `userNames`, `emails`, `entraGroupIds`, or `entraGroupNames` options you can specify multiple values by separating them with a comma. If one of the specified entries is not valid, the command will fail with an error message showing the list of invalid values.

## Examples

Expand All @@ -63,7 +57,7 @@ m365 spo group member add --webUrl https://contoso.sharepoint.com/sites/SiteA --
Add multiple users with the userNames parameter to a SharePoint group with the groupId parameter.

```sh
m365 spo group member add --webUrl https://contoso.sharepoint.com/sites/SiteA --groupId 5 --userNames "[email protected], [email protected]"
m365 spo group member add --webUrl https://contoso.sharepoint.com/sites/SiteA --groupId 5 --userNames "[email protected],[email protected]"
```

Add a user with the emails parameter to a SharePoint group with the groupName parameter.
Expand All @@ -75,7 +69,7 @@ m365 spo group member add --webUrl https://contoso.sharepoint.com/sites/SiteA --
Add multiple users with the emails parameter to a SharePoint group with the groupName parameter.

```sh
m365 spo group member add --webUrl https://contoso.sharepoint.com/sites/SiteA --groupName "Contoso Site Owners" --emails "[email protected], [email protected]"
m365 spo group member add --webUrl https://contoso.sharepoint.com/sites/SiteA --groupName "Contoso Site Owners" --emails "[email protected],[email protected]"
```

Add a user with the userIds parameter to a SharePoint group with the groupId parameter.
Expand Down
16 changes: 5 additions & 11 deletions docs/docs/cmd/spo/group/group-member-remove.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,19 @@ m365 spo group member remove [options]
: Name of the SharePoint group from which user has to be removed. Specify either `groupName` or `groupId`, but not both.

`--userName [userName]`
: The UPN (user principal name, eg. [email protected]) of the user that needs to be removed. Specify either `userName`, `email`, `userId`, `aadGroupId` or `aadGroupName`.
: The UPN (user principal name, eg. [email protected]) of the user that needs to be removed. Specify either `userName`, `email`, `userId`, `entraGroupId` or `entraGroupName`.

`--email [email]`
: The email of the user to remove as a member. Specify either `userName`, `email`, `userId`, `aadGroupId` or `aadGroupName`.
: The email of the user to remove as a member. Specify either `userName`, `email`, `userId`, `entraGroupId` or `entraGroupName`.

`--userId [userId]`
: The user Id (Id of the site user, eg. 14) of the user to remove as a member. Specify either `userName`, `email`, `userId`, `aadGroupId` or `aadGroupName`.
: The user Id (Id of the site user, eg. 14) of the user to remove as a member. Specify either `userName`, `email`, `userId`, `entraGroupId` or `entraGroupName`.

`--entraGroupId [entraGroupId]`
: The object Id of the Entra group to remove as a member. Specify either `userName`, `email`, `userId`, `aadGroupId`, `entraGroupId`, `aadGroupName`, or `entraGroupName`.

`--aadGroupId [aadGroupId]`
: (deprecated. Use `entraGroupId` instead) The object ID of the Microsoft Entra group to remove as a member. Specify either `userName`, `email`, `userId`, `aadGroupId`, `entraGroupId`, `aadGroupName`, or `entraGroupName`.
: The object Id of the Entra group to remove as a member. Specify either `userName`, `email`, `userId`, `entraGroupId`, or `entraGroupName`.

`--entraGroupName [entraGroupName]`
: The name of the Entra group to remove as a member. Specify either `userName`, `email`, `userId`, `aadGroupId`, `entraGroupId`, `aadGroupName`, or `entraGroupName`.

`--aadGroupName [aadGroupName]`
: (deprecated. Use `entraGroupName` instead) The name of the Microsoft Entra group to remove as a member. Specify either `userName`, `email`, `userId`, `aadGroupId`, `entraGroupId`, `aadGroupName`, or `entraGroupName`.
: The name of the Entra group to remove as a member. Specify either `userName`, `email`, `userId`, `entraGroupId`, or `entraGroupName`.
```

<Global />
Expand Down
7 changes: 2 additions & 5 deletions docs/docs/cmd/spo/user/user-ensure.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@ m365 spo user ensure [options]
: Absolute URL of the site.

`--entraId [--entraId]`
: Id of the user in Entra. Specify either `aadId`, `entraId`, or `userName`.

`--aadId [--aadId]`
: (deprecated. Use `entraId` instead) Id of the user in Microsoft Entra. Specify either `aadId`, `entraId`, or `userName`.
: Id of the user in Entra. Specify either `entraId` or `userName`.

`--userName [userName]`
: User's UPN (user principal name, e.g. [email protected]). Specify either `aadId`, `entraId`, or `userName`.
: User's UPN (user principal name, e.g. [email protected]). Specify either `entraId` or `userName`.
```

<Global />
Expand Down
103 changes: 27 additions & 76 deletions src/m365/spo/commands/group/group-member-add.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CommandInfo } from '../../../../cli/CommandInfo.js';
import { Logger } from '../../../../cli/Logger.js';
import request from '../../../../request.js';
import { telemetry } from '../../../../telemetry.js';
import { formatting } from '../../../../utils/formatting.js';
import { pid } from '../../../../utils/pid.js';
import { session } from '../../../../utils/session.js';
import { sinonUtil } from '../../../../utils/sinonUtil.js';
Expand Down Expand Up @@ -163,7 +164,7 @@ describe(commands.GROUP_MEMBER_ADD, () => {

//#region Option values
const webUrl = 'https://contoso.sharepoint.com/sites/Marketing';
const spGroupName = 'Marketing Site Owners';
const spGroupName = "Contoso Site Owners";
const spGroupId = 3;
const spUserIds = userResponses.map(u => u.Id);
const userNames = userResponses.map(u => u.UserPrincipalName);
Expand Down Expand Up @@ -231,7 +232,7 @@ describe(commands.GROUP_MEMBER_ADD, () => {
options: {
webUrl: "https://contoso.sharepoint.com/sites/SiteA",
groupId: 32,
groupName: "Contoso Site Owners",
groupName: spGroupName,
userNames: "[email protected]"
}
}, commandInfo);
Expand Down Expand Up @@ -284,18 +285,6 @@ describe(commands.GROUP_MEMBER_ADD, () => {
assert.notStrictEqual(actual, true);
});

it('fails validation if both emails and aadGroupIds options are passed', async () => {
const actual = await command.validate({
options: {
webUrl: "https://contoso.sharepoint.com/sites/SiteA",
groupId: 32,
emails: "[email protected]",
aadGroupIds: "56ca9023-3449-4e98-a96a-69e81a6f4983"
}
}, commandInfo);
assert.notStrictEqual(actual, true);
});

it('fails validation if both userIds and entraGroupNames options are passed', async () => {
const actual = await command.validate({
options: {
Expand All @@ -308,18 +297,6 @@ describe(commands.GROUP_MEMBER_ADD, () => {
assert.notStrictEqual(actual, true);
});

it('fails validation if both userIds and aadGroupNames options are passed', async () => {
const actual = await command.validate({
options: {
webUrl: "https://contoso.sharepoint.com/sites/SiteA",
groupId: 32,
userIds: 5,
aadGroupNames: "Microsoft Entra Group name"
}
}, commandInfo);
assert.notStrictEqual(actual, true);
});

it('fails validation if both userIds and emails options are passed', async () => {
const actual = await command.validate({
options: {
Expand All @@ -332,7 +309,7 @@ describe(commands.GROUP_MEMBER_ADD, () => {
assert.notStrictEqual(actual, true);
});

it('fails validation if userNames, emails, userIds, entraGroupIds, aadGroupIds, entraGroupNames, or aadGroupNames options are not passed', async () => {
it('fails validation if userNames, emails, userIds, entraGroupIds, or entraGroupNames options are not passed', async () => {
const actual = await command.validate({
options: {
webUrl: "https://contoso.sharepoint.com/sites/SiteA",
Expand Down Expand Up @@ -372,11 +349,6 @@ describe(commands.GROUP_MEMBER_ADD, () => {
assert.notStrictEqual(actual, true);
});

it('fails validation if aadGroupIds is Invalid', async () => {
const actual = await command.validate({ options: { webUrl: "https://contoso.sharepoint.com/sites/SiteA", groupId: 32, aadGroupIds: "56ca9023-3449-4e98-a96a-69e81a6f4983,9" } }, commandInfo);
assert.notStrictEqual(actual, true);
});

it('passes validation if all the required options are specified', async () => {
const actual = await command.validate({ options: { webUrl: "https://contoso.sharepoint.com/sites/SiteA", groupId: 32, userNames: "[email protected]" } }, commandInfo);
assert.strictEqual(actual, true);
Expand All @@ -386,28 +358,6 @@ describe(commands.GROUP_MEMBER_ADD, () => {
assert.deepStrictEqual(command.defaultProperties(), ['Title', 'UserPrincipalName']);
});

it('correctly logs deprecation warning for aadGroupIds option', async () => {
const chalk = (await import('chalk')).default;
const loggerErrSpy = sinon.spy(logger, 'logToStderr');
sinon.stub(request, 'post').resolves();

await command.action(logger, { options: { webUrl: webUrl, groupName: spGroupName, aadGroupIds: entraGroupIds[0] } });
assert.deepStrictEqual(loggerErrSpy.firstCall.firstArg, chalk.yellow(`Option 'aadGroupIds' is deprecated. Please use 'entraGroupIds' instead.`));

sinonUtil.restore(loggerErrSpy);
});

it('correctly logs deprecation warning for aadGroupNames option', async () => {
const chalk = (await import('chalk')).default;
const loggerErrSpy = sinon.spy(logger, 'logToStderr');
sinon.stub(request, 'post').resolves();

await command.action(logger, { options: { webUrl: webUrl, groupName: spGroupName, aadGroupNames: entraGroupNames[0] } });
assert.deepStrictEqual(loggerErrSpy.firstCall.firstArg, chalk.yellow(`Option 'aadGroupNames' is deprecated. Please use 'entraGroupNames' instead.`));

sinonUtil.restore(loggerErrSpy);
});

it('correctly logs result when adding users by userNames', async () => {
const postStub = sinon.stub(request, 'post').callsFake(async (opts) => {
if (opts.url === `${webUrl}/_api/web/SiteGroups/GetById(${spGroupId})/users`) {
Expand All @@ -428,27 +378,6 @@ describe(commands.GROUP_MEMBER_ADD, () => {
assert(loggerLogSpy.calledOnceWithExactly(userResponses));
});

it('correctly adds users to group by UPNs', async () => {
const postStub = sinon.stub(request, 'post').callsFake(async (opts) => {
if (opts.url === `${webUrl}/_api/web/SiteGroups/GetById(${spGroupId})/users`) {
return userResponses[postStub.callCount - 1];
}

throw 'Invalid request: ' + opts.url;
});

await command.action(logger, {
options: {
webUrl: webUrl,
groupId: spGroupId,
userNames: userNames.join(',')
}
});

assert.deepStrictEqual(postStub.firstCall.args[0].data, { LoginName: 'i:0#.f|membership|[email protected]' });
assert.deepStrictEqual(postStub.secondCall.args[0].data, { LoginName: 'i:0#.f|membership|[email protected]' });
});

it('correctly adds users to group by emails', async () => {
const postStub = sinon.stub(request, 'post').callsFake(async (opts) => {
if (opts.url === `${webUrl}/_api/web/SiteGroups/GetById(${spGroupId})/users`) {
Expand Down Expand Up @@ -544,6 +473,28 @@ describe(commands.GROUP_MEMBER_ADD, () => {
assert.deepStrictEqual(postStub.secondCall.args[0].data, { LoginName: `c:0t.c|tenant|${entraGroupResponses[1].id}` });
});

it('correctly adds user to a group by groupName and emails (DEBUG)', async () => {
const postStub = sinon.stub(request, 'post').callsFake(async (opts) => {
if (opts.url === `${webUrl}/_api/web/SiteGroups/GetByName('${formatting.encodeQueryParameter(spGroupName)}')/users`) {
return groupResponses[postStub.callCount - 1];
}

throw 'Invalid request: ' + opts.url;
});

await command.action(logger, {
options: {
debug: true,
webUrl: webUrl,
groupName: spGroupName,
emails: emails.join(',')
}
});

assert.deepStrictEqual(postStub.firstCall.args[0].data, { LoginName: 'i:0#.f|membership|[email protected]' });
assert.deepStrictEqual(postStub.secondCall.args[0].data, { LoginName: 'i:0#.f|membership|[email protected]' });
});

it('correctly adds users to group by entraGroupNames', async () => {
const postStub = sinon.stub(request, 'post').callsFake(async (opts) => {
if (opts.url === `${webUrl}/_api/web/SiteGroups/GetById(${spGroupId})/users`) {
Expand Down Expand Up @@ -584,4 +535,4 @@ describe(commands.GROUP_MEMBER_ADD, () => {
await assert.rejects(command.action(logger, { options: { webUrl: webUrl, groupId: spGroupId, userNames: userNames.join(',') } }),
new CommandError(error.error['odata.error'].message.value));
});
});
});
35 changes: 3 additions & 32 deletions src/m365/spo/commands/group/group-member-add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ interface Options extends GlobalOptions {
emails?: string;
userIds?: string;
entraGroupIds?: string;
aadGroupIds?: string;
entraGroupNames?: string;
aadGroupNames?: string;
}

class SpoGroupMemberAddCommand extends SpoCommand {
Expand Down Expand Up @@ -57,9 +55,7 @@ class SpoGroupMemberAddCommand extends SpoCommand {
emails: typeof args.options.emails !== 'undefined',
userIds: typeof args.options.userIds !== 'undefined',
entraGroupIds: typeof args.options.entraGroupIds !== 'undefined',
aadGroupIds: typeof args.options.aadGroupIds !== 'undefined',
entraGroupNames: typeof args.options.entraGroupNames !== 'undefined',
aadGroupNames: typeof args.options.aadGroupNames !== 'undefined'
entraGroupNames: typeof args.options.entraGroupNames !== 'undefined'
});
});
}
Expand Down Expand Up @@ -87,14 +83,8 @@ class SpoGroupMemberAddCommand extends SpoCommand {
{
option: '--entraGroupIds [entraGroupIds]'
},
{
option: '--aadGroupIds [aadGroupIds]'
},
{
option: '--entraGroupNames [entraGroupNames]'
},
{
option: '--aadGroupNames [aadGroupNames]'
}
);
}
Expand Down Expand Up @@ -139,13 +129,6 @@ class SpoGroupMemberAddCommand extends SpoCommand {
}
}

if (args.options.aadGroupIds) {
const isValidArray = validation.isValidGuidArray(args.options.aadGroupIds);
if (isValidArray !== true) {
return `Option 'aadGroupIds' contains one or more invalid GUIDs: ${isValidArray}.`;
}
}

return true;
}
);
Expand All @@ -154,28 +137,16 @@ class SpoGroupMemberAddCommand extends SpoCommand {
#initOptionSets(): void {
this.optionSets.push(
{ options: ['groupId', 'groupName'] },
{ options: ['userNames', 'emails', 'userIds', 'entraGroupIds', 'aadGroupIds', 'entraGroupNames', 'aadGroupNames'] }
{ options: ['userNames', 'emails', 'userIds', 'entraGroupIds', 'entraGroupNames'] }
);
}

#initTypes(): void {
this.types.string.push('webUrl', 'groupName', 'userNames', 'emails', 'userIds', 'entraGroupIds', 'aadGroupIds', 'entraGroupNames', 'aadGroupNames');
this.types.string.push('webUrl', 'groupName', 'userNames', 'emails', 'userIds', 'entraGroupIds', 'entraGroupNames');
}

public async commandAction(logger: Logger, args: CommandArgs): Promise<void> {
try {
if (args.options.aadGroupIds) {
args.options.entraGroupIds = args.options.aadGroupIds;

await this.warn(logger, `Option 'aadGroupIds' is deprecated. Please use 'entraGroupIds' instead.`);
}

if (args.options.aadGroupNames) {
args.options.entraGroupNames = args.options.aadGroupNames;

await this.warn(logger, `Option 'aadGroupNames' is deprecated. Please use 'entraGroupNames' instead.`);
}

const loginNames = await this.getLoginNames(logger, args.options);

let apiUrl = `${args.options.webUrl}/_api/web/SiteGroups`;
Expand Down
Loading

0 comments on commit a5a3a46

Please sign in to comment.