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

New cmdlet Get-PnPTeamsPrimaryChannel to get primary channel #1572

Merged
merged 5 commits into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 14 additions & 3 deletions src/Commands/Model/Teams/TeamChannel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace PnP.PowerShell.Commands.Model.Teams
Expand Down Expand Up @@ -37,12 +38,22 @@ public partial class TeamChannel
/// Defines the Description of the Channel
/// </summary>
public string Description { get; set; }

/// <summary>
/// Created date time for the channel
/// </summary>
public DateTime? CreatedDateTime { get; set; }
/// <summary>
/// Email for the channel
/// </summary>
public string Email { get; set; }
/// <summary>
/// web url of the channel
/// </summary>
public string WebUrl { get; set; }
/// <summary>
/// Defines whether the Channel is Favorite by default for all members of the Team
/// </summary>
public bool? IsFavoriteByDefault { get; set; }

/// <summary>
/// Declares the ID for the Channel
/// </summary>
Expand Down
33 changes: 33 additions & 0 deletions src/Commands/Teams/GetTeamsPrimaryChannel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using PnP.Framework.Graph;
using PnP.PowerShell.Commands.Attributes;
using PnP.PowerShell.Commands.Base;
using PnP.PowerShell.Commands.Base.PipeBinds;
using PnP.PowerShell.Commands.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;

namespace PnP.PowerShell.Commands.Teams
{
[Cmdlet(VerbsCommon.Get, "PnPTeamsPrimaryChannel")]
[RequiredMinimalApiPermissions("Group.Read.All")]
reshmee011 marked this conversation as resolved.
Show resolved Hide resolved

public class GetTeamsPrimaryChannel : PnPGraphCmdlet
{
[Parameter(Mandatory = true, ValueFromPipeline = true)]
public TeamsTeamPipeBind Team;

protected override void ExecuteCmdlet()
{
var groupId = Team.GetGroupId(HttpClient, AccessToken);
if (groupId != null)
{
WriteObject(TeamsUtility.GetPrimaryChannelAsync(AccessToken, HttpClient, groupId).GetAwaiter().GetResult());
} else
{
throw new PSArgumentException("Team not found", nameof(Team));
}
}
}
}
6 changes: 5 additions & 1 deletion src/Commands/Utilities/TeamsUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,11 @@ public static async Task<IEnumerable<TeamChannel>> GetChannelsAsync(string acces
var collection = await GraphHelper.GetResultCollectionAsync<TeamChannel>(httpClient, $"v1.0/teams/{groupId}/channels", accessToken);
return collection;
}

public static async Task<TeamChannel> GetPrimaryChannelAsync(string accessToken, HttpClient httpClient, string groupId)
{
var collection = await GraphHelper.GetAsync<TeamChannel>(httpClient, $"v1.0/teams/{groupId}/primaryChannel", accessToken);
return collection;
}
public static async Task<HttpResponseMessage> DeleteChannelAsync(string accessToken, HttpClient httpClient, string groupId, string channelId)
{
return await GraphHelper.DeleteAsync(httpClient, $"v1.0/teams/{groupId}/channels/{channelId}", accessToken);
Expand Down