Skip to content

Commit

Permalink
Merge pull request #4125 from KoenZomers/FixNewContainerTypeBilling
Browse files Browse the repository at this point in the history
Fixing `New-PnPContainerType` to allow billing information to be provided for standard containers
  • Loading branch information
KoenZomers authored Oct 3, 2024
2 parents 5829e1a + 62c818f commit e79f941
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 50 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- `-Interactive` login is now the default.
- In case of errors when Graph batch method is used, it will now throw a clearer error message about what was the issue. [#4327](https://github.com/pnp/powershell/pull/4327/)
- `Get-PnPAccessToken`, `Request-PnPAccessToken` and `Get-PnPGraphAccessToken` output type is changed to `Microsoft.IdentityModel.JsonWebTokens.JsonWebToken`. Earlier they returned `System.IdentityModel.Tokens.Jwt`.
- `New-PnPContainerType` will temporarily disable standard containers to be created due to changed being applied at Microsoft to allow this to be possible in the future [#4125](https://github.com/pnp/powershell/pull/4125)

### Fixed

Expand All @@ -39,7 +40,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Fix `Get-PnPSiteTemplate -PersistMultiLanguageResources` not working correctly for xml file types. [#4326](https://github.com/pnp/powershell/pull/4326)
- Fix `Add-PnPDataRowsToSiteTemplate` setting keyColumn to null when not passed. [#4325](https://github.com/pnp/powershell/pull/4325)
- Fix `Connect-PnPOnline` not working correctly when `-DeviceLogin` and `-LaunchBrowser` both are specified. It used to open it in a popup. Now it correctly launches the browser. [#4325](https://github.com/pnp/powershell/pull/4345)

### Removed

### Contributors
Expand Down
8 changes: 4 additions & 4 deletions documentation/New-PnPContainerType.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ Create a Container Type for a SharePoint Embedded Application. Refer to [Hands o
### Trial

```powershell
New-PnPContainerType -ContainerTypeName <string> -OwningApplicationId <Guid> -TrialContainerType <SwitchParameter> [-Region <String>] [-AzureSubscriptionId <Guid>] [-ResourceGroup <String>]
New-PnPContainerType -ContainerTypeName <string> -OwningApplicationId <Guid> -TrialContainerType [-Verbose]
```

### Standard

```powershell
New-PnPContainerType -ContainerTypeName <string> -OwningApplicationId <Guid> -Region <String> -AzureSubscriptionId <Guid> -ResourceGroup <String>
New-PnPContainerType -ContainerTypeName <string> -OwningApplicationId <Guid> -Region <String> -AzureSubscriptionId <Guid> -ResourceGroup <String> [-Verbose]
```

## DESCRIPTION
Expand All @@ -40,7 +40,7 @@ Enables the creation of either a trial or standard SharePoint Container Type. Us
### EXAMPLE 1

```powershell
New-PnPContainerType -ContainerTypeName "test1" -OwningApplicationId 50785fde-3082-47ac-a36d-06282ac5c7da -AzureSubscription c7170373-eb8d-4984-8cc9-59bcc88c65a0 -ResouceGroup "SPEmbed" -Region "Uk-South"
New-PnPContainerType -ContainerTypeName "test1" -OwningApplicationId 50785fde-3082-47ac-a36d-06282ac5c7da -AzureSubscription c7170373-eb8d-4984-8cc9-59bcc88c65a0 -ResouceGroup "SPEmbed" -Region "Uk-South"
```

Creates a standard SharePoint Container Type.
Expand Down Expand Up @@ -149,4 +149,4 @@ Accept wildcard characters: False
## RELATED LINKS
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
[https://pnp.github.io/pnpframework/api/PnP.Framework.Enums.TimeZone.html](https://pnp.github.io/pnpframework/api/PnP.Framework.Enums.TimeZone.html)
[SharePoint Online Embedded Container Types](https://learn.microsoft.com/sharepoint/dev/embedded/concepts/app-concepts/containertypes)
115 changes: 70 additions & 45 deletions src/Commands/Admin/NewContainerType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,70 +6,95 @@

namespace PnP.PowerShell.Commands.Admin
{
[Cmdlet(VerbsCommon.New, "PnPContainerType")]
public class NewContainerType : PnPAdminCmdlet, IDynamicParameters
[Cmdlet(VerbsCommon.New, "PnPContainerType", DefaultParameterSetName = ParameterSet_Trial)]
public class NewContainerType : PnPAdminCmdlet
{
private const string ParameterSet_Trial = "Trial";
private const string ParameterSet_Standard = "Standard";

[Parameter(Mandatory = true)]

[Parameter(Mandatory = true, ParameterSetName = ParameterSet_Trial)]
[Parameter(Mandatory = true, ParameterSetName = ParameterSet_Standard)]
public string ContainerTypeName;

[Parameter(Mandatory = true)]
[Parameter(Mandatory = true, ParameterSetName = ParameterSet_Trial)]
[Parameter(Mandatory = true, ParameterSetName = ParameterSet_Standard)]
public Guid OwningApplicationId;

[Parameter(Mandatory = false)]
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_Trial)]
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_Standard)]
public SwitchParameter TrialContainerType;
private StandardContainerParameters _standardContainerParameters;
public object GetDynamicParameters()

[Parameter(Mandatory = true, ParameterSetName = ParameterSet_Standard)]
public Guid? AzureSubscriptionId;

[Parameter(Mandatory = true, ParameterSetName = ParameterSet_Standard)]
public string ResourceGroup;

[Parameter(Mandatory = true, ParameterSetName = ParameterSet_Standard)]
public string Region;

protected override void ExecuteCmdlet()
{
if(!ParameterSpecified(nameof(TrialContainerType)))
// Ensure when creating a standard container type that the required parameters are provided
if(ParameterSpecified(nameof(TrialContainerType)) && !TrialContainerType.ToBool() && (!AzureSubscriptionId.HasValue || string.IsNullOrWhiteSpace(ResourceGroup) || string.IsNullOrWhiteSpace(Region)))
{
_standardContainerParameters = new StandardContainerParameters();
return _standardContainerParameters;
throw new PSArgumentException($"{nameof(AzureSubscriptionId)}, {nameof(ResourceGroup)} and {nameof(Region)} are required when creating a standard container type");
}
return null;
}

//
// NOTICE: The SharePoint API being used in this code is of temporary nature.
// It will be replaced by Microsoft Graph in due time.
// This SharePoint API should not be called directly or implemented into your own tools or software.
// When the Microsoft Graph alternative becomes available, this PnP cmdlet will be rewritten to use it instead.
// So when using this PnP PowerShell cmdlet, the goal is to seemlessly transition to the new API.
// When you would use it in your own code directly, it will stop working at some point in time without prior announcement.
//
SPContainerTypeProperties sPContainerTypeProperties;
if (!ParameterSpecified(nameof(TrialContainerType)) || !TrialContainerType.ToBool())
{
WriteWarning($"Creation of standard container types is not yet supported. This will be enabled in the future. For now, only trial container types can be created by adding the -{nameof(TrialContainerType)} parameter.");
return;

protected override void ExecuteCmdlet()
{
SPContainerTypeProperties sPContainerTypeProperties = new SPContainerTypeProperties();
sPContainerTypeProperties.DisplayName = ContainerTypeName;
sPContainerTypeProperties.OwningAppId = OwningApplicationId;

sPContainerTypeProperties.SPContainerTypeBillingClassification = TrialContainerType ? SPContainerTypeBillingClassification.Trial : SPContainerTypeBillingClassification.Standard;
if(!ParameterSpecified(nameof(TrialContainerType)))
// NOTICE:
// Currently disabled by request of the product group as it doesn't work reliably yet
// Once the official endpoint to create standard container types is available, this code can be enabled again and will point to the proper API to use

// WriteVerbose("Creating a standard container type");

// sPContainerTypeProperties = new SPContainerTypeProperties
// {
// DisplayName = ContainerTypeName,
// OwningAppId = OwningApplicationId,
// AzureSubscriptionId = AzureSubscriptionId.Value,
// ResourceGroup = ResourceGroup,
// Region = Region,
// SPContainerTypeBillingClassification = SPContainerTypeBillingClassification.Standard
// };
}
else
{
sPContainerTypeProperties.AzureSubscriptionId = _standardContainerParameters.AzureSubscriptionId;
sPContainerTypeProperties.ResourceGroup = _standardContainerParameters.ResourceGroup;
sPContainerTypeProperties.Region = _standardContainerParameters.Region;
WriteVerbose("Creating a trial container type");

sPContainerTypeProperties = new SPContainerTypeProperties
{
DisplayName = ContainerTypeName,
OwningAppId = OwningApplicationId,
SPContainerTypeBillingClassification = SPContainerTypeBillingClassification.Trial
};
}
ClientResult<SPContainerTypeProperties> sPOContainerTypeId = Tenant.NewSPOContainerType(sPContainerTypeProperties);

//
// NOTICE: The SharePoint API being used in this code is of temporary nature.
// It will be replaced by Microsoft Graph in due time.
// This SharePoint API should not be called directly or implemented into your own tools or software.
// When the Microsoft Graph alternative becomes available, this PnP cmdlet will be rewritten to use it instead.
// So when using this PnP PowerShell cmdlet, the goal is to seemlessly transition to the new API.
// When you would use it in your own code directly, it will stop working at some point in time without prior announcement.
//

var sPOContainerTypeId = Tenant.NewSPOContainerType(sPContainerTypeProperties);
AdminContext.ExecuteQueryRetry();

if (sPOContainerTypeId != null && sPOContainerTypeId.Value != null)
{
WriteObject(new Model.SharePoint.SPContainerTypeObj(sPOContainerTypeId.Value));
}
}

public class StandardContainerParameters
{
[Parameter(Mandatory = true, ParameterSetName = ParameterSet_Standard)]
public Guid AzureSubscriptionId;

[Parameter(Mandatory = true, ParameterSetName = ParameterSet_Standard)]
public string ResourceGroup;

[Parameter(Mandatory = true, ParameterSetName = ParameterSet_Standard)]
public string Region;
else
{
WriteVerbose("Failed to create container type");
}
}
}
}

0 comments on commit e79f941

Please sign in to comment.