From 18543dfa2a87a78674f623dc697504d422ed2194 Mon Sep 17 00:00:00 2001 From: Nanddeep Nachan Date: Fri, 12 Jul 2024 10:01:07 +0000 Subject: [PATCH 1/2] Remove aad options --- docs/docs/cmd/spo/group/group-member-add.mdx | 22 ++-- .../cmd/spo/group/group-member-remove.mdx | 16 +-- docs/docs/cmd/spo/user/user-ensure.mdx | 7 +- .../commands/group/group-member-add.spec.ts | 103 +++++------------- .../spo/commands/group/group-member-add.ts | 35 +----- .../group/group-member-remove.spec.ts | 75 ------------- .../spo/commands/group/group-member-remove.ts | 28 +---- .../spo/commands/user/user-ensure.spec.ts | 27 ----- src/m365/spo/commands/user/user-ensure.ts | 17 +-- 9 files changed, 47 insertions(+), 283 deletions(-) diff --git a/docs/docs/cmd/spo/group/group-member-add.mdx b/docs/docs/cmd/spo/group/group-member-add.mdx index 090310f31f3..8973044ffc7 100644 --- a/docs/docs/cmd/spo/group/group-member-add.mdx +++ b/docs/docs/cmd/spo/group/group-member-add.mdx @@ -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. megan.bowen@contoso.com). If multiple users need to be added, they have to be comma-separated (e.g. megan.bowen@contoso.com,alex.wilber@contoso.com). Specify either `userIds`, `userNames`, `emails`, `aadGroupIds` or `aadGroupNames`. +: User's UPN (user principal name, eg. megan.bowen@contoso.com). If multiple users need to be added, they have to be comma-separated (e.g. megan.bowen@contoso.com,alex.wilber@contoso.com). Specify either `userIds`, `userNames`, `emails`, `entraGroupIds` or `entraGroupNames`. `--emails [emails]` -: User's email (eg. megan.bowen@contoso.com). If multiple users need to be added, they have to be comma-separated (e.g. megan.bowen@contoso.com,alex.wilber@contoso.com). Specify either `userIds`, `userNames`, `emails`, `aadGroupIds` or `aadGroupNames`. +: User's email (eg. megan.bowen@contoso.com). If multiple users need to be added, they have to be comma-separated (e.g. megan.bowen@contoso.com,alex.wilber@contoso.com). 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`. ``` ## 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 @@ -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 "Alex.Wilber@contoso.com, Adele.Vance@contoso.com" +m365 spo group member add --webUrl https://contoso.sharepoint.com/sites/SiteA --groupId 5 --userNames "Alex.Wilber@contoso.com,Adele.Vance@contoso.com" ``` Add a user with the emails parameter to a SharePoint group with the groupName parameter. @@ -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 "Alex.Wilber@contoso.com, Adele.Vance@contoso.com" +m365 spo group member add --webUrl https://contoso.sharepoint.com/sites/SiteA --groupName "Contoso Site Owners" --emails "Alex.Wilber@contoso.com,Adele.Vance@contoso.com" ``` Add a user with the userIds parameter to a SharePoint group with the groupId parameter. diff --git a/docs/docs/cmd/spo/group/group-member-remove.mdx b/docs/docs/cmd/spo/group/group-member-remove.mdx index 4b2adc95922..7ed285b92d8 100644 --- a/docs/docs/cmd/spo/group/group-member-remove.mdx +++ b/docs/docs/cmd/spo/group/group-member-remove.mdx @@ -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. megan.bowen@contoso.com) of the user that needs to be removed. Specify either `userName`, `email`, `userId`, `aadGroupId` or `aadGroupName`. +: The UPN (user principal name, eg. megan.bowen@contoso.com) 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`. ``` diff --git a/docs/docs/cmd/spo/user/user-ensure.mdx b/docs/docs/cmd/spo/user/user-ensure.mdx index 077838c0c41..12551b5ef98 100644 --- a/docs/docs/cmd/spo/user/user-ensure.mdx +++ b/docs/docs/cmd/spo/user/user-ensure.mdx @@ -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. john@contoso.com). Specify either `aadId`, `entraId`, or `userName`. +: User's UPN (user principal name, e.g. john@contoso.com). Specify either `entraId` or `userName`. ``` diff --git a/src/m365/spo/commands/group/group-member-add.spec.ts b/src/m365/spo/commands/group/group-member-add.spec.ts index 03b31d42482..c264f73d894 100644 --- a/src/m365/spo/commands/group/group-member-add.spec.ts +++ b/src/m365/spo/commands/group/group-member-add.spec.ts @@ -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'; @@ -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); @@ -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: "Alex.Wilber@contoso.com" } }, commandInfo); @@ -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: "Alex.Wilber@contoso.com", - 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: { @@ -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: { @@ -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", @@ -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: "Alex.Wilber@contoso.com" } }, commandInfo); assert.strictEqual(actual, true); @@ -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`) { @@ -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|adelev@contoso.onmicrosoft.com' }); - assert.deepStrictEqual(postStub.secondCall.args[0].data, { LoginName: 'i:0#.f|membership|johnd@contoso.onmicrosoft.com' }); - }); - 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`) { @@ -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|Adele.Vance@contoso.onmicrosoft.com' }); + assert.deepStrictEqual(postStub.secondCall.args[0].data, { LoginName: 'i:0#.f|membership|John.Doe@contoso.onmicrosoft.com' }); + }); + 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`) { @@ -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)); }); -}); +}); \ No newline at end of file diff --git a/src/m365/spo/commands/group/group-member-add.ts b/src/m365/spo/commands/group/group-member-add.ts index 52779256bd9..fabe2e128ab 100644 --- a/src/m365/spo/commands/group/group-member-add.ts +++ b/src/m365/spo/commands/group/group-member-add.ts @@ -20,9 +20,7 @@ interface Options extends GlobalOptions { emails?: string; userIds?: string; entraGroupIds?: string; - aadGroupIds?: string; entraGroupNames?: string; - aadGroupNames?: string; } class SpoGroupMemberAddCommand extends SpoCommand { @@ -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' }); }); } @@ -87,14 +83,8 @@ class SpoGroupMemberAddCommand extends SpoCommand { { option: '--entraGroupIds [entraGroupIds]' }, - { - option: '--aadGroupIds [aadGroupIds]' - }, { option: '--entraGroupNames [entraGroupNames]' - }, - { - option: '--aadGroupNames [aadGroupNames]' } ); } @@ -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; } ); @@ -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 { 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`; diff --git a/src/m365/spo/commands/group/group-member-remove.spec.ts b/src/m365/spo/commands/group/group-member-remove.spec.ts index 84ecd5fa54c..cbccf4c3882 100644 --- a/src/m365/spo/commands/group/group-member-remove.spec.ts +++ b/src/m365/spo/commands/group/group-member-remove.spec.ts @@ -130,40 +130,6 @@ describe(commands.GROUP_MEMBER_REMOVE, () => { assert(postStub.called); }); - it('Removes Microsoft Entra group from SharePoint group using Microsoft Entra Group Name', async () => { - sinonUtil.restore(cli.promptForConfirmation); - sinon.stub(cli, 'promptForConfirmation').resolves(true); - - sinon.stub(cli, 'executeCommandWithOutput').callsFake(async (command): Promise => { - if (command === spoGroupMemberListCommand) { - return ({ - stdout: spoGroupMemberListCommandOutput - }); - } - - throw new CommandError('Unknown case'); - }); - - const postStub = sinon.stub(request, 'post').callsFake(async opts => { - if ((opts.url as string).indexOf('/_api/web/sitegroups/GetByName') > -1) { - return UserRemovalJSONResponse; - } - - throw `Invalid request ${JSON.stringify(opts)}`; - }); - - await command.action(logger, { - options: { - debug: true, - webUrl: "https://contoso.sharepoint.com/sites/SiteA", - groupName: "Site A Visitors", - aadGroupName: "Microsoft Entra Security Group" - } - }); - - assert(postStub.called); - }); - it('Removes Entra group from SharePoint group using Entra Group ID - Without Confirmation Prompt', async () => { sinon.stub(cli, 'executeCommandWithOutput').callsFake(async (command): Promise => { if (command === spoGroupMemberListCommand) { @@ -194,36 +160,6 @@ describe(commands.GROUP_MEMBER_REMOVE, () => { assert(postStub.called); }); - it('Removes Microsoft Entra group from SharePoint group using Microsoft Entra Group ID - Without Confirmation Prompt', async () => { - sinon.stub(cli, 'executeCommandWithOutput').callsFake(async (command): Promise => { - if (command === spoGroupMemberListCommand) { - return ({ - stdout: spoGroupMemberListCommandOutput - }); - } - - throw new CommandError('Unknown case'); - }); - - const postStub = sinon.stub(request, 'post').callsFake(async opts => { - if ((opts.url as string).indexOf('/_api/web/sitegroups/GetByName') > -1) { - return UserRemovalJSONResponse; - } - - throw `Invalid request ${JSON.stringify(opts)}`; - }); - await command.action(logger, { - options: { - debug: true, - webUrl: "https://contoso.sharepoint.com/sites/SiteA", - groupName: "Site A Visitors", - aadGroupId: "5786b8e8-c495-4734-b345-756733960730", - force: true - } - }); - assert(postStub.called); - }); - it('Removes Entra group from SharePoint group using Entra Group ID and SharePoint Group ID', async () => { sinonUtil.restore(cli.promptForConfirmation); sinon.stub(cli, 'promptForConfirmation').resolves(true); @@ -710,15 +646,4 @@ describe(commands.GROUP_MEMBER_REMOVE, () => { }, commandInfo); assert.notStrictEqual(actual, true); }); - - it('fails validation if aadGroupId is not a valid guid.', async () => { - const actual = await command.validate({ - options: { - webUrl: "https://contoso.sharepoint.com/sites/SiteA", - groupId: 3, - aadGroupId: 'Invalid GUID' - } - }, commandInfo); - assert.notStrictEqual(actual, true); - }); }); \ No newline at end of file diff --git a/src/m365/spo/commands/group/group-member-remove.ts b/src/m365/spo/commands/group/group-member-remove.ts index 4ea58a7bc06..420a5b09d83 100644 --- a/src/m365/spo/commands/group/group-member-remove.ts +++ b/src/m365/spo/commands/group/group-member-remove.ts @@ -22,9 +22,7 @@ interface Options extends GlobalOptions { email?: string; userId?: number; entraGroupId?: string; - aadGroupId?: string; entraGroupName?: string; - aadGroupName?: string; force?: boolean; } @@ -55,9 +53,7 @@ class SpoGroupMemberRemoveCommand extends SpoCommand { email: (!(!args.options.email)).toString(), userId: (!(!args.options.userId)).toString(), entraGroupId: (!(!args.options.entraGroupId)).toString(), - aadGroupId: (!(!args.options.groupId)).toString(), entraGroupName: (!(!args.options.entraGroupName)).toString(), - aadGroupName: (!(!args.options.aadGroupName)).toString(), force: (!(!args.options.force)).toString() }); }); @@ -86,15 +82,9 @@ class SpoGroupMemberRemoveCommand extends SpoCommand { { option: '--entraGroupId [entraGroupId]' }, - { - option: '--aadGroupId [aadGroupId]' - }, { option: '--entraGroupName [entraGroupName]' }, - { - option: '--aadGroupName [aadGroupName]' - }, { option: '-f, --force' } @@ -124,10 +114,6 @@ class SpoGroupMemberRemoveCommand extends SpoCommand { return `${args.options.entraGroupId} is not a valid GUID`; } - if (args.options.aadGroupId && !validation.isValidGuid(args.options.aadGroupId as string)) { - return `${args.options.aadGroupId} is not a valid GUID`; - } - return validation.isValidSharePointUrl(args.options.webUrl); } ); @@ -136,7 +122,7 @@ class SpoGroupMemberRemoveCommand extends SpoCommand { #initOptionSets(): void { this.optionSets.push( { options: ['groupName', 'groupId'] }, - { options: ['userName', 'email', 'userId', 'entraGroupId', 'aadGroupId', 'entraGroupName', 'aadGroupName'] } + { options: ['userName', 'email', 'userId', 'entraGroupId', 'entraGroupName'] } ); } @@ -162,18 +148,6 @@ class SpoGroupMemberRemoveCommand extends SpoCommand { } public async commandAction(logger: Logger, args: CommandArgs): Promise { - if (args.options.aadGroupId) { - args.options.entraGroupId = args.options.aadGroupId; - - await this.warn(logger, `Option 'aadGroupId' is deprecated. Please use 'entraGroupId' instead`); - } - - if (args.options.aadGroupName) { - args.options.entraGroupName = args.options.aadGroupName; - - await this.warn(logger, `Option 'aadGroupName' is deprecated. Please use 'entraGroupName' instead`); - } - if (args.options.force) { if (this.debug) { await logger.logToStderr('Confirmation bypassed by entering confirm option. Removing the user from SharePoint Group...'); diff --git a/src/m365/spo/commands/user/user-ensure.spec.ts b/src/m365/spo/commands/user/user-ensure.spec.ts index c9f99d0ded8..9e8382f0723 100644 --- a/src/m365/spo/commands/user/user-ensure.spec.ts +++ b/src/m365/spo/commands/user/user-ensure.spec.ts @@ -116,23 +116,6 @@ describe(commands.USER_ENSURE, () => { assert(loggerLogSpy.calledWith(ensuredUserResponse)); }); - it('ensures user for a specific web by aadId', async () => { - sinon.stub(entraUser, 'getUpnByUserId').callsFake(async () => { - return validUserName; - }); - - sinon.stub(request, 'post').callsFake(async (opts) => { - if (opts.url === `${validWebUrl}/_api/web/ensureuser`) { - return ensuredUserResponse; - } - - throw 'Invalid request'; - }); - - await command.action(logger, { options: { verbose: true, webUrl: validWebUrl, aadId: validEntraId } }); - assert(loggerLogSpy.calledWith(ensuredUserResponse)); - }); - it('throws error message when no user was found with a specific id', async () => { sinon.stub(entraUser, 'getUpnByUserId').callsFake(async (id) => { throw { @@ -186,11 +169,6 @@ describe(commands.USER_ENSURE, () => { assert.notStrictEqual(actual, true); }); - it('fails validation if aadId is not a valid id', async () => { - const actual = await command.validate({ options: { webUrl: validWebUrl, aadId: 'invalid' } }, commandInfo); - assert.notStrictEqual(actual, true); - }); - it('fails validation if userName is not a valid user principal name', async () => { const actual = await command.validate({ options: { webUrl: validWebUrl, userName: 'invalid' } }, commandInfo); assert.notStrictEqual(actual, true); @@ -201,11 +179,6 @@ describe(commands.USER_ENSURE, () => { assert.strictEqual(actual, true); }); - it('passes validation if the url is valid and aadId is a valid id', async () => { - const actual = await command.validate({ options: { webUrl: validWebUrl, aadId: validEntraId } }, commandInfo); - assert.strictEqual(actual, true); - }); - it('passes validation if the url is valid and userName is a valid user principal name', async () => { const actual = await command.validate({ options: { webUrl: validWebUrl, userName: validUserName } }, commandInfo); assert.strictEqual(actual, true); diff --git a/src/m365/spo/commands/user/user-ensure.ts b/src/m365/spo/commands/user/user-ensure.ts index 7a624851303..c4f681d15aa 100644 --- a/src/m365/spo/commands/user/user-ensure.ts +++ b/src/m365/spo/commands/user/user-ensure.ts @@ -13,7 +13,6 @@ interface CommandArgs { interface Options extends GlobalOptions { webUrl: string; entraId?: string; - aadId?: string; userName?: string; } @@ -39,7 +38,6 @@ class SpoUserEnsureCommand extends SpoCommand { this.telemetry.push((args: CommandArgs) => { Object.assign(this.telemetryProperties, { entraId: typeof args.options.entraId !== 'undefined', - aadId: typeof args.options.aadId !== 'undefined', userName: typeof args.options.userName !== 'undefined' }); }); @@ -53,9 +51,6 @@ class SpoUserEnsureCommand extends SpoCommand { { option: '--entraId [entraId]' }, - { - option: '--aadId [aadId]' - }, { option: '--userName [userName]' } @@ -74,10 +69,6 @@ class SpoUserEnsureCommand extends SpoCommand { return `${args.options.entraId} is not a valid GUID.`; } - if (args.options.aadId && !validation.isValidGuid(args.options.aadId)) { - return `${args.options.aadId} is not a valid GUID.`; - } - if (args.options.userName && !validation.isValidUserPrincipalName(args.options.userName)) { return `${args.options.userName} is not a valid userName.`; } @@ -88,16 +79,10 @@ class SpoUserEnsureCommand extends SpoCommand { } #initOptionSets(): void { - this.optionSets.push({ options: ['entraId', 'aadId', 'userName'] }); + this.optionSets.push({ options: ['entraId', 'userName'] }); } public async commandAction(logger: Logger, args: CommandArgs): Promise { - if (args.options.aadId) { - args.options.entraId = args.options.aadId; - - await this.warn(logger, `Option 'aadId' is deprecated. Please use 'entraId' instead`); - } - if (this.verbose) { await logger.logToStderr(`Ensuring user ${args.options.entraId || args.options.userName} at site ${args.options.webUrl}`); } From 2c1922cbf7918fde673bd0be739fd642ce4100a9 Mon Sep 17 00:00:00 2001 From: Nanddeep Nachan Date: Fri, 9 Aug 2024 17:10:23 +0000 Subject: [PATCH 2/2] v9 guidance --- docs/docs/v9-upgrade-guidance.mdx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 docs/docs/v9-upgrade-guidance.mdx diff --git a/docs/docs/v9-upgrade-guidance.mdx b/docs/docs/v9-upgrade-guidance.mdx new file mode 100644 index 00000000000..a151907295d --- /dev/null +++ b/docs/docs/v9-upgrade-guidance.mdx @@ -0,0 +1,16 @@ +# v9 Upgrade Guidance + +The v9 of CLI for Microsoft 365 introduces several breaking changes. To help you upgrade to the latest version of CLI for Microsoft 365, we've listed those changes along with any actions you may need to take. + +## SharePoint + +### Renamed `aad` options in `spo group member add`, `spo group member remove`, and `spo user ensure` commands + +For this new major version, we've Removed `aad` options in below spo commands: + - Renamed `--aadGroupIds` and `--aadGroupNames` option to `--entraGroupIds' and `--entraGroupNames` in `spo group member add`. + - Renamed `--aadGroupIds` and `--aadGroupNames` option to `--entraGroupIds' and '--entraGroupNames' in 'spo group member remove'. + - Renamed `--aadId` option to `--entraId` in `spo user ensure`. + +#### What action do I need to take? + +Please, check the documentation of the [spo group member add](./cmd/spo/group/group-member-add.mdx), [spo group member remove](./cmd/spo/group/group-member-remove.mdx), and [spo user ensure](./cmd/spo/user/user-ensure.mdx) command to see the updated options and adjust your scripts accordingly.