From 7115d85440bc4d2d80a72f34df06f355a23d6525 Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 12 Jul 2017 14:06:30 +1000 Subject: [PATCH] Removes unused and unneeded APIs on IUserService, updates code comments to describe implicit vs explicit permissions --- .../Interfaces/IUserGroupRepository.cs | 4 +- .../Repositories/UserGroupRepository.cs | 4 +- src/Umbraco.Core/Services/IUserService.cs | 35 +----- src/Umbraco.Core/Services/UserService.cs | 114 +++--------------- .../umbraco/dialogs/cruds.aspx.cs | 76 +----------- 5 files changed, 31 insertions(+), 202 deletions(-) diff --git a/src/Umbraco.Core/Persistence/Repositories/Interfaces/IUserGroupRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Interfaces/IUserGroupRepository.cs index 3b2663e026..3ccfa89885 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Interfaces/IUserGroupRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Interfaces/IUserGroupRepository.cs @@ -26,10 +26,10 @@ namespace Umbraco.Core.Persistence.Repositories void AddOrUpdateGroupWithUsers(IUserGroup userGroup, int[] userIds); /// - /// Gets the group permissions for the specified entities + /// Gets explicilty defined permissions for the group for specified entities /// /// Id of group - /// Array of entity Ids + /// Array of entity Ids, if empty will return permissions for the group for all entities IEnumerable GetPermissionsForEntities(int groupId, params int[] entityIds); /// diff --git a/src/Umbraco.Core/Persistence/Repositories/UserGroupRepository.cs b/src/Umbraco.Core/Persistence/Repositories/UserGroupRepository.cs index 7a160f7f24..e0717deda4 100644 --- a/src/Umbraco.Core/Persistence/Repositories/UserGroupRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/UserGroupRepository.cs @@ -91,10 +91,10 @@ namespace Umbraco.Core.Persistence.Repositories /// - /// Gets the group permissions for the specified entities + /// Gets explicilty defined permissions for the group for specified entities /// /// Id of group - /// Array of entity Ids + /// Array of entity Ids, if empty will return permissions for the group for all entities public IEnumerable GetPermissionsForEntities(int groupId, params int[] entityIds) { var repo = new PermissionRepository(UnitOfWork, _cacheHelper, SqlSyntax); diff --git a/src/Umbraco.Core/Services/IUserService.cs b/src/Umbraco.Core/Services/IUserService.cs index b55048ef4d..de228412da 100644 --- a/src/Umbraco.Core/Services/IUserService.cs +++ b/src/Umbraco.Core/Services/IUserService.cs @@ -86,31 +86,19 @@ namespace Umbraco.Core.Services void DeleteSectionFromAllUserGroups(string sectionAlias); /// - /// Get permissions set for a user and optional node ids + /// Get explicitly assigned permissions for a user and optional node ids /// /// If no permissions are found for a particular entity then the user's default permissions will be applied /// User to retrieve permissions for /// Specifiying nothing will return all user permissions for all nodes /// An enumerable list of /// - /// > 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 /// IEnumerable GetPermissions(IUser user, params int[] nodeIds); - + /// - /// Get permissions set for a group and optional node Ids - /// - /// Group to retrieve permissions for - /// - /// 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 - /// - /// Specifiying nothing will return all permissions for all nodes - /// An enumerable list of - IEnumerable GetPermissions(string groupAlias, bool fallbackToDefaultPermissions, params int[] nodeIds); - - /// - /// Get permissions set for a group and optional node Ids + /// Get explicitly assigned permissions for a group and optional node Ids /// /// Group to retrieve permissions for /// @@ -122,23 +110,12 @@ namespace Umbraco.Core.Services IEnumerable GetPermissions(IUserGroup group, bool fallbackToDefaultPermissions, params int[] nodeIds); /// - /// Gets the permissions for the provided user and path + /// Gets the implicit/inherited permissions for the user for the given path /// /// User to check permissions for /// Path to check permissions for EntityPermissionSet GetPermissionsForPath(IUser user, string path); - - /// - /// Gets the permissions for the provided group and path - /// - /// Group alias to check permissions for - /// Path to check permissions for - /// - /// 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 - /// - EntityPermission GetPermissionsForPath(string groupAlias, string path, bool fallbackToDefaultPermissions = false); - + /// /// Gets the permissions for the provided group and path /// diff --git a/src/Umbraco.Core/Services/UserService.cs b/src/Umbraco.Core/Services/UserService.cs index b2a1ddec58..841a51456e 100644 --- a/src/Umbraco.Core/Services/UserService.cs +++ b/src/Umbraco.Core/Services/UserService.cs @@ -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 } /// - /// Get permissions set for a user and node Id + /// Get explicitly assigned permissions for a user and optional node ids /// /// User to retrieve permissions for /// Specifiying nothing will return all permissions for all nodes /// An enumerable list of public IEnumerable GetPermissions(IUser user, params int[] nodeIds) { - if (nodeIds.Length == 0) - return Enumerable.Empty(); - var result = new List(); foreach (var group in user.Groups) @@ -859,35 +855,21 @@ namespace Umbraco.Core.Services { AddOrAmendPermissionList(result, permission); } - } - + } + return result; - } + } /// - /// Get permissions set for a group and node Id + /// Get explicitly assigned permissions for a group and optional node Ids /// - /// Group to retrieve permissions for + /// Group to retrieve permissions for /// /// 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 /// /// Specifiying nothing will return all permissions for all nodes - /// An enumerable list of - public IEnumerable GetPermissions(string groupAlias, bool fallbackToDefaultPermissions, params int[] nodeIds) - { - if (nodeIds.Length == 0) - return Enumerable.Empty(); - - 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); - } - } - + /// An enumerable list of private IEnumerable 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 GetPermissions(int groupId, bool fallbackToDefaultPermissions, params int[] nodeIds) - { - if (nodeIds.Length == 0) - return Enumerable.Empty(); - - 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); - } - } - /// - /// Get permissions set for a group and optional node Ids + /// Get explicitly assigned permissions for a group and optional node Ids /// /// Group to retrieve permissions for /// @@ -945,10 +906,7 @@ namespace Umbraco.Core.Services private static IEnumerable GetPermissionsInternal(IUserGroupRepository repository, IReadOnlyUserGroup group, bool fallbackToDefaultPermissions, params int[] nodeIds) { if (group == null) throw new ArgumentNullException("group"); - - if (nodeIds.Length == 0) - return Enumerable.Empty(); - + var explicitPermissions = repository.GetPermissionsForEntities(group.Id, nodeIds); var result = new List(explicitPermissions); @@ -972,7 +930,7 @@ namespace Umbraco.Core.Services /// /// List of already found permissions /// New permission to aggregate - private void AddOrAmendPermissionList(IList permissions, EntityPermission groupPermission) + private static void AddOrAmendPermissionList(ICollection 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 } /// - /// Gets the permissions for the provided user and path + /// Gets the implicit/inherited permissions for the user for the given path /// /// User to check permissions for /// Path to check permissions for @@ -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); - } - - /// - /// Gets the permissions for the provided group and path - /// - /// User to check permissions for - /// Path to check permissions for - /// - /// 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 - /// - /// String indicating permissions for provided user and path - 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); - } + } /// /// 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); - //} - + /// /// Returns the permissions for the path ids /// @@ -1136,19 +1068,7 @@ namespace Umbraco.Core.Services .ToArray(); return nodeIds; } - - ///// - ///// Parses a path to find the lowermost node id - ///// - ///// Path as string - ///// Node id - //private static int GetNodeIdFromPath(string path) - //{ - // return path.Contains(",") - // ? int.Parse(path.Substring(path.LastIndexOf(",", StringComparison.Ordinal) + 1)) - // : int.Parse(path); - //} - + /// /// Checks in a set of permissions associated with a user for those related to a given nodeId /// diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/cruds.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/cruds.aspx.cs index ee93aec60b..de4c902ee2 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/cruds.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/cruds.aspx.cs @@ -19,7 +19,8 @@ namespace umbraco.dialogs /// /// Summary description for cruds. /// - 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("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"); }