mirror of https://github.com/abpframework/abp.git
committed by
GitHub
19 changed files with 217 additions and 66 deletions
@ -1,12 +0,0 @@ |
|||
using JetBrains.Annotations; |
|||
using Volo.CmsKit.Reactions; |
|||
using Volo.CmsKit.Tags; |
|||
|
|||
namespace Volo.CmsKit |
|||
{ |
|||
public class CmsKitOptions |
|||
{ |
|||
[NotNull] |
|||
public ReactionDefinitionDictionary Reactions { get; } = new ReactionDefinitionDictionary(); |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
using JetBrains.Annotations; |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.CmsKit.Reactions |
|||
{ |
|||
public class CmsKitReactionOptions |
|||
{ |
|||
[NotNull] |
|||
public List<ReactionEntityTypeDefinition> EntityTypes { get; } = new (); |
|||
} |
|||
} |
|||
@ -1,28 +1,59 @@ |
|||
using System.Collections.Generic; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using JetBrains.Annotations; |
|||
using Microsoft.Extensions.Options; |
|||
using Volo.Abp; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.CmsKit.Reactions |
|||
{ |
|||
public class DefaultReactionDefinitionStore : IReactionDefinitionStore, ITransientDependency |
|||
{ |
|||
protected CmsKitOptions Options { get; } |
|||
protected CmsKitReactionOptions Options { get; } |
|||
|
|||
public DefaultReactionDefinitionStore(IOptions<CmsKitOptions> options) |
|||
public DefaultReactionDefinitionStore(IOptions<CmsKitReactionOptions> options) |
|||
{ |
|||
Options = options.Value; |
|||
} |
|||
|
|||
public virtual Task<List<ReactionDefinition>> GetReactionsAsync(string entityType = null) |
|||
public virtual async Task<List<ReactionDefinition>> GetReactionsAsync([NotNull] string entityType) |
|||
{ |
|||
return Task.FromResult(Options.Reactions.Values.ToList()); |
|||
Check.NotNullOrEmpty(entityType, nameof(entityType)); |
|||
|
|||
var definition = await GetAsync(entityType); |
|||
|
|||
return definition.Reactions; |
|||
} |
|||
|
|||
public virtual async Task<ReactionDefinition> GetReactionOrNullAsync([NotNull] string reactionName, [NotNull] string entityType) |
|||
{ |
|||
Check.NotNullOrEmpty(entityType, nameof(entityType)); |
|||
Check.NotNullOrEmpty(reactionName, nameof(reactionName)); |
|||
|
|||
var definition = await GetAsync(entityType); |
|||
|
|||
return definition.Reactions.SingleOrDefault(x => x.Name == reactionName); |
|||
} |
|||
|
|||
public virtual Task<ReactionDefinition> GetReactionOrNullAsync(string reactionName, string entityType = null) |
|||
public virtual Task<bool> IsDefinedAsync([NotNull] string entityType) |
|||
{ |
|||
return Task.FromResult(Options.Reactions.GetOrDefault(reactionName)); |
|||
Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); |
|||
|
|||
var isDefined = Options.EntityTypes.Any(x => x.EntityType.Equals(entityType, StringComparison.InvariantCultureIgnoreCase)); |
|||
|
|||
return Task.FromResult(isDefined); |
|||
} |
|||
|
|||
public virtual Task<ReactionEntityTypeDefinition> GetAsync([NotNull] string entityType) |
|||
{ |
|||
Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); |
|||
|
|||
var definition = Options.EntityTypes.SingleOrDefault(x => x.EntityType.Equals(entityType, StringComparison.InvariantCultureIgnoreCase)) ?? |
|||
throw new EntityCantHaveReactionException(entityType); |
|||
|
|||
return Task.FromResult(definition); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,23 @@ |
|||
|
|||
using JetBrains.Annotations; |
|||
using System.Runtime.Serialization; |
|||
using Volo.Abp; |
|||
|
|||
namespace Volo.CmsKit.Reactions |
|||
{ |
|||
public class EntityCantHaveReactionException : BusinessException |
|||
{ |
|||
public EntityCantHaveReactionException(SerializationInfo serializationInfo, StreamingContext context) : base(serializationInfo, context) |
|||
{ |
|||
} |
|||
|
|||
public EntityCantHaveReactionException([NotNull] string entityType) |
|||
{ |
|||
EntityType = Check.NotNullOrEmpty(entityType, nameof(entityType)); |
|||
Code = CmsKitErrorCodes.Reactions.EntityCantHaveReaction; |
|||
WithData(nameof(EntityType), EntityType); |
|||
} |
|||
|
|||
public string EntityType { get; } |
|||
} |
|||
} |
|||
@ -1,14 +0,0 @@ |
|||
using System.Collections.Generic; |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.Localization; |
|||
|
|||
namespace Volo.CmsKit.Reactions |
|||
{ |
|||
public class ReactionDefinitionDictionary : Dictionary<string, ReactionDefinition> |
|||
{ |
|||
public void AddOrReplace([NotNull] string name, ILocalizableString displayName = null) |
|||
{ |
|||
this[name] = new ReactionDefinition(name, displayName); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
using JetBrains.Annotations; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
|
|||
namespace Volo.CmsKit.Reactions |
|||
{ |
|||
public class ReactionEntityTypeDefinition : PolicySpecifiedDefinition |
|||
{ |
|||
[NotNull] |
|||
public List<ReactionDefinition> Reactions { get; } = new(); |
|||
|
|||
public ReactionEntityTypeDefinition( |
|||
[NotNull] string entityType, |
|||
[NotNull] IEnumerable<ReactionDefinition> reactions, |
|||
IEnumerable<string> createPolicies = null, |
|||
IEnumerable<string> updatePolicies = null, |
|||
IEnumerable<string> deletePolicies = null) : base(entityType, createPolicies, updatePolicies, deletePolicies) |
|||
{ |
|||
Reactions = Check.NotNull(reactions, nameof(reactions)).ToList(); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue