Skip to content

Commit

Permalink
Fix case sensitivity issue in Get-PnPGroup for consisitency and add c…
Browse files Browse the repository at this point in the history
…onsistent null checks with exceptions.
  • Loading branch information
martinlingstuyl authored and gautamdsheth committed Apr 28, 2022
1 parent 0a9d980 commit 1527d49
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
4 changes: 2 additions & 2 deletions documentation/Get-PnPGroup.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Returns all SharePoint groups in the current site
Get-PnPGroup -Identity 'My Site Users'
```

This will return the group called 'My Site Users' if available in the current site
This will return the group called 'My Site Users' if available in the current site. The name is case sensitive, so a group called 'My site users' would not be found.

### EXAMPLE 3
```powershell
Expand Down Expand Up @@ -127,7 +127,7 @@ Accept wildcard characters: False
```

### -Identity
Get a specific group by its name or id
Get a specific group by its name or id. The name case sensitive.

```yaml
Type: GroupPipeBind
Expand Down
21 changes: 19 additions & 2 deletions src/Commands/Principals/GetGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,25 @@ protected override void ExecuteCmdlet()
{
if (ParameterSetName == "ByName")
{
Group group = Identity.GetGroup(CurrentWeb);
WriteObject(group);
// Get group by name using Core SDK because of
// case sensitivity difference between Core SDK and CSOM
// Loads group using CSOM to bypass a breaking change
var pnpGroup = Identity.GetGroup(PnPContext);

if (pnpGroup != null)
{
var csomGroup = CurrentWeb.SiteGroups.GetById(pnpGroup.Id);
ClientContext.Load(csomGroup);
ClientContext.Load(csomGroup.Users);
ClientContext.ExecuteQueryRetry();

WriteObject(csomGroup);
}
else
{
throw new PSArgumentException("Site group not found", nameof(Identity));
}

}
else if (ParameterSetName == "Members")
{
Expand Down
12 changes: 8 additions & 4 deletions src/Commands/Principals/GetGroupPermissions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ public class GetGroupPermissions : PnPWebCmdlet

protected override void ExecuteCmdlet()
{
var g = Identity.GetGroup(PnPContext);
var r = g.GetRoleDefinitions();
if (r != null)
var group = Identity.GetGroup(PnPContext);

if (group == null)
throw new PSArgumentException("Site group not found", nameof(Identity));

var roleDefinitions = group.GetRoleDefinitions();
if (roleDefinitions != null)
{
WriteObject(r.RequestedItems, true);
WriteObject(roleDefinitions.RequestedItems, true);
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/Commands/Principals/SetGroupPermissions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public class SetGroupPermissions : PnPWebCmdlet
protected override void ExecuteCmdlet()
{
var group = Identity.GetGroup(PnPContext);

if (group == null)
throw new PSArgumentException("Site group not found", nameof(Identity));

PnP.Core.Model.SharePoint.IList list = null;
if (ParameterSpecified(nameof(List)))
{
Expand Down

0 comments on commit 1527d49

Please sign in to comment.