-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
➕ Add entraGroupId and entraGroupName parameters
- Loading branch information
1 parent
6c6be23
commit 8290426
Showing
6 changed files
with
368 additions
and
27 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 |
---|---|---|
|
@@ -20,13 +20,19 @@ m365 spo folder roleassignment add [options] | |
: The server- or site-relative decoded URL of the folder. | ||
|
||
`--principalId [principalId]` | ||
: The SharePoint principal id. It may be either an user id or group id for which the role assignment will be addd. Specify either `upn`, `groupName` or `principalId` but not multiple. | ||
: The SharePoint principal id. It may be either an user id or group id for which the role assignment will be addd. Specify either `upn`, `groupName`, `principalId`, `entraGroupId` or `entraGroupName` but not multiple. | ||
|
||
`--upn [upn]` | ||
: The upn/email of the user. Specify either `upn`, `groupName` or `principalId` but not multiple. | ||
: The upn/email of the user. Specify either `upn`, `groupName`, `principalId`, `entraGroupId` or `entraGroupName` but not multiple. | ||
|
||
`--groupName [groupName]` | ||
: The Microsoft Entra or SharePoint group name. Specify either `upn`, `groupName` or `principalId` but not multiple. | ||
: The Microsoft Entra or SharePoint group name. Specify either `upn`, `groupName`, `principalId`, `entraGroupId` or `entraGroupName` but not multiple. | ||
|
||
`--entraGroupId [entraGroupId]` | ||
: ID of the Microsoft Entra group to add. Specify either `upn`, `groupName`, `principalId`, `entraGroupId` or `entraGroupName` but not multiple. | ||
|
||
`--entraGroupName [entraGroupName]` | ||
: Display name of the Microsoft Entra group to add. Specify either `upn`, `groupName`, `principalId`, `entraGroupId` or `entraGroupName` but not multiple. | ||
|
||
`--roleDefinitionId [roleDefinitionId]` | ||
: ID of the role definition. Specify either `roleDefinitionId` or `roleDefinitionName` but not both. | ||
|
@@ -63,6 +69,12 @@ Add the role assignment to the root folder based on the upn and role definition | |
m365 spo folder roleassignment add --webUrl "https://contoso.sharepoint.com/sites/contoso-sales" --folderUrl "/Shared Documents" --upn "[email protected]" --roleDefinitionName "Edit" | ||
``` | ||
|
||
Add the role assignment to the specified folder based on the Entra Group Id and role definition id. | ||
|
||
```sh | ||
m365 spo folder roleassignment add --webUrl "https://contoso.sharepoint.com/sites/contoso-sales" --folderUrl "/Shared Documents/FolderPermission" --entraGroupId '27ae47f1-48f1-46f3-980b-d3c1470e398d' --roleDefinitionId 1073741827 | ||
``` | ||
|
||
## Response | ||
|
||
The command won't return a response on success. |
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 |
---|---|---|
|
@@ -20,13 +20,19 @@ m365 spo folder roleassignment remove [options] | |
: The server- or site-relative decoded URL of the folder. | ||
|
||
`--principalId [principalId]` | ||
: The SharePoint principal id. It may be either an user id or group id for which the role assignment will be removed. Specify either `upn`, `groupName` or `principalId` but not multiple. | ||
: The SharePoint principal id. It may be either an user id or group id for which the role assignment will be removed. Specify either `upn`, `groupName`, `principalId`, `entraGroupId` or `entraGroupName` but not multiple. | ||
|
||
`--upn [upn]` | ||
: The upn/email of the user. Specify either `upn`, `groupName` or `principalId` but not multiple. | ||
: The upn/email of the user. Specify either `upn`, `groupName`, `principalId`, `entraGroupId` or `entraGroupName` but not multiple. | ||
|
||
`--groupName [groupName]` | ||
: The Microsoft Entra or SharePoint group name. Specify either `upn`, `groupName` or `principalId` but not multiple. | ||
: The Microsoft Entra or SharePoint group name. Specify either `upn`, `groupName`, `principalId`, `entraGroupId` or `entraGroupName` but not multiple. | ||
|
||
`--entraGroupId [entraGroupId]` | ||
: ID of the Microsoft Entra group to remove. Specify either `upn`, `groupName`, `principalId`, `entraGroupId` or `entraGroupName` but not multiple. | ||
|
||
`--entraGroupName [entraGroupName]` | ||
: Display name of the Microsoft Entra group to remove. Specify either `upn`, `groupName`, `principalId`, `entraGroupId` or `entraGroupName` but not multiple. | ||
|
||
`-f, --force` | ||
: Don't prompt for confirmation when removing the role assignment. | ||
|
@@ -60,6 +66,12 @@ Remove the role assignment from the specified folder based on the upn. | |
m365 spo folder roleassignment remove --webUrl "https://contoso.sharepoint.com/sites/contoso-sales" --folderUrl "/Shared Documents/FolderPermission" --upn "[email protected]" | ||
``` | ||
|
||
Remove the role assignment from the specified folder based on the Entra group id. | ||
|
||
```sh | ||
m365 spo folder roleassignment remove --webUrl "https://contoso.sharepoint.com/sites/contoso-sales" --folderUrl "/Shared Documents/FolderPermission" --entraGroupId '27ae47f1-48f1-46f3-980b-d3c1470e398d' | ||
``` | ||
|
||
## Response | ||
|
||
The command won't return a response on success. |
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 |
---|---|---|
|
@@ -16,6 +16,65 @@ import spoRoleDefinitionFolderCommand from '../roledefinition/roledefinition-lis | |
import spoUserGetCommand from '../user/user-get.js'; | ||
import spoFolderGetCommand from './folder-get.js'; | ||
import command from './folder-roleassignment-add.js'; | ||
import { entraGroup } from '../../../../utils/entraGroup.js'; | ||
import { spo } from '../../../../utils/spo.js'; | ||
|
||
const graphGroup = { | ||
id: '27ae47f1-48f1-46f3-980b-d3c1470e398d', | ||
deletedDateTime: null, | ||
classification: null, | ||
createdDateTime: '2024-03-22T20:18:37Z', | ||
creationOptions: [], | ||
description: null, | ||
displayName: 'Marketing', | ||
expirationDateTime: null, | ||
groupTypes: [ | ||
'Unified' | ||
], | ||
isAssignableToRole: null, | ||
mail: '[email protected]', | ||
mailEnabled: true, | ||
mailNickname: 'Marketing', | ||
membershipRule: null, | ||
membershipRuleProcessingState: null, | ||
onPremisesDomainName: null, | ||
onPremisesLastSyncDateTime: null, | ||
onPremisesNetBiosName: null, | ||
onPremisesSamAccountName: null, | ||
onPremisesSecurityIdentifier: null, | ||
onPremisesSyncEnabled: null, | ||
preferredDataLocation: null, | ||
preferredLanguage: null, | ||
proxyAddresses: [ | ||
'SPO:SPO_de7704ba-415d-4dd0-9bbd-fa565007a87e@SPO_18c58817-3bc9-489d-ac63-f7264fb357e5', | ||
'SMTP:[email protected]' | ||
], | ||
renewedDateTime: '2024-03-22T20:18:37Z', | ||
resourceBehaviorOptions: [], | ||
resourceProvisioningOptions: [], | ||
securityEnabled: true, | ||
securityIdentifier: 'S-1-12-1-665733105-1190349041-3268610968-2369326662', | ||
theme: null, | ||
uniqueName: null, | ||
visibility: 'Private', | ||
onPremisesProvisioningErrors: [], | ||
serviceProvisioningErrors: [] | ||
}; | ||
|
||
const entraGroupResponse = { | ||
Id: 11, | ||
IsHiddenInUI: false, | ||
LoginName: 'c:0o.c|federateddirectoryclaimprovider|27ae47f1-48f1-46f3-980b-d3c1470e398d', | ||
Title: 'Marketing members', | ||
PrincipalType: 1, | ||
Email: '', | ||
Expiration: '', | ||
IsEmailAuthenticationGuestUser: false, | ||
IsShareByEmailGuestUser: false, | ||
IsSiteAdmin: false, | ||
UserId: null, | ||
UserPrincipalName: null | ||
}; | ||
|
||
describe(commands.FOLDER_ROLEASSIGNMENT_ADD, () => { | ||
let log: any[]; | ||
|
@@ -49,7 +108,10 @@ describe(commands.FOLDER_ROLEASSIGNMENT_ADD, () => { | |
afterEach(() => { | ||
sinonUtil.restore([ | ||
request.post, | ||
cli.executeCommandWithOutput | ||
cli.executeCommandWithOutput, | ||
entraGroup.getGroupById, | ||
entraGroup.getGroupByDisplayName, | ||
spo.ensureEntraGroup | ||
]); | ||
}); | ||
|
||
|
@@ -126,6 +188,16 @@ describe(commands.FOLDER_ROLEASSIGNMENT_ADD, () => { | |
assert.notStrictEqual(actual, true); | ||
}); | ||
|
||
it('fails validation if the entraGroupId option is not a valid GUID', async () => { | ||
const actual = await command.validate({ options: { webUrl: 'https://contoso.sharepoint.com', folderUrl: '/Shared Documents/FolderPermission', entraGroupId: 'invalid', roleDefinitionId: 1073741827 } }, commandInfo); | ||
assert.notStrictEqual(actual, true); | ||
}); | ||
|
||
it('passes validation if the entraGroupId option is a valid GUID', async () => { | ||
const actual = await command.validate({ options: { webUrl: 'https://contoso.sharepoint.com', folderUrl: '/Shared Documents/FolderPermission', entraGroupId: '37455d5c-e466-4e49-8eba-808b5acec21b', roleDefinitionId: 1073741827 } }, commandInfo); | ||
assert.strictEqual(actual, true); | ||
}); | ||
|
||
it('add the role assignment to the specified folder based on the upn and role definition id', async () => { | ||
sinon.stub(request, 'post').callsFake(async (opts) => { | ||
if (opts.url === 'https://contoso.sharepoint.com/_api/web/GetFolderByServerRelativePath(DecodedUrl=\'%2FShared%20Documents%2FFolderPermission\')/ListItemAllFields/breakroleinheritance(true)') { | ||
|
@@ -384,4 +456,72 @@ describe(commands.FOLDER_ROLEASSIGNMENT_ADD, () => { | |
} | ||
} as any), new CommandError(error)); | ||
}); | ||
|
||
it('adds the role assignment to the specified root folder based on the Entra group id and role definition id', async () => { | ||
sinon.stub(entraGroup, 'getGroupById').withArgs(graphGroup.id).resolves(graphGroup); | ||
sinon.stub(spo, 'ensureEntraGroup').withArgs('https://contoso.sharepoint.com', graphGroup).resolves(entraGroupResponse); | ||
|
||
sinon.stub(request, 'post').callsFake(async (opts) => { | ||
if (opts.url === 'https://contoso.sharepoint.com/_api/web/GetList(\'%2FShared%20Documents\')/breakroleinheritance(true)') { | ||
return; | ||
} | ||
|
||
if (opts.url === 'https://contoso.sharepoint.com/_api/web/GetList(\'%2FShared%20Documents\')/roleassignments/addroleassignment(principalid=\'11\',roledefid=\'1073741827\')') { | ||
return; | ||
} | ||
|
||
throw 'Invalid request'; | ||
}); | ||
|
||
sinon.stub(cli, 'executeCommandWithOutput').callsFake(async (command): Promise<any> => { | ||
if (command === spoFolderGetCommand) { | ||
return { "Exists": true, "IsWOPIEnabled": false, "ItemCount": 0, "Name": "test1", "ProgID": null, "ServerRelativeUrl": "/Shared Documents/FolderPermission", "TimeCreated": "2018-05-02T23:21:45Z", "TimeLastModified": "2018-05-02T23:21:45Z", "UniqueId": "0ac3da45-cacf-4c31-9b38-9ef3697d5a66", "WelcomePage": "" }; | ||
} | ||
throw new CommandError('Unknown case'); | ||
}); | ||
|
||
await command.action(logger, { | ||
options: { | ||
debug: true, | ||
webUrl: 'https://contoso.sharepoint.com', | ||
folderUrl: '/Shared Documents', | ||
entraGroupId: '27ae47f1-48f1-46f3-980b-d3c1470e398d', | ||
roleDefinitionId: 1073741827 | ||
} | ||
}); | ||
}); | ||
|
||
it('adds the role assignment to the specified root folder based on the Entra group name and role definition id', async () => { | ||
sinon.stub(entraGroup, 'getGroupByDisplayName').withArgs(graphGroup.displayName).resolves(graphGroup); | ||
sinon.stub(spo, 'ensureEntraGroup').withArgs('https://contoso.sharepoint.com', graphGroup).resolves(entraGroupResponse); | ||
|
||
sinon.stub(request, 'post').callsFake(async (opts) => { | ||
if (opts.url === 'https://contoso.sharepoint.com/_api/web/GetList(\'%2FShared%20Documents\')/breakroleinheritance(true)') { | ||
return; | ||
} | ||
|
||
if (opts.url === 'https://contoso.sharepoint.com/_api/web/GetList(\'%2FShared%20Documents\')/roleassignments/addroleassignment(principalid=\'11\',roledefid=\'1073741827\')') { | ||
return; | ||
} | ||
|
||
throw 'Invalid request'; | ||
}); | ||
|
||
sinon.stub(cli, 'executeCommandWithOutput').callsFake(async (command): Promise<any> => { | ||
if (command === spoFolderGetCommand) { | ||
return { "Exists": true, "IsWOPIEnabled": false, "ItemCount": 0, "Name": "test1", "ProgID": null, "ServerRelativeUrl": "/Shared Documents/FolderPermission", "TimeCreated": "2018-05-02T23:21:45Z", "TimeLastModified": "2018-05-02T23:21:45Z", "UniqueId": "0ac3da45-cacf-4c31-9b38-9ef3697d5a66", "WelcomePage": "" }; | ||
} | ||
throw new CommandError('Unknown case'); | ||
}); | ||
|
||
await command.action(logger, { | ||
options: { | ||
debug: true, | ||
webUrl: 'https://contoso.sharepoint.com', | ||
folderUrl: '/Shared Documents', | ||
entraGroupName: 'Marketing', | ||
roleDefinitionId: 1073741827 | ||
} | ||
}); | ||
}); | ||
}); |
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.