mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
113 lines
3.4 KiB
113 lines
3.4 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Security.Claims;
|
|
using Squidex.Domain.Apps.Entities.Apps;
|
|
using Squidex.Infrastructure;
|
|
using Squidex.Infrastructure.Security;
|
|
|
|
namespace Squidex.Domain.Apps.Entities
|
|
{
|
|
public sealed class QueryContext : Cloneable<QueryContext>
|
|
{
|
|
private static readonly char[] Separators = { ',', ';' };
|
|
|
|
public ClaimsPrincipal User { get; private set; }
|
|
|
|
public IAppEntity App { get; private set; }
|
|
|
|
public bool Archived { get; private set; }
|
|
|
|
public bool Flatten { get; private set; }
|
|
|
|
public bool Unpublished { get; set; }
|
|
|
|
public ISet<string> AssetUrlsToResolve { get; private set; }
|
|
|
|
public ISet<Language> Languages { get; private set; }
|
|
|
|
private QueryContext()
|
|
{
|
|
}
|
|
|
|
public static QueryContext Create(IAppEntity app, ClaimsPrincipal user)
|
|
{
|
|
return new QueryContext { App = app, User = user };
|
|
}
|
|
|
|
public QueryContext WithUnpublished(bool unpublished)
|
|
{
|
|
return Clone(c => c.Unpublished = unpublished);
|
|
}
|
|
|
|
public QueryContext WithArchived(bool archived)
|
|
{
|
|
return Clone(c => c.Archived = archived);
|
|
}
|
|
|
|
public QueryContext WithFlatten(bool flatten)
|
|
{
|
|
return Clone(c => c.Flatten = flatten);
|
|
}
|
|
|
|
public QueryContext WithAssetUrlsToResolve(IEnumerable<string> fieldNames)
|
|
{
|
|
if (fieldNames != null)
|
|
{
|
|
return Clone(c =>
|
|
{
|
|
var fields = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
|
|
|
foreach (var part in fieldNames)
|
|
{
|
|
foreach (var fieldName in part.Split(Separators, StringSplitOptions.RemoveEmptyEntries))
|
|
{
|
|
fields.Add(fieldName.Trim());
|
|
}
|
|
}
|
|
|
|
c.AssetUrlsToResolve = fields;
|
|
});
|
|
}
|
|
|
|
return this;
|
|
}
|
|
|
|
public QueryContext WithLanguages(IEnumerable<string> languageCodes)
|
|
{
|
|
if (languageCodes != null)
|
|
{
|
|
return Clone(c =>
|
|
{
|
|
var languages = new HashSet<Language>();
|
|
|
|
foreach (var part in languageCodes)
|
|
{
|
|
foreach (var iso2Code in part.Split(Separators, StringSplitOptions.RemoveEmptyEntries))
|
|
{
|
|
if (Language.TryGetLanguage(iso2Code.Trim(), out var language))
|
|
{
|
|
languages.Add(language);
|
|
}
|
|
}
|
|
}
|
|
|
|
c.Languages = languages;
|
|
});
|
|
}
|
|
|
|
return this;
|
|
}
|
|
|
|
public bool IsFrontendClient
|
|
{
|
|
get { return User.IsInClient("squidex-frontend"); }
|
|
}
|
|
}
|
|
}
|
|
|