From 876d390d115df05f1f33e4bd534a3c128be5e149 Mon Sep 17 00:00:00 2001 From: Gavin Faux Date: Fri, 25 Nov 2022 16:34:48 +0000 Subject: [PATCH 1/3] Service Support If current user not authenticated assume background service as root (e.g. scheduled publishing). NOTE: Root user should be added to User Exception list --- .../App_Plugins/MediaProtector/Components/EventBlocker.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/MediaProtector/App_Plugins/MediaProtector/Components/EventBlocker.cs b/MediaProtector/App_Plugins/MediaProtector/Components/EventBlocker.cs index fbe10db..abea2b4 100644 --- a/MediaProtector/App_Plugins/MediaProtector/Components/EventBlocker.cs +++ b/MediaProtector/App_Plugins/MediaProtector/Components/EventBlocker.cs @@ -38,7 +38,7 @@ private void MediaService_Saving(IMediaService sender,SaveEventArgs even int _currentUserId; using(var contextReference = _context.EnsureUmbracoContext()) { - _currentUserId = contextReference.UmbracoContext.Security.CurrentUser.Id; + _currentUserId = contextReference.UmbracoContext.Security.IsAuthenticated() ? contextReference.UmbracoContext.Security.CurrentUser.Id : -1; } using(var scope = _scopeProvider.CreateScope(autoComplete: true)) { @@ -70,7 +70,7 @@ private void MediaService_Deleting(IMediaService sender,DeleteEventArgs int _currentUserId; using(var contextReference = _context.EnsureUmbracoContext()) { - _currentUserId = contextReference.UmbracoContext.Security.CurrentUser.Id; + _currentUserId = contextReference.UmbracoContext.Security.IsAuthenticated() ? contextReference.UmbracoContext.Security.CurrentUser.Id : -1; } using(var scope = _scopeProvider.CreateScope(autoComplete: true)) { @@ -102,7 +102,7 @@ private void MediaService_Moving(IMediaService sender,MoveEventArgs even int _currentUserId; using(var contextReference = _context.EnsureUmbracoContext()) { - _currentUserId = contextReference.UmbracoContext.Security.CurrentUser.Id; + _currentUserId = contextReference.UmbracoContext.Security.IsAuthenticated() ? contextReference.UmbracoContext.Security.CurrentUser.Id : -1; } using(var scope = _scopeProvider.CreateScope(autoComplete: true)) { @@ -134,7 +134,7 @@ private void MediaService_Trashing(IMediaService sender,MoveEventArgs ev int _currentUserId; using(var contextReference = _context.EnsureUmbracoContext()) { - _currentUserId = contextReference.UmbracoContext.Security.CurrentUser.Id; + _currentUserId = contextReference.UmbracoContext.Security.IsAuthenticated() ? contextReference.UmbracoContext.Security.CurrentUser.Id : -1; } using(var scope = _scopeProvider.CreateScope(autoComplete: true)) { From f2d5001b68d5fc63a2994f8654f377b96ce0bf52 Mon Sep 17 00:00:00 2001 From: Gavin Faux Date: Thu, 1 Dec 2022 10:10:21 +0000 Subject: [PATCH 2/3] Use Umbraco Constant --- .../App_Plugins/MediaProtector/Components/EventBlocker.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/MediaProtector/App_Plugins/MediaProtector/Components/EventBlocker.cs b/MediaProtector/App_Plugins/MediaProtector/Components/EventBlocker.cs index abea2b4..cd27cd3 100644 --- a/MediaProtector/App_Plugins/MediaProtector/Components/EventBlocker.cs +++ b/MediaProtector/App_Plugins/MediaProtector/Components/EventBlocker.cs @@ -38,7 +38,7 @@ private void MediaService_Saving(IMediaService sender,SaveEventArgs even 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; } using(var scope = _scopeProvider.CreateScope(autoComplete: true)) { @@ -70,7 +70,7 @@ private void MediaService_Deleting(IMediaService sender,DeleteEventArgs 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; } using(var scope = _scopeProvider.CreateScope(autoComplete: true)) { @@ -102,7 +102,7 @@ private void MediaService_Moving(IMediaService sender,MoveEventArgs even 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; } using(var scope = _scopeProvider.CreateScope(autoComplete: true)) { @@ -134,7 +134,7 @@ private void MediaService_Trashing(IMediaService sender,MoveEventArgs ev 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; } using(var scope = _scopeProvider.CreateScope(autoComplete: true)) { From 31377b3be3aa4e3bc032488da0e8e76b9961864a Mon Sep 17 00:00:00 2001 From: Gavin Faux Date: Thu, 1 Dec 2022 10:11:09 +0000 Subject: [PATCH 3/3] Icons amends (from current release) --- .../MediaProtector/JsControllers/content.controller.js | 2 +- .../MediaProtector/backoffice/mediaProtector/info.html | 2 +- .../MediaProtector/backoffice/mediaProtector/protection.html | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/MediaProtector/App_Plugins/MediaProtector/JsControllers/content.controller.js b/MediaProtector/App_Plugins/MediaProtector/JsControllers/content.controller.js index 2ae8df2..df47075 100644 --- a/MediaProtector/App_Plugins/MediaProtector/JsControllers/content.controller.js +++ b/MediaProtector/App_Plugins/MediaProtector/JsControllers/content.controller.js @@ -12,7 +12,7 @@ { name: 'Protection', alias: 'protection', - icon: 'icon-custom-account-balance-wallet', + icon: 'icon-lock', view: backofficeView + 'protection.html', active: true }, diff --git a/MediaProtector/App_Plugins/MediaProtector/backoffice/mediaProtector/info.html b/MediaProtector/App_Plugins/MediaProtector/backoffice/mediaProtector/info.html index 2aea239..09fa56e 100644 --- a/MediaProtector/App_Plugins/MediaProtector/backoffice/mediaProtector/info.html +++ b/MediaProtector/App_Plugins/MediaProtector/backoffice/mediaProtector/info.html @@ -15,7 +15,7 @@

General Information

indicate that there is a user exception.
  • - indicate that all nodes will be protected, regardless of the selection. + indicate that all nodes will be protected, regardless of the selection.
  • diff --git a/MediaProtector/App_Plugins/MediaProtector/backoffice/mediaProtector/protection.html b/MediaProtector/App_Plugins/MediaProtector/backoffice/mediaProtector/protection.html index b25924c..0715c02 100644 --- a/MediaProtector/App_Plugins/MediaProtector/backoffice/mediaProtector/protection.html +++ b/MediaProtector/App_Plugins/MediaProtector/backoffice/mediaProtector/protection.html @@ -22,7 +22,7 @@

    - +