Files
Umbraco-CMS/src/Umbraco.Web/Models/Mapping/ActionButtonsResolver.cs

45 lines
1.6 KiB
C#
Raw Normal View History

2017-07-20 11:21:28 +02:00
using System;
2017-07-19 13:42:47 +02:00
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
{
2018-03-27 10:04:07 +02:00
public ActionButtonsResolver(IUserService userService, IContentService contentService)
2017-07-19 13:42:47 +02:00
{
2018-03-27 10:04:07 +02:00
UserService = userService;
ContentService = contentService;
2017-07-19 13:42:47 +02:00
}
2018-03-27 10:04:07 +02:00
private IUserService UserService { get; }
private IContentService ContentService { get; }
2017-09-12 16:22:16 +02:00
public IEnumerable<string> Resolve(IContent source)
2017-07-19 13:42:47 +02:00
{
2018-03-27 10:04:07 +02:00
//cannot check permissions without a context
2017-07-19 13:42:47 +02:00
if (UmbracoContext.Current == null)
2017-09-12 16:22:16 +02:00
return Enumerable.Empty<string>();
2017-07-19 13:42:47 +02:00
2018-03-27 10:04:07 +02:00
string path;
if (source.HasIdentity)
path = source.Path;
else
{
var parent = ContentService.GetById(source.ParentId);
path = parent == null ? "-1" : parent.Path;
}
2017-07-19 13:42:47 +02:00
2018-03-27 10:04:07 +02:00
//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 :(
return UserService.GetPermissionsForPath(UmbracoContext.Current.Security.CurrentUser, path).GetAllPermissions();
2017-07-19 13:42:47 +02:00
}
}
2017-07-20 11:21:28 +02:00
}