Skip to content

Commit

Permalink
extension method for httpcontext
Browse files Browse the repository at this point in the history
  • Loading branch information
acn-sbuad committed Oct 16, 2023
1 parent 82c47b8 commit f296797
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public async Task<ActionResult<OrderIdExt>> Post(EmailNotificationOrderRequestEx
return ValidationProblem(ModelState);
}

string? creator = HttpContext.Items["Org"] as string;
string? creator = HttpContext.GetOrg();

if (creator == null)
{
Expand Down
7 changes: 4 additions & 3 deletions src/Altinn.Notifications/Controllers/OrdersController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Altinn.Notifications.Core.Services.Interfaces;
using Altinn.Notifications.Extensions;
using Altinn.Notifications.Mappers;
using Altinn.Notifications.Models;

Expand Down Expand Up @@ -42,7 +43,7 @@ public OrdersController(IGetOrderService getOrderService)
[SwaggerResponse(404, "No order with the provided id was found")]
public async Task<ActionResult<NotificationOrderExt>> GetById([FromRoute] Guid id)
{
string? expectedCreator = HttpContext.Items["Org"] as string;
string? expectedCreator = HttpContext.GetOrg();

if (expectedCreator == null)
{
Expand All @@ -69,7 +70,7 @@ public async Task<ActionResult<NotificationOrderExt>> GetById([FromRoute] Guid i
[SwaggerResponse(200, "The list of notification orders matching the provided senders ref was retrieved successfully", typeof(NotificationOrderListExt))]
public async Task<ActionResult<NotificationOrderListExt>> GetBySendersRef([FromQuery, BindRequired] string sendersReference)
{
string? expectedCreator = HttpContext.Items["Org"] as string;
string? expectedCreator = HttpContext.GetOrg();
if (expectedCreator == null)
{
return Forbid();
Expand Down Expand Up @@ -97,7 +98,7 @@ public async Task<ActionResult<NotificationOrderListExt>> GetBySendersRef([FromQ
[SwaggerResponse(404, "No order with the provided id was found")]
public async Task<ActionResult<NotificationOrderWithStatusExt>> GetWithStatusById([FromRoute] Guid id)
{
string? expectedCreator = HttpContext.Items["Org"] as string;
string? expectedCreator = HttpContext.GetOrg();
if (expectedCreator == null)
{
return Forbid();
Expand Down
15 changes: 15 additions & 0 deletions src/Altinn.Notifications/Extensions/HttpContextExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Altinn.Notifications.Extensions;

/// <summary>
/// Extensions for HTTP Context
/// </summary>
public static class HttpContextExtensions
{
/// <summary>
/// Get the org identifier string or null if it is not an org.
/// </summary>
public static string? GetOrg(this HttpContext context)
{
return context.Items["Org"] as string;
}
}

0 comments on commit f296797

Please sign in to comment.