Browse Source

Fix a bug for deleted apps and schemas.

pull/656/head
Sebastian 5 years ago
parent
commit
f30977589b
  1. 6
      backend/src/Squidex.Domain.Apps.Entities/Apps/Indexes/AppsIndex.cs
  2. 6
      backend/src/Squidex.Domain.Apps.Entities/Schemas/Indexes/SchemasIndex.cs
  3. 2
      backend/tests/Squidex.Domain.Apps.Entities.Tests/Apps/Indexes/AppsIndexTests.cs
  4. 2
      backend/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Indexes/SchemasIndexTests.cs

6
backend/src/Squidex.Domain.Apps.Entities/Apps/Indexes/AppsIndex.cs

@ -227,7 +227,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Indexes
if (app == null)
{
app = await GetAppCoreAsync(appCommand.AggregateId);
app = await GetAppCoreAsync(appCommand.AggregateId, true);
}
if (app != null)
@ -307,11 +307,11 @@ namespace Squidex.Domain.Apps.Entities.Apps.Indexes
return grainFactory.GetGrain<IAppsByUserIndexGrain>(id);
}
private async Task<IAppEntity?> GetAppCoreAsync(DomainId id)
private async Task<IAppEntity?> GetAppCoreAsync(DomainId id, bool allowArchived = false)
{
var app = (await grainFactory.GetGrain<IAppGrain>(id.ToString()).GetStateAsync()).Value;
if (app.Version <= EtagVersion.Empty || app.IsArchived)
if (app.Version <= EtagVersion.Empty || (app.IsArchived && !allowArchived))
{
return null;
}

6
backend/src/Squidex.Domain.Apps.Entities/Schemas/Indexes/SchemasIndex.cs

@ -159,7 +159,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Indexes
if (schema == null)
{
schema = await GetSchemaCoreAsync(schemaCommand.AggregateId);
schema = await GetSchemaCoreAsync(schemaCommand.AggregateId, true);
}
if (schema != null)
@ -204,11 +204,11 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Indexes
return grainFactory.GetGrain<ISchemasByAppIndexGrain>(appId.ToString());
}
private async Task<ISchemaEntity?> GetSchemaCoreAsync(DomainId id)
private async Task<ISchemaEntity?> GetSchemaCoreAsync(DomainId id, bool allowDeleted = false)
{
var schema = (await grainFactory.GetGrain<ISchemaGrain>(id.ToString()).GetStateAsync()).Value;
if (schema.Version <= EtagVersion.Empty || schema.IsDeleted)
if (schema.Version <= EtagVersion.Empty || (schema.IsDeleted && !allowDeleted))
{
return null;
}

2
backend/tests/Squidex.Domain.Apps.Entities.Tests/Apps/Indexes/AppsIndexTests.cs

@ -413,7 +413,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Indexes
[Fact]
public async Task Should_remove_app_from_indexes_when_app_gets_archived()
{
SetupApp();
SetupApp(isArchived: true);
var command = new ArchiveApp { AppId = appId };

2
backend/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Indexes/SchemasIndexTests.cs

@ -287,7 +287,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Indexes
[Fact]
public async Task Should_remove_schema_from_index_when_deleted_and_exists()
{
var (schema, _) = SetupSchema();
var (schema, _) = SetupSchema(isDeleted: true);
var command = new DeleteSchema { SchemaId = schemaId, AppId = appId };

Loading…
Cancel
Save