-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: added support for shared channel creation (#2308)
* Feature: added support for shared channel creation * Adding new parameter to documentation * Cleanup and renaming * Added changelog entry Co-authored-by: Koen Zomers <koen@zomers.eu>
- Loading branch information
1 parent
9955430
commit 1cb1fca
Showing
5 changed files
with
107 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace PnP.PowerShell.Commands.Enums | ||
{ | ||
/// <summary> | ||
/// Defines the types of channels that can be created in a Microsoft Teams team | ||
/// </summary> | ||
public enum TeamsChannelType | ||
{ | ||
/// <summary> | ||
/// Standard channel accessible by all team members | ||
/// </summary> | ||
Standard, | ||
|
||
/// <summary> | ||
/// Private channel only accessible by those explicitly given permissions to the channel | ||
/// </summary> | ||
Private, | ||
|
||
/// <summary> | ||
/// Shared channel allowing for collaboration between multiple tenants | ||
/// </summary> | ||
Shared | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,87 @@ | ||
using PnP.PowerShell.Commands.Attributes; | ||
using PnP.PowerShell.Commands.Base; | ||
using PnP.PowerShell.Commands.Base.PipeBinds; | ||
using PnP.PowerShell.Commands.Enums; | ||
using PnP.PowerShell.Commands.Model.Graph; | ||
using PnP.PowerShell.Commands.Utilities; | ||
using System; | ||
using System.Management.Automation; | ||
|
||
namespace PnP.PowerShell.Commands.Graph | ||
{ | ||
[Cmdlet(VerbsCommon.Add, "PnPTeamsChannel")] | ||
[Cmdlet(VerbsCommon.Add, "PnPTeamsChannel", DefaultParameterSetName = ParameterSET_STANDARD)] | ||
[RequiredMinimalApiPermissions("Group.ReadWrite.All")] | ||
public class AddTeamsChannel : PnPGraphCmdlet | ||
{ | ||
private const string ParameterSET_PRIVATE = "Private channel"; | ||
private const string ParameterSET_PUBLIC = "Public channel"; | ||
private const string ParameterSET_PRIVATE = "Private channel type"; | ||
private const string ParameterSET_STANDARD = "Standard channel type"; | ||
private const string ParameterSET_SPECIFIC = "Specific channel type"; | ||
|
||
[Parameter(Mandatory = true, ParameterSetName = ParameterSET_PUBLIC)] | ||
[Parameter(Mandatory = true, ParameterSetName = ParameterSET_STANDARD)] | ||
[Parameter(Mandatory = true, ParameterSetName = ParameterSET_PRIVATE)] | ||
[Parameter(Mandatory = true, ParameterSetName = ParameterSET_SPECIFIC)] | ||
public TeamsTeamPipeBind Team; | ||
|
||
[Parameter(Mandatory = true, ParameterSetName = ParameterSET_PUBLIC)] | ||
[Parameter(Mandatory = true, ParameterSetName = ParameterSET_STANDARD)] | ||
[Parameter(Mandatory = true, ParameterSetName = ParameterSET_PRIVATE)] | ||
[Parameter(Mandatory = true, ParameterSetName = ParameterSET_SPECIFIC)] | ||
public string DisplayName; | ||
|
||
[Parameter(Mandatory = false, ParameterSetName = ParameterSET_PUBLIC)] | ||
[Parameter(Mandatory = false, ParameterSetName = ParameterSET_STANDARD)] | ||
[Parameter(Mandatory = false, ParameterSetName = ParameterSET_PRIVATE)] | ||
[Parameter(Mandatory = false, ParameterSetName = ParameterSET_SPECIFIC)] | ||
public string Description; | ||
|
||
[Parameter(Mandatory = true, ParameterSetName = ParameterSET_PRIVATE)] | ||
[Obsolete("Use TeamMembershipType instead.")] | ||
public SwitchParameter Private; | ||
|
||
[Parameter(Mandatory = true, ParameterSetName = ParameterSET_SPECIFIC)] | ||
public TeamsChannelType ChannelType; | ||
|
||
[Parameter(Mandatory = true, ParameterSetName = ParameterSET_SPECIFIC)] | ||
[Parameter(Mandatory = true, ParameterSetName = ParameterSET_PRIVATE)] | ||
public string OwnerUPN; | ||
|
||
[Parameter(Mandatory = false, ParameterSetName = ParameterSET_PUBLIC)] | ||
[Parameter(Mandatory = false, ParameterSetName = ParameterSET_SPECIFIC)] | ||
[Parameter(Mandatory = false, ParameterSetName = ParameterSET_STANDARD)] | ||
public bool IsFavoriteByDefault; | ||
|
||
protected override void ExecuteCmdlet() | ||
{ | ||
var groupId = Team.GetGroupId(Connection, AccessToken); | ||
if (groupId != null) | ||
if (groupId == null) | ||
{ | ||
throw new PSArgumentException("Group not found"); | ||
} | ||
|
||
switch (ParameterSetName) | ||
{ | ||
try | ||
case ParameterSET_PRIVATE: | ||
ChannelType = TeamsChannelType.Private; | ||
break; | ||
|
||
case ParameterSET_STANDARD: | ||
ChannelType = TeamsChannelType.Standard; | ||
break; | ||
} | ||
|
||
try | ||
{ | ||
var channel = TeamsUtility.AddChannelAsync(AccessToken, Connection, groupId, DisplayName, Description, ChannelType, OwnerUPN, IsFavoriteByDefault).GetAwaiter().GetResult(); | ||
WriteObject(channel); | ||
} | ||
catch (GraphException ex) | ||
{ | ||
if (ex.Error != null) | ||
{ | ||
var channel = TeamsUtility.AddChannelAsync(AccessToken, Connection, groupId, DisplayName, Description, Private, OwnerUPN, IsFavoriteByDefault).GetAwaiter().GetResult(); | ||
WriteObject(channel); | ||
throw new PSInvalidOperationException(ex.Error.Message); | ||
} | ||
catch (GraphException ex) | ||
else | ||
{ | ||
if (ex.Error != null) | ||
{ | ||
throw new PSInvalidOperationException(ex.Error.Message); | ||
} | ||
else | ||
{ | ||
throw; | ||
} | ||
throw; | ||
} | ||
} | ||
else | ||
{ | ||
throw new PSArgumentException("Group not found"); | ||
} | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters