mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Some more minor renames and reformatting.
This commit is contained in:
@@ -4,7 +4,7 @@ using Orchard.Security.Permissions;
|
|||||||
|
|
||||||
namespace Orchard.AuditTrail {
|
namespace Orchard.AuditTrail {
|
||||||
public class Permissions : IPermissionProvider {
|
public class Permissions : IPermissionProvider {
|
||||||
public static readonly Permission ViewAuditTrail = new Permission { Description = "View Audit Trail", Name = "ViewAuditTrail" };
|
public static readonly Permission ViewAuditTrail = new Permission { Description = "View audit trail", Name = "ViewAuditTrail" };
|
||||||
public static readonly Permission ManageAuditTrailSettings = new Permission { Description = "Manage audit trail settings", Name = "ManageAuditTrailSettings" };
|
public static readonly Permission ManageAuditTrailSettings = new Permission { Description = "Manage audit trail settings", Name = "ManageAuditTrailSettings" };
|
||||||
|
|
||||||
public virtual Feature Feature { get; set; }
|
public virtual Feature Feature { get; set; }
|
||||||
|
@@ -25,12 +25,12 @@ namespace Orchard.AuditTrail.Services {
|
|||||||
metaData.Alternates.Add(String.Format("AuditTrailEvent_{0}", displayType));
|
metaData.Alternates.Add(String.Format("AuditTrailEvent_{0}", displayType));
|
||||||
metaData.Alternates.Add(String.Format("AuditTrailEvent__{0}", record.Category));
|
metaData.Alternates.Add(String.Format("AuditTrailEvent__{0}", record.Category));
|
||||||
metaData.Alternates.Add(String.Format("AuditTrailEvent_{0}__{1}", displayType, record.Category));
|
metaData.Alternates.Add(String.Format("AuditTrailEvent_{0}__{1}", displayType, record.Category));
|
||||||
metaData.Alternates.Add(String.Format("AuditTrailEvent__{0}__{1}", record.Category, GetShortName(record.Event)));
|
metaData.Alternates.Add(String.Format("AuditTrailEvent__{0}__{1}", record.Category, GetShortEventName(record.Event)));
|
||||||
metaData.Alternates.Add(String.Format("AuditTrailEvent_{0}__{1}__{2}", displayType, record.Category, GetShortName(record.Event)));
|
metaData.Alternates.Add(String.Format("AuditTrailEvent_{0}__{1}__{2}", displayType, record.Category, GetShortEventName(record.Event)));
|
||||||
return auditTrailEventShape;
|
return auditTrailEventShape;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetShortName(string fullyQualifiedEventName) {
|
private string GetShortEventName(string fullyQualifiedEventName) {
|
||||||
var index = fullyQualifiedEventName.LastIndexOf('.') + 1;
|
var index = fullyQualifiedEventName.LastIndexOf('.') + 1;
|
||||||
return fullyQualifiedEventName.Substring(index);
|
return fullyQualifiedEventName.Substring(index);
|
||||||
}
|
}
|
||||||
|
@@ -27,13 +27,13 @@ namespace Orchard.AuditTrail.Services {
|
|||||||
|
|
||||||
public AuditTrailManager(
|
public AuditTrailManager(
|
||||||
IRepository<AuditTrailEventRecord> auditTrailRepository,
|
IRepository<AuditTrailEventRecord> auditTrailRepository,
|
||||||
IAuditTrailEventProvider providers,
|
IAuditTrailEventProvider providers,
|
||||||
IClock clock,
|
IClock clock,
|
||||||
IAuditTrailEventHandler auditTrailEventHandlers,
|
IAuditTrailEventHandler auditTrailEventHandlers,
|
||||||
IEventDataSerializer serializer,
|
IEventDataSerializer serializer,
|
||||||
ICacheManager cacheManager,
|
ICacheManager cacheManager,
|
||||||
ISiteService siteService,
|
ISiteService siteService,
|
||||||
ISignals signals,
|
ISignals signals,
|
||||||
IShapeFactory shapeFactory) {
|
IShapeFactory shapeFactory) {
|
||||||
|
|
||||||
_auditTrailRepository = auditTrailRepository;
|
_auditTrailRepository = auditTrailRepository;
|
||||||
@@ -48,13 +48,13 @@ namespace Orchard.AuditTrail.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public IPageOfItems<AuditTrailEventRecord> GetRecords(
|
public IPageOfItems<AuditTrailEventRecord> GetRecords(
|
||||||
int page,
|
int page,
|
||||||
int pageSize,
|
int pageSize,
|
||||||
Filters filters = null,
|
Filters filters = null,
|
||||||
AuditTrailOrderBy orderBy = AuditTrailOrderBy.DateDescending) {
|
AuditTrailOrderBy orderBy = AuditTrailOrderBy.DateDescending) {
|
||||||
|
|
||||||
var query = _auditTrailRepository.Table;
|
var query = _auditTrailRepository.Table;
|
||||||
|
|
||||||
|
|
||||||
if (filters != null) {
|
if (filters != null) {
|
||||||
var filterContext = new QueryFilterContext(query, filters);
|
var filterContext = new QueryFilterContext(query, filters);
|
||||||
@@ -115,9 +115,9 @@ namespace Orchard.AuditTrail.Services {
|
|||||||
return filterDisplay;
|
return filterDisplay;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AuditTrailEventRecordResult CreateRecord<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 CreateRecord<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 = DescribeEvent<T>(eventName);
|
var eventDescriptor = DescribeEvent<T>(eventName);
|
||||||
if(!IsEventEnabled(eventDescriptor))
|
if (!IsEventEnabled(eventDescriptor))
|
||||||
return new AuditTrailEventRecordResult {
|
return new AuditTrailEventRecordResult {
|
||||||
Record = null,
|
Record = null,
|
||||||
IsDisabled = true
|
IsDisabled = true
|
||||||
@@ -156,7 +156,7 @@ namespace Orchard.AuditTrail.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private bool IsEventEnabled(AuditTrailEventDescriptor eventDescriptor) {
|
private bool IsEventEnabled(AuditTrailEventDescriptor eventDescriptor) {
|
||||||
if(eventDescriptor.IsMandatory)
|
if (eventDescriptor.IsMandatory)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
var settingsDictionary = _cacheManager.Get("AuditTrail.EventSettings", context => {
|
var settingsDictionary = _cacheManager.Get("AuditTrail.EventSettings", context => {
|
||||||
@@ -178,17 +178,18 @@ namespace Orchard.AuditTrail.Services {
|
|||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AuditTrailEventDescriptor DescribeEvent<T>(string eventName) where T:IAuditTrailEventProvider {
|
public AuditTrailEventDescriptor DescribeEvent<T>(string eventName) where T : IAuditTrailEventProvider {
|
||||||
var fullyQualifiedEventName = EventNameExtensions.GetFullyQualifiedEventName<T>(eventName);
|
var fullyQualifiedEventName = EventNameExtensions.GetFullyQualifiedEventName<T>(eventName);
|
||||||
return DescribeEvent(fullyQualifiedEventName);
|
return DescribeEvent(fullyQualifiedEventName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AuditTrailEventDescriptor DescribeEvent(string fullyQualifiedEventName) {
|
public AuditTrailEventDescriptor DescribeEvent(string fullyQualifiedEventName) {
|
||||||
var categoryDescriptors = DescribeCategories();
|
var categoryDescriptors = DescribeCategories();
|
||||||
var eventDescriptorQuery = from c in categoryDescriptors
|
var eventDescriptorQuery =
|
||||||
from e in c.Events
|
from c in categoryDescriptors
|
||||||
where e.Event == fullyQualifiedEventName
|
from e in c.Events
|
||||||
select e;
|
where e.Event == fullyQualifiedEventName
|
||||||
|
select e;
|
||||||
var eventDescriptors = eventDescriptorQuery.ToArray();
|
var eventDescriptors = eventDescriptorQuery.ToArray();
|
||||||
|
|
||||||
if (!eventDescriptors.Any()) {
|
if (!eventDescriptors.Any()) {
|
||||||
|
@@ -29,16 +29,15 @@ namespace Orchard.AuditTrail.Services {
|
|||||||
|
|
||||||
public void Sweep() {
|
public void Sweep() {
|
||||||
if (Monitor.TryEnter(_sweepLock)) {
|
if (Monitor.TryEnter(_sweepLock)) {
|
||||||
|
Logger.Debug("Beginning sweep.");
|
||||||
try {
|
try {
|
||||||
Logger.Debug("Beginning sweep.");
|
|
||||||
|
|
||||||
// We don't need to check the audit trail for events to remove every minute. Let's stick with twice a day.
|
// We don't need to check the audit trail for events to remove every minute. Let's stick with twice a day.
|
||||||
if (!TimeToTrim())
|
if (!GetIsTimeToTrim())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Logger.Debug("Starting audit trail trimming operation.");
|
Logger.Debug("Starting audit trail trimming.");
|
||||||
var deletedRecords = _auditTrailManager.Trim(TimeSpan.FromDays(Settings.RetentionPeriod));
|
var deletedRecords = _auditTrailManager.Trim(TimeSpan.FromDays(Settings.RetentionPeriod));
|
||||||
Logger.Debug("Audit trail trimming operation completed. {0} records were deleted.", deletedRecords.Count());
|
Logger.Debug("Audit trail trimming completed. {0} records were deleted.", deletedRecords.Count());
|
||||||
Settings.LastRunUtc = _clock.UtcNow;
|
Settings.LastRunUtc = _clock.UtcNow;
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
@@ -51,7 +50,7 @@ namespace Orchard.AuditTrail.Services {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool TimeToTrim() {
|
private bool GetIsTimeToTrim() {
|
||||||
var lastRun = Settings.LastRunUtc ?? DateTime.MinValue;
|
var lastRun = Settings.LastRunUtc ?? DateTime.MinValue;
|
||||||
var now = _clock.UtcNow;
|
var now = _clock.UtcNow;
|
||||||
var interval = TimeSpan.FromHours(12);
|
var interval = TimeSpan.FromHours(12);
|
||||||
|
@@ -16,7 +16,6 @@ namespace Orchard.AuditTrail.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override void Filter(QueryFilterContext context) {
|
public override void Filter(QueryFilterContext context) {
|
||||||
// Common filters (username, from and to, category).
|
|
||||||
var userName = context.Filters.Get("username");
|
var userName = context.Filters.Get("username");
|
||||||
var fromDate = context.Filters.Get("from.Date");
|
var fromDate = context.Filters.Get("from.Date");
|
||||||
var fromTime = context.Filters.Get("from.Time");
|
var fromTime = context.Filters.Get("from.Time");
|
||||||
@@ -27,16 +26,23 @@ namespace Orchard.AuditTrail.Services {
|
|||||||
var to = _dateServices.ConvertFromLocalString(toDate, toTime).Latest();
|
var to = _dateServices.ConvertFromLocalString(toDate, toTime).Latest();
|
||||||
var query = context.Query;
|
var query = context.Query;
|
||||||
|
|
||||||
if (!String.IsNullOrWhiteSpace(userName)) query = query.Where(x => x.UserName == userName);
|
if (!String.IsNullOrWhiteSpace(userName)) {
|
||||||
if (!String.IsNullOrWhiteSpace(category)) query = query.Where(x => x.Category == category);
|
query = query.Where(x => x.UserName == userName);
|
||||||
if (from != null) query = query.Where(x => x.CreatedUtc >= from);
|
}
|
||||||
if (to != null) query = query.Where(x => x.CreatedUtc <= to);
|
if (!String.IsNullOrWhiteSpace(category)) {
|
||||||
|
query = query.Where(x => x.Category == category);
|
||||||
|
}
|
||||||
|
if (from != null) {
|
||||||
|
query = query.Where(x => x.CreatedUtc >= from);
|
||||||
|
}
|
||||||
|
if (to != null) {
|
||||||
|
query = query.Where(x => x.CreatedUtc <= to);
|
||||||
|
}
|
||||||
|
|
||||||
context.Query = query;
|
context.Query = query;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void DisplayFilter(DisplayFilterContext context) {
|
public override void DisplayFilter(DisplayFilterContext context) {
|
||||||
// Common filters (username, from and to, category).
|
|
||||||
var userName = context.Filters.Get("username");
|
var userName = context.Filters.Get("username");
|
||||||
var fromDate = context.Filters.Get("from.Date");
|
var fromDate = context.Filters.Get("from.Date");
|
||||||
var toDate = context.Filters.Get("to.Date");
|
var toDate = context.Filters.Get("to.Date");
|
||||||
|
@@ -8,7 +8,7 @@ using Orchard.Security;
|
|||||||
namespace Orchard.AuditTrail.Services {
|
namespace Orchard.AuditTrail.Services {
|
||||||
public interface IAuditTrailManager : IDependency {
|
public interface IAuditTrailManager : IDependency {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a page of event records.
|
/// Gets a page of event records from the audit trail.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="page">The page number to get records from.</param>
|
/// <param name="page">The page number to get records from.</param>
|
||||||
/// <param name="pageSize">The number of records to get.</param>
|
/// <param name="pageSize">The number of records to get.</param>
|
||||||
@@ -18,10 +18,10 @@ namespace Orchard.AuditTrail.Services {
|
|||||||
IPageOfItems<AuditTrailEventRecord> GetRecords(int page, int pageSize, Filters filters = null, AuditTrailOrderBy orderBy = AuditTrailOrderBy.DateDescending);
|
IPageOfItems<AuditTrailEventRecord> GetRecords(int page, int pageSize, Filters filters = null, AuditTrailOrderBy orderBy = AuditTrailOrderBy.DateDescending);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a single event record by ID.
|
/// Gets a single event record from the audit trail by ID.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id">The event record ID.</param>
|
/// <param name="id">The event record ID.</param>
|
||||||
/// <returns>A single event record by ID.</returns>
|
/// <returns>A single event record.</returns>
|
||||||
AuditTrailEventRecord GetRecord(int id);
|
AuditTrailEventRecord GetRecord(int id);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@@ -7,10 +7,6 @@ namespace Orchard.AuditTrail.Services.Models {
|
|||||||
public LocalizedString Name { get; set; }
|
public LocalizedString Name { get; set; }
|
||||||
public LocalizedString Description { get; set; }
|
public LocalizedString Description { get; set; }
|
||||||
public bool IsEnabledByDefault { get; set; }
|
public bool IsEnabledByDefault { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Wether the event can be disabled or not.
|
|
||||||
/// </summary>
|
|
||||||
public bool IsMandatory { get; set; }
|
public bool IsMandatory { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -38,6 +38,7 @@ namespace Orchard.AuditTrail.Services.Models {
|
|||||||
IsEnabledByDefault = enableByDefault,
|
IsEnabledByDefault = enableByDefault,
|
||||||
IsMandatory = isMandatory
|
IsMandatory = isMandatory
|
||||||
});
|
});
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user