In the spirit of DRY: centralized IsAdmin() check in an extension method

Made sure that non-admins can't trigger the enable/disable URL tracker endpoint
Renamed "admin" in GetEnableState to "isUserAdmin" for clarity
This commit is contained in:
Sebastiaan Janssen
2016-09-04 11:44:16 +02:00
parent fee217e8d7
commit 8d291efedd
6 changed files with 35 additions and 13 deletions

View File

@@ -1,8 +1,5 @@
using System;
using System.Globalization;
using System.Linq;
using System.Threading;
using Umbraco.Core.Models.Identity;
using Umbraco.Core.Models.Membership;
using Umbraco.Core.Services;
@@ -83,5 +80,19 @@ namespace Umbraco.Core.Models
if (media == null) throw new ArgumentNullException("media");
return HasPathAccess(media.Path, user.StartMediaId, Constants.System.RecycleBinMedia);
}
/// <summary>
/// Determines whether this user is an admin.
/// </summary>
/// <param name="user"></param>
/// <returns>
/// <c>true</c> if this user is admin; otherwise, <c>false</c>.
/// </returns>
public static bool IsAdmin(this IUser user)
{
if (user == null) throw new ArgumentNullException("user");
return user.UserType.Alias == "admin";
}
}
}