From 5d633e40880716fda031addce6bc61dd44adb344 Mon Sep 17 00:00:00 2001 From: Milan Holemans <11723921+milanholemans@users.noreply.github.com> Date: Tue, 7 Jun 2022 23:45:15 +0200 Subject: [PATCH 1/2] Extra parameters for set-plannertask --- documentation/Set-PnPPlannerTask.md | 38 +++++++++++- src/Commands/Model/Planner/PlannerTask.cs | 6 +- .../Model/Planner/PlannerTaskDetails.cs | 8 ++- src/Commands/Planner/SetPlannerTask.cs | 27 +++++++- src/Commands/Utilities/PlannerUtility.cs | 62 ++++++++++++------- 5 files changed, 113 insertions(+), 28 deletions(-) diff --git a/documentation/Set-PnPPlannerTask.md b/documentation/Set-PnPPlannerTask.md index c6d60b8fe..ae5f781d4 100644 --- a/documentation/Set-PnPPlannerTask.md +++ b/documentation/Set-PnPPlannerTask.md @@ -22,7 +22,7 @@ Updates an existing task ``` Set-PnPPlannerTask -TaskId [-Title ] [-Bucket ] [-PercentComplete ] [-DueDateTime ] [-StartDateTime ] - [-AssignedTo ] [-Description ] [] ``` @@ -152,7 +152,41 @@ Type: String[] Parameter Sets: (All) Aliases: -Required: True +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Priority +Sets the priority of the task. Value should be a number between 0 and 10. +- values 0 and 1 are interpreted as _Urgent_ +- values 2, 3 and 4 are interpreted as _Important_ +- values 5, 6 and 7 are interpreted as _Medium_ +- values 8, 9 and 10 are interpreted as _Low_ + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Description +Sets the description (notes) of the task. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False Position: Named Default value: None Accept pipeline input: False diff --git a/src/Commands/Model/Planner/PlannerTask.cs b/src/Commands/Model/Planner/PlannerTask.cs index bf8f4a0f7..450b2cebd 100644 --- a/src/Commands/Model/Planner/PlannerTask.cs +++ b/src/Commands/Model/Planner/PlannerTask.cs @@ -1,8 +1,8 @@ +using PnP.PowerShell.Commands.Model.Graph; +using PnP.PowerShell.Commands.Utilities.JSON; using System; using System.Collections.Generic; using System.Text.Json.Serialization; -using PnP.PowerShell.Commands.Model.Graph; -using PnP.PowerShell.Commands.Utilities.JSON; namespace PnP.PowerShell.Commands.Model.Planner { @@ -16,6 +16,7 @@ public class PlannerTask public string OrderHint { get; set; } public string AssigneePriority { get; set; } public int? PercentComplete { get; set; } + public int? Priority { get; set; } [JsonConverter(typeof(DateTimeISO8601Converter))] public DateTime? StartDateTime { get; set; } @@ -66,5 +67,4 @@ public class AppliedCategories [JsonExtensionData] public IDictionary AdditionalData { get; set; } } - } diff --git a/src/Commands/Model/Planner/PlannerTaskDetails.cs b/src/Commands/Model/Planner/PlannerTaskDetails.cs index 8b52ea7ae..9b5c04fda 100644 --- a/src/Commands/Model/Planner/PlannerTaskDetails.cs +++ b/src/Commands/Model/Planner/PlannerTaskDetails.cs @@ -1,13 +1,19 @@ +using PnP.PowerShell.Commands.Model.Graph; using System; using System.Collections.Generic; using System.Text.Json.Serialization; -using PnP.PowerShell.Commands.Model.Graph; namespace PnP.PowerShell.Commands.Model.Planner { public class PlannerTaskDetails { + [JsonPropertyName("@odata.etag")] + public string ETag { get; set; } + + public string Id { get; set; } + public string Description { get; set; } + public string PreviewType { get; set; } public Dictionary References { get; set; } diff --git a/src/Commands/Planner/SetPlannerTask.cs b/src/Commands/Planner/SetPlannerTask.cs index 2a29d8647..ceb534c6a 100644 --- a/src/Commands/Planner/SetPlannerTask.cs +++ b/src/Commands/Planner/SetPlannerTask.cs @@ -8,7 +8,7 @@ using PnP.PowerShell.Commands.Utilities; using PnP.PowerShell.Commands.Utilities.REST; -namespace PnP.PowerShell.Commands.Graph +namespace PnP.PowerShell.Commands.Planner { [Cmdlet(VerbsCommon.Set, "PnPPlannerTask")] [RequiredMinimalApiPermissions("Group.ReadWrite.All")] @@ -26,12 +26,18 @@ public class SetPlannerTask : PnPGraphCmdlet [Parameter(Mandatory = false)] public int PercentComplete; + [Parameter(Mandatory = false)] + public int Priority; + [Parameter(Mandatory = false)] public DateTime DueDateTime; [Parameter(Mandatory = false)] public DateTime StartDateTime; + [Parameter(Mandatory = false)] + public string Description; + [Parameter(Mandatory = false)] public string[] AssignedTo; @@ -57,14 +63,27 @@ protected override void ExecuteCmdlet() { plannerTask.PercentComplete = PercentComplete; } + + if (ParameterSpecified(nameof(Priority))) + { + if (Priority < 0 || Priority > 10) + { + throw new PSArgumentException($"Parameter '{nameof(Priority)}' must be a number between 0 and 10."); + } + + plannerTask.Priority = Priority; + } + if (ParameterSpecified(nameof(DueDateTime))) { plannerTask.DueDateTime = DueDateTime.ToUniversalTime(); } + if (ParameterSpecified(nameof(StartDateTime))) { plannerTask.StartDateTime = StartDateTime.ToUniversalTime(); } + if (ParameterSpecified(nameof(AssignedTo))) { plannerTask.Assignments = new System.Collections.Generic.Dictionary(); @@ -88,6 +107,12 @@ protected override void ExecuteCmdlet() PlannerUtility.UpdateTaskAsync(HttpClient, AccessToken, existingTask, plannerTask).GetAwaiter().GetResult(); + + if (ParameterSpecified(nameof(Description))) + { + var existingTaskDetails = PlannerUtility.GetTaskDetailsAsync(HttpClient, AccessToken, TaskId, false).GetAwaiter().GetResult(); + PlannerUtility.UpdateTaskDetailsAsync(HttpClient, AccessToken, existingTaskDetails, Description).GetAwaiter().GetResult(); + } } else { diff --git a/src/Commands/Utilities/PlannerUtility.cs b/src/Commands/Utilities/PlannerUtility.cs index e0d8d4f6e..1bd722a62 100644 --- a/src/Commands/Utilities/PlannerUtility.cs +++ b/src/Commands/Utilities/PlannerUtility.cs @@ -125,29 +125,40 @@ public static async Task GetTaskAsync(HttpClient httpClient, string } if (includeDetails) { - var taskDetails = await GraphHelper.GetAsync(httpClient, $"v1.0/planner/tasks/{taskId}/details", accessToken); - if (resolveDisplayNames) + var taskDetails = await GetTaskDetailsAsync(httpClient, accessToken, taskId, resolveDisplayNames); + task.Details = taskDetails; + } + return task; + } + + public static async Task GetTaskDetailsAsync(HttpClient httpClient, string accessToken, string taskId, bool resolveDisplayNames) + { + var taskDetails = await GraphHelper.GetAsync(httpClient, $"v1.0/planner/tasks/{taskId}/details", accessToken); + if (!resolveDisplayNames) + return taskDetails; + + var newItems = new Dictionary(); + foreach (var checklistItem in taskDetails.Checklist) + { + var newCheckListItem = new PlannerTaskCheckListItem { - Dictionary newItems = new Dictionary(); - foreach (var checklistItem in taskDetails.Checklist) + IsChecked = checklistItem.Value.IsChecked, + LastModifiedDateTime = checklistItem.Value.LastModifiedDateTime, + OrderHint = checklistItem.Value.OrderHint, + Title = checklistItem.Value.Title + }; + if (checklistItem.Value.LastModifiedBy != null) + { + newCheckListItem.LastModifiedBy = new IdentitySet { - var newCheckListItem = new PlannerTaskCheckListItem(); - newCheckListItem.IsChecked = checklistItem.Value.IsChecked; - newCheckListItem.LastModifiedDateTime = checklistItem.Value.LastModifiedDateTime; - newCheckListItem.OrderHint = checklistItem.Value.OrderHint; - newCheckListItem.Title = checklistItem.Value.Title; - if (checklistItem.Value.LastModifiedBy != null) - { - newCheckListItem.LastModifiedBy = new IdentitySet(); - newCheckListItem.LastModifiedBy.User = await ResolveIdentityAsync(httpClient, accessToken, checklistItem.Value.LastModifiedBy.User); - } - newItems.Add(checklistItem.Key, newCheckListItem); - } - taskDetails.Checklist = newItems; + User = await ResolveIdentityAsync(httpClient, accessToken, checklistItem.Value.LastModifiedBy.User) + }; } - task.Details = taskDetails; + newItems.Add(checklistItem.Key, newCheckListItem); } - return task; + taskDetails.Checklist = newItems; + + return taskDetails; } public static async Task AddTaskAsync(HttpClient httpClient, string accessToken, string planId, string bucketId, string title, string[] assignedTo = null) @@ -186,9 +197,18 @@ public static async Task DeleteTaskAsync(HttpClient httpClient, string accessTok public static async Task UpdateTaskAsync(HttpClient httpClient, string accessToken, PlannerTask taskToUpdate, PlannerTask task) { - - return await GraphHelper.PatchAsync(httpClient, accessToken, $"v1.0/planner/tasks/{taskToUpdate.Id}", task, new Dictionary() { { "IF-MATCH", taskToUpdate.ETag } }); + return await GraphHelper.PatchAsync(httpClient, accessToken, $"v1.0/planner/tasks/{taskToUpdate.Id}", task, new Dictionary { { "IF-MATCH", taskToUpdate.ETag } }); } + + public static async Task UpdateTaskDetailsAsync(HttpClient httpClient, string accessToken, PlannerTaskDetails taskToUpdate, string description) + { + var body = new PlannerTaskDetails + { + Description = description, + }; + await GraphHelper.PatchAsync(httpClient, accessToken, $"v1.0/planner/tasks/{taskToUpdate.Id}/details", body, new Dictionary { { "IF-MATCH", taskToUpdate.ETag } }); + } + #endregion #region Rosters From 2e1dccf5828994e74bb3d8c728bff8615655d239 Mon Sep 17 00:00:00 2001 From: = <=> Date: Fri, 10 Jun 2022 00:05:30 +0200 Subject: [PATCH 2/2] Added changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b0d019560..ba16a9201 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Added optional `-Connection` parameter to `Get-PnPConnection`, `Get-PnPContext` and `Set-PnPContext` which allows for using any of these for a specific connection [#1919](https://github.com/pnp/powershell/pull/1919) - Added `-IncludeDeprecated` parameter to `Get-PnPTerm` cmdlet to fetch deprecated terms if specified [#1903](https://github.com/pnp/powershell/pull/1903) - Added optional `-ValidateConnection` to `Connect-PnPOnline` which will check if the site you are connecting to exists and if not, will throw an exception [#1924](https://github.com/pnp/powershell/pull/1924) +- Added `-Description` and `-Priority` to `Set-PnPPlannerTask` [#1947](https://github.com/pnp/powershell/pull/1947) ### Changed - Changed `Sync-PnPSharePointUserProfilesFromAzureActiveDirectory` to map users based on their Ids instead which should resolve some issues around user identities reporting not to exist. You can use the new `-IdType` option to switch it back to `PrincipalName` if needed. [#1752](https://github.com/pnp/powershell/pull/1752)