public async Task CreatePublicChannelTest() { string teamid = await CreateTeamWithMembers(10, 10); CSEntryChange channel = CSEntryChange.Create(); channel.ObjectType = "publicChannel"; channel.ObjectModificationType = ObjectModificationType.Add; channel.CreateAttributeAdd("team", teamid); channel.CreateAttributeAdd("displayName", "my test channel"); channel.CreateAttributeAdd("description", "my description"); channel.CreateAttributeAdd("isFavoriteByDefault", true); CSEntryChangeResult channelResult = await channelExportProvider.PutCSEntryChangeAsync(channel); string channelid = channelResult.GetAnchorValueOrDefault <string>("id"); Assert.IsTrue(channelResult.ErrorCode == MAExportError.Success); Beta.Channel newChannel = await GetChannelFromTeam(teamid, channelid); Assert.AreEqual("my test channel", newChannel.DisplayName); Assert.AreEqual("my description", newChannel.Description); // 2020-05-15 This currently doesn't come in with a GET request // https://github.com/microsoftgraph/microsoft-graph-docs/issues/6792 //Assert.AreEqual(true, newChannel.IsFavoriteByDefault); }
private async Task <CSEntryChangeResult> PutCSEntryChangeDelete(CSEntryChange csentry) { string teamid = csentry.GetAnchorValueOrDefault <string>("teamid"); try { if (this.context.ConfigParameters[ConfigParameterNames.RandomizeChannelNameOnDelete].Value == "1") { string newname = $"deleted-{Guid.NewGuid():N}"; Beta.Channel c = new Beta.Channel(); c.DisplayName = newname; await GraphHelperTeams.UpdateChannel(this.betaClient, teamid, csentry.DN, c, this.token); logger.Info($"Renamed channel {csentry.DN} on team {teamid} to {newname}"); } await GraphHelperTeams.DeleteChannel(this.betaClient, teamid, csentry.DN, this.token); } catch (ServiceException ex) { if (ex.StatusCode == HttpStatusCode.NotFound) { logger.Warn($"The request to delete the channel {csentry.DN} failed because it doesn't exist"); } else { throw; } } return(CSEntryChangeResult.Create(csentry.Identifier, null, MAExportError.Success)); }
private async Task <CSEntryChangeResult> PutCSEntryChangeAdd(CSEntryChange csentry) { string teamid = csentry.GetValueAdd <string>("team"); if (teamid == null) { logger.Error($"Export of item {csentry.DN} failed as no 'team' attribute was provided\r\n{string.Join(",", csentry.ChangedAttributeNames)}"); return(CSEntryChangeResult.Create(csentry.Identifier, null, MAExportError.ExportActionRetryReferenceAttribute)); } Beta.Channel c = new Beta.Channel(); c.DisplayName = csentry.GetValueAdd <string>("displayName"); c.Description = csentry.GetValueAdd <string>("description"); // 2020-05-15 This currently doesn't come in with a GET request, so for now, it needs to be initial-flow only // https://github.com/microsoftgraph/microsoft-graph-docs/issues/6792 c.IsFavoriteByDefault = csentry.HasAttributeChange("isFavoriteByDefault") && csentry.GetValueAdd <bool>("isFavoriteByDefault"); if (csentry.ObjectType == "privateChannel") { if (!csentry.HasAttributeChangeAdd("owner")) { throw new InvalidProvisioningStateException("At least one owner must be specified when creating a channel"); } string ownerID = csentry.GetValueAdds <string>("owner").First(); c.MembershipType = Beta.ChannelMembershipType.Private; c.AdditionalData = new Dictionary <string, object>(); c.AdditionalData.Add("members", new[] { GraphHelperTeams.CreateAadUserConversationMember(ownerID, "owner") }); } logger.Trace($"{csentry.DN}: Channel data: {JsonConvert.SerializeObject(c)}"); var channel = await GraphHelperTeams.CreateChannel(this.betaClient, teamid, c, this.token); logger.Trace($"Created channel {channel.Id} for team {teamid}"); if (csentry.ObjectType == "privateChannel") { await this.PutMemberChanges(csentry, teamid, channel.Id); } List <AttributeChange> anchorChanges = new List <AttributeChange>(); anchorChanges.Add(AttributeChange.CreateAttributeAdd("id", channel.Id)); anchorChanges.Add(AttributeChange.CreateAttributeAdd("teamid", teamid)); return(CSEntryChangeResult.Create(csentry.Identifier, anchorChanges, MAExportError.Success)); }
public async Task CreatePrivateChannelTest() { string teamid = await CreateTeamWithMembers(10, 10); List <DirectoryObject> owners = await GraphHelperGroups.GetGroupOwners(UnitTestControl.Client, teamid, CancellationToken.None); await Task.Delay(TimeSpan.FromDays(1)); string ownerid = owners.First().Id; owners.RemoveAt(0); List <string> ownerIds = owners.Select(t => t.Id).ToList(); CSEntryChange channel = CSEntryChange.Create(); channel.ObjectType = "privateChannel"; channel.ObjectModificationType = ObjectModificationType.Add; channel.CreateAttributeAdd("team", teamid); channel.CreateAttributeAdd("displayName", "my test channel"); channel.CreateAttributeAdd("description", "my description"); channel.CreateAttributeAdd("isFavoriteByDefault", true); channel.CreateAttributeAdd("owner", ownerid); channel.CreateAttributeAdd("member", ownerIds.ToList <object>()); CSEntryChangeResult channelResult = await channelExportProvider.PutCSEntryChangeAsync(channel); string channelid = channelResult.GetAnchorValueOrDefault <string>("id"); Assert.IsTrue(channelResult.ErrorCode == MAExportError.Success); Beta.Channel newChannel = await GetChannelFromTeam(teamid, channelid); Assert.AreEqual("my test channel", newChannel.DisplayName); Assert.AreEqual("my description", newChannel.Description); Assert.AreEqual(Beta.ChannelMembershipType.Private, newChannel.MembershipType); var members = await GraphHelperTeams.GetChannelMembers(UnitTestControl.BetaClient, teamid, channelid, CancellationToken.None); Assert.IsTrue(members.Any(t => t.Id == ownerid && (t.Roles?.Contains("owner") ?? false))); CollectionAssert.AreEquivalent(ownerIds, members.Where(t => t.Roles == null).Select(t => t.Id).ToList()); // 2020-05-15 This currently doesn't come in with a GET request // https://github.com/microsoftgraph/microsoft-graph-docs/issues/6792 //Assert.AreEqual(true, newChannel.IsFavoriteByDefault); }
public static async Task <Beta.Channel> UpdateChannel(Beta.GraphServiceClient client, string teamid, string channelid, Beta.Channel channel, CancellationToken token) { return(await GraphHelper.ExecuteWithRetryAndRateLimit(async() => await client.Teams[teamid].Channels[channelid].Request().UpdateAsync(channel, token), token, 1)); }
private async Task PutCSEntryChangeUpdateChannel(CSEntryChange csentry) { string teamid = csentry.GetAnchorValueOrDefault <string>("teamid"); string channelid = csentry.GetAnchorValueOrDefault <string>("id"); bool changed = false; Beta.Channel channel = new Beta.Channel(); foreach (AttributeChange change in csentry.AttributeChanges) { if (change.DataType == AttributeType.Boolean && change.ModificationType == AttributeModificationType.Delete) { throw new UnsupportedBooleanAttributeDeleteException(change.Name); } if (change.Name == "team") { throw new InitialFlowAttributeModificationException(change.Name); } else if (change.Name == "isFavoriteByDefault") { channel.IsFavoriteByDefault = change.GetValueAdd <bool>(); } else if (change.Name == "displayName") { if (change.ModificationType == AttributeModificationType.Delete) { throw new UnsupportedAttributeDeleteException(change.Name); } channel.DisplayName = change.GetValueAdd <string>(); } else if (change.Name == "description") { if (change.ModificationType == AttributeModificationType.Delete) { channel.AssignNullToProperty("description"); } else { channel.Description = change.GetValueAdd <string>(); } } else { continue; } changed = true; } if (changed) { logger.Trace($"{csentry.DN}:Updating channel data: {JsonConvert.SerializeObject(channel)}"); await GraphHelperTeams.UpdateChannel(this.betaClient, teamid, channelid, channel, this.token); logger.Info($"{csentry.DN}: Updated channel"); } if (csentry.ObjectType == "privateChannel") { await this.PutMemberChanges(csentry, teamid, channelid); } }