Mapping the DateStamp and UserName to AuditLog

Refactored how the the Username is displayed due to some misunderstanding on my part.
This commit is contained in:
Robert
2017-09-19 11:01:07 +02:00
parent 2ccf74a921
commit a74c4433f7
3 changed files with 18 additions and 8 deletions

View File

@@ -95,8 +95,16 @@ namespace Umbraco.Core.Persistence.Repositories
var pagedResult = Database.Page<LogDto>(pageIndex + 1, pageSize, translatedQuery);
totalRecords = pagedResult.TotalItems;
return pagedResult.Items.Select(
var pages = pagedResult.Items.Select(
dto => new AuditItem(dto.Id, dto.Comment, Enum<AuditType>.Parse(dto.Header), dto.UserId)).ToArray();
//Mapping the DateStamp
for (int i = 0; i < pages.Length; i++)
{
pages[i].CreateDate = pagedResult.Items[i].Datestamp;
}
return pages;
}
protected override void PersistUpdatedItem(IAuditItem entity)

View File

@@ -2452,9 +2452,7 @@ namespace Umbraco.Core.Services
_publishingStrategy.PublishingFinalized(uow, descendants, false);
}
var user = ApplicationContext.Current.Services.UserService.GetProfileById(userId);
Audit(uow, AuditType.Publish, "Save and Publish performed by user " + user.Name, userId, content.Id);
Audit(uow, AuditType.Publish, "Save and Publish performed by user", userId, content.Id);
uow.Commit();
return Attempt.If(publishStatus.StatusType == PublishStatusType.Success, publishStatus);
}

View File

@@ -34,10 +34,12 @@ namespace Umbraco.Web.Editors
var result = Services.AuditService.GetPagedItemsByEntity(id, pageNumber - 1, pageSize, out totalRecords, orderDirection, customFilter: dateQuery);
var mapped = Mapper.Map<IEnumerable<AuditLog>>(result);
return new PagedResult<AuditLog>(totalRecords, pageNumber, pageSize)
var page = new PagedResult<AuditLog>(totalRecords, pageNumber, pageSize)
{
Items = MapAvatars(mapped)
Items = MapAvatarsAndNames(mapped)
};
return page;
}
public PagedResult<AuditLog> GetPagedCurrentUserLog(
@@ -52,7 +54,7 @@ namespace Umbraco.Web.Editors
var mapped = Mapper.Map<IEnumerable<AuditLog>>(result);
return new PagedResult<AuditLog>(totalRecords, pageNumber + 1, pageSize)
{
Items = MapAvatars(mapped)
Items = MapAvatarsAndNames(mapped)
};
}
@@ -84,14 +86,16 @@ namespace Umbraco.Web.Editors
Log.Instance.GetLogItems(Enum<LogTypes>.Parse(logType.ToString()), sinceDate.Value));
}
private IEnumerable<AuditLog> MapAvatars(IEnumerable<AuditLog> items)
private IEnumerable<AuditLog> MapAvatarsAndNames(IEnumerable<AuditLog> items)
{
var userIds = items.Select(x => x.UserId).ToArray();
var users = Services.UserService.GetUsersById(userIds)
.ToDictionary(x => x.Id, x => x.GetUserAvatarUrls(ApplicationContext.ApplicationCache.RuntimeCache));
var userNames = Services.UserService.GetUsersById(userIds).ToDictionary(x => x.Id, x => x.Name);
foreach (var item in items)
{
item.UserAvatars = users[item.UserId];
item.UserName = userNames[item.UserId];
}
return items;
}