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.
44 lines
1.4 KiB
44 lines
1.4 KiB
// ==========================================================================
|
|
// SchemaGuard.cs
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex Group
|
|
// All rights reserved.
|
|
// ==========================================================================
|
|
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Squidex.Domain.Apps.Core.Schemas;
|
|
using Squidex.Infrastructure;
|
|
|
|
namespace Squidex.Domain.Apps.Write.Schemas.Guards
|
|
{
|
|
public static class SchemaGuard
|
|
{
|
|
public static void GuardCanReorder(Schema schema, List<long> fieldIds)
|
|
{
|
|
if (fieldIds.Count != schema.Fields.Count || fieldIds.Any(x => !schema.FieldsById.ContainsKey(x)))
|
|
{
|
|
var error = new ValidationError("Ids must cover all fields.", "FieldIds");
|
|
|
|
throw new ValidationException("Cannot reorder schema fields.", error);
|
|
}
|
|
}
|
|
|
|
public static void GuardCanPublish(Schema schema)
|
|
{
|
|
if (schema.IsPublished)
|
|
{
|
|
throw new DomainException("Schema is already published.");
|
|
}
|
|
}
|
|
|
|
public static void GuardCanUnpublish(Schema schema)
|
|
{
|
|
if (!schema.IsPublished)
|
|
{
|
|
throw new DomainException("Schema is not published.");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|