diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/ContentDomainObject.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/ContentDomainObject.cs index 0d943aa95..712d6c315 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/ContentDomainObject.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/ContentDomainObject.cs @@ -100,7 +100,7 @@ namespace Squidex.Domain.Apps.Entities.Contents { await LoadContext(Snapshot.AppId, Snapshot.SchemaId, c, () => "Failed to create draft."); - GuardContent.CanCreateDraft(c, context.Schema, Snapshot); + GuardContent.CanCreateDraft(c, Snapshot); var status = await contentWorkflow.GetInitialStatusAsync(context.Schema); @@ -114,7 +114,7 @@ namespace Squidex.Domain.Apps.Entities.Contents { await LoadContext(Snapshot.AppId, Snapshot.SchemaId, c, () => "Failed to delete draft."); - GuardContent.CanDeleteDraft(c, context.Schema, Snapshot); + GuardContent.CanDeleteDraft(c, Snapshot); DeleteDraft(c); diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/Guards/GuardContent.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/Guards/GuardContent.cs index d97b5ae06..b44872c2f 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/Guards/GuardContent.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/Guards/GuardContent.cs @@ -63,30 +63,20 @@ namespace Squidex.Domain.Apps.Entities.Contents.Guards await ValidateCanUpdate(content, contentWorkflow, command.User); } - public static void CanDeleteDraft(DeleteContentDraft command, ISchemaEntity schema, ContentState content) + public static void CanDeleteDraft(DeleteContentDraft command, ContentState content) { Guard.NotNull(command); - if (schema.SchemaDef.IsSingleton) - { - throw new DomainException("Singleton content cannot be updated."); - } - if (content.NewStatus == null) { throw new DomainException("There is nothing to delete."); } } - public static void CanCreateDraft(CreateContentDraft command, ISchemaEntity schema, ContentState content) + public static void CanCreateDraft(CreateContentDraft command, ContentState content) { Guard.NotNull(command); - if (schema.SchemaDef.IsSingleton) - { - throw new DomainException("Singleton content cannot be updated."); - } - if (content.Status != Status.Published) { throw new DomainException("You can only create a new version when the content is published."); diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Guard/GuardContentTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Guard/GuardContentTests.cs index 9de90d70b..f7377694c 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Guard/GuardContentTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Guard/GuardContentTests.cs @@ -229,17 +229,6 @@ namespace Squidex.Domain.Apps.Entities.Contents.Guard await GuardContent.CanChangeStatus(schema, content, contentWorkflow, command); } - [Fact] - public void CreateDraft_should_throw_exception_if_singleton() - { - var schema = CreateSchema(true); - - var content = CreateContent(Status.Published); - var command = new CreateContentDraft(); - - Assert.Throws(() => GuardContent.CanCreateDraft(command, schema, content)); - } - [Fact] public void CreateDraft_should_throw_exception_if_not_published() { @@ -248,7 +237,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Guard var content = CreateContent(Status.Draft); var command = new CreateContentDraft(); - Assert.Throws(() => GuardContent.CanCreateDraft(command, schema, content)); + Assert.Throws(() => GuardContent.CanCreateDraft(command, content)); } [Fact] @@ -259,7 +248,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Guard var content = CreateContent(Status.Published); var command = new CreateContentDraft(); - GuardContent.CanCreateDraft(command, schema, content); + GuardContent.CanCreateDraft(command, content); } [Fact] @@ -270,18 +259,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Guard var content = new ContentState(); var command = new DeleteContentDraft(); - Assert.Throws(() => GuardContent.CanDeleteDraft(command, schema, content)); - } - - [Fact] - public void CanDeleteDraft_should_throw_exception_if_singleton() - { - var schema = CreateSchema(true); - - var content = CreateDraftContent(Status.Draft); - var command = new DeleteContentDraft(); - - Assert.Throws(() => GuardContent.CanDeleteDraft(command, schema, content)); + Assert.Throws(() => GuardContent.CanDeleteDraft(command, content)); } [Fact] @@ -292,7 +270,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Guard var content = CreateDraftContent(Status.Draft); var command = new DeleteContentDraft(); - GuardContent.CanDeleteDraft(command, schema, content); + GuardContent.CanDeleteDraft(command, content); } [Fact]