mirror of https://github.com/Squidex/squidex.git
20 changed files with 225 additions and 97 deletions
@ -0,0 +1,50 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Contents |
|||
{ |
|||
public static class ContextExtensions |
|||
{ |
|||
private static readonly char[] Separators = { ',', ';' }; |
|||
|
|||
public static bool IsUnpublished(this Context context) |
|||
{ |
|||
return context.Headers.ContainsKey("X-Unpublished"); |
|||
} |
|||
|
|||
public static Context WithUnpublished(this Context context) |
|||
{ |
|||
context.Headers["X-Unpublished"] = "1"; |
|||
|
|||
return context; |
|||
} |
|||
|
|||
public static bool IsFlatten(this Context context) |
|||
{ |
|||
return context.Headers.ContainsKey("X-Flatten"); |
|||
} |
|||
|
|||
public static Context WithFlatten(this Context context) |
|||
{ |
|||
context.Headers["X-Flatten"] = "1"; |
|||
|
|||
return context; |
|||
} |
|||
|
|||
public static bool IsResolveFlow(this Context context) |
|||
{ |
|||
return context.Headers.ContainsKey("X-ResolveFlow"); |
|||
} |
|||
|
|||
public static Context WithResolveFlow(this Context context) |
|||
{ |
|||
context.Headers["X-ResolveFlow"] = "1"; |
|||
|
|||
return context; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,47 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System.Collections.Generic; |
|||
using System.Security.Claims; |
|||
using Squidex.Domain.Apps.Entities.Apps; |
|||
using Squidex.Infrastructure.Security; |
|||
using Squidex.Shared.Identity; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities |
|||
{ |
|||
public sealed class Context |
|||
{ |
|||
public IAppEntity App { get; set; } |
|||
|
|||
public ClaimsPrincipal User { get; set; } |
|||
|
|||
public PermissionSet Permissions { get; set; } |
|||
|
|||
public IDictionary<string, string> Headers { get; } = new Dictionary<string, string>(); |
|||
|
|||
public Context() |
|||
{ |
|||
} |
|||
|
|||
public Context(ClaimsPrincipal user, IAppEntity app) |
|||
{ |
|||
User = user; |
|||
|
|||
if (user != null) |
|||
{ |
|||
Permissions = user.Permissions(); |
|||
} |
|||
|
|||
App = app; |
|||
} |
|||
|
|||
public bool IsFrontendClient |
|||
{ |
|||
get { return User != null && User.IsInClient("squidex-frontend"); } |
|||
} |
|||
} |
|||
} |
|||
@ -1,16 +1,14 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using Squidex.Domain.Apps.Entities.Apps; |
|||
|
|||
namespace Squidex.Web |
|||
namespace Squidex.Domain.Apps.Entities |
|||
{ |
|||
public interface IAppFeature |
|||
public interface IContextProvider |
|||
{ |
|||
IAppEntity App { get; } |
|||
Context Context { get; } |
|||
} |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using Microsoft.AspNetCore.Http; |
|||
using Squidex.Domain.Apps.Entities; |
|||
|
|||
namespace Squidex.Web |
|||
{ |
|||
public static class ContextExtensions |
|||
{ |
|||
public static Context Context(this HttpContext httpContext) |
|||
{ |
|||
var result = httpContext.Features.Get<Context>(); |
|||
|
|||
if (result == null) |
|||
{ |
|||
httpContext.Features.Set(new Context { User = httpContext.User }); |
|||
} |
|||
|
|||
return result; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using Microsoft.AspNetCore.Http; |
|||
using Squidex.Domain.Apps.Entities; |
|||
using Squidex.Infrastructure; |
|||
|
|||
namespace Squidex.Web |
|||
{ |
|||
public sealed class ContextProvider : IContextProvider |
|||
{ |
|||
private readonly IHttpContextAccessor httpContextAccessor; |
|||
|
|||
public Context Context |
|||
{ |
|||
get { return httpContextAccessor.HttpContext.Context(); } |
|||
} |
|||
|
|||
public ContextProvider(IHttpContextAccessor httpContextAccessor) |
|||
{ |
|||
Guard.NotNull(httpContextAccessor, nameof(httpContextAccessor)); |
|||
|
|||
this.httpContextAccessor = httpContextAccessor; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue