Skip to content

Commit 3f3b6b1

Browse files
gautamdshethGautam Sheth
andauthored
Feature #3517: Refactor code to use confirm message (#4456)
* Feature #3517: Refactor code to use confirm message * Update docs for cmdlets --------- Co-authored-by: Gautam Sheth <gautam.sheth@staffbase.com>
1 parent 9be6a75 commit 3f3b6b1

30 files changed

+82
-110
lines changed

documentation/Remove-PnPAvailableSiteClassification.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Accept pipeline input: False
5858
Accept wildcard characters: False
5959
```
6060
61-
### -Confirm
61+
### -Force
6262
If provided or set to $true, a confirmation will be asked before the actual remove takes place. If omitted or set to $false, it will remove the site classification(s) without asking for confirmation.
6363
6464
```yaml

documentation/Remove-PnPUser.md

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,27 +47,13 @@ Remove the user with e-mail address user@tenant.onmicrosoft.com from the User In
4747

4848
### EXAMPLE 4
4949
```powershell
50-
Remove-PnPUser -Identity i:0#.f|membership|user@tenant.onmicrosoft.com -Confirm:$false
50+
Remove-PnPUser -Identity i:0#.f|membership|user@tenant.onmicrosoft.com -Force:$false
5151
```
5252

5353
Remove the user with LoginName i:0#.f|membership|user@tenant.onmicrosoft.com from the User Information List of the current site collection without asking to confirm the removal first
5454

5555
## PARAMETERS
5656

57-
### -Confirm
58-
Specifying the Confirm parameter will allow the confirmation question to be skipped
59-
60-
```yaml
61-
Type: SwitchParameter
62-
Parameter Sets: (All)
63-
64-
Required: False
65-
Position: Named
66-
Default value: None
67-
Accept pipeline input: False
68-
Accept wildcard characters: False
69-
```
70-
7157
### -Connection
7258
Optional connection to be used by the cmdlet. Retrieve the value for this parameter by either specifying -ReturnConnection on Connect-PnPOnline or by executing Get-PnPConnection.
7359

