Skip to content

Commit

Permalink
#2355 Add "Deleted system log" activity log record
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanovM committed Aug 23, 2017
1 parent dff5851 commit 65527a5
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 32 deletions.
Expand Up @@ -11497,6 +11497,12 @@ protected virtual void InstallActivityLogTypes()
Name = "Delete a store"
},
new ActivityLogType
{
SystemKeyword = "DeleteSystemLog",
Enabled = true,
Name = "Delete system log"
},
new ActivityLogType
{
SystemKeyword = "DeleteTopic",
Enabled = true,
Expand Down
Expand Up @@ -867,6 +867,9 @@
<LocaleResource Name="ActivityLog.DeleteStore">
<Value>Deleted a store (ID = {0})</Value>
</LocaleResource>
<LocaleResource Name="ActivityLog.DeleteSystemLog">
<Value>Deleted system log</Value>
</LocaleResource>
<LocaleResource Name="ActivityLog.DeleteTopic">
<Value>Deleted a topic ('{0}')</Value>
</LocaleResource>
Expand Down
72 changes: 40 additions & 32 deletions src/Presentation/Nop.Web/Areas/Admin/Controllers/LogController.cs
Expand Up @@ -20,25 +20,30 @@ public partial class LogController : BaseAdminController
{
#region Fields

private readonly ILogger _logger;
private readonly IWorkContext _workContext;
private readonly ILocalizationService _localizationService;
private readonly ICustomerActivityService _customerActivityService;
private readonly IDateTimeHelper _dateTimeHelper;
private readonly ILocalizationService _localizationService;
private readonly ILogger _logger;
private readonly IPermissionService _permissionService;
private readonly IWorkContext _workContext;

#endregion

#region Ctor

public LogController(ILogger logger, IWorkContext workContext,
ILocalizationService localizationService, IDateTimeHelper dateTimeHelper,
IPermissionService permissionService)
public LogController(ICustomerActivityService customerActivityService,
IDateTimeHelper dateTimeHelper,
ILocalizationService localizationService,
ILogger logger,
IPermissionService permissionService,
IWorkContext workContext)
{
this._logger = logger;
this._workContext = workContext;
this._localizationService = localizationService;
this._customerActivityService = customerActivityService;
this._dateTimeHelper = dateTimeHelper;
this._localizationService = localizationService;
this._logger = logger;
this._permissionService = permissionService;
this._workContext = workContext;
}

#endregion
Expand Down Expand Up @@ -68,32 +73,29 @@ public virtual IActionResult LogList(DataSourceRequest command, LogListModel mod
if (!_permissionService.Authorize(StandardPermissionProvider.ManageSystemLog))
return AccessDeniedKendoGridJson();

DateTime? createdOnFromValue = (model.CreatedOnFrom == null) ? null
: (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.CreatedOnFrom.Value, _dateTimeHelper.CurrentTimeZone);
var createdOnFromValue = model.CreatedOnFrom != null
? (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.CreatedOnFrom.Value, _dateTimeHelper.CurrentTimeZone) : null;

DateTime? createdToFromValue = (model.CreatedOnTo == null) ? null
: (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.CreatedOnTo.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);
var createdToFromValue = model.CreatedOnTo != null
? (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.CreatedOnTo.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1) : null;

LogLevel? logLevel = model.LogLevelId > 0 ? (LogLevel?)(model.LogLevelId) : null;
var logLevel = model.LogLevelId > 0 ? (LogLevel?)(model.LogLevelId) : null;


var logItems = _logger.GetAllLogs(createdOnFromValue, createdToFromValue, model.Message,
logLevel, command.Page - 1, command.PageSize);
var logItems = _logger.GetAllLogs(createdOnFromValue, createdToFromValue, model.Message, logLevel, command.Page - 1, command.PageSize);
var gridModel = new DataSourceResult
{
Data = logItems.Select(x => new LogModel
Data = logItems.Select(logItem => new LogModel
{
Id = x.Id,
LogLevel = x.LogLevel.GetLocalizedEnum(_localizationService, _workContext),
ShortMessage = x.ShortMessage,
//little performance optimization: ensure that "FullMessage" is not returned
FullMessage = "",
IpAddress = x.IpAddress,
CustomerId = x.CustomerId,
CustomerEmail = x.Customer != null ? x.Customer.Email : null,
PageUrl = x.PageUrl,
ReferrerUrl = x.ReferrerUrl,
CreatedOn = _dateTimeHelper.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc)
Id = logItem.Id,
LogLevel = logItem.LogLevel.GetLocalizedEnum(_localizationService, _workContext),
ShortMessage = logItem.ShortMessage,
FullMessage = string.Empty, //little performance optimization: ensure that "FullMessage" is not returned
IpAddress = logItem.IpAddress,
CustomerId = logItem.CustomerId,
CustomerEmail = logItem.Customer?.Email,
PageUrl = logItem.PageUrl,
ReferrerUrl = logItem.ReferrerUrl,
CreatedOn = _dateTimeHelper.ConvertToUserTime(logItem.CreatedOnUtc, DateTimeKind.Utc)
}),
Total = logItems.TotalCount
};
Expand All @@ -110,6 +112,9 @@ public virtual IActionResult ClearAll()

_logger.ClearLog();

//activity log
_customerActivityService.InsertActivity("DeleteSystemLog", _localizationService.GetResource("ActivityLog.DeleteSystemLog"));

SuccessNotification(_localizationService.GetResource("Admin.System.Log.Cleared"));
return RedirectToAction("List");
}
Expand All @@ -132,7 +137,7 @@ public virtual IActionResult View(int id)
FullMessage = log.FullMessage,
IpAddress = log.IpAddress,
CustomerId = log.CustomerId,
CustomerEmail = log.Customer != null ? log.Customer.Email : null,
CustomerEmail = log.Customer?.Email,
PageUrl = log.PageUrl,
ReferrerUrl = log.ReferrerUrl,
CreatedOn = _dateTimeHelper.ConvertToUserTime(log.CreatedOnUtc, DateTimeKind.Utc)
Expand All @@ -154,6 +159,8 @@ public virtual IActionResult Delete(int id)

_logger.DeleteLog(log);

//activity log
_customerActivityService.InsertActivity("DeleteSystemLog", _localizationService.GetResource("ActivityLog.DeleteSystemLog"));

SuccessNotification(_localizationService.GetResource("Admin.System.Log.Deleted"));
return RedirectToAction("List");
Expand All @@ -166,9 +173,10 @@ public virtual IActionResult DeleteSelected(ICollection<int> selectedIds)
return AccessDeniedView();

if (selectedIds != null)
{
_logger.DeleteLogs(_logger.GetLogByIds(selectedIds.ToArray()).ToList());
}

//activity log
_customerActivityService.InsertActivity("DeleteSystemLog", _localizationService.GetResource("ActivityLog.DeleteSystemLog"));

return Json(new {Result = true});
}
Expand Down
11 changes: 11 additions & 0 deletions upgradescripts/3.90-4.00 (under development)/upgrade.sql
Expand Up @@ -131,6 +131,9 @@ set @resources='
<LocaleResource Name="Admin.Configuration.Settings.GeneralCommon.PopupForTermsOfServiceLinks.Hint">
<Value>Check if you want "accept terms of service" or "accept privacy policy" links to be open in popup window. If disabled, then they''ll be open on a new page.</Value>
</LocaleResource>
<LocaleResource Name="ActivityLog.DeleteSystemLog">
<Value>Deleted system log</Value>
</LocaleResource>
</Language>
'

Expand Down Expand Up @@ -325,4 +328,12 @@ IF NOT EXISTS (SELECT 1 from sys.indexes WHERE [NAME]=N'IX_Customer_CreatedOnUtc
BEGIN
CREATE NONCLUSTERED INDEX [IX_Customer_CreatedOnUtc] ON [Customer] ([CreatedOnUtc] DESC)
END
GO

--new activity types
IF NOT EXISTS (SELECT 1 FROM [ActivityLogType] WHERE [SystemKeyword] = N'DeleteSystemLog')
BEGIN
INSERT [ActivityLogType] ([SystemKeyword], [Name], [Enabled])
VALUES (N'DeleteSystemLog', N'Delete system log', N'true')
END
GO

0 comments on commit 65527a5

Please sign in to comment.