diff --git a/src/Squidex.Domain.Apps.Entities/Contents/Guards/GuardContent.cs b/src/Squidex.Domain.Apps.Entities/Contents/Guards/GuardContent.cs index c40c5e629..8c02f6d88 100644 --- a/src/Squidex.Domain.Apps.Entities/Contents/Guards/GuardContent.cs +++ b/src/Squidex.Domain.Apps.Entities/Contents/Guards/GuardContent.cs @@ -25,7 +25,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Guards ValidateData(command, e); }); - if (schema.Singleton && command.ContentId != Guid.Empty) + if (schema.IsSingleton && command.ContentId != Guid.Empty) { throw new DomainException("Singleton content cannot be created."); } @@ -65,7 +65,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Guards { Guard.NotNull(command, nameof(command)); - if (schema.Singleton && command.Status != Status.Published) + if (schema.IsSingleton && command.Status != Status.Published) { throw new DomainException("Singleton content archived or unpublished."); } @@ -102,7 +102,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Guards { Guard.NotNull(command, nameof(command)); - if (schema.Singleton) + if (schema.IsSingleton) { throw new DomainException("Singleton content cannot be deleted."); } diff --git a/src/Squidex.Domain.Apps.Entities/Schemas/ISchemaEntity.cs b/src/Squidex.Domain.Apps.Entities/Schemas/ISchemaEntity.cs index 58233780d..98913f9e3 100644 --- a/src/Squidex.Domain.Apps.Entities/Schemas/ISchemaEntity.cs +++ b/src/Squidex.Domain.Apps.Entities/Schemas/ISchemaEntity.cs @@ -23,7 +23,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas string Category { get; } - bool Singleton { get; } + bool IsSingleton { get; } bool IsPublished { get; } diff --git a/src/Squidex.Domain.Apps.Entities/Schemas/State/SchemaState.cs b/src/Squidex.Domain.Apps.Entities/Schemas/State/SchemaState.cs index 070ca131d..01bd7a7d1 100644 --- a/src/Squidex.Domain.Apps.Entities/Schemas/State/SchemaState.cs +++ b/src/Squidex.Domain.Apps.Entities/Schemas/State/SchemaState.cs @@ -38,7 +38,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.State public bool IsDeleted { get; set; } [JsonProperty] - public bool Singleton { get; set; } + public bool IsSingleton { get; set; } [JsonProperty] public string ScriptQuery { get; set; } @@ -68,7 +68,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.State { Name = @event.Name; - Singleton = @event.Singleton; + IsSingleton = @event.Singleton; var schema = new Schema(@event.Name); diff --git a/src/Squidex/Areas/Api/Controllers/Schemas/Models/CreateSchemaDto.cs b/src/Squidex/Areas/Api/Controllers/Schemas/Models/CreateSchemaDto.cs index 1835ecc51..922647abc 100644 --- a/src/Squidex/Areas/Api/Controllers/Schemas/Models/CreateSchemaDto.cs +++ b/src/Squidex/Areas/Api/Controllers/Schemas/Models/CreateSchemaDto.cs @@ -33,14 +33,14 @@ namespace Squidex.Areas.Api.Controllers.Schemas.Models public List Fields { get; set; } /// - /// Set it to true to autopublish the schema. + /// Set to true to allow a single content item only. /// - public bool Publish { get; set; } + public bool Singleton { get; set; } /// - /// Set to true to allow a single content item only. + /// Set it to true to autopublish the schema. /// - public bool Singleton { get; set; } + public bool Publish { get; set; } public CreateSchema ToCommand() { diff --git a/src/Squidex/Areas/Api/Controllers/Schemas/Models/SchemaDto.cs b/src/Squidex/Areas/Api/Controllers/Schemas/Models/SchemaDto.cs index 54b0fd561..370d6a91d 100644 --- a/src/Squidex/Areas/Api/Controllers/Schemas/Models/SchemaDto.cs +++ b/src/Squidex/Areas/Api/Controllers/Schemas/Models/SchemaDto.cs @@ -40,14 +40,14 @@ namespace Squidex.Areas.Api.Controllers.Schemas.Models public SchemaPropertiesDto Properties { get; set; } /// - /// Indicates if the schema is published. + /// Indicates if the schema is a singleton. /// - public bool IsPublished { get; set; } + public bool IsSingleton { get; set; } /// - /// Indicates if the schema is a singleton. + /// Indicates if the schema is published. /// - public bool IsSingleton { get; set; } + public bool IsPublished { get; set; } /// /// The user that has created the schema. diff --git a/src/Squidex/app/shared/services/schemas.service.spec.ts b/src/Squidex/app/shared/services/schemas.service.spec.ts index b5d99e774..3b7df6d12 100644 --- a/src/Squidex/app/shared/services/schemas.service.spec.ts +++ b/src/Squidex/app/shared/services/schemas.service.spec.ts @@ -78,6 +78,7 @@ describe('SchemasService', () => { label: 'label1', hints: 'hints1' }, + isSingleton: true, isPublished: true, created: '2016-12-12T10:10', createdBy: 'Created1', @@ -94,6 +95,7 @@ describe('SchemasService', () => { label: 'label2', hints: 'hints2' }, + isSingleton: true, isPublished: true, created: '2016-10-12T10:10', createdBy: 'Created2', @@ -106,11 +108,11 @@ describe('SchemasService', () => { expect(schemas!).toEqual( [ - new SchemaDto('id1', 'name1', 'category1', new SchemaPropertiesDto('label1', 'hints1'), true, + new SchemaDto('id1', 'name1', 'category1', new SchemaPropertiesDto('label1', 'hints1'), true, true, DateTime.parseISO_UTC('2016-12-12T10:10'), 'Created1', DateTime.parseISO_UTC('2017-12-12T10:10'), 'LastModifiedBy1', new Version('11')), - new SchemaDto('id2', 'name2', 'category2', new SchemaPropertiesDto('label2', 'hints2'), true, + new SchemaDto('id2', 'name2', 'category2', new SchemaPropertiesDto('label2', 'hints2'), true, true, DateTime.parseISO_UTC('2016-10-12T10:10'), 'Created2', DateTime.parseISO_UTC('2017-10-12T10:10'), 'LastModifiedBy2', new Version('22')) @@ -135,6 +137,7 @@ describe('SchemasService', () => { id: 'id1', name: 'name1', category: 'category1', + isSingleton: true, isPublished: true, created: '2016-12-12T10:10', createdBy: 'Created1', @@ -290,7 +293,7 @@ describe('SchemasService', () => { }); expect(schema!).toEqual( - new SchemaDetailsDto('id1', 'name1', 'category1', new SchemaPropertiesDto('label1', 'hints1'), true, + new SchemaDetailsDto('id1', 'name1', 'category1', new SchemaPropertiesDto('label1', 'hints1'), true, true, DateTime.parseISO_UTC('2016-12-12T10:10'), 'Created1', DateTime.parseISO_UTC('2017-12-12T10:10'), 'LastModifiedBy1', new Version('2'), @@ -319,7 +322,7 @@ describe('SchemasService', () => { it('should make post request to create schema', inject([SchemasService, HttpTestingController], (schemasService: SchemasService, httpMock: HttpTestingController) => { - const dto = new CreateSchemaDto('name'); + const dto = new CreateSchemaDto('name', undefined, undefined, true); let schema: SchemaDetailsDto; @@ -341,7 +344,7 @@ describe('SchemasService', () => { }); expect(schema!).toEqual( - new SchemaDetailsDto('1', dto.name, '', new SchemaPropertiesDto(), false, now, user, now, user, new Version('2'), [])); + new SchemaDetailsDto('1', dto.name, '', new SchemaPropertiesDto(), true, false, now, user, now, user, new Version('2'), [])); })); it('should make put request to update schema', diff --git a/src/Squidex/app/shared/services/schemas.service.ts b/src/Squidex/app/shared/services/schemas.service.ts index 6d4f3eb5e..90135bd28 100644 --- a/src/Squidex/app/shared/services/schemas.service.ts +++ b/src/Squidex/app/shared/services/schemas.service.ts @@ -34,6 +34,7 @@ export class SchemaDto extends Model { public readonly name: string, public readonly category: string, public readonly properties: SchemaPropertiesDto, + public readonly isSingleton: boolean, public readonly isPublished: boolean, public readonly created: DateTime, public readonly createdBy: string, @@ -53,7 +54,7 @@ export class SchemaDetailsDto extends SchemaDto { public listFields: RootFieldDto[]; public listFieldsEditable: RootFieldDto[]; - constructor(id: string, name: string, category: string, properties: SchemaPropertiesDto, isPublished: boolean, created: DateTime, createdBy: string, lastModified: DateTime, lastModifiedBy: string, version: Version, + constructor(id: string, name: string, category: string, properties: SchemaPropertiesDto, isSingleton: boolean, isPublished: boolean, created: DateTime, createdBy: string, lastModified: DateTime, lastModifiedBy: string, version: Version, public readonly fields: RootFieldDto[], public readonly scriptQuery?: string, public readonly scriptCreate?: string, @@ -61,7 +62,7 @@ export class SchemaDetailsDto extends SchemaDto { public readonly scriptDelete?: string, public readonly scriptChange?: string ) { - super(id, name, category, properties, isPublished, created, createdBy, lastModified, lastModifiedBy, version); + super(id, name, category, properties, isSingleton, isPublished, created, createdBy, lastModified, lastModifiedBy, version); this.onCloned(); } @@ -177,7 +178,8 @@ export class CreateSchemaDto { constructor( public readonly name: string, public readonly fields?: RootFieldDto[], - public readonly properties?: SchemaPropertiesDto + public readonly properties?: SchemaPropertiesDto, + public readonly singleton?: boolean ) { } } @@ -240,6 +242,7 @@ export class SchemasService { item.id, item.name, item.category, properties, + item.isSingleton, item.isPublished, DateTime.parseISO_UTC(item.created), item.createdBy, DateTime.parseISO_UTC(item.lastModified), item.lastModifiedBy, @@ -300,6 +303,7 @@ export class SchemasService { body.name, body.category, properties, + body.isSingleton, body.isPublished, DateTime.parseISO_UTC(body.created), body.createdBy, DateTime.parseISO_UTC(body.lastModified), body.lastModifiedBy, @@ -328,6 +332,7 @@ export class SchemasService { dto.name, '', dto.properties || new SchemaPropertiesDto(), + dto.singleton === true, false, now, user, now, user, diff --git a/src/Squidex/app/shared/state/contents.forms.spec.ts b/src/Squidex/app/shared/state/contents.forms.spec.ts index fbf86b36a..61da6789d 100644 --- a/src/Squidex/app/shared/state/contents.forms.spec.ts +++ b/src/Squidex/app/shared/state/contents.forms.spec.ts @@ -371,7 +371,7 @@ describe('StringField', () => { }); function createSchema(properties: SchemaPropertiesDto, index = 1, fields: RootFieldDto[]) { - return new SchemaDetailsDto('id' + index, 'schema' + index, '', properties, true, null!, null!, null!, null!, null!, fields); + return new SchemaDetailsDto('id' + index, 'schema' + index, '', properties, false, true, null!, null!, null!, null!, null!, fields); } function createField(properties: FieldPropertiesDto, index = 1, partitioning = 'languages') { diff --git a/src/Squidex/app/shared/state/schemas.state.spec.ts b/src/Squidex/app/shared/state/schemas.state.spec.ts index b25f318b6..c02091aac 100644 --- a/src/Squidex/app/shared/state/schemas.state.spec.ts +++ b/src/Squidex/app/shared/state/schemas.state.spec.ts @@ -41,8 +41,8 @@ describe('SchemasState', () => { const newVersion = new Version('2'); const oldSchemas = [ - new SchemaDto('id1', 'name1', 'category1', {}, false, creation, creator, creation, creator, version), - new SchemaDto('id2', 'name2', 'category2', {}, true , creation, creator, creation, creator, version) + new SchemaDto('id1', 'name1', 'category1', {}, false, false, creation, creator, creation, creator, version), + new SchemaDto('id2', 'name2', 'category2', {}, false, true , creation, creator, creation, creator, version) ]; const nested1 = new NestedFieldDto(3, '3', createProperties('Number'), 2); @@ -52,7 +52,7 @@ describe('SchemasState', () => { const field2 = new RootFieldDto(2, '2', createProperties('Array'), 'invariant', true, true, true, [nested1, nested2]); const schema = - new SchemaDetailsDto('id2', 'name2', 'category2', {}, true, + new SchemaDetailsDto('id2', 'name2', 'category2', {}, false, true, creation, creator, creation, creator, version, @@ -284,7 +284,7 @@ describe('SchemasState', () => { it('should add schema to snapshot when created', () => { const request = new CreateSchemaDto('newName'); - const result = new SchemaDetailsDto('id4', 'newName', '', {}, false, modified, modifier, modified, modifier, version, []); + const result = new SchemaDetailsDto('id4', 'newName', '', {}, false, false, modified, modifier, modified, modifier, version, []); schemasService.setup(x => x.postSchema(app, request, modifier, modified)) .returns(() => of(result)); diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Guard/GuardContentTests.cs b/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Guard/GuardContentTests.cs index a69db5009..56357383f 100644 --- a/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Guard/GuardContentTests.cs +++ b/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Guard/GuardContentTests.cs @@ -35,7 +35,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Guard [Fact] public void CanCreate_should_throw_exception_if_singleton() { - A.CallTo(() => schema.Singleton).Returns(true); + A.CallTo(() => schema.IsSingleton).Returns(true); var command = new CreateContent { Data = new NamedContentData() }; @@ -45,7 +45,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Guard [Fact] public void CanCreate_should_not_throw_exception_if_singleton_and_id_empty() { - A.CallTo(() => schema.Singleton).Returns(true); + A.CallTo(() => schema.IsSingleton).Returns(true); var command = new CreateContent { Data = new NamedContentData(), ContentId = Guid.Empty }; @@ -133,7 +133,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Guard [Fact] public void CanChangeContentStatus_should_throw_exception_if_singleton() { - A.CallTo(() => schema.Singleton).Returns(true); + A.CallTo(() => schema.IsSingleton).Returns(true); var command = new ChangeContentStatus { Status = Status.Draft }; @@ -143,7 +143,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Guard [Fact] public void CanChangeContentStatus_should_not_throw_exception_if_publishing_with_pending_changes() { - A.CallTo(() => schema.Singleton).Returns(true); + A.CallTo(() => schema.IsSingleton).Returns(true); var command = new ChangeContentStatus { Status = Status.Published }; @@ -177,7 +177,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Guard [Fact] public void CanDelete_should_throw_exception_if_singleton() { - A.CallTo(() => schema.Singleton).Returns(true); + A.CallTo(() => schema.IsSingleton).Returns(true); var command = new DeleteContent(); diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/SchemaGrainTests.cs b/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/SchemaGrainTests.cs index b2f00be97..cd880f849 100644 --- a/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/SchemaGrainTests.cs +++ b/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/SchemaGrainTests.cs @@ -72,7 +72,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas Assert.Equal(SchemaName, sut.Snapshot.Name); Assert.Equal(SchemaName, sut.Snapshot.SchemaDef.Name); - Assert.True(sut.Snapshot.Singleton); + Assert.True(sut.Snapshot.IsSingleton); LastEvents .ShouldHaveSameEvents(