Skip to content

Commit

Permalink
Merge pull request #1947 from milanholemans/setplannertask-params
Browse files Browse the repository at this point in the history
Adds `-Priority` and `-Description` for cmdlet `Set-PnPPlannerTask`
  • Loading branch information
KoenZomers authored Jun 9, 2022
2 parents d387980 + 36c87ab commit 457a769
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 28 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added `-IncludeDeprecated` parameter to `Get-PnPTerm` cmdlet to fetch deprecated terms if specified [#1903](https://github.com/pnp/powershell/pull/1903)
- Added `-IncludeContentType` parameter, which if specified will retrieve content type information of the list items. [#1921](https://github.com/pnp/powershell/pull/1921)
- 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)
- Added `AllowTenantMoveWithDataMigration` to `Get-PnPPlannerConfiguration` and `Set-PnPPlannerConfiguration` [#1934](https://github.com/pnp/powershell/pull/1934)
- Added the ability to retrieve a Planner plan by only its Id using `Get-PnPPlannerPlan -Identity <id>` [#1935](https://github.com/pnp/powershell/pull/1935)
- Added `Add-PnPListItemAttachment` cmdlet to provide ability to upload a file as an attachment to a SharePoint list item. [#1932](https://github.com/pnp/powershell/pull/1932)
Expand Down
38 changes: 36 additions & 2 deletions documentation/Set-PnPPlannerTask.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Updates an existing task
```
Set-PnPPlannerTask -TaskId <String> [-Title <String>] [-Bucket <PlannerBucketPipeBind>]
[-PercentComplete <Int32>] [-DueDateTime <DateTime>] [-StartDateTime <DateTime>]
[-AssignedTo <String[]
[-AssignedTo <String[]] [-Priority <Int32>] [-Description <String>]
[<CommonParameters>]
```

Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/Commands/Model/Planner/PlannerTask.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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; }
Expand Down Expand Up @@ -66,5 +67,4 @@ public class AppliedCategories
[JsonExtensionData]
public IDictionary<string, object> AdditionalData { get; set; }
}

}
8 changes: 7 additions & 1 deletion src/Commands/Model/Planner/PlannerTaskDetails.cs
Original file line number Diff line number Diff line change
@@ -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<string, PlannerTaskExternalReference> References { get; set; }
Expand Down
27 changes: 26 additions & 1 deletion src/Commands/Planner/SetPlannerTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand 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;

Expand All @@ -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<string, TaskAssignment>();
Expand All @@ -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
{
Expand Down
62 changes: 41 additions & 21 deletions src/Commands/Utilities/PlannerUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,29 +125,40 @@ public static async Task<PlannerTask> GetTaskAsync(HttpClient httpClient, string
}
if (includeDetails)
{
var taskDetails = await GraphHelper.GetAsync<PlannerTaskDetails>(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<PlannerTaskDetails> GetTaskDetailsAsync(HttpClient httpClient, string accessToken, string taskId, bool resolveDisplayNames)
{
var taskDetails = await GraphHelper.GetAsync<PlannerTaskDetails>(httpClient, $"v1.0/planner/tasks/{taskId}/details", accessToken);
if (!resolveDisplayNames)
return taskDetails;

var newItems = new Dictionary<string, PlannerTaskCheckListItem>();
foreach (var checklistItem in taskDetails.Checklist)
{
var newCheckListItem = new PlannerTaskCheckListItem
{
Dictionary<string, PlannerTaskCheckListItem> newItems = new Dictionary<string, PlannerTaskCheckListItem>();
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<PlannerTask> AddTaskAsync(HttpClient httpClient, string accessToken, string planId, string bucketId, string title, string[] assignedTo = null)
Expand Down Expand Up @@ -186,9 +197,18 @@ public static async Task DeleteTaskAsync(HttpClient httpClient, string accessTok

public static async Task<PlannerTask> UpdateTaskAsync(HttpClient httpClient, string accessToken, PlannerTask taskToUpdate, PlannerTask task)
{

return await GraphHelper.PatchAsync<PlannerTask>(httpClient, accessToken, $"v1.0/planner/tasks/{taskToUpdate.Id}", task, new Dictionary<string, string>() { { "IF-MATCH", taskToUpdate.ETag } });
return await GraphHelper.PatchAsync(httpClient, accessToken, $"v1.0/planner/tasks/{taskToUpdate.Id}", task, new Dictionary<string, string> { { "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<string, string> { { "IF-MATCH", taskToUpdate.ETag } });
}

#endregion

#region Rosters
Expand Down

0 comments on commit 457a769

Please sign in to comment.