Skip to content

Commit b0c7628

Browse files
authored
Merge pull request #79 from microsoftgraph/po/AddNewGroupMember
Add New-MgGroupMember cmdlet to Groups.DirectoryObject Module
2 parents 963ab93 + b8eb6ca commit b0c7628

File tree

12 files changed

+1600
-11
lines changed

12 files changed

+1600
-11
lines changed

config/ModulesMapping.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,4 @@
108108
// Invalid / No longer supported
109109
// "Sites.ListItem": "^sites.baseItem$",
110110
// "OnlineMeetings": "^app\\.",
111-
}
111+
}

src/Beta/Groups.DirectoryObject/Groups.DirectoryObject/Microsoft.Graph.Groups.DirectoryObject.psd1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# Generated by: Microsoft Corporation
55
#
6-
# Generated on: 12/13/2019
6+
# Generated on: 1/16/2020
77
#
88

99
@{
@@ -12,13 +12,13 @@
1212
RootModule = './Microsoft.Graph.Groups.DirectoryObject.psm1'
1313

1414
# Version number of this module.
15-
ModuleVersion = '0.1.1'
15+
ModuleVersion = '0.1.2'
1616

1717
# Supported PSEditions
1818
CompatiblePSEditions = 'Core', 'Desktop'
1919

2020
# ID used to uniquely identify this module
21-
GUID = '054d9469-626e-4951-8e44-e7266fdc8031'
21+
GUID = '10998c8e-9fed-4ac4-a527-2275a2ee0fdf'
2222

2323
# Author of this module
2424
Author = 'Microsoft Corporation'
@@ -77,8 +77,8 @@ CmdletsToExport = 'Get-MgGroupAcceptedSender', 'Get-MgGroupCreatedOnBehalf',
7777
'Get-MgGroupMemberWithLicenseError', 'Get-MgGroupOwner',
7878
'Get-MgGroupRejectedSender', 'Get-MgGroupTransitiveMember',
7979
'Get-MgGroupTransitiveMemberOf', 'New-MgGroupAcceptedSender',
80-
'New-MgGroupRejectedSender', 'Update-MgGroupAcceptedSender',
81-
'Update-MgGroupRejectedSender'
80+
'New-MgGroupMember', 'New-MgGroupRejectedSender',
81+
'Update-MgGroupAcceptedSender', 'Update-MgGroupRejectedSender'
8282

8383
# Variables to export from this module
8484
# VariablesToExport = @()
@@ -113,7 +113,7 @@ PrivateData = @{
113113
IconUri = 'https://raw.githubusercontent.com/microsoftgraph/g-raph/master/g-raph.png'
114114

115115
# ReleaseNotes of this module
116-
# ReleaseNotes = ''
116+
ReleaseNotes = 'Added New-MgGroupMember'
117117

118118
# Prerelease string of this module
119119
# Prerelease = ''
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
namespace Microsoft.Graph.PowerShell
2+
{
3+
using Microsoft.Graph.PowerShell.Runtime.Json;
4+
using System.Collections.Generic;
5+
using static Microsoft.Graph.PowerShell.Runtime.Extensions;
6+
7+
/// <summary>
8+
/// Custom Low-level API implementation for the Groups.DirectoryObject service.
9+
/// </summary>
10+
public partial class GroupsDirectoryObject
11+
{
12+
private static string baseUrl = "https://graph.microsoft.com/beta";
13+
/// <summary>Create new navigation property to members for groups</summary>
14+
/// <param name="groupId">key: group-id of group</param>
15+
/// <param name="body">New navigation property</param>
16+
/// <param name="onCreated">a delegate that is called when the remote service returns 204 (No Content).</param>
17+
/// <param name="onDefault">a delegate that is called when the remote service returns default (any response code not handled
18+
/// elsewhere).</param>
19+
/// <param name="eventListener">an <see cref="Runtime.IEventListener" /> instance that will receive events.</param>
20+
/// <param name="sender">an instance of an Microsoft.Graph.PowerShell.Runtime.ISendAsync pipeline to use to make the request.</param>
21+
/// <returns>
22+
/// A <see cref="System.Threading.Tasks.Task" /> that will be complete when handling of the response is completed.
23+
/// </returns>
24+
public async System.Threading.Tasks.Task GroupsCreateGroupMember(string groupId, Models.IMicrosoftGraphDirectoryObject body, System.Func<System.Net.Http.HttpResponseMessage, System.Threading.Tasks.Task<Models.IMicrosoftGraphDirectoryObject>, System.Threading.Tasks.Task> onCreated, System.Func<System.Net.Http.HttpResponseMessage, System.Threading.Tasks.Task<Models.IOdataError>, System.Threading.Tasks.Task> onDefault, Runtime.IEventListener eventListener, Runtime.ISendAsync sender)
25+
{
26+
// Constant Parameters
27+
using( NoSynchronizationContext )
28+
{
29+
// construct URL
30+
var _url = new System.Uri(
31+
System.Text.RegularExpressions.Regex.Replace($"{baseUrl}/groups/{System.Uri.EscapeDataString(groupId)}/members/$ref",
32+
"\\?&*$|&*$|(\\?)&+|(&)&+", "$1$2"));
33+
34+
await eventListener.Signal(Runtime.Events.URLCreated, _url); if( eventListener.Token.IsCancellationRequested ) { return; }
35+
36+
// generate request object
37+
var request = new System.Net.Http.HttpRequestMessage(Runtime.Method.Post, _url);
38+
await eventListener.Signal(Runtime.Events.RequestCreated, _url); if( eventListener.Token.IsCancellationRequested ) { return; }
39+
40+
await eventListener.Signal(Runtime.Events.HeaderParametersAdded, _url); if( eventListener.Token.IsCancellationRequested ) { return; }
41+
// set body content
42+
string requestContent = null != body ? new JsonObject(new Dictionary<string, string> { { "@odata.id", $"{baseUrl}/directoryObjects/{body.Id}" } }) : @"{}";
43+
request.Content = new System.Net.Http.StringContent(requestContent, System.Text.Encoding.UTF8); ;
44+
request.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json");
45+
await eventListener.Signal(Runtime.Events.BodyContentSet, _url); if( eventListener.Token.IsCancellationRequested ) { return; }
46+
// make the call
47+
await this.GroupsCreateGroupMember_Call(request,onCreated,onDefault,eventListener,sender);
48+
}
49+
}
50+
51+
/// <summary>Actual wire call for <see cref="GroupsCreateGroupMember" /> method.</summary>
52+
/// <param name="request">the prepared HttpRequestMessage to send.</param>
53+
/// <param name="onCreated">a delegate that is called when the remote service returns 204 (No content).</param>
54+
/// <param name="onDefault">a delegate that is called when the remote service returns default (any response code not handled
55+
/// elsewhere).</param>
56+
/// <param name="eventListener">an <see cref="Runtime.IEventListener" /> instance that will receive events.</param>
57+
/// <param name="sender">an instance of an Microsoft.Graph.PowerShell.Runtime.ISendAsync pipeline to use to make the request.</param>
58+
/// <returns>
59+
/// A <see cref="System.Threading.Tasks.Task" /> that will be complete when handling of the response is completed.
60+
/// </returns>
61+
internal async System.Threading.Tasks.Task GroupsCreateGroupMember_Call(System.Net.Http.HttpRequestMessage request, System.Func<System.Net.Http.HttpResponseMessage, System.Threading.Tasks.Task<Models.IMicrosoftGraphDirectoryObject>, System.Threading.Tasks.Task> onCreated, System.Func<System.Net.Http.HttpResponseMessage, System.Threading.Tasks.Task<Models.IOdataError>, System.Threading.Tasks.Task> onDefault, Runtime.IEventListener eventListener, Runtime.ISendAsync sender)
62+
{
63+
using( NoSynchronizationContext )
64+
{
65+
System.Net.Http.HttpResponseMessage _response = null;
66+
try
67+
{
68+
await eventListener.Signal(Runtime.Events.BeforeCall, request); if( eventListener.Token.IsCancellationRequested ) { return; }
69+
_response = await sender.SendAsync(request, eventListener);
70+
await eventListener.Signal(Runtime.Events.ResponseCreated, _response); if( eventListener.Token.IsCancellationRequested ) { return; }
71+
var _contentType = _response.Content.Headers.ContentType?.MediaType;
72+
73+
switch ( _response.StatusCode )
74+
{
75+
case System.Net.HttpStatusCode.NoContent:
76+
{
77+
await eventListener.Signal(Runtime.Events.BeforeResponseDispatch, _response); if( eventListener.Token.IsCancellationRequested ) { return; }
78+
await onCreated(_response,_response.Content.ReadAsStringAsync().ContinueWith( body => Models.MicrosoftGraphDirectoryObject.FromJson(Runtime.Json.JsonNode.Parse(body.Result)) ));
79+
break;
80+
}
81+
default:
82+
{
83+
await eventListener.Signal(Runtime.Events.BeforeResponseDispatch, _response); if( eventListener.Token.IsCancellationRequested ) { return; }
84+
await onDefault(_response,_response.Content.ReadAsStringAsync().ContinueWith( body => Models.OdataError.FromJson(Runtime.Json.JsonNode.Parse(body.Result)) ));
85+
break;
86+
}
87+
}
88+
}
89+
finally
90+
{
91+
// finally statements
92+
await eventListener.Signal(Runtime.Events.Finally, request, _response);
93+
_response?.Dispose();
94+
request?.Dispose();
95+
}
96+
}
97+
}
98+
99+
/// <summary>
100+
/// Validation method for <see cref="GroupsCreateGroupMember" /> method. Call this like the actual call, but you will
101+
/// get validation events back.
102+
/// </summary>
103+
/// <param name="groupId">key: group-id of group</param>
104+
/// <param name="body">New navigation property</param>
105+
/// <param name="eventListener">an <see cref="Runtime.IEventListener" /> instance that will receive events.</param>
106+
/// <returns>
107+
/// A <see cref="System.Threading.Tasks.Task" /> that will be complete when handling of the response is completed.
108+
/// </returns>
109+
internal async System.Threading.Tasks.Task GroupsCreateGroupMember_Validate(string groupId, Models.IMicrosoftGraphDirectoryObject body, Runtime.IEventListener eventListener)
110+
{
111+
using( NoSynchronizationContext )
112+
{
113+
await eventListener.AssertNotNull(nameof(groupId),groupId);
114+
await eventListener.AssertNotNull(nameof(body), body);
115+
await eventListener.AssertObjectIsValid(nameof(body), body);
116+
}
117+
}
118+
}
119+
}

0 commit comments

Comments
 (0)