Removes unused and unneeded APIs on IUserService, updates code comments to describe implicit vs explicit permissions
This commit is contained in:
@@ -26,10 +26,10 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
void AddOrUpdateGroupWithUsers(IUserGroup userGroup, int[] userIds);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the group permissions for the specified entities
|
||||
/// Gets explicilty defined permissions for the group for specified entities
|
||||
/// </summary>
|
||||
/// <param name="groupId">Id of group</param>
|
||||
/// <param name="entityIds">Array of entity Ids</param>
|
||||
/// <param name="entityIds">Array of entity Ids, if empty will return permissions for the group for all entities</param>
|
||||
IEnumerable<EntityPermission> GetPermissionsForEntities(int groupId, params int[] entityIds);
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -91,10 +91,10 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the group permissions for the specified entities
|
||||
/// Gets explicilty defined permissions for the group for specified entities
|
||||
/// </summary>
|
||||
/// <param name="groupId">Id of group</param>
|
||||
/// <param name="entityIds">Array of entity Ids</param>
|
||||
/// <param name="entityIds">Array of entity Ids, if empty will return permissions for the group for all entities</param>
|
||||
public IEnumerable<EntityPermission> GetPermissionsForEntities(int groupId, params int[] entityIds)
|
||||
{
|
||||
var repo = new PermissionRepository<IContent>(UnitOfWork, _cacheHelper, SqlSyntax);
|
||||
|
||||
@@ -86,31 +86,19 @@ namespace Umbraco.Core.Services
|
||||
void DeleteSectionFromAllUserGroups(string sectionAlias);
|
||||
|
||||
/// <summary>
|
||||
/// Get permissions set for a user and optional node ids
|
||||
/// Get explicitly assigned permissions for a user and optional node ids
|
||||
/// </summary>
|
||||
/// <remarks>If no permissions are found for a particular entity then the user's default permissions will be applied</remarks>
|
||||
/// <param name="user">User to retrieve permissions for</param>
|
||||
/// <param name="nodeIds">Specifiying nothing will return all user permissions for all nodes</param>
|
||||
/// <returns>An enumerable list of <see cref="EntityPermission"/></returns>
|
||||
/// <remarks>
|
||||
/// > This is the ONLY one for permissions from 7.6!
|
||||
/// This will return the default permissions for the user's groups for nodes that don't have explicitly defined permissions
|
||||
/// </remarks>
|
||||
IEnumerable<EntityPermission> GetPermissions(IUser user, params int[] nodeIds);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get permissions set for a group and optional node Ids
|
||||
/// </summary>
|
||||
/// <param name="groupAlias">Group to retrieve permissions for</param>
|
||||
/// <param name="fallbackToDefaultPermissions">
|
||||
/// Flag indicating if we want to get just the permissions directly assigned for the group and path,
|
||||
/// or fall back to the group's default permissions when nothing is directly assigned
|
||||
/// </param>
|
||||
/// <param name="nodeIds">Specifiying nothing will return all permissions for all nodes</param>
|
||||
/// <returns>An enumerable list of <see cref="EntityPermission"/></returns>
|
||||
IEnumerable<EntityPermission> GetPermissions(string groupAlias, bool fallbackToDefaultPermissions, params int[] nodeIds);
|
||||
|
||||
/// <summary>
|
||||
/// Get permissions set for a group and optional node Ids
|
||||
/// Get explicitly assigned permissions for a group and optional node Ids
|
||||
/// </summary>
|
||||
/// <param name="group">Group to retrieve permissions for</param>
|
||||
/// <param name="fallbackToDefaultPermissions">
|
||||
@@ -122,23 +110,12 @@ namespace Umbraco.Core.Services
|
||||
IEnumerable<EntityPermission> GetPermissions(IUserGroup group, bool fallbackToDefaultPermissions, params int[] nodeIds);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the permissions for the provided user and path
|
||||
/// Gets the implicit/inherited permissions for the user for the given path
|
||||
/// </summary>
|
||||
/// <param name="user">User to check permissions for</param>
|
||||
/// <param name="path">Path to check permissions for</param>
|
||||
EntityPermissionSet GetPermissionsForPath(IUser user, string path);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the permissions for the provided group and path
|
||||
/// </summary>
|
||||
/// <param name="groupAlias">Group alias to check permissions for</param>
|
||||
/// <param name="path">Path to check permissions for</param>
|
||||
/// <param name="fallbackToDefaultPermissions">
|
||||
/// Flag indicating if we want to get just the permissions directly assigned for the group and path,
|
||||
/// or fall back to the group's default permissions when nothing is directly assigned
|
||||
/// </param>
|
||||
EntityPermission GetPermissionsForPath(string groupAlias, string path, bool fallbackToDefaultPermissions = false);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the permissions for the provided group and path
|
||||
/// </summary>
|
||||
|
||||
@@ -13,7 +13,6 @@ using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
using Umbraco.Core.Security;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
|
||||
namespace Umbraco.Core.Services
|
||||
{
|
||||
@@ -841,16 +840,13 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get permissions set for a user and node Id
|
||||
/// Get explicitly assigned permissions for a user and optional node ids
|
||||
/// </summary>
|
||||
/// <param name="user">User to retrieve permissions for</param>
|
||||
/// <param name="nodeIds">Specifiying nothing will return all permissions for all nodes</param>
|
||||
/// <returns>An enumerable list of <see cref="EntityPermission"/></returns>
|
||||
public IEnumerable<EntityPermission> GetPermissions(IUser user, params int[] nodeIds)
|
||||
{
|
||||
if (nodeIds.Length == 0)
|
||||
return Enumerable.Empty<EntityPermission>();
|
||||
|
||||
var result = new List<EntityPermission>();
|
||||
|
||||
foreach (var group in user.Groups)
|
||||
@@ -859,35 +855,21 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
AddOrAmendPermissionList(result, permission);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get permissions set for a group and node Id
|
||||
/// Get explicitly assigned permissions for a group and optional node Ids
|
||||
/// </summary>
|
||||
/// <param name="groupAlias">Group to retrieve permissions for</param>
|
||||
/// <param name="group">Group to retrieve permissions for</param>
|
||||
/// <param name="fallbackToDefaultPermissions">
|
||||
/// Flag indicating if we want to get just the permissions directly assigned for the group and path,
|
||||
/// or fall back to the group's default permissions when nothing is directly assigned
|
||||
/// </param>
|
||||
/// <param name="nodeIds">Specifiying nothing will return all permissions for all nodes</param>
|
||||
/// <returns>An enumerable list of <see cref="EntityPermission"/></returns>
|
||||
public IEnumerable<EntityPermission> GetPermissions(string groupAlias, bool fallbackToDefaultPermissions, params int[] nodeIds)
|
||||
{
|
||||
if (nodeIds.Length == 0)
|
||||
return Enumerable.Empty<EntityPermission>();
|
||||
|
||||
using (var uow = UowProvider.GetUnitOfWork(readOnly: true))
|
||||
{
|
||||
var repository = RepositoryFactory.CreateUserGroupRepository(uow);
|
||||
var group = repository.Get(groupAlias);
|
||||
if (group == null) throw new InvalidOperationException("No group found with alias " + groupAlias);
|
||||
return GetPermissionsInternal(repository, group.ToReadOnlyGroup(), fallbackToDefaultPermissions, nodeIds);
|
||||
}
|
||||
}
|
||||
|
||||
/// <returns>An enumerable list of <see cref="EntityPermission"/></returns>
|
||||
private IEnumerable<EntityPermission> GetPermissions(IReadOnlyUserGroup group, bool fallbackToDefaultPermissions, params int[] nodeIds)
|
||||
{
|
||||
if (group == null) throw new ArgumentNullException("group");
|
||||
@@ -899,31 +881,10 @@ namespace Umbraco.Core.Services
|
||||
var repository = RepositoryFactory.CreateUserGroupRepository(uow);
|
||||
return GetPermissionsInternal(repository, group, fallbackToDefaultPermissions, nodeIds);
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<EntityPermission> GetPermissions(int groupId, bool fallbackToDefaultPermissions, params int[] nodeIds)
|
||||
{
|
||||
if (nodeIds.Length == 0)
|
||||
return Enumerable.Empty<EntityPermission>();
|
||||
|
||||
using (var uow = UowProvider.GetUnitOfWork(readOnly: true))
|
||||
{
|
||||
var repository = RepositoryFactory.CreateUserGroupRepository(uow);
|
||||
}
|
||||
|
||||
if (fallbackToDefaultPermissions == false)
|
||||
{
|
||||
//if fallbackToDefaultPermissions is false, we don't have to lookup the group
|
||||
return repository.GetPermissionsForEntities(groupId, nodeIds);
|
||||
}
|
||||
|
||||
var group = repository.Get(groupId);
|
||||
if (group == null) throw new InvalidOperationException("No group found with id " + groupId);
|
||||
return GetPermissionsInternal(repository, group.ToReadOnlyGroup(), true, nodeIds);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get permissions set for a group and optional node Ids
|
||||
/// Get explicitly assigned permissions for a group and optional node Ids
|
||||
/// </summary>
|
||||
/// <param name="group">Group to retrieve permissions for</param>
|
||||
/// <param name="fallbackToDefaultPermissions">
|
||||
@@ -945,10 +906,7 @@ namespace Umbraco.Core.Services
|
||||
private static IEnumerable<EntityPermission> GetPermissionsInternal(IUserGroupRepository repository, IReadOnlyUserGroup group, bool fallbackToDefaultPermissions, params int[] nodeIds)
|
||||
{
|
||||
if (group == null) throw new ArgumentNullException("group");
|
||||
|
||||
if (nodeIds.Length == 0)
|
||||
return Enumerable.Empty<EntityPermission>();
|
||||
|
||||
|
||||
var explicitPermissions = repository.GetPermissionsForEntities(group.Id, nodeIds);
|
||||
var result = new List<EntityPermission>(explicitPermissions);
|
||||
|
||||
@@ -972,7 +930,7 @@ namespace Umbraco.Core.Services
|
||||
/// </summary>
|
||||
/// <param name="permissions">List of already found permissions</param>
|
||||
/// <param name="groupPermission">New permission to aggregate</param>
|
||||
private void AddOrAmendPermissionList(IList<EntityPermission> permissions, EntityPermission groupPermission)
|
||||
private static void AddOrAmendPermissionList(ICollection<EntityPermission> permissions, EntityPermission groupPermission)
|
||||
{
|
||||
//TODO: Fix the performance of this, we need to use things like HashSet and equality checkers, we are iterating too much
|
||||
|
||||
@@ -988,7 +946,7 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the permissions for the provided user and path
|
||||
/// Gets the implicit/inherited permissions for the user for the given path
|
||||
/// </summary>
|
||||
/// <param name="user">User to check permissions for</param>
|
||||
/// <param name="path">Path to check permissions for</param>
|
||||
@@ -997,13 +955,13 @@ namespace Umbraco.Core.Services
|
||||
var nodeIds = GetIdsFromPath(path);
|
||||
|
||||
if (nodeIds.Length == 0)
|
||||
return null;
|
||||
return EntityPermissionSet.Empty();
|
||||
|
||||
var permissionsByGroup = GetPermissionsForGroupsAndPath(user.Groups, nodeIds);
|
||||
|
||||
// not sure this will ever happen, it shouldn't since this should return defaults, but maybe those are empty?
|
||||
if (permissionsByGroup.Count == 0)
|
||||
return null;
|
||||
return EntityPermissionSet.Empty();
|
||||
|
||||
var entityId = nodeIds[0];
|
||||
|
||||
@@ -1036,25 +994,7 @@ namespace Umbraco.Core.Services
|
||||
permissions = GetPermissionsForPath(g, pathIds, fallbackToDefaultPermissions: true)
|
||||
})
|
||||
.ToDictionary(x => x.group, x => x.permissions);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the permissions for the provided group and path
|
||||
/// </summary>
|
||||
/// <param name="groupAlias">User to check permissions for</param>
|
||||
/// <param name="path">Path to check permissions for</param>
|
||||
/// <param name="fallbackToDefaultPermissions">
|
||||
/// Flag indicating if we want to get just the permissions directly assigned for the group and path,
|
||||
/// or fall back to the group's default permissions when nothing is directly assigned
|
||||
/// </param>
|
||||
/// <returns>String indicating permissions for provided user and path</returns>
|
||||
public EntityPermission GetPermissionsForPath(string groupAlias, string path, bool fallbackToDefaultPermissions = false)
|
||||
{
|
||||
var nodeIds = GetIdsFromPath(path);
|
||||
//get permissions for all nodes in the path
|
||||
var permissions = GetPermissions(groupAlias, fallbackToDefaultPermissions, nodeIds);
|
||||
return GetPermissionsForPath(permissions, nodeIds, fallbackToDefaultPermissions);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the permissions for the provided group and path
|
||||
@@ -1078,15 +1018,7 @@ namespace Umbraco.Core.Services
|
||||
var permissions = GetPermissions(group, fallbackToDefaultPermissions, pathIds);
|
||||
return GetPermissionsForPath(permissions, pathIds, fallbackToDefaultPermissions);
|
||||
}
|
||||
|
||||
//private EntityPermission GetPermissionsForPath(int groupId, string path, bool fallbackToDefaultPermissions = false)
|
||||
//{
|
||||
// var nodeIds = GetIdsFromPath(path);
|
||||
// //get permissions for all nodes in the path
|
||||
// var permissions = GetPermissions(groupId, fallbackToDefaultPermissions, nodeIds);
|
||||
// return GetPermissionsForPath(permissions, groupId, nodeIds, fallbackToDefaultPermissions);
|
||||
//}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns the permissions for the path ids
|
||||
/// </summary>
|
||||
@@ -1136,19 +1068,7 @@ namespace Umbraco.Core.Services
|
||||
.ToArray();
|
||||
return nodeIds;
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// Parses a path to find the lowermost node id
|
||||
///// </summary>
|
||||
///// <param name="path">Path as string</param>
|
||||
///// <returns>Node id</returns>
|
||||
//private static int GetNodeIdFromPath(string path)
|
||||
//{
|
||||
// return path.Contains(",")
|
||||
// ? int.Parse(path.Substring(path.LastIndexOf(",", StringComparison.Ordinal) + 1))
|
||||
// : int.Parse(path);
|
||||
//}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Checks in a set of permissions associated with a user for those related to a given nodeId
|
||||
/// </summary>
|
||||
|
||||
@@ -19,7 +19,8 @@ namespace umbraco.dialogs
|
||||
/// <summary>
|
||||
/// Summary description for cruds.
|
||||
/// </summary>
|
||||
public partial class cruds : BasePages.UmbracoEnsuredPage
|
||||
[Obsolete("Remove this for 7.7 release!")]
|
||||
public class cruds : BasePages.UmbracoEnsuredPage
|
||||
{
|
||||
|
||||
public cruds()
|
||||
@@ -37,78 +38,9 @@ namespace umbraco.dialogs
|
||||
pane_form.Text = ui.Text("actions", "SetPermissionsForThePage",_node.Text);
|
||||
}
|
||||
|
||||
override protected void OnInit(EventArgs e)
|
||||
protected override void OnInit(EventArgs e)
|
||||
{
|
||||
base.OnInit(e);
|
||||
|
||||
_node = new CMSNode(Request.GetItemAs<int>("id"));
|
||||
|
||||
var ht = new HtmlTable();
|
||||
ht.Attributes.Add("class", "table");
|
||||
|
||||
var names = new HtmlTableRow();
|
||||
|
||||
var corner = new HtmlTableCell("th");
|
||||
corner.Style.Add("border", "none");
|
||||
names.Cells.Add(corner);
|
||||
|
||||
foreach (var a in ActionsResolver.Current.Actions)
|
||||
{
|
||||
if (a.CanBePermissionAssigned == false) continue;
|
||||
|
||||
var permissionRow = new HtmlTableRow();
|
||||
var label = new HtmlTableCell
|
||||
{
|
||||
InnerText = ui.Text("actions", a.Alias)
|
||||
};
|
||||
permissionRow.Cells.Add(label);
|
||||
_permissions.Add(a.Alias, permissionRow);
|
||||
}
|
||||
|
||||
ht.Rows.Add(names);
|
||||
|
||||
var userService = ApplicationContext.Current.Services.UserService;
|
||||
foreach (var group in userService.GetAllUserGroups())
|
||||
{
|
||||
var hc = new HtmlTableCell("th")
|
||||
{
|
||||
InnerText = group.Name
|
||||
};
|
||||
hc.Style.Add("text-align", "center");
|
||||
hc.Style.Add("border", "none");
|
||||
names.Cells.Add(hc);
|
||||
|
||||
foreach (var a in ActionsResolver.Current.Actions)
|
||||
{
|
||||
var chk = new CheckBox
|
||||
{
|
||||
//Each checkbox is named with the group _ permission alias so we can parse
|
||||
ID = group.Id + "_" + a.Letter
|
||||
};
|
||||
|
||||
if (a.CanBePermissionAssigned == false) continue;
|
||||
|
||||
var permissions = userService.GetPermissionsForPath(group, _node.Path);
|
||||
if (permissions.AssignedPermissions.Contains(a.Letter.ToString()))
|
||||
{
|
||||
chk.Checked = true;
|
||||
}
|
||||
|
||||
var cell = new HtmlTableCell();
|
||||
cell.Style.Add("text-align", "center");
|
||||
cell.Controls.Add(chk);
|
||||
|
||||
_permissions[a.Alias].Cells.Add(cell);
|
||||
}
|
||||
}
|
||||
|
||||
//add all collected rows
|
||||
foreach (var perm in _permissions.Values)
|
||||
{
|
||||
ht.Rows.Add(perm);
|
||||
}
|
||||
|
||||
PlaceHolder1.Controls.Add(ht);
|
||||
throw new NotSupportedException("This cruds.aspx.cs needs to be removed, it is no longer required");
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user