mirror of https://github.com/Squidex/squidex.git
56 changed files with 1044 additions and 867 deletions
@ -0,0 +1,119 @@ |
|||
// ==========================================================================
|
|||
// AppStateGrainState_Apps.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using Squidex.Domain.Apps.Core.Apps; |
|||
using Squidex.Domain.Apps.Events; |
|||
using Squidex.Domain.Apps.Events.Apps; |
|||
using Squidex.Domain.Apps.Events.Apps.Utils; |
|||
using Squidex.Infrastructure; |
|||
using Squidex.Infrastructure.CQRS.Events; |
|||
using Squidex.Infrastructure.Reflection; |
|||
|
|||
namespace Squidex.Domain.Apps.Read.State.Orleans.Grains.Implementations |
|||
{ |
|||
public sealed partial class AppStateGrainState |
|||
{ |
|||
public void On(AppCreated @event, EnvelopeHeaders headers) |
|||
{ |
|||
Reset(); |
|||
|
|||
App = EntityMapper.Create<JsonAppEntity>(@event, headers, a => |
|||
{ |
|||
SimpleMapper.Map(@event, a); |
|||
|
|||
a.LanguagesConfig = LanguagesConfig.Build(Language.EN); |
|||
}); |
|||
} |
|||
|
|||
public void On(AppLanguageAdded @event, EnvelopeHeaders headers) |
|||
{ |
|||
UpdateApp(@event, headers, a => |
|||
{ |
|||
a.LanguagesConfig = a.LanguagesConfig.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
public void On(AppLanguageRemoved @event, EnvelopeHeaders headers) |
|||
{ |
|||
UpdateApp(@event, headers, a => |
|||
{ |
|||
a.LanguagesConfig = a.LanguagesConfig.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
public void On(AppLanguageUpdated @event, EnvelopeHeaders headers) |
|||
{ |
|||
UpdateApp(@event, headers, a => |
|||
{ |
|||
a.LanguagesConfig = a.LanguagesConfig.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
public void On(AppContributorAssigned @event, EnvelopeHeaders headers) |
|||
{ |
|||
UpdateApp(@event, headers, a => |
|||
{ |
|||
a.Contributors = a.Contributors.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
public void On(AppContributorRemoved @event, EnvelopeHeaders headers) |
|||
{ |
|||
UpdateApp(@event, headers, a => |
|||
{ |
|||
a.Contributors = a.Contributors.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
public void On(AppClientAttached @event, EnvelopeHeaders headers) |
|||
{ |
|||
UpdateApp(@event, headers, a => |
|||
{ |
|||
a.Clients = a.Clients.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
public void On(AppClientUpdated @event, EnvelopeHeaders headers) |
|||
{ |
|||
UpdateApp(@event, headers, a => |
|||
{ |
|||
a.Clients = a.Clients.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
public void On(AppClientRenamed @event, EnvelopeHeaders headers) |
|||
{ |
|||
UpdateApp(@event, headers, a => |
|||
{ |
|||
a.Clients = a.Clients.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
public void On(AppClientRevoked @event, EnvelopeHeaders headers) |
|||
{ |
|||
UpdateApp(@event, headers, a => |
|||
{ |
|||
a.Clients = a.Clients.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
public void On(AppPlanChanged @event, EnvelopeHeaders headers) |
|||
{ |
|||
UpdateApp(@event, headers, a => |
|||
{ |
|||
SimpleMapper.Map(@event, a); |
|||
}); |
|||
} |
|||
|
|||
private void UpdateApp(AppEvent @event, EnvelopeHeaders headers, Action<JsonAppEntity> updater = null) |
|||
{ |
|||
App = App.Clone().Update(@event, headers, updater); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,60 @@ |
|||
// ==========================================================================
|
|||
// AppStateGrainState_Rules.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using Squidex.Domain.Apps.Events.Rules; |
|||
using Squidex.Domain.Apps.Events.Rules.Utils; |
|||
using Squidex.Infrastructure.CQRS.Events; |
|||
|
|||
namespace Squidex.Domain.Apps.Read.State.Orleans.Grains.Implementations |
|||
{ |
|||
public sealed partial class AppStateGrainState |
|||
{ |
|||
public void On(RuleCreated @event, EnvelopeHeaders headers) |
|||
{ |
|||
Rules[@event.RuleId] = EntityMapper.Create<JsonRuleEntity>(@event, headers, r => |
|||
{ |
|||
r.RuleDef = RuleEventDispatcher.Create(@event); |
|||
}); |
|||
} |
|||
|
|||
public void On(RuleUpdated @event, EnvelopeHeaders headers) |
|||
{ |
|||
UpdateRule(@event, headers, r => |
|||
{ |
|||
r.RuleDef = r.RuleDef.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
public void On(RuleEnabled @event, EnvelopeHeaders headers) |
|||
{ |
|||
UpdateRule(@event, headers, r => |
|||
{ |
|||
r.RuleDef = r.RuleDef.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
public void On(RuleDisabled @event, EnvelopeHeaders headers) |
|||
{ |
|||
UpdateRule(@event, headers, r => |
|||
{ |
|||
r.RuleDef = r.RuleDef.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
public void On(RuleDeleted @event, EnvelopeHeaders headers) |
|||
{ |
|||
Rules.Remove(@event.RuleId); |
|||
} |
|||
|
|||
private void UpdateRule(RuleEvent @event, EnvelopeHeaders headers, Action<JsonRuleEntity> updater = null) |
|||
{ |
|||
Rules[@event.RuleId].Clone().Update(@event, headers, updater); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,157 @@ |
|||
// ==========================================================================
|
|||
// AppStateGrainState_Schemas.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using Squidex.Domain.Apps.Events; |
|||
using Squidex.Domain.Apps.Events.Schemas; |
|||
using Squidex.Domain.Apps.Events.Schemas.Old; |
|||
using Squidex.Domain.Apps.Events.Schemas.Utils; |
|||
using Squidex.Infrastructure.CQRS.Events; |
|||
using Squidex.Infrastructure.Reflection; |
|||
|
|||
#pragma warning disable CS0612 // Type or member is obsolete
|
|||
|
|||
namespace Squidex.Domain.Apps.Read.State.Orleans.Grains.Implementations |
|||
{ |
|||
public sealed partial class AppStateGrainState |
|||
{ |
|||
public void On(SchemaCreated @event, EnvelopeHeaders headers) |
|||
{ |
|||
Schemas[@event.SchemaId.Id] = EntityMapper.Create<JsonSchemaEntity>(@event, headers, s => |
|||
{ |
|||
s.SchemaDef = SchemaEventDispatcher.Create(@event, registry); |
|||
|
|||
SimpleMapper.Map(@event, s); |
|||
}); |
|||
} |
|||
|
|||
public void On(SchemaPublished @event, EnvelopeHeaders headers) |
|||
{ |
|||
UpdateSchema(@event, headers, s => |
|||
{ |
|||
s.SchemaDef = s.SchemaDef.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
public void On(SchemaUnpublished @event, EnvelopeHeaders headers) |
|||
{ |
|||
UpdateSchema(@event, headers, s => |
|||
{ |
|||
s.SchemaDef = s.SchemaDef.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
public void On(ScriptsConfigured @event, EnvelopeHeaders headers) |
|||
{ |
|||
UpdateSchema(@event, headers, s => |
|||
{ |
|||
SimpleMapper.Map(s, @event); |
|||
}); |
|||
} |
|||
|
|||
public void On(SchemaUpdated @event, EnvelopeHeaders headers) |
|||
{ |
|||
UpdateSchema(@event, headers, s => |
|||
{ |
|||
s.SchemaDef = s.SchemaDef.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
public void On(SchemaFieldsReordered @event, EnvelopeHeaders headers) |
|||
{ |
|||
UpdateSchema(@event, headers, s => |
|||
{ |
|||
s.SchemaDef = s.SchemaDef.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
public void On(SchemaDeleted @event) |
|||
{ |
|||
Schemas.Remove(@event.SchemaId.Id); |
|||
} |
|||
|
|||
public void On(FieldAdded @event, EnvelopeHeaders headers) |
|||
{ |
|||
UpdateSchema(@event, headers, s => |
|||
{ |
|||
s.SchemaDef = s.SchemaDef.Apply(@event, registry); |
|||
}); |
|||
} |
|||
|
|||
public void On(FieldUpdated @event, EnvelopeHeaders headers) |
|||
{ |
|||
UpdateSchema(@event, headers, s => |
|||
{ |
|||
s.SchemaDef = s.SchemaDef.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
public void On(FieldLocked @event, EnvelopeHeaders headers) |
|||
{ |
|||
UpdateSchema(@event, headers, s => |
|||
{ |
|||
s.SchemaDef = s.SchemaDef.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
public void On(FieldDisabled @event, EnvelopeHeaders headers) |
|||
{ |
|||
UpdateSchema(@event, headers, s => |
|||
{ |
|||
s.SchemaDef = s.SchemaDef.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
public void On(FieldEnabled @event, EnvelopeHeaders headers) |
|||
{ |
|||
UpdateSchema(@event, headers, s => |
|||
{ |
|||
s.SchemaDef = s.SchemaDef.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
public void On(FieldHidden @event, EnvelopeHeaders headers) |
|||
{ |
|||
UpdateSchema(@event, headers, s => |
|||
{ |
|||
s.SchemaDef = s.SchemaDef.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
public void On(FieldShown @event, EnvelopeHeaders headers) |
|||
{ |
|||
UpdateSchema(@event, headers, s => |
|||
{ |
|||
s.SchemaDef = s.SchemaDef.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
public void On(FieldDeleted @event, EnvelopeHeaders headers) |
|||
{ |
|||
UpdateSchema(@event, headers, s => |
|||
{ |
|||
s.SchemaDef = s.SchemaDef.Apply(@event); |
|||
}); |
|||
} |
|||
|
|||
public void On(WebhookAdded @event, EnvelopeHeaders headers) |
|||
{ |
|||
UpdateSchema(@event, headers); |
|||
} |
|||
|
|||
public void On(WebhookDeleted @event, EnvelopeHeaders headers) |
|||
{ |
|||
UpdateSchema(@event, headers); |
|||
} |
|||
|
|||
private void UpdateSchema(SchemaEvent @event, EnvelopeHeaders headers, Action<JsonSchemaEntity> updater = null) |
|||
{ |
|||
Schemas[@event.SchemaId.Id].Clone().Update(@event, headers, updater); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
// ==========================================================================
|
|||
// AppClientJsonTests.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using FluentAssertions; |
|||
using Newtonsoft.Json; |
|||
using Newtonsoft.Json.Linq; |
|||
using Squidex.Domain.Apps.Core.Apps; |
|||
using Xunit; |
|||
|
|||
namespace Squidex.Domain.Apps.Core.Model.Apps |
|||
{ |
|||
public class AppClientJsonTests |
|||
{ |
|||
private readonly JsonSerializer serializer = TestData.DefaultSerializer(); |
|||
|
|||
[Fact] |
|||
public void Should_serialize_and_deserialize() |
|||
{ |
|||
var clients = AppClients.Empty; |
|||
|
|||
clients = clients.Add("1", "my-secret"); |
|||
clients = clients.Add("2", "my-secret"); |
|||
clients = clients.Add("3", "my-secret"); |
|||
clients = clients.Add("4", "my-secret"); |
|||
|
|||
clients = clients.Update("3", AppClientPermission.Editor); |
|||
|
|||
clients = clients.Rename("3", "My Client 3"); |
|||
clients = clients.Rename("2", "My Client 2"); |
|||
|
|||
clients = clients.Revoke("4"); |
|||
|
|||
var appClients = JToken.FromObject(clients, serializer).ToObject<AppClients>(serializer); |
|||
|
|||
appClients.ShouldBeEquivalentTo(clients); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
// ==========================================================================
|
|||
// AppContributorsJsonTests.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using FluentAssertions; |
|||
using Newtonsoft.Json; |
|||
using Newtonsoft.Json.Linq; |
|||
using Squidex.Domain.Apps.Core.Apps; |
|||
using Xunit; |
|||
|
|||
namespace Squidex.Domain.Apps.Core.Model.Apps |
|||
{ |
|||
public class AppContributorsJsonTests |
|||
{ |
|||
private readonly JsonSerializer serializer = TestData.DefaultSerializer(); |
|||
|
|||
[Fact] |
|||
public void Should_serialize_and_deserialize() |
|||
{ |
|||
var contributors = AppContributors.Empty; |
|||
|
|||
contributors = contributors.Assign("1", AppContributorPermission.Developer); |
|||
contributors = contributors.Assign("2", AppContributorPermission.Editor); |
|||
contributors = contributors.Assign("3", AppContributorPermission.Owner); |
|||
|
|||
var serialized = JToken.FromObject(contributors, serializer).ToObject<AppContributors>(serializer); |
|||
|
|||
serialized.ShouldBeEquivalentTo(contributors); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue