mirror of https://github.com/Squidex/squidex.git
31 changed files with 671 additions and 240 deletions
@ -0,0 +1,143 @@ |
|||||
|
// ==========================================================================
|
||||
|
// AppHistoryEventsCreator.cs
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex Group
|
||||
|
// All rights reserved.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.Collections.Generic; |
||||
|
using System.Threading.Tasks; |
||||
|
using Squidex.Events.Apps; |
||||
|
using Squidex.Infrastructure; |
||||
|
using Squidex.Infrastructure.CQRS; |
||||
|
using Squidex.Infrastructure.CQRS.Events; |
||||
|
using Squidex.Infrastructure.Dispatching; |
||||
|
using Squidex.Read.History; |
||||
|
|
||||
|
namespace Squidex.Read.Apps |
||||
|
{ |
||||
|
public class AppHistoryEventsCreator : IHistoryEventsCreator |
||||
|
{ |
||||
|
private static readonly IReadOnlyDictionary<string, string> TextsEN = |
||||
|
new Dictionary<string, string> |
||||
|
{ |
||||
|
{ |
||||
|
TypeNameRegistry.GetName<AppContributorAssigned>(), |
||||
|
"assigned {user:[Contributor]} as [Permission]" |
||||
|
}, |
||||
|
{ |
||||
|
TypeNameRegistry.GetName<AppContributorRemoved>(), |
||||
|
"removed {user:[Contributor]} from app" |
||||
|
}, |
||||
|
{ |
||||
|
TypeNameRegistry.GetName<AppClientAttached>(), |
||||
|
"added client {[Id]} to app" |
||||
|
}, |
||||
|
{ |
||||
|
TypeNameRegistry.GetName<AppClientRevoked>(), |
||||
|
"revoked client {[Id]}" |
||||
|
}, |
||||
|
{ |
||||
|
TypeNameRegistry.GetName<AppClientRenamed>(), |
||||
|
"named client {[Id]} as {[Name]}" |
||||
|
}, |
||||
|
{ |
||||
|
TypeNameRegistry.GetName<AppLanguageAdded>(), |
||||
|
"added language {[Language]}" |
||||
|
}, |
||||
|
{ |
||||
|
TypeNameRegistry.GetName<AppLanguageRemoved>(), |
||||
|
"removed language {[Language]}" |
||||
|
}, |
||||
|
{ |
||||
|
TypeNameRegistry.GetName<AppMasterLanguageSet>(), |
||||
|
"changed master language to {[Language]}" |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
public IReadOnlyDictionary<string, string> Texts |
||||
|
{ |
||||
|
get { return TextsEN; } |
||||
|
} |
||||
|
|
||||
|
protected Task<HistoryEventToStore> On(AppContributorAssigned @event, EnvelopeHeaders headers) |
||||
|
{ |
||||
|
const string channel = "settings.contributors"; |
||||
|
|
||||
|
return Task.FromResult( |
||||
|
HistoryEventToStore.Create(@event, channel) |
||||
|
.AddParameter("Contributor", @event.ContributorId) |
||||
|
.AddParameter("Permission", @event.Permission.ToString())); |
||||
|
} |
||||
|
|
||||
|
protected Task<HistoryEventToStore> On(AppContributorRemoved @event, EnvelopeHeaders headers) |
||||
|
{ |
||||
|
const string channel = "settings.contributors"; |
||||
|
|
||||
|
return Task.FromResult( |
||||
|
HistoryEventToStore.Create(@event, channel) |
||||
|
.AddParameter("Contributor", @event.ContributorId)); |
||||
|
} |
||||
|
|
||||
|
protected Task<HistoryEventToStore> On(AppClientRenamed @event, EnvelopeHeaders headers) |
||||
|
{ |
||||
|
const string channel = "settings.clients"; |
||||
|
|
||||
|
return Task.FromResult( |
||||
|
HistoryEventToStore.Create(@event, channel) |
||||
|
.AddParameter("Id", @event.Id) |
||||
|
.AddParameter("Name", !string.IsNullOrWhiteSpace(@event.Name) ? @event.Name : @event.Id)); |
||||
|
} |
||||
|
|
||||
|
protected Task<HistoryEventToStore> On(AppClientAttached @event, EnvelopeHeaders headers) |
||||
|
{ |
||||
|
const string channel = "settings.clients"; |
||||
|
|
||||
|
return Task.FromResult( |
||||
|
HistoryEventToStore.Create(@event, channel) |
||||
|
.AddParameter("Id", @event.Id)); |
||||
|
} |
||||
|
|
||||
|
protected Task<HistoryEventToStore> On(AppClientRevoked @event, EnvelopeHeaders headers) |
||||
|
{ |
||||
|
const string channel = "settings.clients"; |
||||
|
|
||||
|
return Task.FromResult( |
||||
|
HistoryEventToStore.Create(@event, channel) |
||||
|
.AddParameter("Id", @event.Id)); |
||||
|
} |
||||
|
|
||||
|
protected Task<HistoryEventToStore> On(AppLanguageAdded @event, EnvelopeHeaders headers) |
||||
|
{ |
||||
|
const string channel = "settings.languages"; |
||||
|
|
||||
|
return Task.FromResult( |
||||
|
HistoryEventToStore.Create(@event, channel) |
||||
|
.AddParameter("Language", @event.Language.EnglishName)); |
||||
|
} |
||||
|
|
||||
|
protected Task<HistoryEventToStore> On(AppLanguageRemoved @event, EnvelopeHeaders headers) |
||||
|
{ |
||||
|
const string channel = "settings.languages"; |
||||
|
|
||||
|
return Task.FromResult( |
||||
|
HistoryEventToStore.Create(@event, channel) |
||||
|
.AddParameter("Language", @event.Language.EnglishName)); |
||||
|
} |
||||
|
|
||||
|
protected Task<HistoryEventToStore> On(AppMasterLanguageSet @event, EnvelopeHeaders headers) |
||||
|
{ |
||||
|
const string channel = "settings.languages"; |
||||
|
|
||||
|
return Task.FromResult( |
||||
|
HistoryEventToStore.Create(@event, channel) |
||||
|
.AddParameter("Language", @event.Language.EnglishName)); |
||||
|
} |
||||
|
|
||||
|
public Task<HistoryEventToStore> CreateEventAsync(Envelope<IEvent> @event) |
||||
|
{ |
||||
|
return this.DispatchFuncAsync(@event.Payload, @event.Headers, (HistoryEventToStore)null); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,51 @@ |
|||||
|
// ==========================================================================
|
||||
|
// HistoryEventToStore.cs
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex Group
|
||||
|
// All rights reserved.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.Collections.Generic; |
||||
|
using Squidex.Infrastructure; |
||||
|
using Squidex.Infrastructure.CQRS.Events; |
||||
|
|
||||
|
namespace Squidex.Read.History |
||||
|
{ |
||||
|
public class HistoryEventToStore |
||||
|
{ |
||||
|
private readonly Dictionary<string, string> parameters = new Dictionary<string, string>(); |
||||
|
|
||||
|
public string Channel { get; } |
||||
|
|
||||
|
public string Message { get; } |
||||
|
|
||||
|
public IReadOnlyDictionary<string, string> Parameters |
||||
|
{ |
||||
|
get { return parameters; } |
||||
|
} |
||||
|
|
||||
|
public static HistoryEventToStore Create(IEvent @event, string channel) |
||||
|
{ |
||||
|
Guard.NotNull(@event, nameof(@event)); |
||||
|
|
||||
|
return new HistoryEventToStore(channel, TypeNameRegistry.GetName(@event.GetType())); |
||||
|
} |
||||
|
|
||||
|
public HistoryEventToStore(string channel, string message) |
||||
|
{ |
||||
|
Guard.NotNullOrEmpty(channel, nameof(channel)); |
||||
|
Guard.NotNullOrEmpty(message, nameof(message)); |
||||
|
|
||||
|
Channel = channel; |
||||
|
Message = message; |
||||
|
} |
||||
|
|
||||
|
public HistoryEventToStore AddParameter(string key, string value) |
||||
|
{ |
||||
|
parameters[key] = value; |
||||
|
|
||||
|
return this; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,22 @@ |
|||||
|
// ==========================================================================
|
||||
|
// IHistoryEventCreator.cs
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex Group
|
||||
|
// All rights reserved.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.Collections.Generic; |
||||
|
using System.Threading.Tasks; |
||||
|
using Squidex.Infrastructure.CQRS; |
||||
|
using Squidex.Infrastructure.CQRS.Events; |
||||
|
|
||||
|
namespace Squidex.Read.History |
||||
|
{ |
||||
|
public interface IHistoryEventsCreator |
||||
|
{ |
||||
|
IReadOnlyDictionary<string, string> Texts { get; } |
||||
|
|
||||
|
Task<HistoryEventToStore> CreateEventAsync(Envelope<IEvent> @event); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,113 @@ |
|||||
|
// ==========================================================================
|
||||
|
// AppHistoryEventsCreator.cs
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex Group
|
||||
|
// All rights reserved.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.Collections.Generic; |
||||
|
using System.Threading.Tasks; |
||||
|
using Squidex.Events; |
||||
|
using Squidex.Events.Schemas; |
||||
|
using Squidex.Infrastructure; |
||||
|
using Squidex.Infrastructure.CQRS; |
||||
|
using Squidex.Infrastructure.CQRS.Events; |
||||
|
using Squidex.Infrastructure.Dispatching; |
||||
|
using Squidex.Read.History; |
||||
|
using Squidex.Read.Schemas.Services; |
||||
|
|
||||
|
namespace Squidex.Read.Schemas |
||||
|
{ |
||||
|
public class SchemaHistoryEventsCreator : IHistoryEventsCreator |
||||
|
{ |
||||
|
private readonly ISchemaProvider schemaProvider; |
||||
|
|
||||
|
private static readonly IReadOnlyDictionary<string, string> TextsEN = |
||||
|
new Dictionary<string, string> |
||||
|
{ |
||||
|
{ |
||||
|
TypeNameRegistry.GetName<SchemaCreated>(), |
||||
|
"created schema {[Name]}" |
||||
|
}, |
||||
|
{ |
||||
|
TypeNameRegistry.GetName<SchemaUpdated>(), |
||||
|
"updated schema {[Name]}" |
||||
|
}, |
||||
|
{ |
||||
|
TypeNameRegistry.GetName<SchemaPublished>(), |
||||
|
"published schema {[Name]}" |
||||
|
}, |
||||
|
{ |
||||
|
TypeNameRegistry.GetName<SchemaUnpublished>(), |
||||
|
"unpublished schema {[Name]}" |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
public SchemaHistoryEventsCreator(ISchemaProvider schemaProvider) |
||||
|
{ |
||||
|
this.schemaProvider = schemaProvider; |
||||
|
} |
||||
|
|
||||
|
public IReadOnlyDictionary<string, string> Texts |
||||
|
{ |
||||
|
get { return TextsEN; } |
||||
|
} |
||||
|
|
||||
|
protected Task<HistoryEventToStore> On(SchemaCreated @event, EnvelopeHeaders headers) |
||||
|
{ |
||||
|
var name = @event.Name; |
||||
|
|
||||
|
string channel = $"schemas.{name}"; |
||||
|
|
||||
|
return Task.FromResult( |
||||
|
HistoryEventToStore.Create(@event, channel) |
||||
|
.AddParameter("Name", name)); |
||||
|
} |
||||
|
|
||||
|
protected async Task<HistoryEventToStore> On(SchemaUpdated @event, EnvelopeHeaders headers) |
||||
|
{ |
||||
|
var name = await FindSchemaNameAsync(headers); |
||||
|
|
||||
|
string channel = $"schemas.{name}"; |
||||
|
|
||||
|
return |
||||
|
HistoryEventToStore.Create(@event, channel) |
||||
|
.AddParameter("Name", name); |
||||
|
} |
||||
|
|
||||
|
protected async Task<HistoryEventToStore> On(SchemaPublished @event, EnvelopeHeaders headers) |
||||
|
{ |
||||
|
var name = await FindSchemaNameAsync(headers); |
||||
|
|
||||
|
string channel = $"schemas.{name}"; |
||||
|
|
||||
|
return |
||||
|
HistoryEventToStore.Create(@event, channel) |
||||
|
.AddParameter("Name", name); |
||||
|
} |
||||
|
|
||||
|
protected async Task<HistoryEventToStore> On(SchemaUnpublished @event, EnvelopeHeaders headers) |
||||
|
{ |
||||
|
var name = await FindSchemaNameAsync(headers); |
||||
|
|
||||
|
string channel = $"schemas.{name}"; |
||||
|
|
||||
|
return |
||||
|
HistoryEventToStore.Create(@event, channel) |
||||
|
.AddParameter("Name", name); |
||||
|
} |
||||
|
|
||||
|
public Task<HistoryEventToStore> CreateEventAsync(Envelope<IEvent> @event) |
||||
|
{ |
||||
|
return this.DispatchFuncAsync(@event.Payload, @event.Headers, (HistoryEventToStore)null); |
||||
|
} |
||||
|
|
||||
|
private Task<string> FindSchemaNameAsync(EnvelopeHeaders headers) |
||||
|
{ |
||||
|
var name = schemaProvider.FindSchemaNameByIdAsync(headers.AppId(), headers.AggregateId()); |
||||
|
|
||||
|
return name; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,54 +0,0 @@ |
|||||
// ==========================================================================
|
|
||||
// MessagesEN.cs
|
|
||||
// Squidex Headless CMS
|
|
||||
// ==========================================================================
|
|
||||
// Copyright (c) Squidex Group
|
|
||||
// All rights reserved.
|
|
||||
// ==========================================================================
|
|
||||
|
|
||||
using System.Collections.Generic; |
|
||||
using Squidex.Events.Apps; |
|
||||
using Squidex.Infrastructure; |
|
||||
|
|
||||
namespace Squidex.Store.MongoDb.History |
|
||||
{ |
|
||||
public static class MessagesEN |
|
||||
{ |
|
||||
public static readonly IReadOnlyDictionary<string, string> Texts = |
|
||||
new Dictionary<string, string> |
|
||||
{ |
|
||||
{ |
|
||||
TypeNameRegistry.GetName<AppContributorAssigned>(), |
|
||||
"assigned {user:[Contributor]} as [Permission]" |
|
||||
}, |
|
||||
{ |
|
||||
TypeNameRegistry.GetName<AppContributorRemoved>(), |
|
||||
"removed {user:[Contributor]} from app" |
|
||||
}, |
|
||||
{ |
|
||||
TypeNameRegistry.GetName<AppClientAttached>(), |
|
||||
"added client {[Id]} to app" |
|
||||
}, |
|
||||
{ |
|
||||
TypeNameRegistry.GetName<AppClientRevoked>(), |
|
||||
"revoked client {[Id]}" |
|
||||
}, |
|
||||
{ |
|
||||
TypeNameRegistry.GetName<AppClientRenamed>(), |
|
||||
"named client {[Id]} as {[Name]}" |
|
||||
}, |
|
||||
{ |
|
||||
TypeNameRegistry.GetName<AppLanguageAdded>(), |
|
||||
"added language {[Language]}" |
|
||||
}, |
|
||||
{ |
|
||||
TypeNameRegistry.GetName<AppLanguageRemoved>(), |
|
||||
"removed language {[Language]}" |
|
||||
}, |
|
||||
{ |
|
||||
TypeNameRegistry.GetName<AppMasterLanguageSet>(), |
|
||||
"changed master language to {[Language]}" |
|
||||
} |
|
||||
}; |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,14 @@ |
|||||
|
/* |
||||
|
* Squidex Headless CMS |
||||
|
* |
||||
|
* @license |
||||
|
* Copyright (c) Sebastian Stehle. All rights reserved |
||||
|
*/ |
||||
|
|
||||
|
export class SchemaUpdated { |
||||
|
constructor( |
||||
|
public readonly name: string, |
||||
|
public readonly isPublished: boolean |
||||
|
) { |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue