mirror of https://github.com/Squidex/squidex.git
committed by
GitHub
307 changed files with 8017 additions and 6393 deletions
@ -0,0 +1,46 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using Squidex.Infrastructure; |
||||
|
using System; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Core.Contents |
||||
|
{ |
||||
|
public struct Status2 : IEquatable<Status2> |
||||
|
{ |
||||
|
public static readonly Status2 Published = new Status2("Published"); |
||||
|
|
||||
|
public string Name { get; } |
||||
|
|
||||
|
public Status2(string name) |
||||
|
{ |
||||
|
Guard.NotNullOrEmpty(name, nameof(name)); |
||||
|
|
||||
|
Name = name; |
||||
|
} |
||||
|
|
||||
|
public override bool Equals(object obj) |
||||
|
{ |
||||
|
return obj is Status2 status && Equals(status); |
||||
|
} |
||||
|
|
||||
|
public bool Equals(Status2 other) |
||||
|
{ |
||||
|
return Name.Equals(other.Name); |
||||
|
} |
||||
|
|
||||
|
public override int GetHashCode() |
||||
|
{ |
||||
|
return base.GetHashCode(); |
||||
|
} |
||||
|
|
||||
|
public override string ToString() |
||||
|
{ |
||||
|
return Name; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,39 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.Threading; |
||||
|
using MongoDB.Bson.Serialization; |
||||
|
using MongoDB.Bson.Serialization.Serializers; |
||||
|
using Squidex.Domain.Apps.Core.Contents; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Entities.MongoDb.Contents |
||||
|
{ |
||||
|
public sealed class StatusSerializer : SerializerBase<Status2> |
||||
|
{ |
||||
|
private static volatile int isRegistered; |
||||
|
|
||||
|
public static void Register() |
||||
|
{ |
||||
|
if (Interlocked.Increment(ref isRegistered) == 1) |
||||
|
{ |
||||
|
BsonSerializer.RegisterSerializer(new StatusSerializer()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public override Status2 Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args) |
||||
|
{ |
||||
|
var value = context.Reader.ReadString(); |
||||
|
|
||||
|
return new Status2(value); |
||||
|
} |
||||
|
|
||||
|
public override void Serialize(BsonSerializationContext context, BsonSerializationArgs args, Status2 value) |
||||
|
{ |
||||
|
context.Writer.WriteString(value.Name); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,25 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Entities.Assets |
||||
|
{ |
||||
|
public class AssetResult |
||||
|
{ |
||||
|
public IAssetEntity Asset { get; } |
||||
|
|
||||
|
public HashSet<string> Tags { get; } |
||||
|
|
||||
|
public AssetResult(IAssetEntity asset, HashSet<string> tags) |
||||
|
{ |
||||
|
Asset = asset; |
||||
|
|
||||
|
Tags = tags; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,25 +0,0 @@ |
|||||
// ==========================================================================
|
|
||||
// Squidex Headless CMS
|
|
||||
// ==========================================================================
|
|
||||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|
||||
// All rights reserved. Licensed under the MIT license.
|
|
||||
// ==========================================================================
|
|
||||
|
|
||||
using Squidex.Infrastructure.Commands; |
|
||||
|
|
||||
namespace Squidex.Domain.Apps.Entities.Assets |
|
||||
{ |
|
||||
public class AssetSavedResult : EntitySavedResult |
|
||||
{ |
|
||||
public long FileVersion { get; } |
|
||||
|
|
||||
public string FileHash { get; } |
|
||||
|
|
||||
public AssetSavedResult(long version, long fileVersion, string fileHash) |
|
||||
: base(version) |
|
||||
{ |
|
||||
FileVersion = fileVersion; |
|
||||
FileHash = fileHash; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,20 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using Squidex.Infrastructure.Assets; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Entities.Assets.Commands |
||||
|
{ |
||||
|
public abstract class UploadAssetCommand : AssetCommand |
||||
|
{ |
||||
|
public AssetFile File { get; set; } |
||||
|
|
||||
|
public ImageInfo ImageInfo { get; set; } |
||||
|
|
||||
|
public string FileHash { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -1,23 +0,0 @@ |
|||||
// ==========================================================================
|
|
||||
// Squidex Headless CMS
|
|
||||
// ==========================================================================
|
|
||||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|
||||
// All rights reserved. Licensed under the MIT license.
|
|
||||
// ==========================================================================
|
|
||||
|
|
||||
using Squidex.Domain.Apps.Core.Contents; |
|
||||
using Squidex.Infrastructure.Commands; |
|
||||
|
|
||||
namespace Squidex.Domain.Apps.Entities.Contents |
|
||||
{ |
|
||||
public sealed class ContentDataChangedResult : EntitySavedResult |
|
||||
{ |
|
||||
public NamedContentData Data { get; } |
|
||||
|
|
||||
public ContentDataChangedResult(NamedContentData data, long version) |
|
||||
: base(version) |
|
||||
{ |
|
||||
Data = data; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,24 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.Threading.Tasks; |
||||
|
using Squidex.Domain.Apps.Core.Contents; |
||||
|
using Squidex.Domain.Apps.Entities.Schemas; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Entities.Contents |
||||
|
{ |
||||
|
public interface IContentWorkflow |
||||
|
{ |
||||
|
Task<Status2> GetInitialStatusAsync(ISchemaEntity schema); |
||||
|
|
||||
|
Task<bool> IsValidNextStatus(IContentEntity content, Status2 next); |
||||
|
|
||||
|
Task<Status2[]> GetNextsAsync(IContentEntity content); |
||||
|
|
||||
|
Task<Status2[]> GetAllAsync(ISchemaEntity schema); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,76 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using Microsoft.AspNetCore.Http; |
||||
|
using Squidex.Infrastructure.Security; |
||||
|
using Squidex.Shared.Identity; |
||||
|
|
||||
|
namespace Squidex.Web |
||||
|
{ |
||||
|
public static class PermissionExtensions |
||||
|
{ |
||||
|
private sealed class PermissionFeature |
||||
|
{ |
||||
|
public PermissionSet Permissions { get; } |
||||
|
|
||||
|
public PermissionFeature(PermissionSet permissions) |
||||
|
{ |
||||
|
Permissions = permissions; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public static PermissionSet Permissions(this HttpContext httpContext) |
||||
|
{ |
||||
|
var feature = httpContext.Features.Get<PermissionFeature>(); |
||||
|
|
||||
|
if (feature == null) |
||||
|
{ |
||||
|
feature = new PermissionFeature(httpContext.User.Permissions()); |
||||
|
|
||||
|
httpContext.Features.Set(feature); |
||||
|
} |
||||
|
|
||||
|
return feature.Permissions; |
||||
|
} |
||||
|
|
||||
|
public static bool HasPermission(this HttpContext httpContext, Permission permission, PermissionSet permissions = null) |
||||
|
{ |
||||
|
return httpContext.Permissions().Includes(permission) || permissions?.Includes(permission) == true; |
||||
|
} |
||||
|
|
||||
|
public static bool HasPermission(this HttpContext httpContext, string id, string app = "*", string schema = "*", PermissionSet permissions = null) |
||||
|
{ |
||||
|
return httpContext.HasPermission(Shared.Permissions.ForApp(id, app, schema), permissions); |
||||
|
} |
||||
|
|
||||
|
public static bool HasPermission(this ApiController controller, Permission permission, PermissionSet permissions = null) |
||||
|
{ |
||||
|
return controller.HttpContext.HasPermission(permission, permissions); |
||||
|
} |
||||
|
|
||||
|
public static bool HasPermission(this ApiController controller, string id, string app = "*", string schema = "*", PermissionSet permissions = null) |
||||
|
{ |
||||
|
if (app == "*") |
||||
|
{ |
||||
|
if (controller.RouteData.Values.TryGetValue("app", out var value) && value is string s) |
||||
|
{ |
||||
|
app = s; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (schema == "*") |
||||
|
{ |
||||
|
if (controller.RouteData.Values.TryGetValue("name", out var value) && value is string s) |
||||
|
{ |
||||
|
schema = s; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return controller.HasPermission(Shared.Permissions.ForApp(id, app, schema), permissions); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,61 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using Newtonsoft.Json; |
||||
|
using Squidex.Infrastructure; |
||||
|
using System.Collections.Generic; |
||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
|
||||
|
namespace Squidex.Web |
||||
|
{ |
||||
|
public abstract class Resource |
||||
|
{ |
||||
|
[JsonProperty("_links")] |
||||
|
[Required] |
||||
|
[Display(Description = "The links.")] |
||||
|
public Dictionary<string, ResourceLink> Links { get; } = new Dictionary<string, ResourceLink>(); |
||||
|
|
||||
|
public void AddSelfLink(string href) |
||||
|
{ |
||||
|
AddGetLink("self", href); |
||||
|
} |
||||
|
|
||||
|
public void AddGetLink(string rel, string href) |
||||
|
{ |
||||
|
AddLink(rel, "GET", href); |
||||
|
} |
||||
|
|
||||
|
public void AddPatchLink(string rel, string href) |
||||
|
{ |
||||
|
AddLink(rel, "PATCH", href); |
||||
|
} |
||||
|
|
||||
|
public void AddPostLink(string rel, string href) |
||||
|
{ |
||||
|
AddLink(rel, "POST", href); |
||||
|
} |
||||
|
|
||||
|
public void AddPutLink(string rel, string href) |
||||
|
{ |
||||
|
AddLink(rel, "PUT", href); |
||||
|
} |
||||
|
|
||||
|
public void AddDeleteLink(string rel, string href) |
||||
|
{ |
||||
|
AddLink(rel, "DELETE", href); |
||||
|
} |
||||
|
|
||||
|
public void AddLink(string rel, string method, string href) |
||||
|
{ |
||||
|
Guard.NotNullOrEmpty(rel, nameof(rel)); |
||||
|
Guard.NotNullOrEmpty(href, nameof(href)); |
||||
|
Guard.NotNullOrEmpty(method, nameof(method)); |
||||
|
|
||||
|
Links[rel] = new ResourceLink { Href = href, Method = method }; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,44 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using System; |
||||
|
|
||||
|
namespace Squidex.Web |
||||
|
{ |
||||
|
public static class UrlHelperExtensions |
||||
|
{ |
||||
|
private static class NameOf<T> |
||||
|
{ |
||||
|
public static readonly string Controller; |
||||
|
|
||||
|
static NameOf() |
||||
|
{ |
||||
|
const string suffix = "Controller"; |
||||
|
|
||||
|
var name = typeof(T).Name; |
||||
|
|
||||
|
if (name.EndsWith(suffix)) |
||||
|
{ |
||||
|
name = name.Substring(0, name.Length - suffix.Length); |
||||
|
} |
||||
|
|
||||
|
Controller = name; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public static string Url<T>(this IUrlHelper urlHelper, Func<T, string> action, object values = null) where T : Controller |
||||
|
{ |
||||
|
return urlHelper.Action(action(null), NameOf<T>.Controller, values); |
||||
|
} |
||||
|
|
||||
|
public static string Url<T>(this Controller controller, Func<T, string> action, object values = null) where T : Controller |
||||
|
{ |
||||
|
return controller.Url.Url<T>(action, values); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,70 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using NJsonSchema; |
||||
|
using NSwag; |
||||
|
using NSwag.SwaggerGeneration.Processors; |
||||
|
using NSwag.SwaggerGeneration.Processors.Contexts; |
||||
|
using Squidex.ClientLibrary.Management; |
||||
|
using Squidex.Pipeline.Swagger; |
||||
|
|
||||
|
namespace Squidex.Areas.Api.Config.Swagger |
||||
|
{ |
||||
|
public sealed class ErrorDtoProcessor : IDocumentProcessor |
||||
|
{ |
||||
|
public async Task ProcessAsync(DocumentProcessorContext context) |
||||
|
{ |
||||
|
var errorSchema = await GetErrorSchemaAsync(context); |
||||
|
|
||||
|
foreach (var operation in context.Document.Paths.Values.SelectMany(x => x.Values)) |
||||
|
{ |
||||
|
AddErrorResponses(operation, errorSchema); |
||||
|
|
||||
|
CleanupResponses(operation); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private static void AddErrorResponses(SwaggerOperation operation, JsonSchema4 errorSchema) |
||||
|
{ |
||||
|
if (!operation.Responses.ContainsKey("500")) |
||||
|
{ |
||||
|
operation.AddResponse("500", "Operation failed", errorSchema); |
||||
|
} |
||||
|
|
||||
|
foreach (var (code, response) in operation.Responses) |
||||
|
{ |
||||
|
if (code != "404" && code.StartsWith("4", StringComparison.OrdinalIgnoreCase) && response.Schema == null) |
||||
|
{ |
||||
|
response.Schema = errorSchema; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private static void CleanupResponses(SwaggerOperation operation) |
||||
|
{ |
||||
|
foreach (var (code, response) in operation.Responses.ToList()) |
||||
|
{ |
||||
|
if (string.IsNullOrWhiteSpace(response.Description) || |
||||
|
response.Description?.Contains("=>") == true || |
||||
|
response.Description?.Contains("=>") == true) |
||||
|
{ |
||||
|
operation.Responses.Remove(code); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private Task<JsonSchema4> GetErrorSchemaAsync(DocumentProcessorContext context) |
||||
|
{ |
||||
|
var errorType = typeof(ErrorDto); |
||||
|
|
||||
|
return context.SchemaGenerator.GenerateWithReferenceAsync<JsonSchema4>(errorType, Enumerable.Empty<Attribute>(), context.SchemaResolver); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,59 +0,0 @@ |
|||||
// ==========================================================================
|
|
||||
// Squidex Headless CMS
|
|
||||
// ==========================================================================
|
|
||||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|
||||
// All rights reserved. Licensed under the MIT license.
|
|
||||
// ==========================================================================
|
|
||||
|
|
||||
using System; |
|
||||
using System.ComponentModel.DataAnnotations; |
|
||||
using System.Linq; |
|
||||
using Squidex.Domain.Apps.Core.Apps; |
|
||||
using Squidex.Domain.Apps.Entities.Apps.Services; |
|
||||
using Squidex.Infrastructure.Commands; |
|
||||
|
|
||||
namespace Squidex.Areas.Api.Controllers.Apps.Models |
|
||||
{ |
|
||||
public sealed class AppCreatedDto |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Id of the created entity.
|
|
||||
/// </summary>
|
|
||||
[Required] |
|
||||
public string Id { get; set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// The permission level of the user.
|
|
||||
/// </summary>
|
|
||||
public string[] Permissions { get; set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// The new version of the entity.
|
|
||||
/// </summary>
|
|
||||
public long Version { get; set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets the current plan name.
|
|
||||
/// </summary>
|
|
||||
public string PlanName { get; set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets the next plan name.
|
|
||||
/// </summary>
|
|
||||
public string PlanUpgrade { get; set; } |
|
||||
|
|
||||
public static AppCreatedDto FromResult(string name, EntityCreatedResult<Guid> result, IAppPlansProvider apps) |
|
||||
{ |
|
||||
var response = new AppCreatedDto |
|
||||
{ |
|
||||
Id = result.IdOrValue.ToString(), |
|
||||
Permissions = Role.CreateOwner(name).Permissions.ToIds().ToArray(), |
|
||||
PlanName = apps.GetPlan(null)?.Name, |
|
||||
PlanUpgrade = apps.GetPlanUpgrade(null)?.Name, |
|
||||
Version = result.Version |
|
||||
}; |
|
||||
|
|
||||
return response; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,53 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
using System.Linq; |
||||
|
using Squidex.Domain.Apps.Core.Apps; |
||||
|
using Squidex.Domain.Apps.Entities.Apps; |
||||
|
using Squidex.Shared; |
||||
|
using Squidex.Web; |
||||
|
|
||||
|
namespace Squidex.Areas.Api.Controllers.Apps.Models |
||||
|
{ |
||||
|
public sealed class AppLanguagesDto : Resource |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// The languages.
|
||||
|
/// </summary>
|
||||
|
[Required] |
||||
|
public AppLanguageDto[] Items { get; set; } |
||||
|
|
||||
|
public static AppLanguagesDto FromApp(IAppEntity app, ApiController controller) |
||||
|
{ |
||||
|
var result = new AppLanguagesDto |
||||
|
{ |
||||
|
Items = app.LanguagesConfig.OfType<LanguageConfig>() |
||||
|
.Select(x => AppLanguageDto.FromLanguage(x, app, controller)) |
||||
|
.OrderByDescending(x => x.IsMaster) |
||||
|
.ThenBy(x => x.Iso2Code) |
||||
|
.ToArray() |
||||
|
}; |
||||
|
|
||||
|
return result.CreateLinks(controller, app.Name); |
||||
|
} |
||||
|
|
||||
|
private AppLanguagesDto CreateLinks(ApiController controller, string app) |
||||
|
{ |
||||
|
var values = new { app }; |
||||
|
|
||||
|
AddSelfLink(controller.Url<AppLanguagesController>(x => nameof(x.GetLanguages), values)); |
||||
|
|
||||
|
if (controller.HasPermission(Permissions.AppLanguagesCreate, app)) |
||||
|
{ |
||||
|
AddPostLink("create", controller.Url<AppLanguagesController>(x => nameof(x.PostLanguage), values)); |
||||
|
} |
||||
|
|
||||
|
return this; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,48 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
using System.Linq; |
||||
|
using Squidex.Domain.Apps.Entities.Apps; |
||||
|
using Squidex.Shared; |
||||
|
using Squidex.Web; |
||||
|
|
||||
|
namespace Squidex.Areas.Api.Controllers.Apps.Models |
||||
|
{ |
||||
|
public sealed class ClientsDto : Resource |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// The clients.
|
||||
|
/// </summary>
|
||||
|
[Required] |
||||
|
public ClientDto[] Items { get; set; } |
||||
|
|
||||
|
public static ClientsDto FromApp(IAppEntity app, ApiController controller) |
||||
|
{ |
||||
|
var result = new ClientsDto |
||||
|
{ |
||||
|
Items = app.Clients.Select(x => ClientDto.FromClient(x.Key, x.Value, controller, app.Name)).ToArray() |
||||
|
}; |
||||
|
|
||||
|
return result.CreateLinks(controller, app.Name); |
||||
|
} |
||||
|
|
||||
|
private ClientsDto CreateLinks(ApiController controller, string app) |
||||
|
{ |
||||
|
var values = new { app }; |
||||
|
|
||||
|
AddSelfLink(controller.Url<AppClientsController>(x => nameof(x.GetClients), values)); |
||||
|
|
||||
|
if (controller.HasPermission(Permissions.AppClientsCreate, app)) |
||||
|
{ |
||||
|
AddPostLink("create", controller.Url<AppClientsController>(x => nameof(x.PostClient), values)); |
||||
|
} |
||||
|
|
||||
|
return this; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,17 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
namespace Squidex.Areas.Api.Controllers.Apps.Models |
||||
|
{ |
||||
|
public sealed class ContributorsMetadata |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Indicates whether the user has been invited.
|
||||
|
/// </summary>
|
||||
|
public string IsInvited { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,48 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
using System.Linq; |
||||
|
using Squidex.Domain.Apps.Entities.Apps; |
||||
|
using Squidex.Shared; |
||||
|
using Squidex.Web; |
||||
|
|
||||
|
namespace Squidex.Areas.Api.Controllers.Apps.Models |
||||
|
{ |
||||
|
public sealed class PatternsDto : Resource |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// The patterns.
|
||||
|
/// </summary>
|
||||
|
[Required] |
||||
|
public PatternDto[] Items { get; set; } |
||||
|
|
||||
|
public static PatternsDto FromApp(IAppEntity app, ApiController controller) |
||||
|
{ |
||||
|
var result = new PatternsDto |
||||
|
{ |
||||
|
Items = app.Patterns.Select(x => PatternDto.FromPattern(x.Key, x.Value, controller, app.Name)).ToArray() |
||||
|
}; |
||||
|
|
||||
|
return result.CreateLinks(controller, app.Name); |
||||
|
} |
||||
|
|
||||
|
private PatternsDto CreateLinks(ApiController controller, string app) |
||||
|
{ |
||||
|
var values = new { app }; |
||||
|
|
||||
|
AddSelfLink(controller.Url<AppPatternsController>(x => nameof(x.GetPatterns), values)); |
||||
|
|
||||
|
if (controller.HasPermission(Permissions.AppPatternsCreate, app)) |
||||
|
{ |
||||
|
AddPostLink("create", controller.Url<AppPatternsController>(x => nameof(x.PostPattern), values)); |
||||
|
} |
||||
|
|
||||
|
return this; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,108 +0,0 @@ |
|||||
// ==========================================================================
|
|
||||
// Squidex Headless CMS
|
|
||||
// ==========================================================================
|
|
||||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|
||||
// All rights reserved. Licensed under the MIT license.
|
|
||||
// ==========================================================================
|
|
||||
|
|
||||
using System; |
|
||||
using System.Collections.Generic; |
|
||||
using System.ComponentModel.DataAnnotations; |
|
||||
using Squidex.Domain.Apps.Entities.Assets; |
|
||||
using Squidex.Domain.Apps.Entities.Assets.Commands; |
|
||||
using Squidex.Infrastructure; |
|
||||
|
|
||||
namespace Squidex.Areas.Api.Controllers.Assets.Models |
|
||||
{ |
|
||||
public sealed class AssetCreatedDto |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// The id of the asset.
|
|
||||
/// </summary>
|
|
||||
public Guid Id { get; set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// The file type.
|
|
||||
/// </summary>
|
|
||||
[Required] |
|
||||
public string FileType { get; set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// The file name.
|
|
||||
/// </summary>
|
|
||||
[Required] |
|
||||
public string FileName { get; set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// The slug.
|
|
||||
/// </summary>
|
|
||||
[Required] |
|
||||
public string Slug { get; set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// The mime type.
|
|
||||
/// </summary>
|
|
||||
[Required] |
|
||||
public string MimeType { get; set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// The default tags.
|
|
||||
/// </summary>
|
|
||||
[Required] |
|
||||
public HashSet<string> Tags { get; set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// The size of the file in bytes.
|
|
||||
/// </summary>
|
|
||||
public long FileSize { get; set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// The version of the file.
|
|
||||
/// </summary>
|
|
||||
public long FileVersion { get; set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Determines of the created file is an image.
|
|
||||
/// </summary>
|
|
||||
public bool IsImage { get; set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// The width of the image in pixels if the asset is an image.
|
|
||||
/// </summary>
|
|
||||
public int? PixelWidth { get; set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// The height of the image in pixels if the asset is an image.
|
|
||||
/// </summary>
|
|
||||
public int? PixelHeight { get; set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Indicates if the asset has been already uploaded.
|
|
||||
/// </summary>
|
|
||||
public bool IsDuplicate { get; set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// The version of the asset.
|
|
||||
/// </summary>
|
|
||||
public long Version { get; set; } |
|
||||
|
|
||||
public static AssetCreatedDto FromCommand(CreateAsset command, AssetCreatedResult result) |
|
||||
{ |
|
||||
return new AssetCreatedDto |
|
||||
{ |
|
||||
Id = result.IdOrValue, |
|
||||
FileName = command.File.FileName, |
|
||||
FileSize = command.File.FileSize, |
|
||||
FileType = command.File.FileName.FileType(), |
|
||||
FileVersion = result.FileVersion, |
|
||||
MimeType = command.File.MimeType, |
|
||||
IsImage = command.ImageInfo != null, |
|
||||
IsDuplicate = result.IsDuplicate, |
|
||||
PixelWidth = command.ImageInfo?.PixelWidth, |
|
||||
PixelHeight = command.ImageInfo?.PixelHeight, |
|
||||
Tags = result.Tags, |
|
||||
Version = result.Version |
|
||||
}; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,74 +0,0 @@ |
|||||
// ==========================================================================
|
|
||||
// Squidex Headless CMS
|
|
||||
// ==========================================================================
|
|
||||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|
||||
// All rights reserved. Licensed under the MIT license.
|
|
||||
// ==========================================================================
|
|
||||
|
|
||||
using System.ComponentModel.DataAnnotations; |
|
||||
using Squidex.Domain.Apps.Entities.Assets; |
|
||||
using Squidex.Domain.Apps.Entities.Assets.Commands; |
|
||||
|
|
||||
namespace Squidex.Areas.Api.Controllers.Assets.Models |
|
||||
{ |
|
||||
public sealed class AssetReplacedDto |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// The mime type.
|
|
||||
/// </summary>
|
|
||||
[Required] |
|
||||
public string MimeType { get; set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// The file hash.
|
|
||||
/// </summary>
|
|
||||
[Required] |
|
||||
public string FileHash { get; set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// The size of the file in bytes.
|
|
||||
/// </summary>
|
|
||||
public long FileSize { get; set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// The version of the file.
|
|
||||
/// </summary>
|
|
||||
public long FileVersion { get; set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Determines of the created file is an image.
|
|
||||
/// </summary>
|
|
||||
public bool IsImage { get; set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// The width of the image in pixels if the asset is an image.
|
|
||||
/// </summary>
|
|
||||
public int? PixelWidth { get; set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// The height of the image in pixels if the asset is an image.
|
|
||||
/// </summary>
|
|
||||
public int? PixelHeight { get; set; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// The version of the asset.
|
|
||||
/// </summary>
|
|
||||
public long Version { get; set; } |
|
||||
|
|
||||
public static AssetReplacedDto FromCommand(UpdateAsset command, AssetSavedResult result) |
|
||||
{ |
|
||||
var response = new AssetReplacedDto |
|
||||
{ |
|
||||
FileSize = command.File.FileSize, |
|
||||
FileVersion = result.FileVersion, |
|
||||
MimeType = command.File.MimeType, |
|
||||
IsImage = command.ImageInfo != null, |
|
||||
PixelWidth = command.ImageInfo?.PixelWidth, |
|
||||
PixelHeight = command.ImageInfo?.PixelHeight, |
|
||||
Version = result.Version |
|
||||
}; |
|
||||
|
|
||||
return response; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,49 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.Collections.Generic; |
||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
using System.Linq; |
||||
|
using Squidex.Domain.Apps.Entities.Backup; |
||||
|
using Squidex.Shared; |
||||
|
using Squidex.Web; |
||||
|
|
||||
|
namespace Squidex.Areas.Api.Controllers.Backups.Models |
||||
|
{ |
||||
|
public sealed class BackupJobsDto : Resource |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// The backups.
|
||||
|
/// </summary>
|
||||
|
[Required] |
||||
|
public BackupJobDto[] Items { get; set; } |
||||
|
|
||||
|
public static BackupJobsDto FromBackups(IEnumerable<IBackupJob> backups, ApiController controller, string app) |
||||
|
{ |
||||
|
var result = new BackupJobsDto |
||||
|
{ |
||||
|
Items = backups.Select(x => BackupJobDto.FromBackup(x, controller, app)).ToArray() |
||||
|
}; |
||||
|
|
||||
|
return result.CreateLinks(controller, app); |
||||
|
} |
||||
|
|
||||
|
private BackupJobsDto CreateLinks(ApiController controller, string app) |
||||
|
{ |
||||
|
var values = new { app }; |
||||
|
|
||||
|
AddSelfLink(controller.Url<BackupsController>(x => nameof(x.GetBackups), values)); |
||||
|
|
||||
|
if (controller.HasPermission(Permissions.AppBackupsCreate, app)) |
||||
|
{ |
||||
|
AddPostLink("create", controller.Url<BackupsController>(x => nameof(x.PostBackup), values)); |
||||
|
} |
||||
|
|
||||
|
return this; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,23 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using Squidex.Domain.Apps.Core.Contents; |
||||
|
using Squidex.Infrastructure.Security; |
||||
|
using Squidex.Shared; |
||||
|
|
||||
|
namespace Squidex.Areas.Api.Controllers.Contents |
||||
|
{ |
||||
|
public static class Helper |
||||
|
{ |
||||
|
public static Permission StatusPermission(string app, string schema, Status status) |
||||
|
{ |
||||
|
var id = Permissions.AppContentsStatus.Replace("{status}", status.ToString()); |
||||
|
|
||||
|
return Permissions.ForApp(id, app, schema); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,39 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using Squidex.Infrastructure.EventSourcing; |
||||
|
using Squidex.Web; |
||||
|
|
||||
|
namespace Squidex.Areas.Api.Controllers.EventConsumers.Models |
||||
|
{ |
||||
|
public sealed class EventConsumersDto : Resource |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// The event consumers.
|
||||
|
/// </summary>
|
||||
|
public EventConsumerDto[] Items { get; set; } |
||||
|
|
||||
|
public static EventConsumersDto FromResults(IEnumerable<EventConsumerInfo> items, ApiController controller) |
||||
|
{ |
||||
|
var result = new EventConsumersDto |
||||
|
{ |
||||
|
Items = items.Select(x => EventConsumerDto.FromEventConsumerInfo(x, controller)).ToArray() |
||||
|
}; |
||||
|
|
||||
|
return result.CreateLinks(controller); |
||||
|
} |
||||
|
|
||||
|
private EventConsumersDto CreateLinks(ApiController controller) |
||||
|
{ |
||||
|
AddSelfLink(controller.Url<EventConsumersController>(c => nameof(c.GetEventConsumers))); |
||||
|
|
||||
|
return this; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue