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

Update GetGroupSettings endpoint #4479

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions src/Commands/Base/PipeBinds/Microsoft365GroupSettingsPipeBind.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using PnP.PowerShell.Commands.Model;
using PnP.PowerShell.Commands.Utilities;
using System;
using System.Management.Automation;

namespace PnP.PowerShell.Commands.Base.PipeBinds
{
public class Microsoft365GroupSettingsPipeBind
{
private readonly Microsoft365GroupSetting _group;
private readonly Guid _groupId;
private readonly string _displayName;

public Microsoft365GroupSettingsPipeBind()
{
}

public Microsoft365GroupSettingsPipeBind(Microsoft365GroupSetting group)
{
_group = group;
}

public Microsoft365GroupSettingsPipeBind(string input)
{
Guid idValue;
if (Guid.TryParse(input, out idValue))
{
_groupId = idValue;
}
else
{
_displayName = input;
}
}

public Microsoft365GroupSettingsPipeBind(Guid guid)
{
_groupId = guid;
}

public Microsoft365GroupSetting Group => _group;

public String DisplayName => _displayName;

public Guid GroupId => _groupId;

public Guid GetGroupSettingId(Cmdlet cmdlet, PnPConnection connection, string accessToken)
{
if (Group != null)
{
return _group.Id.Value;
}
else if (_groupId != Guid.Empty)
{
return _groupId;
}
else if (!string.IsNullOrEmpty(DisplayName))
{
var groups = ClearOwners.GetGroupSettings(cmdlet, connection, accessToken);
if (groups != null)
{
var collection = groups.Where(p => p.displayName.Equals(displayName));
return group.Id.Value;
}
}
throw new PSInvalidOperationException("Group not found");
}
}
}
18 changes: 13 additions & 5 deletions src/Commands/Microsoft365Groups/GetMicrosoft365GroupSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,25 @@
public class GetMicrosoft365GroupSettings : PnPGraphCmdlet
{
[Parameter(Mandatory = false)]
public Microsoft365GroupPipeBind Identity;
public Microsoft365GroupPipeBind Group;

[Parameter(Mandatory = false)]
public Microsoft365GroupSettingsPipeBind Identity;

protected override void ExecuteCmdlet()
{
if (Identity != null)
if (Identity != null && Group !=null)
{
var groupId = Group.GetGroupId(this, Connection, AccessToken);
var groupSettings = ClearOwners.GetGroupSettings(this, Connection, AccessToken,Identity.Id.ToString ,groupId.ToString());
WriteObject(groupSettings?.Value, true);
}
elseif(Identity != null && Group == null)

Check failure on line 28 in src/Commands/Microsoft365Groups/GetMicrosoft365GroupSettings.cs

View workflow job for this annotation

GitHub Actions / build_dev_branch

; expected

Check failure on line 28 in src/Commands/Microsoft365Groups/GetMicrosoft365GroupSettings.cs

View workflow job for this annotation

GitHub Actions / build_dev_branch

; expected
{
var groupId = Identity.GetGroupId(this, Connection, AccessToken);
var groupSettings = ClearOwners.GetGroupSettings(this, Connection, AccessToken, groupId.ToString());
var groupSettings = ClearOwners.GetGroupSettings(this, Connection, AccessToken,Identity.Id.ToString());
WriteObject(groupSettings?.Value, true);
}
else
elseif(Identity == null && Group ==null)

Check failure on line 33 in src/Commands/Microsoft365Groups/GetMicrosoft365GroupSettings.cs

View workflow job for this annotation

GitHub Actions / build_dev_branch

; expected

Check failure on line 33 in src/Commands/Microsoft365Groups/GetMicrosoft365GroupSettings.cs

View workflow job for this annotation

GitHub Actions / build_dev_branch

; expected
{
var groupSettings = ClearOwners.GetGroupSettings(this, Connection, AccessToken);
WriteObject(groupSettings?.Value, true);
Expand Down
10 changes: 8 additions & 2 deletions src/Commands/Utilities/Microsoft365GroupsUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -713,9 +713,15 @@ internal static Microsoft365GroupSettingValueCollection GetGroupSettings(Cmdlet
return result;
}

internal static Microsoft365GroupSettingValueCollection GetGroupSettings(Cmdlet cmdlet, PnPConnection connection, string accessToken, string groupId)
internal static Microsoft365GroupSettingValueCollection GetGroupTenantSettings(Cmdlet cmdlet, PnPConnection connection, string accessToken, string groupSettingId)
{
var result = GraphHelper.Get<Microsoft365GroupSettingValueCollection>(cmdlet, connection, $"v1.0/groups/{groupId}/settings", accessToken, propertyNameCaseInsensitive: true);
var result = GraphHelper.Get<Microsoft365GroupSettingValueCollection>(cmdlet, connection, $"v1.0/groupSettings/{groupSettingId}", accessToken, propertyNameCaseInsensitive: true);
return result;
}

internal static Microsoft365GroupSettingValueCollection GetGroupSettings(Cmdlet cmdlet, PnPConnection connection, string accessToken, string groupSettingId,string groupId)
{
var result = GraphHelper.Get<Microsoft365GroupSettingValueCollection>(cmdlet, connection, $"v1.0/groups/{groupId}/settings/{groupSettingId}", accessToken, propertyNameCaseInsensitive: true);
return result;
}

Expand Down
Loading