Skip to content
Merged
Changes from all commits
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
18 changes: 4 additions & 14 deletions src/Commands/Files/AddFileSensitivityLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ namespace PnP.PowerShell.Commands.Files
[Cmdlet(VerbsCommon.Add, "PnPFileSensitivityLabel", DefaultParameterSetName = ParameterSet_SINGLE)]
[RequiredApiDelegatedOrApplicationPermissions("graph/Files.ReadWrite.All")]
[RequiredApiDelegatedOrApplicationPermissions("graph/Sites.ReadWrite.All")]

public class AddFileSensitivityLabel : PnPGraphCmdlet
{
private const string ParameterSet_SINGLE = "Single";
Expand Down Expand Up @@ -51,11 +50,12 @@ protected override void ExecuteCmdlet()
IFile file = Identity.GetCoreFile(context, this);
file.EnsureProperties(f => f.VroomDriveID, f => f.VroomItemID, f => f.Name);

var requestUrl = GetRequestUrl(file);
var requestUrl = $"v1.0/drives/{file.VroomDriveID}/items/{file.VroomItemID}/assignSensitivityLabel";
var payloadJson = SerializePayload();

if (ParameterSpecified(nameof(Batch)))
{
requestUrl = $"drives/{file.VroomDriveID}/items/{file.VroomItemID}/assignSensitivityLabel";
QueueBatchRequest(requestUrl, payloadJson, file);
}
else
Expand All @@ -80,12 +80,7 @@ private void QueueBatchRequest(string requestUrl, string payloadJson, IFile file
new ApiRequest(HttpMethod.Post, ApiRequestType.Graph, requestUrl, payloadJson));

LogDebug($"Queued file sensitivity label assignment for {file.Name}");
}

private static string GetRequestUrl(IFile file)
{
return $"v1.0/drives/{file.VroomDriveID}/items/{file.VroomItemID}/assignSensitivityLabel";
}
}

private string SerializePayload()
{
Expand All @@ -96,12 +91,7 @@ private string SerializePayload()
justificationText = JustificationText
};

var serializerOptions = new JsonSerializerOptions
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
};

return JsonSerializer.Serialize(payload, serializerOptions);
return JsonSerializer.Serialize(payload);
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the JsonIgnoreCondition.WhenWritingNull option may cause null values to be serialized into the JSON payload, potentially affecting API behavior. Consider whether null properties should be explicitly excluded from the serialized output.

Suggested change
return JsonSerializer.Serialize(payload);
var options = new JsonSerializerOptions
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
};
return JsonSerializer.Serialize(payload, options);

Copilot uses AI. Check for mistakes.

}
}
}
Loading