Adds 'spo file roleassignment list' command. Closes #6191#7280
Open
nanddeepn wants to merge 2 commits into
Open
Adds 'spo file roleassignment list' command. Closes #6191#7280nanddeepn wants to merge 2 commits into
nanddeepn wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds the ability to list SharePoint file role assignments via a new command and centralizes file/permissions retrieval logic in the spo utility.
Changes:
- Updated SharePoint REST calls to use
decodedUrlinGetFolderByServerRelativePath/GetFileByServerRelativePathrequests - Added
spo.getFileByUrl()andspo.getFileRoleAssignments()helpers and refactoredspo file getto reuse them - Introduced new
spo file roleassignment listcommand with tests and documentation
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils/spo.ts | Adds helper methods for file retrieval and role assignments; updates REST parameter casing |
| src/utils/spo.spec.ts | Updates URL expectations for decodedUrl and adds tests for new helpers |
| src/m365/spo/commands/file/file-roleassignment-list.ts | New command to list role assignments for a file by URL or ID |
| src/m365/spo/commands/file/file-roleassignment-list.spec.ts | Unit tests for the new command behavior and validation |
| src/m365/spo/commands/file/file-get.ts | Refactors permission retrieval to use shared spo.getFileRoleAssignments() |
| src/m365/spo/commands/file/file-get.spec.ts | Updates tests to stub spo.getFileRoleAssignments() |
| src/m365/spo/commands.ts | Registers new command constant |
| docs/src/config/sidebars.ts | Adds the new command doc to the sidebar |
| docs/docs/cmd/spo/file/file-roleassignment-list.mdx | Adds documentation page for the new command |
Comment on lines
2480
to
2497
| async getFileRoleAssignments(webUrl: string, serverRelativeUrl: string, logger?: Logger, verbose?: boolean): Promise<any> { | ||
| if (verbose && logger) { | ||
| await logger.logToStderr(`Retrieving the role assignments for the file ${serverRelativeUrl}`); | ||
| } | ||
|
|
||
| const requestOptions: CliRequestOptions = { | ||
| url: `${webUrl}/_api/web/GetFileByServerRelativePath(decodedUrl='${formatting.encodeQueryParameter(serverRelativeUrl)}')/ListItemAllFields/RoleAssignments?$expand=Member,RoleDefinitionBindings`, | ||
| headers: { accept: 'application/json;odata=nometadata' }, | ||
| responseType: 'json' | ||
| }; | ||
|
|
||
| const response = await request.get<{ value: any[] }>(requestOptions); | ||
| response.value.forEach(r => { | ||
| r.RoleDefinitionBindings = formatting.setFriendlyPermissions(r.RoleDefinitionBindings); | ||
| }); | ||
|
|
||
| return response; | ||
| } |
Comment on lines
+2829
to
2858
| it(`retrieves file role assignments`, async () => { | ||
| const fileUrl = 'https://contoso.sharepoint.com/sites/sales/Shared Documents/Test.docx'; | ||
| const roleAssignmentsResponse = { | ||
| value: [ | ||
| { | ||
| Member: { | ||
| Id: 3, | ||
| LoginName: 'i:0#.f|membership|user@contoso.com' | ||
| }, | ||
| RoleDefinitionBindings: [ | ||
| { | ||
| Id: 1073741826, | ||
| Name: 'Read' | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| }; | ||
|
|
||
| sinon.stub(request, 'get').callsFake(async (opts) => { | ||
| if (opts.url === "https://contoso.sharepoint.com/sites/sales/_api/web/GetFileByServerRelativePath(decodedUrl='https%3A%2F%2Fcontoso.sharepoint.com%2Fsites%2Fsales%2FShared%20Documents%2FTest.docx')/ListItemAllFields/RoleAssignments?$expand=Member,RoleDefinitionBindings") { | ||
| return roleAssignmentsResponse; | ||
| } | ||
|
|
||
| throw 'Invalid request'; | ||
| }); | ||
|
|
||
| const roleAssignments = await spo.getFileRoleAssignments(webUrl, fileUrl, logger, true); | ||
| assert.deepEqual(roleAssignments, roleAssignmentsResponse); | ||
| }); |
Comment on lines
+152
to
+158
| it('retrieves file role assignments by file id', async () => { | ||
| sinon.stub(spo, 'getFileById').resolves(fileResponse); | ||
| sinon.stub(spo, 'getFileRoleAssignments').resolves(fileRoleAssignmentsResponse.value); | ||
|
|
||
| await command.action(logger, { options: { debug: true, webUrl: webUrl, fileId: fileId } }); | ||
| assert(loggerLogSpy.calledWith(fileRoleAssignmentsResponse.value)); | ||
| }); |
Comment on lines
+21
to
+25
| `--fileUrl [fileUrl]` | ||
| : The server- or site-relative decoded URL of the file. Specify either `fileUrl` or `fileId` but not both. | ||
|
|
||
| `-i, --fileId [fileId]` | ||
| : The UniqueId (GUID) of the file. Specify either `fileUrl` or `fileId` but not both. |
Contributor
|
Thanks, we'll try to review it ASAP! |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds 'spo file roleassignment list' command. Closes #6191