mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Completed extraction of roles and users audit trail providers into separate features by removing duplicated interfaces. Renamed some helper classes as extensions. Some minor reformating and naming changes. Fixed bugs in the role audit trail provider.
This commit is contained in:
@@ -27,22 +27,26 @@ namespace Orchard.AuditTrail.Drivers {
|
||||
return ContentShape("Parts_AuditTrailSettings_Edit", () => {
|
||||
var descriptors = _auditTrailManager.DescribeCategories();
|
||||
var eventSettings = part.EventSettings.ToList();
|
||||
var categoriesQuery =
|
||||
from categoryDescriptor in descriptors
|
||||
let eventsQuery =
|
||||
from eventDescriptor in categoryDescriptor.Events
|
||||
let eventSetting = eventSettings.FirstOrDefault(x => x.EventName == eventDescriptor.Event)
|
||||
select new AuditTrailEventSettingsViewModel {
|
||||
Event = eventDescriptor.Event,
|
||||
Name = eventDescriptor.Name,
|
||||
Description = eventDescriptor.Description,
|
||||
IsEnabled = eventDescriptor.IsMandatory || (eventSetting != null ? eventSetting.IsEnabled : eventDescriptor.IsEnabledByDefault),
|
||||
IsMandatory = eventDescriptor.IsMandatory
|
||||
}
|
||||
select new AuditTrailCategorySettingsViewModel {
|
||||
Category = categoryDescriptor.Category,
|
||||
Name = categoryDescriptor.Name,
|
||||
Events = eventsQuery.ToArray()
|
||||
};
|
||||
|
||||
var viewModel = new AuditTrailSettingsViewModel {
|
||||
Categories = (from categoryDescriptor in descriptors
|
||||
select new AuditTrailCategorySettingsViewModel {
|
||||
Category = categoryDescriptor.Category,
|
||||
Name = categoryDescriptor.Name,
|
||||
Events =
|
||||
(from eventDescriptor in categoryDescriptor.Events
|
||||
let eventSetting = eventSettings.FirstOrDefault(x => x.EventName == eventDescriptor.Event)
|
||||
select new AuditTrailEventSettingsViewModel {
|
||||
Event = eventDescriptor.Event,
|
||||
Name = eventDescriptor.Name,
|
||||
Description = eventDescriptor.Description,
|
||||
IsEnabled = eventDescriptor.IsMandatory || (eventSetting != null ? eventSetting.IsEnabled : eventDescriptor.IsEnabledByDefault),
|
||||
IsMandatory = eventDescriptor.IsMandatory
|
||||
}).ToList()
|
||||
}).ToList()
|
||||
Categories = categoriesQuery.ToArray()
|
||||
};
|
||||
|
||||
if (updater != null) {
|
||||
@@ -55,6 +59,7 @@ namespace Orchard.AuditTrail.Drivers {
|
||||
eventSettings.Add(eventSetting);
|
||||
}
|
||||
|
||||
// TODO: Security hole! IsMandatory could be spoofed in the request!
|
||||
eventSetting.IsEnabled = eventSettingViewModel.IsEnabled || eventSettingViewModel.IsMandatory;
|
||||
}
|
||||
part.EventSettings = eventSettings;
|
||||
|
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
|
||||
namespace Orchard.AuditTrail.Helpers {
|
||||
public static class DateTimeHelper {
|
||||
public static class DateTimeExtensions {
|
||||
public static DateTime? Earliest(this DateTime? value) {
|
||||
if (value == null)
|
||||
return null;
|
@@ -2,7 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Orchard.AuditTrail.Helpers {
|
||||
public static class EventDataHelper {
|
||||
public static class EventDataExtensions {
|
||||
public static T Get<T>(this IDictionary<string, object> eventData, string key) {
|
||||
if (eventData == null || !eventData.ContainsKey(key))
|
||||
return default(T);
|
@@ -2,7 +2,7 @@
|
||||
using Orchard.AuditTrail.Services;
|
||||
|
||||
namespace Orchard.AuditTrail.Helpers {
|
||||
internal static class EventNameHelper {
|
||||
internal static class EventNameExtensions {
|
||||
public static string GetFullyQualifiedEventName<T>(string eventName) where T : IAuditTrailEventProvider {
|
||||
return GetFullyQualifiedEventName(typeof(T), eventName);
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
using Orchard.AuditTrail.Services.Models;
|
||||
|
||||
namespace Orchard.AuditTrail.Helpers {
|
||||
public static class FiltersHelper {
|
||||
public static class FiltersExtensions {
|
||||
public static string Get(this Filters filters, string key) {
|
||||
if (!filters.ContainsKey(key))
|
||||
return null;
|
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
|
||||
namespace Orchard.AuditTrail.Helpers {
|
||||
public static class StringConversionHelper {
|
||||
public static class StringExtensions {
|
||||
public static int? ToInt32(this string value) {
|
||||
if (String.IsNullOrWhiteSpace(value))
|
||||
return null;
|
@@ -161,6 +161,14 @@
|
||||
<Project>{fe5c5947-d2d5-42c5-992a-13d672946135}</Project>
|
||||
<Name>Orchard.ImportExport</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Orchard.Roles\Orchard.Roles.csproj">
|
||||
<Project>{d10ad48f-407d-4db5-a328-173ec7cb010f}</Project>
|
||||
<Name>Orchard.Roles</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Orchard.Users\Orchard.Users.csproj">
|
||||
<Project>{79aed36e-abd0-4747-93d3-8722b042454b}</Project>
|
||||
<Name>Orchard.Users</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AdminMenu.cs" />
|
||||
@@ -169,9 +177,9 @@
|
||||
<Compile Include="Drivers\AuditTrailTrimmingSettingsPartDriver.cs" />
|
||||
<Compile Include="Drivers\AuditTrailSettingsPartDriver.cs" />
|
||||
<Compile Include="Handlers\AuditTrailTrimmingSettingsPartHandler.cs" />
|
||||
<Compile Include="Helpers\FiltersHelper.cs" />
|
||||
<Compile Include="Helpers\DateTimeHelper.cs" />
|
||||
<Compile Include="Helpers\StringConversionHelper.cs" />
|
||||
<Compile Include="Helpers\FiltersExtensions.cs" />
|
||||
<Compile Include="Helpers\DateTimeExtensions.cs" />
|
||||
<Compile Include="Helpers\StringExtensions.cs" />
|
||||
<Compile Include="ImportExport\AuditTrailExportStep.cs" />
|
||||
<Compile Include="ImportExport\AuditTrailExportHandler.cs" />
|
||||
<Compile Include="ImportExport\AuditTrailImportHandler.cs" />
|
||||
@@ -206,19 +214,17 @@
|
||||
<Compile Include="Providers\ContentDefinition\ContentPartAuditTrailEventProvider.cs" />
|
||||
<Compile Include="Providers\ContentDefinition\ContentTypeAuditTrailEventProvider.cs" />
|
||||
<Compile Include="Providers\Content\AuditTrailEventHandler.cs" />
|
||||
<Compile Include="Helpers\EventDataHelper.cs" />
|
||||
<Compile Include="Helpers\EventDataExtensions.cs" />
|
||||
<Compile Include="Services\Models\AuditTrailFilterParameters.cs" />
|
||||
<Compile Include="Providers\Roles\IRoleEventHandler.cs" />
|
||||
<Compile Include="Providers\Roles\RoleEventHandler.cs" />
|
||||
<Compile Include="Providers\Roles\RoleAuditTrailEventProvider.cs" />
|
||||
<Compile Include="Providers\Users\UserAuditTrailEventProvider.cs" />
|
||||
<Compile Include="Providers\Users\IUserEventHandler.cs" />
|
||||
<Compile Include="Providers\Users\UserEventHandler.cs" />
|
||||
<Compile Include="Settings\AuditTrailPartSettings.cs" />
|
||||
<Compile Include="Settings\AuditTrailPartSettingsEvents.cs" />
|
||||
<Compile Include="ViewModels\AuditTrailEventSummaryViewModel.cs" />
|
||||
<Compile Include="Drivers\AuditTrailPartDriver.cs" />
|
||||
<Compile Include="Helpers\EventNameHelper.cs" />
|
||||
<Compile Include="Helpers\EventNameExtensions.cs" />
|
||||
<Compile Include="Models\AuditTrailPart.cs" />
|
||||
<Compile Include="Services\AuditTrailEventDisplayBuilder.cs" />
|
||||
<Compile Include="Services\EventDataSerializer.cs" />
|
||||
|
@@ -8,13 +8,11 @@ using Microsoft.XmlDiffPatch;
|
||||
namespace Orchard.AuditTrail.Providers.Content {
|
||||
public class DiffGramAnalyzer : IDiffGramAnalyzer {
|
||||
public XElement GenerateDiffGram(XElement element1, XElement element2) {
|
||||
using(var node1Reader = element1.CreateReader())
|
||||
using (var node1Reader = element1.CreateReader())
|
||||
using (var node2Reader = element2.CreateReader()) {
|
||||
var result = new XDocument();
|
||||
using (var writer = result.CreateWriter()) {
|
||||
var diff =
|
||||
new XmlDiff(XmlDiffOptions.IgnoreChildOrder | XmlDiffOptions.IgnoreWhitespace |
|
||||
XmlDiffOptions.IgnoreComments | XmlDiffOptions.IgnoreXmlDecl);
|
||||
var diff = new XmlDiff(XmlDiffOptions.IgnoreChildOrder | XmlDiffOptions.IgnoreWhitespace | XmlDiffOptions.IgnoreComments | XmlDiffOptions.IgnoreXmlDecl);
|
||||
diff.Compare(node1Reader, node2Reader, writer);
|
||||
writer.Flush();
|
||||
writer.Close();
|
||||
|
@@ -9,8 +9,8 @@ namespace Orchard.AuditTrail.Providers.Content {
|
||||
XElement GenerateDiffGram(XElement element1, XElement element2);
|
||||
|
||||
/// <summary>
|
||||
/// Analyzes the specified DiffGram against the specified original XML element and returns a list of diff nodes,
|
||||
/// where each node describes the difference between the original and updated document.
|
||||
/// Analyzes the specified DiffGram element against the specified original XML element and returns a list of diff nodes,
|
||||
/// where each node describes a difference between the original and updated document.
|
||||
/// </summary>
|
||||
IEnumerable<DiffNode> Analyze(XElement original, XElement diffGram);
|
||||
}
|
||||
|
@@ -1,13 +0,0 @@
|
||||
using Orchard.Events;
|
||||
|
||||
namespace Orchard.AuditTrail.Providers.Roles {
|
||||
public interface IRoleEventHandler : IEventHandler {
|
||||
void Created(dynamic context);
|
||||
void Removed(dynamic context);
|
||||
void Renamed(dynamic context);
|
||||
void PermissionAdded(dynamic context);
|
||||
void PermissionRemoved(dynamic context);
|
||||
void UserAdded(dynamic context);
|
||||
void UserRemoved(dynamic context);
|
||||
}
|
||||
}
|
@@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.AuditTrail.Services;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Roles.Events;
|
||||
using Orchard.Security;
|
||||
|
||||
namespace Orchard.AuditTrail.Providers.Roles {
|
||||
@@ -14,38 +15,38 @@ namespace Orchard.AuditTrail.Providers.Roles {
|
||||
_wca = wca;
|
||||
}
|
||||
|
||||
public void Created(dynamic context) {
|
||||
public void Created(RoleCreatedContext context) {
|
||||
RecordAuditTrailEvent(RoleAuditTrailEventProvider.Created, context.Role.Name);
|
||||
}
|
||||
|
||||
public void Removed(dynamic context) {
|
||||
public void Removed(RoleRemovedContext context) {
|
||||
RecordAuditTrailEvent(RoleAuditTrailEventProvider.Removed, context.Role.Name);
|
||||
}
|
||||
|
||||
public void Renamed(dynamic context) {
|
||||
public void Renamed(RoleRenamedContext context) {
|
||||
var eventData = new Dictionary<string, object> {
|
||||
{"RoleName", (string)context.Role.Name},
|
||||
{"PreviousRoleName", (string)context.PreviousRoleName},
|
||||
{"NewRoleName", (string)context.NewRoleName},
|
||||
{"RoleName", context.Role.Name},
|
||||
{"PreviousRoleName", context.PreviousRoleName},
|
||||
{"NewRoleName", context.NewRoleName},
|
||||
};
|
||||
|
||||
RecordAuditTrailEvent(RoleAuditTrailEventProvider.Renamed, context.Role.Name, properties: null, eventData:eventData);
|
||||
}
|
||||
|
||||
public void PermissionAdded(dynamic context) {
|
||||
RecordAuditTrailEvent(RoleAuditTrailEventProvider.PermissionAdded, (string) context.Role.Name, (IUser) context.Permission.Name);
|
||||
public void PermissionAdded(PermissionAddedContext context) {
|
||||
RecordAuditTrailEvent(RoleAuditTrailEventProvider.PermissionAdded, context.Role.Name);
|
||||
}
|
||||
|
||||
public void PermissionRemoved(dynamic context) {
|
||||
RecordAuditTrailEvent(RoleAuditTrailEventProvider.PermissionRemoved, (string) context.Role.Name, (IUser) context.Permission.Name);
|
||||
public void PermissionRemoved(PermissionRemovedContext context) {
|
||||
RecordAuditTrailEvent(RoleAuditTrailEventProvider.PermissionRemoved, context.Role.Name);
|
||||
}
|
||||
|
||||
public void UserAdded(dynamic context) {
|
||||
RecordAuditTrailEvent(RoleAuditTrailEventProvider.UserAdded, (string) context.Role.Name, (IUser) context.User);
|
||||
public void UserAdded(UserAddedContext context) {
|
||||
RecordAuditTrailEvent(RoleAuditTrailEventProvider.UserAdded, context.Role.Name, context.User);
|
||||
}
|
||||
|
||||
public void UserRemoved(dynamic context) {
|
||||
RecordAuditTrailEvent(RoleAuditTrailEventProvider.UserRemoved, (string) context.Role.Name, (IUser) context.User);
|
||||
public void UserRemoved(UserRemovedContext context) {
|
||||
RecordAuditTrailEvent(RoleAuditTrailEventProvider.UserRemoved, context.Role.Name, context.User);
|
||||
}
|
||||
|
||||
private void RecordAuditTrailEvent(string eventName, string roleName) {
|
||||
|
@@ -1,27 +0,0 @@
|
||||
using Orchard.Events;
|
||||
using Orchard.Security;
|
||||
|
||||
namespace Orchard.AuditTrail.Providers.Users {
|
||||
public interface IUserEventHandler : IEventHandler {
|
||||
|
||||
/// <summary>
|
||||
/// Called after a user has logged in.
|
||||
/// </summary>
|
||||
void LoggedIn(IUser user);
|
||||
|
||||
/// <summary>
|
||||
/// Called when a user explicitly logs out (as opposed to one whose session cookie simply expires).
|
||||
/// </summary>
|
||||
void LoggedOut(IUser user);
|
||||
|
||||
/// <summary>
|
||||
/// Called when a login attempt failed.
|
||||
/// </summary>
|
||||
void LogInFailed(string userNameOrEmail, string password);
|
||||
|
||||
/// <summary>
|
||||
/// Called after a user has changed password.
|
||||
/// </summary>
|
||||
void ChangedPassword(IUser user);
|
||||
}
|
||||
}
|
@@ -2,6 +2,7 @@
|
||||
using Orchard.AuditTrail.Services;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Security;
|
||||
using Orchard.Users.Events;
|
||||
|
||||
namespace Orchard.AuditTrail.Providers.Users {
|
||||
[OrchardFeature("Orchard.AuditTrail.Users")]
|
||||
@@ -47,5 +48,26 @@ namespace Orchard.AuditTrail.Providers.Users {
|
||||
|
||||
_auditTrailManager.CreateRecord<UserAuditTrailEventProvider>(eventName, _wca.GetContext().CurrentUser, properties, eventData, eventFilterKey: "user", eventFilterData: user.UserName);
|
||||
}
|
||||
|
||||
public void Creating(UserContext context) {
|
||||
}
|
||||
|
||||
public void Created(UserContext context) {
|
||||
}
|
||||
|
||||
public void LoggingIn(string userNameOrEmail, string password) {
|
||||
}
|
||||
|
||||
public void AccessDenied(IUser user) {
|
||||
}
|
||||
|
||||
public void SentChallengeEmail(IUser user) {
|
||||
}
|
||||
|
||||
public void ConfirmedEmail(IUser user) {
|
||||
}
|
||||
|
||||
public void Approved(IUser user) {
|
||||
}
|
||||
}
|
||||
}
|
@@ -179,7 +179,7 @@ namespace Orchard.AuditTrail.Services {
|
||||
}
|
||||
|
||||
public AuditTrailEventDescriptor DescribeEvent<T>(string eventName) where T:IAuditTrailEventProvider {
|
||||
var fullyQualifiedEventName = EventNameHelper.GetFullyQualifiedEventName<T>(eventName);
|
||||
var fullyQualifiedEventName = EventNameExtensions.GetFullyQualifiedEventName<T>(eventName);
|
||||
return DescribeEvent(fullyQualifiedEventName);
|
||||
}
|
||||
|
||||
|
@@ -32,7 +32,7 @@ namespace Orchard.AuditTrail.Services.Models {
|
||||
Name = Name,
|
||||
Events = Events
|
||||
},
|
||||
Event = EventNameHelper.GetFullyQualifiedEventName(provider.GetType(), eventName),
|
||||
Event = EventNameExtensions.GetFullyQualifiedEventName(provider.GetType(), eventName),
|
||||
Name = name,
|
||||
Description = description,
|
||||
IsEnabledByDefault = enableByDefault,
|
||||
|
@@ -5,6 +5,6 @@ namespace Orchard.AuditTrail.ViewModels {
|
||||
public class AuditTrailCategorySettingsViewModel {
|
||||
public string Category { get; set; }
|
||||
public LocalizedString Name { get; set; }
|
||||
public IList<AuditTrailEventSettingsViewModel> Events { get; set; }
|
||||
public IEnumerable<AuditTrailEventSettingsViewModel> Events { get; set; }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user