maps avatars in log
This commit is contained in:
@@ -23,33 +23,9 @@ namespace Umbraco.Core.Models
|
||||
EnableChangeTracking();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for creating an item that is returned from the database
|
||||
/// </summary>
|
||||
/// <param name="objectId"></param>
|
||||
/// <param name="comment"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="userName"></param>
|
||||
/// <param name="userAvatar"></param>
|
||||
public AuditItem(int objectId, string comment, AuditType type, int userId, string userName, string userAvatar)
|
||||
{
|
||||
DisableChangeTracking();
|
||||
|
||||
Id = objectId;
|
||||
Comment = comment;
|
||||
AuditType = type;
|
||||
UserId = userId;
|
||||
UserName = userName;
|
||||
UserAvatar = userAvatar;
|
||||
|
||||
EnableChangeTracking();
|
||||
}
|
||||
|
||||
public string Comment { get; private set; }
|
||||
public AuditType AuditType { get; private set; }
|
||||
public int UserId { get; private set; }
|
||||
public string UserName { get; private set; }
|
||||
public string UserAvatar { get; private set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,5 @@ namespace Umbraco.Core.Models
|
||||
string Comment { get; }
|
||||
AuditType AuditType { get; }
|
||||
int UserId { get; }
|
||||
string UserName { get; }
|
||||
string UserAvatar { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
using System;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.DatabaseAnnotations;
|
||||
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
|
||||
|
||||
namespace Umbraco.Core.Models.Rdbms
|
||||
{
|
||||
/// <summary>
|
||||
/// object used for returning data from the umbracoLog table
|
||||
/// </summary>
|
||||
[TableName("umbracoLog")]
|
||||
[PrimaryKey("id")]
|
||||
[ExplicitColumns]
|
||||
internal class ReadOnlyLogDto
|
||||
{
|
||||
[Column("id")]
|
||||
[PrimaryKeyColumn]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Column("userId")]
|
||||
public int UserId { get; set; }
|
||||
|
||||
[Column("NodeId")]
|
||||
public int NodeId { get; set; }
|
||||
|
||||
[Column("Datestamp")]
|
||||
public DateTime Datestamp { get; set; }
|
||||
|
||||
[Column("logHeader")]
|
||||
public string Header { get; set; }
|
||||
|
||||
[Column("logComment")]
|
||||
public string Comment { get; set; }
|
||||
|
||||
[ResultColumn("userName")]
|
||||
public string UserName { get; set; }
|
||||
|
||||
[ResultColumn("userAvatar")]
|
||||
public string UserAvatar { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -24,12 +24,11 @@ namespace Umbraco.Core.Models
|
||||
/// Tries to lookup the user's gravatar to see if the endpoint can be reached, if so it returns the valid URL
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="userService"></param>
|
||||
/// <param name="staticCache"></param>
|
||||
/// <returns>
|
||||
/// A list of 5 different sized avatar URLs
|
||||
/// </returns>
|
||||
internal static string[] GetCurrentUserAvatarUrls(this IUser user, IUserService userService, ICacheProvider staticCache)
|
||||
internal static string[] GetUserAvatarUrls(this IUser user, ICacheProvider staticCache)
|
||||
{
|
||||
//check if the user has explicitly removed all avatars including a gravatar, this will be possible and the value will be "none"
|
||||
if (user.Avatar == "none")
|
||||
|
||||
@@ -92,11 +92,11 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
translatedQuery.OrderBy("Datestamp");
|
||||
|
||||
// Get page of results and total count
|
||||
var pagedResult = Database.Page<ReadOnlyLogDto>(pageIndex + 1, pageSize, translatedQuery);
|
||||
var pagedResult = Database.Page<LogDto>(pageIndex + 1, pageSize, translatedQuery);
|
||||
totalRecords = pagedResult.TotalItems;
|
||||
|
||||
return pagedResult.Items.Select(
|
||||
dto => new AuditItem(dto.Id, dto.Comment, Enum<AuditType>.Parse(dto.Header), dto.UserId, dto.UserName, dto.UserAvatar)).ToArray();
|
||||
dto => new AuditItem(dto.Id, dto.Comment, Enum<AuditType>.Parse(dto.Header), dto.UserId)).ToArray();
|
||||
}
|
||||
|
||||
protected override void PersistUpdatedItem(IAuditItem entity)
|
||||
|
||||
@@ -371,7 +371,6 @@
|
||||
<Compile Include="Models\Membership\UserState.cs" />
|
||||
<Compile Include="Models\Membership\UserType.cs" />
|
||||
<Compile Include="Models\PublishedContent\PublishedContentTypeConverter.cs" />
|
||||
<Compile Include="Models\Rdbms\ReadOnlyLogDto.cs" />
|
||||
<Compile Include="Models\Rdbms\UserStartNodeDto.cs" />
|
||||
<Compile Include="Models\UserControl.cs" />
|
||||
<Compile Include="OrderedHashSet.cs" />
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http;
|
||||
@@ -31,9 +33,10 @@ namespace Umbraco.Web.Editors
|
||||
var dateQuery = sinceDate.HasValue ? Query<IAuditItem>.Builder.Where(x => x.CreateDate >= sinceDate) : null;
|
||||
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)
|
||||
{
|
||||
Items = mapped
|
||||
Items = MapAvatars(mapped)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -49,7 +52,7 @@ namespace Umbraco.Web.Editors
|
||||
var mapped = Mapper.Map<IEnumerable<AuditLog>>(result);
|
||||
return new PagedResult<AuditLog>(totalRecords, pageNumber + 1, pageSize)
|
||||
{
|
||||
Items = mapped
|
||||
Items = MapAvatars(mapped)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -81,5 +84,16 @@ namespace Umbraco.Web.Editors
|
||||
Log.Instance.GetLogItems(Enum<LogTypes>.Parse(logType.ToString()), sinceDate.Value));
|
||||
}
|
||||
|
||||
private IEnumerable<AuditLog> MapAvatars(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));
|
||||
foreach (var item in items)
|
||||
{
|
||||
item.UserAvatars = users[item.UserId];
|
||||
}
|
||||
return items;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace Umbraco.Web.Editors
|
||||
/// <returns></returns>
|
||||
public string[] GetCurrentUserAvatarUrls()
|
||||
{
|
||||
var urls = UmbracoContext.Security.CurrentUser.GetCurrentUserAvatarUrls(Services.UserService, ApplicationContext.ApplicationCache.StaticCache);
|
||||
var urls = UmbracoContext.Security.CurrentUser.GetUserAvatarUrls(ApplicationContext.ApplicationCache.StaticCache);
|
||||
if (urls == null)
|
||||
throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not access Gravatar endpoint"));
|
||||
|
||||
@@ -141,7 +141,7 @@ namespace Umbraco.Web.Editors
|
||||
});
|
||||
}
|
||||
|
||||
return request.CreateResponse(HttpStatusCode.OK, user.GetCurrentUserAvatarUrls(userService, staticCache));
|
||||
return request.CreateResponse(HttpStatusCode.OK, user.GetUserAvatarUrls(staticCache));
|
||||
}
|
||||
|
||||
[AppendUserModifiedHeader("id")]
|
||||
@@ -174,7 +174,7 @@ namespace Umbraco.Web.Editors
|
||||
FileSystemProviderManager.Current.MediaFileSystem.DeleteFile(filePath);
|
||||
}
|
||||
|
||||
return Request.CreateResponse(HttpStatusCode.OK, found.GetCurrentUserAvatarUrls(Services.UserService, ApplicationContext.ApplicationCache.StaticCache));
|
||||
return Request.CreateResponse(HttpStatusCode.OK, found.GetUserAvatarUrls(ApplicationContext.ApplicationCache.StaticCache));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -13,8 +13,8 @@ namespace Umbraco.Web.Models.ContentEditing
|
||||
[DataMember(Name = "userName")]
|
||||
public string UserName { get; set; }
|
||||
|
||||
[DataMember(Name = "userAvatar")]
|
||||
public string UserAvatar { get; set; }
|
||||
[DataMember(Name = "userAvatars")]
|
||||
public string[] UserAvatars { get; set; }
|
||||
|
||||
[DataMember(Name = "nodeId")]
|
||||
public int NodeId { get; set; }
|
||||
|
||||
@@ -24,11 +24,13 @@ namespace Umbraco.Web.Models.Mapping
|
||||
|
||||
//for the logging controller (and assuming dashboard that is used in uaas? otherwise not sure what that controller is used for)
|
||||
config.CreateMap<LogItem, AuditLog>()
|
||||
.ForMember(log => log.UserAvatar, expression => expression.Ignore())
|
||||
.ForMember(log => log.UserAvatars, expression => expression.Ignore())
|
||||
.ForMember(log => log.UserName, expression => expression.Ignore())
|
||||
.ForMember(log => log.LogType, expression => expression.MapFrom(item => Enum<AuditType>.Parse(item.LogType.ToString())));
|
||||
|
||||
config.CreateMap<IAuditItem, AuditLog>()
|
||||
.ForMember(log => log.UserAvatars, expression => expression.Ignore())
|
||||
.ForMember(log => log.UserName, expression => expression.Ignore())
|
||||
.ForMember(log => log.NodeId, expression => expression.MapFrom(item => item.Id))
|
||||
.ForMember(log => log.Timestamp, expression => expression.MapFrom(item => item.CreateDate))
|
||||
.ForMember(log => log.LogType, expression => expression.MapFrom(item => item.AuditType));
|
||||
|
||||
@@ -231,7 +231,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
//Important! Currently we are never mapping to multiple UserDisplay objects but if we start doing that
|
||||
// this will cause an N+1 and we'll need to change how this works.
|
||||
config.CreateMap<IUser, UserDisplay>()
|
||||
.ForMember(detail => detail.Avatars, opt => opt.MapFrom(user => user.GetCurrentUserAvatarUrls(applicationContext.Services.UserService, applicationContext.ApplicationCache.RuntimeCache)))
|
||||
.ForMember(detail => detail.Avatars, opt => opt.MapFrom(user => user.GetUserAvatarUrls(applicationContext.ApplicationCache.RuntimeCache)))
|
||||
.ForMember(detail => detail.Username, opt => opt.MapFrom(user => user.Username))
|
||||
.ForMember(detail => detail.LastLoginDate, opt => opt.MapFrom(user => user.LastLoginDate == default(DateTime) ? null : (DateTime?) user.LastLoginDate))
|
||||
.ForMember(detail => detail.UserGroups, opt => opt.MapFrom(user => user.Groups))
|
||||
@@ -292,7 +292,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
//like the load time is waiting.
|
||||
.ForMember(detail =>
|
||||
detail.Avatars,
|
||||
opt => opt.MapFrom(user => user.GetCurrentUserAvatarUrls(applicationContext.Services.UserService, applicationContext.ApplicationCache.RuntimeCache)))
|
||||
opt => opt.MapFrom(user => user.GetUserAvatarUrls(applicationContext.ApplicationCache.RuntimeCache)))
|
||||
.ForMember(detail => detail.Username, opt => opt.MapFrom(user => user.Username))
|
||||
.ForMember(detail => detail.UserGroups, opt => opt.MapFrom(user => user.Groups))
|
||||
.ForMember(detail => detail.LastLoginDate, opt => opt.MapFrom(user => user.LastLoginDate == default(DateTime) ? null : (DateTime?) user.LastLoginDate))
|
||||
@@ -312,7 +312,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
.ForMember(detail => detail.AdditionalData, opt => opt.Ignore());
|
||||
|
||||
config.CreateMap<IUser, UserDetail>()
|
||||
.ForMember(detail => detail.Avatars, opt => opt.MapFrom(user => user.GetCurrentUserAvatarUrls(applicationContext.Services.UserService, applicationContext.ApplicationCache.RuntimeCache)))
|
||||
.ForMember(detail => detail.Avatars, opt => opt.MapFrom(user => user.GetUserAvatarUrls(applicationContext.ApplicationCache.RuntimeCache)))
|
||||
.ForMember(detail => detail.UserId, opt => opt.MapFrom(user => GetIntId(user.Id)))
|
||||
.ForMember(detail => detail.StartContentIds, opt => opt.MapFrom(user => user.CalculateContentStartNodeIds(applicationContext.Services.EntityService)))
|
||||
.ForMember(detail => detail.StartMediaIds, opt => opt.MapFrom(user => user.CalculateMediaStartNodeIds(applicationContext.Services.EntityService)))
|
||||
|
||||
Reference in New Issue
Block a user