44 lines
1.7 KiB
C#
44 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Umbraco.Core.Models;
|
|
using Umbraco.Core.Services;
|
|
|
|
namespace Umbraco.Web.Models.Mapping
|
|
{
|
|
/// <summary>
|
|
/// Creates the list of action buttons allowed for this user - Publish, Send to publish, save, unpublish returned as the button's 'letter'
|
|
/// </summary>
|
|
internal class ActionButtonsResolver
|
|
{
|
|
private readonly Lazy<IUserService> _userService;
|
|
|
|
public ActionButtonsResolver(Lazy<IUserService> userService)
|
|
{
|
|
_userService = userService;
|
|
}
|
|
|
|
public IEnumerable<string> Resolve(IContent source)
|
|
{
|
|
if (UmbracoContext.Current == null)
|
|
{
|
|
//cannot check permissions without a context
|
|
return Enumerable.Empty<string>();
|
|
}
|
|
var svc = _userService.Value;
|
|
|
|
var permissions = svc.GetPermissions(
|
|
//TODO: This is certainly not ideal usage here - perhaps the best way to deal with this in the future is
|
|
// with the IUmbracoContextAccessor. In the meantime, if used outside of a web app this will throw a null
|
|
// refrence exception :(
|
|
UmbracoContext.Current.Security.CurrentUser,
|
|
// Here we need to do a special check since this could be new content, in which case we need to get the permissions
|
|
// from the parent, not the existing one otherwise permissions would be coming from the root since Id is 0.
|
|
source.HasIdentity ? source.Id : source.ParentId)
|
|
.GetAllPermissions();
|
|
|
|
return permissions;
|
|
}
|
|
}
|
|
}
|