diff --git a/src/Umbraco.Core/Cache/CacheKeys.cs b/src/Umbraco.Core/Cache/CacheKeys.cs index f41bc92053..c9991ba45a 100644 --- a/src/Umbraco.Core/Cache/CacheKeys.cs +++ b/src/Umbraco.Core/Cache/CacheKeys.cs @@ -55,7 +55,9 @@ namespace Umbraco.Core.Cache [Obsolete("This is no longer used and will be removed from the codebase in the future")] [EditorBrowsable(EditorBrowsableState.Never)] public const string UserCacheKey = "UmbracoUser"; - + + [Obsolete("This is no longer used and will be removed from the codebase in the future")] + [EditorBrowsable(EditorBrowsableState.Never)] public const string UserGroupPermissionsCacheKey = "UmbracoUserGroupPermissions"; [UmbracoWillObsolete("This cache key is only used for legacy business logic caching, remove in v8")] diff --git a/src/Umbraco.Core/Models/Content.cs b/src/Umbraco.Core/Models/Content.cs index cef06ec4f7..b3fbe4164b 100644 --- a/src/Umbraco.Core/Models/Content.cs +++ b/src/Umbraco.Core/Models/Content.cs @@ -87,7 +87,6 @@ namespace Umbraco.Core.Models public readonly PropertyInfo ExpireDateSelector = ExpressionHelper.GetPropertyInfo(x => x.ExpireDate); public readonly PropertyInfo WriterSelector = ExpressionHelper.GetPropertyInfo(x => x.WriterId); public readonly PropertyInfo NodeNameSelector = ExpressionHelper.GetPropertyInfo(x => x.NodeName); - public readonly PropertyInfo PermissionsChangedSelector = ExpressionHelper.GetPropertyInfo(x => x.PermissionsChanged); } /// @@ -196,16 +195,7 @@ namespace Umbraco.Core.Models get { return _nodeName; } set { SetPropertyValueAndDetectChanges(value, ref _nodeName, Ps.Value.NodeNameSelector); } } - - /// - /// Used internally to track if permissions have been changed during the saving process for this entity - /// - [IgnoreDataMember] - internal bool PermissionsChanged - { - get { return _permissionsChanged; } - set { SetPropertyValueAndDetectChanges(value, ref _permissionsChanged, Ps.Value.PermissionsChangedSelector); } - } + /// /// Gets the ContentType used by this content object diff --git a/src/Umbraco.Core/Persistence/Repositories/PermissionRepository.cs b/src/Umbraco.Core/Persistence/Repositories/PermissionRepository.cs index 7dc751040d..7dc6996b57 100644 --- a/src/Umbraco.Core/Persistence/Repositories/PermissionRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/PermissionRepository.cs @@ -159,9 +159,6 @@ namespace Umbraco.Core.Persistence.Repositories } UnitOfWork.Database.BulkInsertRecords(toInsert, SqlSyntax); - - //Raise the event - UnitOfWork.Events.Dispatch(AssignedPermissions, this, new SaveEventArgs(ConvertToPermissionList(toInsert), false)); } @@ -191,10 +188,7 @@ namespace Umbraco.Core.Persistence.Repositories }).ToArray(); UnitOfWork.Database.BulkInsertRecords(actions, SqlSyntax); - - //Raise the event - UnitOfWork.Events.Dispatch(AssignedPermissions, this, new SaveEventArgs(ConvertToPermissionList(actions), false)); - + } /// @@ -223,10 +217,7 @@ namespace Umbraco.Core.Persistence.Repositories }).ToArray(); UnitOfWork.Database.BulkInsertRecords(actions, SqlSyntax); - - //Raise the event - UnitOfWork.Events.Dispatch(AssignedPermissions, this, new SaveEventArgs(ConvertToPermissionList(actions), false)); - + } /// @@ -258,11 +249,7 @@ namespace Umbraco.Core.Persistence.Repositories } UnitOfWork.Database.BulkInsertRecords(toInsert, SqlSyntax); - - //Raise the event - UnitOfWork.Events.Dispatch(AssignedPermissions, this, new SaveEventArgs(permissionSet.PermissionsSet, false)); - - + } @@ -350,7 +337,6 @@ namespace Umbraco.Core.Persistence.Repositories return permissions; } - - public static event TypedEventHandler, SaveEventArgs> AssignedPermissions; + } } \ No newline at end of file diff --git a/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs b/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs index 8e628204d8..daf405a562 100644 --- a/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs +++ b/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs @@ -111,22 +111,8 @@ namespace Umbraco.Web.Cache Bind(() => MemberTypeService.Saved += MemberTypeService_Saved, () => MemberTypeService.Saved -= MemberTypeService_Saved); Bind(() => MemberTypeService.Deleted += MemberTypeService_Deleted, - () => MemberTypeService.Deleted -= MemberTypeService_Deleted); - - // bind to permission events - // we should wrap legacy permissions so we can get rid of this - // fixme - the method names here (PermissionNew...) are not supported - // by the event handling mechanism for scopes and deploy, and not sure - // how to fix with the generic repository - Bind(() => Permission.New += PermissionNew, - () => Permission.New -= PermissionNew); - Bind(() => Permission.Updated += PermissionUpdated, - () => Permission.Updated -= PermissionUpdated); - Bind(() => Permission.Deleted += PermissionDeleted, - () => Permission.Deleted -= PermissionDeleted); - Bind(() => PermissionRepository.AssignedPermissions += CacheRefresherEventHandler_AssignedPermissions, - () => PermissionRepository.AssignedPermissions -= CacheRefresherEventHandler_AssignedPermissions); - + () => MemberTypeService.Deleted -= MemberTypeService_Deleted); + // bind to template events Bind(() => FileService.SavedTemplate += FileService_SavedTemplate, () => FileService.SavedTemplate -= FileService_SavedTemplate); @@ -360,13 +346,6 @@ namespace Umbraco.Web.Cache /// static void ContentService_Copied(IContentService sender, CopyEventArgs e) { - //check if permissions have changed - var permissionsChanged = ((Content)e.Copy).WasPropertyDirty("PermissionsChanged"); - if (permissionsChanged) - { - DistributedCache.Instance.RefreshAllUserGroupPermissionsCache(); - } - //run the un-published cache refresher since copied content is not published DistributedCache.Instance.RefreshUnpublishedPageCache(e.Copy); } @@ -388,33 +367,10 @@ namespace Umbraco.Web.Cache /// /// /// When an entity is saved we need to notify other servers about the change in order for the Examine indexes to - /// stay up-to-date for unpublished content. - /// - /// When an entity is created new permissions may be assigned to it based on it's parent, if that is the - /// case then we need to clear all user group permissions cache. + /// stay up-to-date for unpublished content. /// static void ContentService_Saved(IContentService sender, SaveEventArgs e) { - var clearUserGroupPermissions = false; - e.SavedEntities.ForEach(x => - { - //check if it is new - if (x.IsNewEntity()) - { - //check if permissions have changed - var permissionsChanged = ((Content)x).WasPropertyDirty("PermissionsChanged"); - if (permissionsChanged) - { - clearUserGroupPermissions = true; - } - } - }); - - if (clearUserGroupPermissions) - { - DistributedCache.Instance.RefreshAllUserGroupPermissionsCache(); - } - //filter out the entities that have only been saved (not newly published) since // newly published ones will be synced with the published page cache refresher var unpublished = e.SavedEntities.Where(x => x.JustPublished() == false); @@ -598,30 +554,7 @@ namespace Umbraco.Web.Cache #endregion #region User/permissions event handlers - - static void CacheRefresherEventHandler_AssignedPermissions(PermissionRepository sender, SaveEventArgs e) - { - var groupIds = e.SavedEntities.Select(x => x.UserGroupId).Distinct(); - foreach (var groupId in groupIds) - { - DistributedCache.Instance.RefreshUserGroupPermissionsCache(groupId); - } - } - - static void PermissionDeleted(UserGroupPermission sender, DeleteEventArgs e) - { - InvalidateCacheForPermissionsChange(sender); - } - - static void PermissionUpdated(UserGroupPermission sender, SaveEventArgs e) - { - InvalidateCacheForPermissionsChange(sender); - } - - static void PermissionNew(UserGroupPermission sender, NewEventArgs e) - { - InvalidateCacheForPermissionsChange(sender); - } + static void UserService_SavedUser(IUserService sender, SaveEventArgs e) { @@ -642,22 +575,7 @@ namespace Umbraco.Web.Cache { e.DeletedEntities.ForEach(x => DistributedCache.Instance.RemoveUserGroupCache(x.Id)); } - - private static void InvalidateCacheForPermissionsChange(UserGroupPermission sender) - { - if (sender.UserGroup != null) - { - DistributedCache.Instance.RefreshUserGroupPermissionsCache(sender.UserGroup.Id); - } - else if (sender.UserId > -1) - { - DistributedCache.Instance.RefreshUserGroupPermissionsCache(sender.UserId); - } - else if (sender.NodeIds.Any()) - { - DistributedCache.Instance.RefreshAllUserGroupPermissionsCache(); - } - } + #endregion diff --git a/src/Umbraco.Web/Cache/DistributedCacheExtensions.cs b/src/Umbraco.Web/Cache/DistributedCacheExtensions.cs index f8e8b412c5..397410dbd5 100644 --- a/src/Umbraco.Web/Cache/DistributedCacheExtensions.cs +++ b/src/Umbraco.Web/Cache/DistributedCacheExtensions.cs @@ -79,24 +79,6 @@ namespace Umbraco.Web.Cache #endregion - #region User group permissions cache - - public static void RemoveUserGroupPermissionsCache(this DistributedCache dc, int groupId) - { - dc.Remove(DistributedCache.UserGroupPermissionsCacheRefresherGuid, groupId); - } - - public static void RefreshUserGroupPermissionsCache(this DistributedCache dc, int groupId) - { - dc.Refresh(DistributedCache.UserGroupPermissionsCacheRefresherGuid, groupId); - } - - public static void RefreshAllUserGroupPermissionsCache(this DistributedCache dc) - { - dc.RefreshAll(DistributedCache.UserGroupPermissionsCacheRefresherGuid); - } - - #endregion #region Template cache diff --git a/src/Umbraco.Web/Cache/UserGroupCacheRefresher.cs b/src/Umbraco.Web/Cache/UserGroupCacheRefresher.cs index e6447d1f45..84496b61fd 100644 --- a/src/Umbraco.Web/Cache/UserGroupCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/UserGroupCacheRefresher.cs @@ -34,10 +34,6 @@ namespace Umbraco.Web.Cache { userGroupCache.Result.ClearCacheByKeySearch(UserGroupRepository.GetByAliasCacheKeyPrefix); } - if (UserGroupPermissionsCache) - { - UserGroupPermissionsCache.Result.ClearCacheByKeySearch(CacheKeys.UserGroupPermissionsCacheKey); - } base.RefreshAll(); } @@ -56,20 +52,8 @@ namespace Umbraco.Web.Cache userGroupCache.Result.ClearCacheItem(RepositoryBase.GetCacheIdKey(id)); userGroupCache.Result.ClearCacheByKeySearch(UserGroupRepository.GetByAliasCacheKeyPrefix); } - - if (UserGroupPermissionsCache) - { - //TODO: Is this good enough for all users attached to this? - var keyStartsWith = string.Format("{0}{1}", CacheKeys.UserGroupPermissionsCacheKey, id); - UserGroupPermissionsCache.Result.ClearCacheByKeySearch(keyStartsWith); - } - + base.Remove(id); } - - private Attempt UserGroupPermissionsCache - { - get { return ApplicationContext.Current.ApplicationCache.IsolatedRuntimeCache.GetCache(); } - } } } \ No newline at end of file diff --git a/src/Umbraco.Web/Cache/UserGroupPermissionsCacheRefresher.cs b/src/Umbraco.Web/Cache/UserGroupPermissionsCacheRefresher.cs index 8ea1b26f47..405da0b306 100644 --- a/src/Umbraco.Web/Cache/UserGroupPermissionsCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/UserGroupPermissionsCacheRefresher.cs @@ -1,17 +1,13 @@ using System; +using System.ComponentModel; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Models.Membership; namespace Umbraco.Web.Cache { - /// - /// Used only to invalidate the user permissions cache - /// - /// - /// The UserGroupCacheRefresher will also clear a groups's permissions cache, this refresher is for invalidating only permissions - /// for user groups/content, not the groups themselves. - /// + [Obsolete("This is no longer used and will be removed from the codebase in the future")] + [EditorBrowsable(EditorBrowsableState.Never)] public sealed class UserGroupPermissionsCacheRefresher : CacheRefresherBase { protected override UserGroupPermissionsCacheRefresher Instance @@ -29,30 +25,6 @@ namespace Umbraco.Web.Cache { get { return "User group permissions cache refresher"; } } - - public override void RefreshAll() - { - if (UserGroupPermissionsCache) - UserGroupPermissionsCache.Result.ClearCacheByKeySearch(CacheKeys.UserGroupPermissionsCacheKey); - base.RefreshAll(); - } - - public override void Refresh(int id) - { - Remove(id); - base.Refresh(id); - } - - public override void Remove(int id) - { - if (UserGroupPermissionsCache) - UserGroupPermissionsCache.Result.ClearCacheByKeySearch(string.Format("{0}{1}", CacheKeys.UserGroupPermissionsCacheKey, id)); - base.Remove(id); - } - - private Attempt UserGroupPermissionsCache - { - get { return ApplicationContext.Current.ApplicationCache.IsolatedRuntimeCache.GetCache(); } - } + } } \ No newline at end of file