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 {
|
||||
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 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}", 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}__{2}", displayType, 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, GetShortEventName(record.Event)));
|
||||
return auditTrailEventShape;
|
||||
}
|
||||
|
||||
private string GetShortName(string fullyQualifiedEventName) {
|
||||
private string GetShortEventName(string fullyQualifiedEventName) {
|
||||
var index = fullyQualifiedEventName.LastIndexOf('.') + 1;
|
||||
return fullyQualifiedEventName.Substring(index);
|
||||
}
|
||||
|
@@ -27,13 +27,13 @@ namespace Orchard.AuditTrail.Services {
|
||||
|
||||
public AuditTrailManager(
|
||||
IRepository<AuditTrailEventRecord> auditTrailRepository,
|
||||
IAuditTrailEventProvider providers,
|
||||
IAuditTrailEventProvider providers,
|
||||
IClock clock,
|
||||
IAuditTrailEventHandler auditTrailEventHandlers,
|
||||
IEventDataSerializer serializer,
|
||||
ICacheManager cacheManager,
|
||||
ISiteService siteService,
|
||||
ISignals signals,
|
||||
IAuditTrailEventHandler auditTrailEventHandlers,
|
||||
IEventDataSerializer serializer,
|
||||
ICacheManager cacheManager,
|
||||
ISiteService siteService,
|
||||
ISignals signals,
|
||||
IShapeFactory shapeFactory) {
|
||||
|
||||
_auditTrailRepository = auditTrailRepository;
|
||||
@@ -48,13 +48,13 @@ namespace Orchard.AuditTrail.Services {
|
||||
}
|
||||
|
||||
public IPageOfItems<AuditTrailEventRecord> GetRecords(
|
||||
int page,
|
||||
int pageSize,
|
||||
Filters filters = null,
|
||||
int page,
|
||||
int pageSize,
|
||||
Filters filters = null,
|
||||
AuditTrailOrderBy orderBy = AuditTrailOrderBy.DateDescending) {
|
||||
|
||||
|
||||
var query = _auditTrailRepository.Table;
|
||||
|
||||
|
||||
|
||||
if (filters != null) {
|
||||
var filterContext = new QueryFilterContext(query, filters);
|
||||
@@ -115,9 +115,9 @@ namespace Orchard.AuditTrail.Services {
|
||||
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);
|
||||
if(!IsEventEnabled(eventDescriptor))
|
||||
if (!IsEventEnabled(eventDescriptor))
|
||||
return new AuditTrailEventRecordResult {
|
||||
Record = null,
|
||||
IsDisabled = true
|
||||
@@ -156,7 +156,7 @@ namespace Orchard.AuditTrail.Services {
|
||||
}
|
||||
|
||||
private bool IsEventEnabled(AuditTrailEventDescriptor eventDescriptor) {
|
||||
if(eventDescriptor.IsMandatory)
|
||||
if (eventDescriptor.IsMandatory)
|
||||
return true;
|
||||
|
||||
var settingsDictionary = _cacheManager.Get("AuditTrail.EventSettings", context => {
|
||||
@@ -178,17 +178,18 @@ namespace Orchard.AuditTrail.Services {
|
||||
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);
|
||||
return DescribeEvent(fullyQualifiedEventName);
|
||||
}
|
||||
|
||||
public AuditTrailEventDescriptor DescribeEvent(string fullyQualifiedEventName) {
|
||||
var categoryDescriptors = DescribeCategories();
|
||||
var eventDescriptorQuery = from c in categoryDescriptors
|
||||
from e in c.Events
|
||||
where e.Event == fullyQualifiedEventName
|
||||
select e;
|
||||
var eventDescriptorQuery =
|
||||
from c in categoryDescriptors
|
||||
from e in c.Events
|
||||
where e.Event == fullyQualifiedEventName
|
||||
select e;
|
||||
var eventDescriptors = eventDescriptorQuery.ToArray();
|
||||
|
||||
if (!eventDescriptors.Any()) {
|
||||
|
@@ -29,16 +29,15 @@ namespace Orchard.AuditTrail.Services {
|
||||
|
||||
public void Sweep() {
|
||||
if (Monitor.TryEnter(_sweepLock)) {
|
||||
Logger.Debug("Beginning sweep.");
|
||||
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.
|
||||
if (!TimeToTrim())
|
||||
if (!GetIsTimeToTrim())
|
||||
return;
|
||||
|
||||
Logger.Debug("Starting audit trail trimming operation.");
|
||||
Logger.Debug("Starting audit trail trimming.");
|
||||
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;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
@@ -51,7 +50,7 @@ namespace Orchard.AuditTrail.Services {
|
||||
}
|
||||
}
|
||||
|
||||
private bool TimeToTrim() {
|
||||
private bool GetIsTimeToTrim() {
|
||||
var lastRun = Settings.LastRunUtc ?? DateTime.MinValue;
|
||||
var now = _clock.UtcNow;
|
||||
var interval = TimeSpan.FromHours(12);
|
||||
|
@@ -16,7 +16,6 @@ namespace Orchard.AuditTrail.Services {
|
||||
}
|
||||
|
||||
public override void Filter(QueryFilterContext context) {
|
||||
// Common filters (username, from and to, category).
|
||||
var userName = context.Filters.Get("username");
|
||||
var fromDate = context.Filters.Get("from.Date");
|
||||
var fromTime = context.Filters.Get("from.Time");
|
||||
@@ -27,16 +26,23 @@ namespace Orchard.AuditTrail.Services {
|
||||
var to = _dateServices.ConvertFromLocalString(toDate, toTime).Latest();
|
||||
var query = context.Query;
|
||||
|
||||
if (!String.IsNullOrWhiteSpace(userName)) query = query.Where(x => x.UserName == userName);
|
||||
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);
|
||||
if (!String.IsNullOrWhiteSpace(userName)) {
|
||||
query = query.Where(x => x.UserName == userName);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
public override void DisplayFilter(DisplayFilterContext context) {
|
||||
// Common filters (username, from and to, category).
|
||||
var userName = context.Filters.Get("username");
|
||||
var fromDate = context.Filters.Get("from.Date");
|
||||
var toDate = context.Filters.Get("to.Date");
|
||||
|
@@ -8,7 +8,7 @@ using Orchard.Security;
|
||||
namespace Orchard.AuditTrail.Services {
|
||||
public interface IAuditTrailManager : IDependency {
|
||||
/// <summary>
|
||||
/// Returns a page of event records.
|
||||
/// Gets a page of event records from the audit trail.
|
||||
/// </summary>
|
||||
/// <param name="page">The page number to get records from.</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);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a single event record by ID.
|
||||
/// Gets a single event record from the audit trail by ID.
|
||||
/// </summary>
|
||||
/// <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);
|
||||
|
||||
/// <summary>
|
||||
|
@@ -7,10 +7,6 @@ namespace Orchard.AuditTrail.Services.Models {
|
||||
public LocalizedString Name { get; set; }
|
||||
public LocalizedString Description { get; set; }
|
||||
public bool IsEnabledByDefault { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Wether the event can be disabled or not.
|
||||
/// </summary>
|
||||
public bool IsMandatory { get; set; }
|
||||
}
|
||||
}
|
@@ -38,6 +38,7 @@ namespace Orchard.AuditTrail.Services.Models {
|
||||
IsEnabledByDefault = enableByDefault,
|
||||
IsMandatory = isMandatory
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user