Skip to content

Commit

Permalink
Fixes #1365 (#1397)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdriscoll authored Dec 18, 2019
1 parent 4d0ea7f commit ec1f6df
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/UniversalDashboard.UITest/Integration/Api.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ Describe "Api" {
param($test)
@("Adam", "Bill", "Frank", $test) | ConvertTo-Json
}
New-UDEndpoint -Url "user" -Method "PATCH" -Endpoint {
param($test)
@("Adam", "Bill", "Frank", $test) | ConvertTo-Json
}
New-UDEndpoint -Url "project" -Method "GET" -Endpoint {

Set-UDContentType "application/xml"
Expand Down Expand Up @@ -193,6 +197,14 @@ Describe "Api" {
$users[3] | Should be "xyz"
}

It "returns users from the patch endpoint" -Skip {
$users = Invoke-RestMethod -Uri http://localhost:10001/api/user -Method Patch -Body @{Test="xyz"}
$users[0] | Should be "Adam"
$users[1] | Should be "Bill"
$users[2] | Should be "Frank"
$users[3] | Should be "xyz"
}

It "returns users from query string" {
$users = Invoke-RestMethod -Uri http://localhost:10001/api/querystring?Test=xyz -Method POST
$users[0] | Should be "Adam"
Expand Down
2 changes: 1 addition & 1 deletion src/UniversalDashboard/Cmdlets/NewEndpointCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class NewEndpointCommand : PSCmdlet
public SwitchParameter EvaluateUrlAsRegex { get; set; }

[Parameter(ParameterSetName = "Rest")]
[ValidateSet("GET", "POST", "DELETE", "PUT")]
[ValidateSet("GET", "POST", "DELETE", "PUT", "PATCH")]
public string Method { get; set; } = "GET";

[Parameter(ParameterSetName = "Rest")]
Expand Down
33 changes: 32 additions & 1 deletion src/UniversalDashboard/Controllers/ComponentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,38 @@ public async Task<IActionResult> PostEndpoint()
return StatusCode(404);
}

[HttpPut]
[HttpPatch]
[Route("/api/{*parts}")]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public async Task<IActionResult> PatchEndpoint()
{
var parts = HttpContext.GetRouteValue("parts") as string;

Log.Info($"PatchEndpoint - {parts}");

var variables = new Dictionary<string, object>();
SetQueryStringValues(variables);

if (!await TryProcessBodyAsForm(Request, variables))
{
//If we made it here we either have a non-form content type
//or the request was made with the default content type of form
//when it is really something else (probably application/json)
ProcessBodyAsRaw(Request, variables);
}

var endpoint = _dashboardService.EndpointService.GetByUrl(parts, "PATCH", variables);
if (endpoint != null)
{
return await RunScript(endpoint, variables);
}

Log.Info("Did not match endpoint.");

return StatusCode(404);
}

[HttpPut]
[Route("/api/{*parts}")]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public async Task<IActionResult> PutEndpoint()
Expand Down

0 comments on commit ec1f6df

Please sign in to comment.