Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhances spo web roleassignment commands with Microsoft Entra groups, Closes #6193 #6463

Conversation

nicodecleyre
Copy link
Contributor

Closes #6193

@milanholemans
Copy link
Contributor

Thank you! We'll have a look at it soon.

@Adam-it Adam-it self-assigned this Jan 5, 2025
Copy link
Member

@Adam-it Adam-it left a comment

Choose a reason for hiding this comment

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

@nicodecleyre Awesome work 👏
I added some small comments connected to refactoring that if you want and have time you could resolve and if not I will do it when merging 👍 no problem
Checked and works
image

image

add role assignment using a Entra Group ID and a role definition

```sh
m365 spo web roleassignment add --webUrl "https://contoso.sharepoint.com/sites/project-x" --entraGroupId '27ae47f1-48f1-46f3-980b-d3c1470e398d' --roleDefinitionId 1073741829
Copy link
Member

Choose a reason for hiding this comment

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

we could use double quotes just to align with what we already have

Suggested change
m365 spo web roleassignment add --webUrl "https://contoso.sharepoint.com/sites/project-x" --entraGroupId '27ae47f1-48f1-46f3-980b-d3c1470e398d' --roleDefinitionId 1073741829
m365 spo web roleassignment add --webUrl "https://contoso.sharepoint.com/sites/project-x" --entraGroupId "27ae47f1-48f1-46f3-980b-d3c1470e398d" --roleDefinitionId 1073741829

Remove roleassignment from web based on Entra Group Id

```sh
m365 spo web roleassignment remove --webUrl "https://contoso.sharepoint.com/sites/contoso-sales" --entraGroupId '27ae47f1-48f1-46f3-980b-d3c1470e398d' --force
Copy link
Member

Choose a reason for hiding this comment

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

same here

Suggested change
m365 spo web roleassignment remove --webUrl "https://contoso.sharepoint.com/sites/contoso-sales" --entraGroupId '27ae47f1-48f1-46f3-980b-d3c1470e398d' --force
m365 spo web roleassignment remove --webUrl "https://contoso.sharepoint.com/sites/contoso-sales" --entraGroupId "27ae47f1-48f1-46f3-980b-d3c1470e398d" --force

@@ -57,6 +63,12 @@ Remove roleassignment from web based on principal Id without prompting for confi
m365 spo web roleassignment remove --webUrl "https://contoso.sharepoint.com/sites/contoso-sales" --principalId 2 --force
```

Remove roleassignment from web based on Entra Group Id
Copy link
Member

Choose a reason for hiding this comment

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

lets add a remark that this is force delete as it someone just do a copy/past and execute than this may have some not pleasent implications

Suggested change
Remove roleassignment from web based on Entra Group Id
Remove roleassignment from web based on Entra Group Id and don't prompt for confirmation

Comment on lines 158 to +161
});


it('fails validation if the entaGroupId is not a valid guid', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

Lets keep no more than single blank line in code

Suggested change
});
it('fails validation if the entaGroupId is not a valid guid', async () => {
});
it('fails validation if the entaGroupId is not a valid guid', async () => {

Comment on lines +144 to +150
let group: Group;
if (args.options.entraGroupId) {
group = await entraGroup.getGroupById(args.options.entraGroupId);
}
else {
group = await entraGroup.getGroupByDisplayName(args.options.entraGroupName!);
}
Copy link
Member

Choose a reason for hiding this comment

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

similar like in the listItem PR we may just simplify this and remove the type. The type is returned by the method so it is applied allready no need to mention it I guess.

Suggested change
let group: Group;
if (args.options.entraGroupId) {
group = await entraGroup.getGroupById(args.options.entraGroupId);
}
else {
group = await entraGroup.getGroupByDisplayName(args.options.entraGroupName!);
}
const group = args.options.entraGroupId ? await entraGroup.getGroupById(args.options.entraGroupId) : await entraGroup.getGroupByDisplayName(args.options.entraGroupName!);

@@ -1,3 +1,4 @@
import { Group } from '@microsoft/microsoft-graph-types';
Copy link
Member

Choose a reason for hiding this comment

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

When we apply my previous comment we may get rid of this line

Suggested change
import { Group } from '@microsoft/microsoft-graph-types';

sinon.stub(spo, 'ensureEntraGroup').withArgs('https://contoso.sharepoint.com', graphGroup).resolves(entraGroupResponse);

sinon.stub(request, 'post').callsFake(async (opts) => {
if ((opts.url as string).indexOf('_api/web/roleassignments/removeroleassignment(principalid=\'11\')') > -1) {
Copy link
Member

Choose a reason for hiding this comment

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

in general we should avoid using indexOf and instead use exact equal to url using ===

@@ -1,3 +1,4 @@
import { Group } from '@microsoft/microsoft-graph-types';
Copy link
Member

Choose a reason for hiding this comment

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

when we refactor the if condition we may remove this line

Suggested change
import { Group } from '@microsoft/microsoft-graph-types';

Comment on lines +143 to +149
let group: Group;
if (options.entraGroupId) {
group = await entraGroup.getGroupById(options.entraGroupId);
}
else {
group = await entraGroup.getGroupByDisplayName(options.entraGroupName!);
}
Copy link
Member

Choose a reason for hiding this comment

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

this may be simplified to

Suggested change
let group: Group;
if (options.entraGroupId) {
group = await entraGroup.getGroupById(options.entraGroupId);
}
else {
group = await entraGroup.getGroupByDisplayName(options.entraGroupName!);
}
const group = options.entraGroupId
? await entraGroup.getGroupById(options.entraGroupId)
: await entraGroup.getGroupByDisplayName(options.entraGroupName!);

@Adam-it
Copy link
Member

Adam-it commented Jan 5, 2025

Ready to merge 🚀 I should perform small fixup before merge

@Adam-it
Copy link
Member

Adam-it commented Jan 8, 2025

Merged manually. Thank you for your awesome contribution. You Rock 🤩👏

@Adam-it Adam-it closed this Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhance spo web roleassignment commands with Microsoft Entra groups
3 participants