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.
54 lines
1.8 KiB
54 lines
1.8 KiB
// ==========================================================================
|
|
// 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.Rules;
|
|
using Squidex.Shared;
|
|
using Squidex.Web;
|
|
|
|
namespace Squidex.Areas.Api.Controllers.Rules.Models
|
|
{
|
|
public sealed class RulesDto : Resource
|
|
{
|
|
/// <summary>
|
|
/// The rules.
|
|
/// </summary>
|
|
[Required]
|
|
public RuleDto[] Items { get; set; }
|
|
|
|
public static RulesDto FromRules(IEnumerable<IEnrichedRuleEntity> items, ApiController controller, string app)
|
|
{
|
|
var result = new RulesDto
|
|
{
|
|
Items = items.Select(x => RuleDto.FromRule(x, controller, app)).ToArray()
|
|
};
|
|
|
|
return result.CreateLinks(controller, app);
|
|
}
|
|
|
|
private RulesDto CreateLinks(ApiController controller, string app)
|
|
{
|
|
var values = new { app };
|
|
|
|
AddSelfLink(controller.Url<RulesController>(x => nameof(x.GetRules), values));
|
|
|
|
if (controller.HasPermission(Permissions.AppRulesCreate, app))
|
|
{
|
|
AddPostLink("create", controller.Url<RulesController>(x => nameof(x.PostRule), values));
|
|
}
|
|
|
|
if (controller.HasPermission(Permissions.AppRulesEvents, app))
|
|
{
|
|
AddGetLink("events", controller.Url<RulesController>(x => nameof(x.GetEvents), values));
|
|
}
|
|
|
|
return this;
|
|
}
|
|
}
|
|
}
|
|
|