-
Notifications
You must be signed in to change notification settings - Fork 359
/
Copy pathUpdateSiteClassification.cs
87 lines (81 loc) · 3.64 KB
/
UpdateSiteClassification.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using PnP.Framework.Graph.Model;
using PnP.PowerShell.Commands.Attributes;
using PnP.PowerShell.Commands.Base;
using System;
using System.Collections.Generic;
using System.Management.Automation;
namespace PnP.PowerShell.Commands.Site
{
[Cmdlet(VerbsData.Update, "PnPSiteClassification")]
[RequiredMinimalApiPermissions("Directory.ReadWrite.All")]
public class UpdateSiteClassification : PnPGraphCmdlet
{
const string ParameterSet_SETTINGS = "Settings";
const string ParameterSet_SPECIFIC = "Specific";
[Parameter(Mandatory = true, ParameterSetName = ParameterSet_SETTINGS)]
public SiteClassificationsSettings Settings;
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_SPECIFIC)]
public List<string> Classifications;
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_SPECIFIC)]
public string DefaultClassification;
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_SPECIFIC)]
public string UsageGuidelinesUrl = "";
protected override void ExecuteCmdlet()
{
try
{
var changed = false;
var settings = PnP.Framework.Graph.SiteClassificationsUtility.GetSiteClassificationsSettings(AccessToken);
if (ParameterSpecified(nameof(Classifications)))
{
if (settings.Classifications != Classifications)
{
settings.Classifications = Classifications;
changed = true;
}
}
if (ParameterSpecified(nameof(DefaultClassification)))
{
if (settings.Classifications.Contains(DefaultClassification))
{
if (settings.DefaultClassification != DefaultClassification)
{
settings.DefaultClassification = DefaultClassification;
changed = true;
}
}
}
if (ParameterSpecified(nameof(UsageGuidelinesUrl)))
{
if (settings.UsageGuidelinesUrl != UsageGuidelinesUrl)
{
settings.UsageGuidelinesUrl = UsageGuidelinesUrl;
changed = true;
}
}
if (changed)
{
if (settings.Classifications.Contains(settings.DefaultClassification))
{
PnP.Framework.Graph.SiteClassificationsUtility.UpdateSiteClassificationsSettings(AccessToken, settings);
}
else
{
WriteError(new ErrorRecord(new InvalidOperationException("You are trying to set the default classification to a value that is not available in the list of possible values."), "SITECLASSIFICATION_DEFAULTVALUE_INVALID", ErrorCategory.InvalidArgument, null));
}
}
}
catch (ApplicationException ex)
{
if (ex.Message == @"Missing DirectorySettingTemplate for ""Group.Unified""")
{
WriteError(new ErrorRecord(new InvalidOperationException("Site Classification is not enabled for this tenant. Use Enable-PnPSiteClassification to enable classifications."), "SITECLASSIFICATION_NOT_ENABLED", ErrorCategory.ResourceUnavailable, null));
}
else
{
throw;
}
}
}
}
}