mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Updating audit trail manager to take event settings into account.
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Orchard.AuditTrail.Models;
|
||||
using Orchard.Caching;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Localization;
|
||||
@@ -10,7 +11,10 @@ using Orchard.Logging;
|
||||
|
||||
namespace Orchard.AuditTrail.Handlers {
|
||||
public class AuditTrailSiteSettingsPartHandler : ContentHandler {
|
||||
public AuditTrailSiteSettingsPartHandler() {
|
||||
private readonly ISignals _signals;
|
||||
|
||||
public AuditTrailSiteSettingsPartHandler(ISignals signals) {
|
||||
_signals = signals;
|
||||
OnActivated<AuditTrailSiteSettingsPart>(SetupLazyFields);
|
||||
OnGetContentItemMetadata<AuditTrailSiteSettingsPart>(GetMetadata);
|
||||
T = NullLocalizer.Instance;
|
||||
@@ -26,6 +30,7 @@ namespace Orchard.AuditTrail.Handlers {
|
||||
part._eventProviderSettingsField.Loader(() => DeserializeProviderConfiguration(part.Retrieve<string>("Events")));
|
||||
part._eventProviderSettingsField.Setter(value => {
|
||||
part.Store("Events", SerializeProviderConfiguration(value));
|
||||
_signals.Trigger("AuditTrail.EventSettings");
|
||||
return value;
|
||||
});
|
||||
}
|
||||
|
@@ -0,0 +1,6 @@
|
||||
namespace Orchard.AuditTrail.Models {
|
||||
public class AuditTrailEventRecordResult {
|
||||
public AuditTrailEventRecord Record { get; set; }
|
||||
public bool IsDisabled { get; set; }
|
||||
}
|
||||
}
|
@@ -119,6 +119,7 @@
|
||||
<Compile Include="AdminMenu.cs" />
|
||||
<Compile Include="Controllers\AdminController.cs" />
|
||||
<Compile Include="Drivers\AuditTrailSiteSettingsPartDriver.cs" />
|
||||
<Compile Include="Models\AuditTrailEventRecordResult.cs" />
|
||||
<Compile Include="ViewModels\AuditTrailCategorySettingsViewModel.cs" />
|
||||
<Compile Include="ViewModels\AuditTrailEventSettingsViewModel.cs" />
|
||||
<Compile Include="ViewModels\AuditTrailSiteSettingsViewModel.cs" />
|
||||
|
@@ -3,10 +3,13 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Orchard.AuditTrail.Helpers;
|
||||
using Orchard.AuditTrail.Models;
|
||||
using Orchard.Caching;
|
||||
using Orchard.Collections;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Data;
|
||||
using Orchard.Security;
|
||||
using Orchard.Services;
|
||||
using Orchard.Settings;
|
||||
|
||||
namespace Orchard.AuditTrail.Services {
|
||||
public class AuditTrailManager : Component, IAuditTrailManager {
|
||||
@@ -15,19 +18,28 @@ namespace Orchard.AuditTrail.Services {
|
||||
private readonly IClock _clock;
|
||||
private readonly IAuditTrailEventHandler _auditTrailEventHandlers;
|
||||
private readonly IEventDataSerializer _serializer;
|
||||
private readonly ICacheManager _cacheManager;
|
||||
private readonly ISiteService _siteService;
|
||||
private readonly ISignals _signals;
|
||||
|
||||
public AuditTrailManager(
|
||||
IRepository<AuditTrailEventRecord> auditTrailRepository,
|
||||
IAuditTrailEventProvider providers,
|
||||
IClock clock,
|
||||
IAuditTrailEventHandler auditTrailEventHandlers,
|
||||
IEventDataSerializer serializer) {
|
||||
IEventDataSerializer serializer,
|
||||
ICacheManager cacheManager,
|
||||
ISiteService siteService,
|
||||
ISignals signals) {
|
||||
|
||||
_auditTrailRepository = auditTrailRepository;
|
||||
_providers = providers;
|
||||
_clock = clock;
|
||||
_auditTrailEventHandlers = auditTrailEventHandlers;
|
||||
_serializer = serializer;
|
||||
_cacheManager = cacheManager;
|
||||
_siteService = siteService;
|
||||
_signals = signals;
|
||||
}
|
||||
|
||||
public IPageOfItems<AuditTrailEventRecord> GetRecords(int page, int pageSize, AuditTrailFilterParameters filter = null, AuditTrailOrderBy orderBy = AuditTrailOrderBy.DateDescending) {
|
||||
@@ -66,7 +78,14 @@ namespace Orchard.AuditTrail.Services {
|
||||
return _auditTrailRepository.Get(id);
|
||||
}
|
||||
|
||||
public AuditTrailEventRecord Record<T>(string eventName, IUser user, IDictionary<string, object> properties = null, IDictionary<string, object> eventData = null, string eventFilterKey = null, string eventFilterData = null) where T:IAuditTrailEventProvider {
|
||||
public AuditTrailEventRecordResult Record<T>(string eventName, IUser user, IDictionary<string, object> properties = null, IDictionary<string, object> eventData = null, string eventFilterKey = null, string eventFilterData = null) where T:IAuditTrailEventProvider {
|
||||
var eventDescriptor = Describe<T>(eventName);
|
||||
if(!IsEnabled(eventDescriptor))
|
||||
return new AuditTrailEventRecordResult {
|
||||
Record = null,
|
||||
IsDisabled = true
|
||||
};
|
||||
|
||||
if (properties == null) properties = new Dictionary<string, object>();
|
||||
if (eventData == null) eventData = new Dictionary<string, object>();
|
||||
|
||||
@@ -80,7 +99,6 @@ namespace Orchard.AuditTrail.Services {
|
||||
};
|
||||
|
||||
_auditTrailEventHandlers.Create(context);
|
||||
var eventDescriptor = Describe<T>(eventName);
|
||||
|
||||
var record = new AuditTrailEventRecord {
|
||||
Category = eventDescriptor.CategoryDescriptor.Category,
|
||||
@@ -94,7 +112,19 @@ namespace Orchard.AuditTrail.Services {
|
||||
};
|
||||
|
||||
_auditTrailRepository.Create(record);
|
||||
return record;
|
||||
return new AuditTrailEventRecordResult {
|
||||
Record = record,
|
||||
IsDisabled = false
|
||||
};
|
||||
}
|
||||
|
||||
private bool IsEnabled(AuditTrailEventDescriptor eventDescriptor) {
|
||||
var settingsDictionary = _cacheManager.Get("AuditTrail.EventSettings", context => {
|
||||
context.Monitor(_signals.When("AuditTrail.EventSettings"));
|
||||
return _siteService.GetSiteSettings().As<AuditTrailSiteSettingsPart>().EventSettings.ToDictionary(x => x.EventName);
|
||||
});
|
||||
var setting = settingsDictionary.ContainsKey(eventDescriptor.Event) ? settingsDictionary[eventDescriptor.Event] : default(AuditTrailEventSetting);
|
||||
return setting != null ? setting.IsEnabled : eventDescriptor.IsEnabledByDefault;
|
||||
}
|
||||
|
||||
public IEnumerable<AuditTrailCategoryDescriptor> Describe() {
|
||||
|
@@ -33,8 +33,8 @@ namespace Orchard.AuditTrail.Services {
|
||||
/// <param name="eventData">A property bag of custom event data that will be stored with the event record.</param>
|
||||
/// <param name="eventFilterKey">The name of a custom key to use when filtering events.</param>
|
||||
/// <param name="eventFilterData">The value of a custom filter key to filter on.</param>
|
||||
/// <returns>Returns the created audit trail event record.</returns>
|
||||
AuditTrailEventRecord Record<T>(string eventName, IUser user, IDictionary<string, object> properties = null, IDictionary<string, object> eventData = null, string eventFilterKey = null, string eventFilterData = null) where T : IAuditTrailEventProvider;
|
||||
/// <returns>Returns the created audit trail event record if the specified event was not disabled.</returns>
|
||||
AuditTrailEventRecordResult Record<T>(string eventName, IUser user, IDictionary<string, object> properties = null, IDictionary<string, object> eventData = null, string eventFilterKey = null, string eventFilterData = null) where T : IAuditTrailEventProvider;
|
||||
|
||||
/// <summary>
|
||||
/// Describes all audit trail events provided by the system.
|
||||
|
Reference in New Issue
Block a user