-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
47 additions
and
283 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
|
@@ -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. | ||
|
@@ -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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 /> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 /> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: "[email protected]" | ||
} | ||
}, 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: "[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: { | ||
|
@@ -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: "[email protected]" } }, 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|[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`) { | ||
|
@@ -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`) { | ||
|
@@ -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)); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.