Skip to content

Adds 'spo file roleassignment list' command. Closes #6191#7280

Open
nanddeepn wants to merge 2 commits into
pnp:mainfrom
nanddeepn:issue-6191-1
Open

Adds 'spo file roleassignment list' command. Closes #6191#7280
nanddeepn wants to merge 2 commits into
pnp:mainfrom
nanddeepn:issue-6191-1

Conversation

@nanddeepn
Copy link
Copy Markdown
Contributor

Adds 'spo file roleassignment list' command. Closes #6191

Copilot AI review requested due to automatic review settings May 22, 2026 12:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 decodedUrl in GetFolderByServerRelativePath/GetFileByServerRelativePath requests
  • Added spo.getFileByUrl() and spo.getFileRoleAssignments() helpers and refactored spo file get to reuse them
  • Introduced new spo file roleassignment list command 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 thread src/utils/spo.ts Outdated
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 thread src/utils/spo.spec.ts
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.
Comment thread src/utils/spo.spec.ts Outdated
Comment thread src/utils/spo.spec.ts Outdated
@milanholemans
Copy link
Copy Markdown
Contributor

Thanks, we'll try to review it ASAP!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New command: spo file roleassignment list

3 participants