Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions ContentProtector/Components/ActionBlocker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private void ContentService_Trashing(IContentService sender,MoveEventArgs<IConte
int _currentUserId;

using(var contextReference = _context.EnsureUmbracoContext()) {
_currentUserId = contextReference.UmbracoContext.Security.CurrentUser.Id;
_currentUserId = contextReference.UmbracoContext.Security.IsAuthenticated() ? contextReference.UmbracoContext.Security.CurrentUser.Id : Umbraco.Core.Constants.Security.SuperUserId;
}

try {
Expand All @@ -57,9 +57,9 @@ private void ContentService_Trashing(IContentService sender,MoveEventArgs<IConte
}

foreach(var node in eventArgs.MoveInfoCollection) {
if(trash != null) {
if(trash != null) {
if(trash.nodes.Contains(node.Entity.Id.ToString()) || trash.disableAction) {
if(!trash.userExceptions.Split(',').Contains(_currentUserId.ToString())) {
if(!trash.userExceptions.Split(',').Contains(_currentUserId.ToString())) {
eventArgs.CancelOperation(new EventMessage("Action rejected. Contact website admin","You cannot trash " + node.Entity.Name,EventMessageType.Error));
}
}
Expand All @@ -72,7 +72,7 @@ private void ContentService_Deleting(IContentService sender,DeleteEventArgs<ICon
int _currentUserId;

using(var contextReference = _context.EnsureUmbracoContext()) {
_currentUserId = contextReference.UmbracoContext.Security.CurrentUser.Id;
_currentUserId = contextReference.UmbracoContext.Security.IsAuthenticated() ? contextReference.UmbracoContext.Security.CurrentUser.Id : Umbraco.Core.Constants.Security.SuperUserId;
}

try {
Expand Down Expand Up @@ -103,7 +103,7 @@ private void ContentService_RollingBack(IContentService sender,RollbackEventArgs
int _currentUserId;

using(var contextReference = _context.EnsureUmbracoContext()) {
_currentUserId = contextReference.UmbracoContext.Security.CurrentUser.Id;
_currentUserId = contextReference.UmbracoContext.Security.IsAuthenticated() ? contextReference.UmbracoContext.Security.CurrentUser.Id : Umbraco.Core.Constants.Security.SuperUserId;
}

try {
Expand All @@ -117,22 +117,22 @@ private void ContentService_RollingBack(IContentService sender,RollbackEventArgs
catch(Exception ex) {
_logger.Error<ActionModel>("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<IContent> eventArgs) {
ActionModel unpublish = null;
int _currentUserId;

using(var contextReference = _context.EnsureUmbracoContext()) {
_currentUserId = contextReference.UmbracoContext.Security.CurrentUser.Id;
_currentUserId = contextReference.UmbracoContext.Security.IsAuthenticated() ? contextReference.UmbracoContext.Security.CurrentUser.Id : Umbraco.Core.Constants.Security.SuperUserId;
}

try {
Expand Down Expand Up @@ -163,7 +163,7 @@ private void ContentService_Publishing(IContentService sender,ContentPublishingE
int _currentUserId;

using(var contextReference = _context.EnsureUmbracoContext()) {
_currentUserId = contextReference.UmbracoContext.Security.CurrentUser.Id;
_currentUserId = contextReference.UmbracoContext.Security.IsAuthenticated() ? contextReference.UmbracoContext.Security.CurrentUser.Id : Umbraco.Core.Constants.Security.SuperUserId;
}

try {
Expand Down Expand Up @@ -194,7 +194,7 @@ private void ContentService_Publishing(IContentService sender,ContentPublishingE
// int _currentUserId;

// using(var contextReference = _context.EnsureUmbracoContext()) {
// _currentUserId = contextReference.UmbracoContext.Security.CurrentUser.Id;
// _currentUserId = contextReference.UmbracoContext.Security.IsAuthenticated() ? contextReference.UmbracoContext.Security.CurrentUser.Id : Umbraco.Core.Constants.Security.SuperUserId;
// }

// try {
Expand All @@ -208,25 +208,25 @@ private void ContentService_Publishing(IContentService sender,ContentPublishingE
// catch(Exception ex) {
// _logger.Error<ActionModel>("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<IContent> eventArgs) {
// ActionModel move = null;
// int _currentUserId;

// using(var contextReference = _context.EnsureUmbracoContext()) {
// _currentUserId = contextReference.UmbracoContext.Security.CurrentUser.Id;
// _currentUserId = contextReference.UmbracoContext.Security.IsAuthenticated() ? contextReference.UmbracoContext.Security.CurrentUser.Id : Umbraco.Core.Constants.Security.SuperUserId;
// }

// try {
Expand Down Expand Up @@ -257,7 +257,7 @@ private void ContentService_Saving(IContentService sender,ContentSavingEventArgs
int _currentUserId;

using(var contextReference = _context.EnsureUmbracoContext()) {
_currentUserId = contextReference.UmbracoContext.Security.CurrentUser.Id;
_currentUserId = contextReference.UmbracoContext.Security.IsAuthenticated() ? contextReference.UmbracoContext.Security.CurrentUser.Id : Umbraco.Core.Constants.Security.SuperUserId;
}

try {
Expand All @@ -280,8 +280,8 @@ private void ContentService_Saving(IContentService sender,ContentSavingEventArgs
}
}
}
}
}
}
}

public void Terminate() {
}
Expand Down