mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
#182: Storing updated audit trail settings with the event record and adding audit trail event settings changed event shape views.
This commit is contained in:
@@ -37,9 +37,9 @@ namespace Orchard.AuditTrail.Handlers {
|
||||
}
|
||||
|
||||
private void SetupLazyFields(ActivatedContentContext context, AuditTrailSettingsPart part) {
|
||||
part._eventProviderSettingsField.Loader(() => DeserializeProviderConfiguration(part.Retrieve<string>("Events")));
|
||||
part._eventProviderSettingsField.Loader(() => _auditTrailManager.DeserializeProviderConfiguration(part.Retrieve<string>("Events")));
|
||||
part._eventProviderSettingsField.Setter(value => {
|
||||
part.Store("Events", SerializeProviderConfiguration(value));
|
||||
part.Store("Events", _auditTrailManager.SerializeProviderConfiguration(value));
|
||||
_signals.Trigger("AuditTrail.EventSettings");
|
||||
return value;
|
||||
});
|
||||
@@ -57,37 +57,11 @@ namespace Orchard.AuditTrail.Handlers {
|
||||
|
||||
_auditTrailManager.CreateRecord<SettingsAuditTrailEventProvider>(
|
||||
eventName: SettingsAuditTrailEventProvider.EventsChanged,
|
||||
eventData: new Dictionary<string, object> {
|
||||
{"OldSettings", _oldEventSettings},
|
||||
{"NewSettings", newEventSettings}
|
||||
},
|
||||
user: _wca.GetContext().CurrentUser);
|
||||
}
|
||||
|
||||
|
||||
private IEnumerable<AuditTrailEventSetting> DeserializeProviderConfiguration(string data) {
|
||||
if (String.IsNullOrWhiteSpace(data))
|
||||
return Enumerable.Empty<AuditTrailEventSetting>();
|
||||
|
||||
try {
|
||||
var doc = XDocument.Parse(data);
|
||||
return doc.Element("Events").Elements("Event").Select(x => new AuditTrailEventSetting {
|
||||
EventName = x.Attr<string>("Name"),
|
||||
IsEnabled = x.Attr<bool>("IsEnabled")
|
||||
}).ToArray();
|
||||
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Logger.Error(ex, "Error occurred during deserialization of audit trail settings.");
|
||||
}
|
||||
return Enumerable.Empty<AuditTrailEventSetting>();
|
||||
}
|
||||
|
||||
private string SerializeProviderConfiguration(IEnumerable<AuditTrailEventSetting> settings) {
|
||||
var doc = new XDocument(
|
||||
new XElement("Events",
|
||||
settings.Select(x =>
|
||||
new XElement("Event",
|
||||
new XAttribute("Name", x.EventName),
|
||||
new XAttribute("IsEnabled", x.IsEnabled)))));
|
||||
|
||||
return doc.ToString(SaveOptions.DisableFormatting);
|
||||
}
|
||||
}
|
||||
}
|
@@ -2,7 +2,7 @@
|
||||
using Orchard.AuditTrail.Services;
|
||||
|
||||
namespace Orchard.AuditTrail.Helpers {
|
||||
internal static class EventNameExtensions {
|
||||
public static class EventNameExtensions {
|
||||
public static string GetFullyQualifiedEventName<T>(string eventName) where T : IAuditTrailEventProvider {
|
||||
return GetFullyQualifiedEventName(typeof(T), eventName);
|
||||
}
|
||||
@@ -10,5 +10,10 @@ namespace Orchard.AuditTrail.Helpers {
|
||||
public static string GetFullyQualifiedEventName(Type providerType, string eventName) {
|
||||
return String.Format("{0}.{1}", providerType.FullName, eventName);
|
||||
}
|
||||
|
||||
public static string GetShortEventName(string fullyQualifiedEventName) {
|
||||
var index = fullyQualifiedEventName.LastIndexOf('.') + 1;
|
||||
return fullyQualifiedEventName.Substring(index);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Orchard.Data.Conventions;
|
||||
|
||||
namespace Orchard.AuditTrail.Models {
|
||||
public class AuditTrailEventRecord {
|
||||
@@ -8,9 +9,13 @@ namespace Orchard.AuditTrail.Models {
|
||||
public virtual string EventName { get; set; }
|
||||
public virtual string FullEventName { get; set; }
|
||||
public virtual string Category { get; set; }
|
||||
|
||||
[StringLengthMax]
|
||||
public virtual string EventData { get; set; }
|
||||
public virtual string EventFilterKey { get; set; }
|
||||
public virtual string EventFilterData { get; set; }
|
||||
|
||||
[StringLengthMax]
|
||||
public virtual string Comment { get; set; }
|
||||
}
|
||||
}
|
@@ -84,6 +84,7 @@
|
||||
<Content Include="Styles\audittrail-display.css" />
|
||||
<Content Include="Styles\audittrail-disabledcontent.css" />
|
||||
<Content Include="Styles\audittrail-part.css" />
|
||||
<Content Include="Styles\audittrail-settings-event.css" />
|
||||
<Content Include="Styles\audittrail-settings.css" />
|
||||
<Content Include="Styles\menu.audit-trail-admin.css" />
|
||||
<Content Include="Web.config" />
|
||||
@@ -126,6 +127,8 @@
|
||||
</Content>
|
||||
<Content Include="Views\AuditTrailFilter.cshtml" />
|
||||
<Content Include="Views\AuditTrailFilter-Common-Date-To.cshtml" />
|
||||
<Content Include="Views\AuditTrailEvent-AuditTrailSettings-EventsChanged.SummaryAdminx.cshtml" />
|
||||
<Content Include="Views\AuditTrailEvent-AuditTrailSettings-EventsChanged.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\Orchard\Orchard.Framework.csproj">
|
||||
@@ -187,8 +190,10 @@
|
||||
<Compile Include="Services\Models\Filters.cs" />
|
||||
<Compile Include="Providers\Content\IDiffGramAnalyzer.cs" />
|
||||
<Compile Include="Services\AuditTrailTrimmingBackgroundTask.cs" />
|
||||
<Compile Include="Shapes\AuditTrailShapes.cs" />
|
||||
<Compile Include="Shapes\AuditTrailFilterShapes.cs" />
|
||||
<Compile Include="Shapes\AuditTrailSettingsEventShape.cs" />
|
||||
<Compile Include="ViewModels\AuditTrailCategorySettingsViewModel.cs" />
|
||||
<Compile Include="ViewModels\AuditTrailEventDescriptorSettingViewModel.cs" />
|
||||
<Compile Include="ViewModels\AuditTrailEventSettingsViewModel.cs" />
|
||||
<Compile Include="ViewModels\AuditTrailTrimmingSettingsViewModel.cs" />
|
||||
<Compile Include="ViewModels\AuditTrailSettingsViewModel.cs" />
|
||||
|
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Orchard.AuditTrail.Helpers;
|
||||
using Orchard.AuditTrail.Models;
|
||||
using Orchard.AuditTrail.Services.Models;
|
||||
@@ -9,6 +10,7 @@ using Orchard.Collections;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Data;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Security;
|
||||
using Orchard.Services;
|
||||
using Orchard.Settings;
|
||||
@@ -215,5 +217,34 @@ namespace Orchard.AuditTrail.Services {
|
||||
|
||||
return records;
|
||||
}
|
||||
|
||||
public string SerializeProviderConfiguration(IEnumerable<AuditTrailEventSetting> settings) {
|
||||
var doc = new XDocument(
|
||||
new XElement("Events",
|
||||
settings.Select(x =>
|
||||
new XElement("Event",
|
||||
new XAttribute("Name", x.EventName),
|
||||
new XAttribute("IsEnabled", x.IsEnabled)))));
|
||||
|
||||
return doc.ToString(SaveOptions.DisableFormatting);
|
||||
}
|
||||
|
||||
public IEnumerable<AuditTrailEventSetting> DeserializeProviderConfiguration(string data) {
|
||||
if (String.IsNullOrWhiteSpace(data))
|
||||
return Enumerable.Empty<AuditTrailEventSetting>();
|
||||
|
||||
try {
|
||||
var doc = XDocument.Parse(data);
|
||||
return doc.Element("Events").Elements("Event").Select(x => new AuditTrailEventSetting {
|
||||
EventName = x.Attr<string>("Name"),
|
||||
IsEnabled = x.Attr<bool>("IsEnabled")
|
||||
}).ToArray();
|
||||
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Logger.Error(ex, "Error occurred during deserialization of audit trail settings.");
|
||||
}
|
||||
return Enumerable.Empty<AuditTrailEventSetting>();
|
||||
}
|
||||
}
|
||||
}
|
@@ -76,5 +76,14 @@ namespace Orchard.AuditTrail.Services {
|
||||
/// <returns>A list of deleted records.</returns>
|
||||
IEnumerable<AuditTrailEventRecord> Trim(TimeSpan retentionPeriod);
|
||||
|
||||
/// <summary>
|
||||
/// Serializes the specified list of settings into a string.
|
||||
/// </summary>
|
||||
string SerializeProviderConfiguration(IEnumerable<AuditTrailEventSetting> settings);
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes the specified string into a list of settings.
|
||||
/// </summary>
|
||||
IEnumerable<AuditTrailEventSetting> DeserializeProviderConfiguration(string data);
|
||||
}
|
||||
}
|
@@ -2,7 +2,7 @@
|
||||
using Orchard.DisplayManagement;
|
||||
|
||||
namespace Orchard.AuditTrail.Shapes {
|
||||
public class AuditTrailShapes : IDependency {
|
||||
public class AuditTrailFilterShapes : IDependency {
|
||||
[Shape]
|
||||
public void AuditTrailFilterDisplay(dynamic Shape, dynamic Display, TextWriter Output) {
|
||||
DispayChildren(Shape, Display, Output);
|
@@ -0,0 +1,48 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Orchard.AuditTrail.Helpers;
|
||||
using Orchard.AuditTrail.Models;
|
||||
using Orchard.AuditTrail.Providers.AuditTrail;
|
||||
using Orchard.AuditTrail.Services;
|
||||
using Orchard.AuditTrail.Services.Models;
|
||||
using Orchard.AuditTrail.ViewModels;
|
||||
using Orchard.DisplayManagement.Descriptors;
|
||||
using Orchard.Environment;
|
||||
|
||||
namespace Orchard.AuditTrail.Shapes {
|
||||
public class AuditTrailSettingsEventShape : IShapeTableProvider {
|
||||
private readonly Work<IAuditTrailManager> _auditTrailManager;
|
||||
public AuditTrailSettingsEventShape(Work<IAuditTrailManager> auditTrailManager) {
|
||||
_auditTrailManager = auditTrailManager;
|
||||
}
|
||||
|
||||
public void Discover(ShapeTableBuilder builder) {
|
||||
builder.Describe("AuditTrailEvent").OnDisplaying(context => {
|
||||
var descriptor = (AuditTrailEventDescriptor) context.Shape.Descriptor;
|
||||
if (descriptor.Event != EventNameExtensions.GetFullyQualifiedEventName<SettingsAuditTrailEventProvider>(SettingsAuditTrailEventProvider.EventsChanged))
|
||||
return;
|
||||
|
||||
var eventData = (IDictionary<string, object>)context.Shape.EventData;
|
||||
var oldSettings = _auditTrailManager.Value.DeserializeProviderConfiguration((string)eventData["OldSettings"]);
|
||||
var newSettings = _auditTrailManager.Value.DeserializeProviderConfiguration((string)eventData["NewSettings"]);
|
||||
var diff = GetDiffQuery(oldSettings, newSettings).ToArray();
|
||||
|
||||
context.Shape.OldSettings = oldSettings;
|
||||
context.Shape.NewSettings = newSettings;
|
||||
context.Shape.Diff = diff;
|
||||
});
|
||||
}
|
||||
|
||||
private IEnumerable<AuditTrailEventDescriptorSettingViewModel> GetDiffQuery(IEnumerable<AuditTrailEventSetting> oldSettings, IEnumerable<AuditTrailEventSetting> newSettings) {
|
||||
var oldDictionary = oldSettings.ToDictionary(x => x.EventName);
|
||||
|
||||
return from newSetting in newSettings
|
||||
let oldSetting = oldDictionary.ContainsKey(newSetting.EventName) ? oldDictionary[newSetting.EventName] : default(AuditTrailEventSetting)
|
||||
where oldSetting == null || oldSetting.IsEnabled != newSetting.IsEnabled
|
||||
select new AuditTrailEventDescriptorSettingViewModel {
|
||||
Setting = newSetting,
|
||||
Descriptor = _auditTrailManager.Value.DescribeEvent(newSetting.EventName)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
section.audittrail-settings-event table.audittrail-events {
|
||||
width: auto;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
section.audittrail-settings-event tbody.audittrail-category tr th {
|
||||
background-color: #ebebeb;
|
||||
font-size: 1.1em;
|
||||
font-weight: bold;
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
using Orchard.AuditTrail.Models;
|
||||
using Orchard.AuditTrail.Services.Models;
|
||||
|
||||
namespace Orchard.AuditTrail.ViewModels {
|
||||
public class AuditTrailEventDescriptorSettingViewModel {
|
||||
public AuditTrailEventDescriptor Descriptor { get; set; }
|
||||
public AuditTrailEventSetting Setting { get; set; }
|
||||
}
|
||||
}
|
@@ -1,4 +1,3 @@
|
||||
using System.Collections;
|
||||
using Orchard.Localization;
|
||||
|
||||
namespace Orchard.AuditTrail.ViewModels {
|
||||
|
@@ -0,0 +1,9 @@
|
||||
@using Orchard.AuditTrail.ViewModels
|
||||
@{
|
||||
var diff = (IList<AuditTrailEventDescriptorSettingViewModel>)Model.Diff;
|
||||
var descriptions = String.Join("<br/>", diff.Select(x => T("<strong>{0}</strong> ({1}) was <strong>{2}</strong>", x.Descriptor.Name, x.Descriptor.CategoryDescriptor.Name, x.Setting.IsEnabled ? "enabled" : "disabled").Text));
|
||||
}
|
||||
|
||||
<section class="audittrail-settings-summary">
|
||||
@Html.Raw(descriptions)
|
||||
</section>
|
@@ -0,0 +1,34 @@
|
||||
@using Orchard.AuditTrail.ViewModels
|
||||
@{
|
||||
Style.Include("audittrail-settings-event.css");
|
||||
}
|
||||
@{
|
||||
var diff = (IList<AuditTrailEventDescriptorSettingViewModel>)Model.Diff;
|
||||
var groups = diff.GroupBy(x => x.Descriptor.CategoryDescriptor.Name).OrderBy(x => x.Key.Text);
|
||||
}
|
||||
|
||||
<section class="audittrail-settings-event">
|
||||
<table class="audittrail-events items">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>@T("Event")</th>
|
||||
<th>@T("Description")</th>
|
||||
<th>@T("New Status")</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@foreach (var group in groups) {
|
||||
<tbody class="audittrail-category">
|
||||
<tr>
|
||||
<th colspan="3">@group.Key</th>
|
||||
</tr>
|
||||
@foreach (var eventSetting in group.OrderBy(x => x.Descriptor.Name.Text)) {
|
||||
<tr>
|
||||
<td>@eventSetting.Descriptor.Name</td>
|
||||
<td>@eventSetting.Descriptor.Description</td>
|
||||
<td>@T(eventSetting.Setting.IsEnabled ? "Enabled" : "Disabled")</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
}
|
||||
</table>
|
||||
</section>
|
@@ -2,7 +2,6 @@
|
||||
@{
|
||||
Style.Include("audittrail-settings.css");
|
||||
Script.Require("ShapesBase");
|
||||
//Script.Include("~/Themes/TheAdmin/scripts/admin.js").AtFoot();
|
||||
Script.Include("audittrail-checkall.js").AtFoot();
|
||||
}
|
||||
<section class="audittrail-settings-section">
|
||||
|
Reference in New Issue
Block a user