From 9993bcfe97a5bc98a041878d21a7320415b0f60c Mon Sep 17 00:00:00 2001 From: Gavin Faux Date: Fri, 25 Nov 2022 16:10:03 +0000 Subject: [PATCH 1/2] Fix #2 If current user not authenticated assume scheduled publishing as root. NOTE: Root user should be added to User Exception list --- ContentProtector/Components/ActionBlocker.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ContentProtector/Components/ActionBlocker.cs b/ContentProtector/Components/ActionBlocker.cs index 6fcb4b9..fbbf0a5 100644 --- a/ContentProtector/Components/ActionBlocker.cs +++ b/ContentProtector/Components/ActionBlocker.cs @@ -41,7 +41,7 @@ private void ContentService_Trashing(IContentService sender,MoveEventArgs Date: Thu, 1 Dec 2022 10:06:47 +0000 Subject: [PATCH 2/2] Use Umbraco Constant --- ContentProtector/Components/ActionBlocker.cs | 36 ++++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/ContentProtector/Components/ActionBlocker.cs b/ContentProtector/Components/ActionBlocker.cs index fbbf0a5..c397f51 100644 --- a/ContentProtector/Components/ActionBlocker.cs +++ b/ContentProtector/Components/ActionBlocker.cs @@ -41,7 +41,7 @@ private void ContentService_Trashing(IContentService sender,MoveEventArgs("Failed to get Content Protector setting for rollBack action: " + ex.Message); } - + if(rollBack != null) { if(rollBack.nodes.Contains(eventArgs.Entity.Id.ToString()) || rollBack.disableAction) { if(!rollBack.userExceptions.Split(',').Contains(_currentUserId.ToString())) { - eventArgs.CancelOperation(new EventMessage("Action rejected. Contact website admin","You cannot rollBack " + eventArgs.Entity.Name,EventMessageType.Error)); + eventArgs.CancelOperation(new EventMessage("Action rejected. Contact website admin","You cannot rollBack " + eventArgs.Entity.Name,EventMessageType.Error)); } } - } + } } private void ContentService_Unpublishing(IContentService sender,PublishEventArgs eventArgs) { @@ -132,7 +132,7 @@ private void ContentService_Unpublishing(IContentService sender,PublishEventArgs int _currentUserId; using(var contextReference = _context.EnsureUmbracoContext()) { - _currentUserId = contextReference.UmbracoContext.Security.IsAuthenticated() ? contextReference.UmbracoContext.Security.CurrentUser.Id : -1; + _currentUserId = contextReference.UmbracoContext.Security.IsAuthenticated() ? contextReference.UmbracoContext.Security.CurrentUser.Id : Umbraco.Core.Constants.Security.SuperUserId; } try { @@ -163,7 +163,7 @@ private void ContentService_Publishing(IContentService sender,ContentPublishingE int _currentUserId; using(var contextReference = _context.EnsureUmbracoContext()) { - _currentUserId = contextReference.UmbracoContext.Security.IsAuthenticated() ? contextReference.UmbracoContext.Security.CurrentUser.Id : -1; + _currentUserId = contextReference.UmbracoContext.Security.IsAuthenticated() ? contextReference.UmbracoContext.Security.CurrentUser.Id : Umbraco.Core.Constants.Security.SuperUserId; } try { @@ -194,7 +194,7 @@ private void ContentService_Publishing(IContentService sender,ContentPublishingE // int _currentUserId; // using(var contextReference = _context.EnsureUmbracoContext()) { - // _currentUserId = contextReference.UmbracoContext.Security.IsAuthenticated() ? contextReference.UmbracoContext.Security.CurrentUser.Id : -1; + // _currentUserId = contextReference.UmbracoContext.Security.IsAuthenticated() ? contextReference.UmbracoContext.Security.CurrentUser.Id : Umbraco.Core.Constants.Security.SuperUserId; // } // try { @@ -208,17 +208,17 @@ private void ContentService_Publishing(IContentService sender,ContentPublishingE // catch(Exception ex) { // _logger.Error("Failed to get Content Protector setting for copy action: " + ex.Message); // } - + // if(copy != null) { // if(copy.nodes.Contains(eventArgs.Copy.Id.ToString())) { - // if(!copy.userExceptions.Split(',').Contains(_currentUserId.ToString())) { + // if(!copy.userExceptions.Split(',').Contains(_currentUserId.ToString())) { // eventArgs.Cancel = true; // eventArgs.CanCancel = true; // eventArgs.Messages.Add(new EventMessage("Action rejected. Contact website admin","You cannot copy " + eventArgs.Copy.Name,EventMessageType.Error)); // } // } // } - + //} //private void ContentService_Moving(IContentService sender,MoveEventArgs eventArgs) { @@ -226,7 +226,7 @@ private void ContentService_Publishing(IContentService sender,ContentPublishingE // int _currentUserId; // using(var contextReference = _context.EnsureUmbracoContext()) { - // _currentUserId = contextReference.UmbracoContext.Security.IsAuthenticated() ? contextReference.UmbracoContext.Security.CurrentUser.Id : -1; + // _currentUserId = contextReference.UmbracoContext.Security.IsAuthenticated() ? contextReference.UmbracoContext.Security.CurrentUser.Id : Umbraco.Core.Constants.Security.SuperUserId; // } // try { @@ -257,7 +257,7 @@ private void ContentService_Saving(IContentService sender,ContentSavingEventArgs int _currentUserId; using(var contextReference = _context.EnsureUmbracoContext()) { - _currentUserId = contextReference.UmbracoContext.Security.IsAuthenticated() ? contextReference.UmbracoContext.Security.CurrentUser.Id : -1; + _currentUserId = contextReference.UmbracoContext.Security.IsAuthenticated() ? contextReference.UmbracoContext.Security.CurrentUser.Id : Umbraco.Core.Constants.Security.SuperUserId; } try { @@ -280,8 +280,8 @@ private void ContentService_Saving(IContentService sender,ContentSavingEventArgs } } } - } - } + } + } public void Terminate() { }