@@ -110,8 +96,6 @@ Accept pipeline input: True (ByValue)
11096
Accept wildcard characters: False
11197
```
11298
113-
114-
11599
## RELATED LINKS
116100
117101
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)

src/Commands/Admin/NewSdnProvider.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace PnP.PowerShell.Commands.Admin
66
{
7-
[Cmdlet(VerbsCommon.New, "PnPSdnProvider", SupportsShouldProcess = true)]
7+
[Cmdlet(VerbsCommon.New, "PnPSdnProvider")]
88
public class NewSdnProvider : PnPAdminCmdlet
99
{
1010
[Parameter(Mandatory = true)]
@@ -15,9 +15,9 @@ public class NewSdnProvider : PnPAdminCmdlet
1515

1616
protected override void ExecuteCmdlet()
1717
{
18-
if (ShouldProcess("Adds a new SDN Provider"))
18+
if (ShouldContinue("Add a new SDN Provider", Properties.Resources.Confirm))
1919
{
20-
this.Tenant.AddSdnProvider(Identity, License);
20+
Tenant.AddSdnProvider(Identity, License);
2121
AdminContext.ExecuteQueryRetry();
2222
}
2323
}

src/Commands/Admin/RemoveExternalUser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ protected override void ExecuteCmdlet()
1515
var office365Tenant = new Office365Tenant(AdminContext);
1616

1717
var results = office365Tenant.RemoveExternalUsers(UniqueIDs);
18-
if (this.ShouldProcess(nameof(UniqueIDs), "Remove External Users"))
18+
if (ShouldContinue("Remove External Users ?", Properties.Resources.Confirm))
1919
{
2020
var resultObject = new PSObject();
2121
AdminContext.Load(results);

src/Commands/Admin/RemoveSdnProvider.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
namespace PnP.PowerShell.Commands.Admin
66
{
7-
[Cmdlet(VerbsCommon.Remove, "PnPSdnProvider", SupportsShouldProcess = true)]
7+
[Cmdlet(VerbsCommon.Remove, "PnPSdnProvider")]
88
public class RemoveSdnProvider : PnPAdminCmdlet
99
{
1010
protected override void ExecuteCmdlet()
1111
{
12-
if (ShouldProcess("Removes a SDN Provider"))
12+
if (ShouldContinue("Removes a SDN Provider", Properties.Resources.Confirm))
1313
{
14-
this.Tenant.RemoveSdnProvider();
14+
Tenant.RemoveSdnProvider();
1515
AdminContext.ExecuteQueryRetry();
1616
}
1717
}

src/Commands/Admin/RepairSite.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using Microsoft.SharePoint.Client;
22
using PnP.PowerShell.Commands.Base;
3-
using System.Management.Automation;
43
using PnP.PowerShell.Commands.Base.PipeBinds;
54
using System;
6-
using System.Text;
75
using System.Collections.Generic;
6+
using System.Management.Automation;
7+
using System.Text;
88

99
namespace PnP.PowerShell.Commands.Admin
1010
{
@@ -39,7 +39,7 @@ protected override void ExecuteCmdlet()
3939
{
4040
builder.Append($", RuleId {RuleId}");
4141
}
42-
if (this.ShouldProcess(builder.ToString()))
42+
if (ShouldContinue(builder.ToString(), Properties.Resources.Confirm))
4343
{
4444
var result = new PSObject();
4545
result.Properties.Add(new PSNoteProperty("SiteUrl", site.Url));

src/Commands/Admin/RevokeUserSession.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
namespace PnP.PowerShell.Commands.Admin
77
{
8-
[Cmdlet(VerbsSecurity.Revoke, "PnPUserSession", SupportsShouldProcess = true)]
8+
[Cmdlet(VerbsSecurity.Revoke, "PnPUserSession")]
99
public class RevokeUserSession : PnPAdminCmdlet
1010
{
1111
[Parameter(Mandatory = true)]
1212
[ValidateNotNull]
1313
public string User;
1414
protected override void ExecuteCmdlet()
1515
{
16-
if (ShouldProcess($"Sign out user {User} from all devices"))
16+
if (ShouldContinue($"Sign out user {User} from all devices ?", Properties.Resources.Confirm))
1717
{
1818
var office365Tenant = new Office365Tenant(AdminContext);
1919

src/Commands/Admin/SetHomeSite.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected override void ExecuteCmdlet()
3030

3131
if (Tenant.IsMultipleVivaConnectionsFlightEnabled)
3232
{
33-
if (Force.IsPresent || ShouldContinue("Before you update a home site or Viva Connections experiences, make sure you review the documentation at https://aka.ms/homesites. Continue?", string.Empty))
33+
if (Force || ShouldContinue("Before you update a home site or Viva Connections experiences, make sure you review the documentation at https://aka.ms/homesites.", Properties.Resources.Confirm))
3434
{
3535
IEnumerable<TargetedSiteDetails> enumerable = Tenant.GetTargetedSitesDetails()?.Where((TargetedSiteDetails hs) => !hs.IsVivaBackendSite);
3636
AdminContext.ExecuteQueryRetry();
@@ -61,9 +61,9 @@ protected override void ExecuteCmdlet()
6161
WriteObject(clientResult.Value);
6262
}
6363
}
64-
else if (Force.IsPresent || ShouldContinue("Before you set a Home site, make sure you review the documentation at https://aka.ms/homesites. Continue?", string.Empty))
64+
else if (Force || ShouldContinue("Before you set a Home site, make sure you review the documentation at https://aka.ms/homesites.", Properties.Resources.Confirm))
6565
{
66-
Tenant.ValidateVivaHomeParameterExists(VivaConnectionsDefaultStart);
66+
Tenant.ValidateVivaHomeParameterExists(VivaConnectionsDefaultStart);
6767
HomeSiteConfigurationParam configuration = null;
6868
if (VivaConnectionsDefaultStart || DraftMode)
6969
{
@@ -78,7 +78,7 @@ protected override void ExecuteCmdlet()
7878
ClientResult<string> clientResult = Tenant.SetSPHSiteWithConfiguration(HomeSiteUrl, configuration);
7979
AdminContext.ExecuteQueryRetry();
8080
WriteObject(clientResult.Value);
81-
}
81+
}
8282
}
8383

8484
private static bool IsSameSiteUrl(string url1, string url2)

src/Commands/Admin/SetSiteArchiveState.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected override void ExecuteCmdlet()
3232
{
3333
WriteObject("The site and its contents cannot be accessed when a site is archived. The site needs to be reactivated if it needs to be accessed. Archived sites can be reactivated instantaneously, without any additional charges within 7 days of the action. After 7 days, reactivations will be charged as per Microsoft 365 Archive Billing, and will take time.");
3434

35-
if (Force || ShouldProcess(Identity.Url))
35+
if (Force || ShouldContinue(Identity.Url, Properties.Resources.Confirm))
3636
{
3737
spoOperation = Tenant.ArchiveSiteByUrl(Identity.Url);
3838
AdminContext.Load(spoOperation);
@@ -52,7 +52,7 @@ protected override void ExecuteCmdlet()
5252
case "FullyArchived":
5353
{
5454
WriteWarning("Reactivating a site from \"Archived\" state is a paid operation. It can take upto 24hrs for the site to be reactivated. Performing the operation \"Reactivate Archived site\" on target.");
55-
if (Force || ShouldProcess(Identity.Url))
55+
if (Force || ShouldContinue(Identity.Url, Properties.Resources.Confirm))
5656
{
5757
spoOperation = Tenant.UnarchiveSiteByUrl(Identity.Url);
5858
AdminContext.Load(spoOperation);
@@ -65,7 +65,7 @@ protected override void ExecuteCmdlet()
6565
{
6666
string resourceString = "Reactivating a site from \"Recently Archived\" state is free. Site will be available as an Active site soon.";
6767
WriteObject(resourceString);
68-
if (Force || ShouldProcess(Identity.Url))
68+
if (Force || ShouldContinue(Identity.Url, Properties.Resources.Confirm))
6969
{
7070
spoOperation = Tenant.UnarchiveSiteByUrl(Identity.Url);
7171
AdminContext.Load(spoOperation);

src/Commands/Admin/TestSite.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using Microsoft.SharePoint.Client;
22
using PnP.PowerShell.Commands.Base;
3-
using System.Management.Automation;
43
using PnP.PowerShell.Commands.Base.PipeBinds;
54
using System;
6-
using System.Text;
75
using System.Collections.Generic;
6+
using System.Management.Automation;
7+
using System.Text;
88

99
namespace PnP.PowerShell.Commands.Admin
1010
{
@@ -28,7 +28,7 @@ protected override void ExecuteCmdlet()
2828
siteUrl = Identity.Url;
2929
}
3030

31-
var site = this.Tenant.GetSiteByUrl(siteUrl);
31+
var site = Tenant.GetSiteByUrl(siteUrl);
3232
AdminContext.Load(site);
3333
AdminContext.ExecuteQueryRetry();
3434

@@ -39,7 +39,7 @@ protected override void ExecuteCmdlet()
3939
{
4040
builder.Append($", RuleId {RuleId}");
4141
}
42-
if (this.ShouldProcess(builder.ToString()))
42+
if (ShouldContinue(builder.ToString(), Properties.Resources.Confirm))
4343
{
4444
var result = new PSObject();
4545
result.Properties.Add(new PSNoteProperty("SiteUrl", site.Url));

0 commit comments

Comments
 (0)