adds the IsCurrentUser flag to the UserDisplay model
This commit is contained in:
56
src/Umbraco.Web/Editors/IsCurrentUserModelFilterAttribute.cs
Normal file
56
src/Umbraco.Web/Editors/IsCurrentUserModelFilterAttribute.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Web.Http.Filters;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
|
||||
namespace Umbraco.Web.Editors
|
||||
{
|
||||
/// <summary>
|
||||
/// This sets the IsCurrentUser property on any outgoing <see cref="UserDisplay"/> model or any collection of <see cref="UserDisplay"/> models
|
||||
/// </summary>
|
||||
internal class IsCurrentUserModelFilterAttribute : ActionFilterAttribute
|
||||
{
|
||||
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
|
||||
{
|
||||
if (actionExecutedContext.Response == null) return;
|
||||
|
||||
var user = UmbracoContext.Current.Security.CurrentUser;
|
||||
if (user == null) return;
|
||||
|
||||
var objectContent = actionExecutedContext.Response.Content as ObjectContent;
|
||||
if (objectContent != null)
|
||||
{
|
||||
var model = objectContent.Value as UserDisplay;
|
||||
if (model != null)
|
||||
{
|
||||
model.IsCurrentUser = (int) model.Id == user.Id;
|
||||
}
|
||||
else
|
||||
{
|
||||
var collection = objectContent.Value as IEnumerable<UserDisplay>;
|
||||
if (collection != null)
|
||||
{
|
||||
foreach (var userDisplay in collection)
|
||||
{
|
||||
userDisplay.IsCurrentUser = (int) userDisplay.Id == user.Id;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var paged = objectContent.Value as UsersController.PagedUserResult;
|
||||
if (paged != null)
|
||||
{
|
||||
foreach (var userDisplay in paged.Items)
|
||||
{
|
||||
userDisplay.IsCurrentUser = (int)userDisplay.Id == user.Id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
base.OnActionExecuted(actionExecutedContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
@@ -37,6 +38,7 @@ namespace Umbraco.Web.Editors
|
||||
[PluginController("UmbracoApi")]
|
||||
[UmbracoApplicationAuthorize(Constants.Applications.Users)]
|
||||
[PrefixlessBodyModelValidator]
|
||||
[IsCurrentUserModelFilter]
|
||||
public class UsersController : UmbracoAuthorizedJsonController
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -39,6 +39,14 @@ namespace Umbraco.Web.Models.ContentEditing
|
||||
/// If the password is reset on save, this value will be populated
|
||||
/// </summary>
|
||||
[DataMember(Name = "resetPasswordValue")]
|
||||
[ReadOnly(true)]
|
||||
public string ResetPasswordValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// This is an info flag to denote if this object is the equivalent of the currently logged in user
|
||||
/// </summary>
|
||||
[DataMember(Name = "isCurrentUser")]
|
||||
[ReadOnly(true)]
|
||||
public bool IsCurrentUser { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -331,6 +331,7 @@
|
||||
<Compile Include="Editors\EditorValidationResolver.cs" />
|
||||
<Compile Include="Editors\EditorValidator.cs" />
|
||||
<Compile Include="Editors\FromJsonPathAttribute.cs" />
|
||||
<Compile Include="Editors\IsCurrentUserModelFilterAttribute.cs" />
|
||||
<Compile Include="Editors\PasswordChangeControllerHelper.cs" />
|
||||
<Compile Include="Editors\TemplateController.cs" />
|
||||
<Compile Include="Editors\ParameterSwapControllerActionSelector.cs" />
|
||||
|
||||
Reference in New Issue
Block a user