Skip to content

Commit

Permalink
Refactor: Simplify POST request handling in Microsoft365GroupsUtility…
Browse files Browse the repository at this point in the history
… and TeamsUtility (#4655)

Co-authored-by: Gautam Sheth <[email protected]>
  • Loading branch information
gautamdsheth and Gautam Sheth authored Dec 27, 2024
1 parent 860ad27 commit 8db178e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
10 changes: 2 additions & 8 deletions src/Commands/Utilities/Microsoft365GroupsUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using PnP.PowerShell.Commands.Utilities.REST;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
Expand Down Expand Up @@ -301,10 +300,8 @@ private static void AddUsersToGroup(ApiRequestHelper requestHelper, string group
"@odata.id", $"https://{requestHelper.GraphEndPoint}/v1.0/users/{idProperty.GetString()}"
}
};
var stringContent = new StringContent(JsonSerializer.Serialize(postData));
stringContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");

requestHelper.Post($"v1.0/groups/{groupId}/{groupName}/$ref", stringContent);
requestHelper.Post($"v1.0/groups/{groupId}/{groupName}/$ref", postData);
}
}
}
Expand All @@ -319,10 +316,7 @@ private static void AddDirectoryObjectsToGroup(ApiRequestHelper requestHelper, s
}
};

var stringContent = new StringContent(JsonSerializer.Serialize(postData));
stringContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");

requestHelper.Post($"v1.0/groups/{groupId}/{groupName}/$ref", stringContent);
requestHelper.Post($"v1.0/groups/{groupId}/{groupName}/$ref", postData);
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/Commands/Utilities/TeamsUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -469,10 +469,8 @@ public static void AddUser(ApiRequestHelper requestHelper, string groupId, strin
"@odata.id", $"https://{requestHelper.GraphEndPoint}/v1.0/users/{idProperty.GetString()}"
}
};
var stringContent = new StringContent(JsonSerializer.Serialize(postData));
stringContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");

requestHelper.Post($"v1.0/groups/{groupId}/{role.ToLower()}s/$ref", stringContent);
requestHelper.Post($"v1.0/groups/{groupId}/{role.ToLower()}s/$ref", postData);
}
}

Expand Down

0 comments on commit 8db178e

Please sign in to comment.