From e9970f63fa9f8b7f516e473ddf04a7a043ac741c Mon Sep 17 00:00:00 2001 From: "Paige.Ligeti" Date: Thu, 17 Oct 2024 17:02:53 +0100 Subject: [PATCH] Fix for bug #49 to ensure only user ids set are unfrozen when maintenance mode is active --- .../Models/MaintenanceModeSettings.cs | 15 +++++++++++++++ .../Content/FreezeContentDeletingNotification.cs | 2 +- .../Content/FreezeContentMovingNotification.cs | 2 +- ...FreezeContentMovingToRecycleBinNotification.cs | 2 +- .../FreezeContentPublishingNotification.cs | 2 +- .../Content/FreezeContentSavingNotification.cs | 2 +- .../FreezeContentUnpublishingNotification.cs | 2 +- .../Media/FreezeMediaDeletingNotification.cs | 2 +- .../Media/FreezeMediaMovingNotification.cs | 2 +- .../FreezeMediaMovingToRecycleBinNotification.cs | 2 +- .../Media/FreezeMediaSavingNotification.cs | 2 +- 11 files changed, 25 insertions(+), 10 deletions(-) diff --git a/Our.Umbraco.MaintenanceMode/Models/MaintenanceModeSettings.cs b/Our.Umbraco.MaintenanceMode/Models/MaintenanceModeSettings.cs index bb8e323..5867eb5 100644 --- a/Our.Umbraco.MaintenanceMode/Models/MaintenanceModeSettings.cs +++ b/Our.Umbraco.MaintenanceMode/Models/MaintenanceModeSettings.cs @@ -1,5 +1,7 @@ using Newtonsoft.Json.Serialization; using Newtonsoft.Json; +using System.Linq; +using System.Collections.Generic; namespace Our.Umbraco.MaintenanceMode.Models { @@ -13,6 +15,19 @@ public class MaintenanceModeSettings /// users who can get past the content freeze /// public string UnfrozenUsers { get; set; } = ""; + + public List UnfrozenUsersList + { + get + { + return UnfrozenUsers?.Split(',') + .Select(s => s.Trim()) + .Where(s => !string.IsNullOrEmpty(s)) + .Distinct() + .ToList() ?? new List(); + } + } + public MaintenanceMode ViewModel { get; set; } } } diff --git a/Our.Umbraco.MaintenanceMode/NotificationHandlers/Content/FreezeContentDeletingNotification.cs b/Our.Umbraco.MaintenanceMode/NotificationHandlers/Content/FreezeContentDeletingNotification.cs index de3ee93..1ca93f8 100644 --- a/Our.Umbraco.MaintenanceMode/NotificationHandlers/Content/FreezeContentDeletingNotification.cs +++ b/Our.Umbraco.MaintenanceMode/NotificationHandlers/Content/FreezeContentDeletingNotification.cs @@ -21,7 +21,7 @@ public void Handle(ContentDeletingNotification notification) { if (_backofficeUserAccessor.BackofficeUser == null) return; - if (_maintenanceModeService.Status.Settings.UnfrozenUsers.Contains(_backofficeUserAccessor.BackofficeUser.GetId().ToString())) return; + if (_maintenanceModeService.Status.Settings.UnfrozenUsersList.Contains(_backofficeUserAccessor.BackofficeUser.GetId().ToString())) return; notification.CancelOperation(new EventMessage("Warning", "This site is currently frozen during updates", EventMessageType.Error)); diff --git a/Our.Umbraco.MaintenanceMode/NotificationHandlers/Content/FreezeContentMovingNotification.cs b/Our.Umbraco.MaintenanceMode/NotificationHandlers/Content/FreezeContentMovingNotification.cs index 981e0fc..0b31f8f 100644 --- a/Our.Umbraco.MaintenanceMode/NotificationHandlers/Content/FreezeContentMovingNotification.cs +++ b/Our.Umbraco.MaintenanceMode/NotificationHandlers/Content/FreezeContentMovingNotification.cs @@ -21,7 +21,7 @@ public void Handle(ContentMovingNotification notification) { if (_backofficeUserAccessor.BackofficeUser == null) return; - if (_maintenanceModeService.Status.Settings.UnfrozenUsers.Contains(_backofficeUserAccessor.BackofficeUser.GetId().ToString())) return; + if (_maintenanceModeService.Status.Settings.UnfrozenUsersList.Contains(_backofficeUserAccessor.BackofficeUser.GetId().ToString())) return; notification.CancelOperation(new EventMessage("Warning", "This site is currently frozen during updates", EventMessageType.Error)); diff --git a/Our.Umbraco.MaintenanceMode/NotificationHandlers/Content/FreezeContentMovingToRecycleBinNotification.cs b/Our.Umbraco.MaintenanceMode/NotificationHandlers/Content/FreezeContentMovingToRecycleBinNotification.cs index e7f0d56..969381a 100644 --- a/Our.Umbraco.MaintenanceMode/NotificationHandlers/Content/FreezeContentMovingToRecycleBinNotification.cs +++ b/Our.Umbraco.MaintenanceMode/NotificationHandlers/Content/FreezeContentMovingToRecycleBinNotification.cs @@ -21,7 +21,7 @@ public void Handle(ContentMovingToRecycleBinNotification notification) { if (_backofficeUserAccessor.BackofficeUser == null) return; - if (_maintenanceModeService.Status.Settings.UnfrozenUsers.Contains(_backofficeUserAccessor.BackofficeUser.GetId().ToString())) return; + if (_maintenanceModeService.Status.Settings.UnfrozenUsersList.Contains(_backofficeUserAccessor.BackofficeUser.GetId().ToString())) return; notification.CancelOperation(new EventMessage("Warning", "This site is currently frozen during updates", EventMessageType.Error)); diff --git a/Our.Umbraco.MaintenanceMode/NotificationHandlers/Content/FreezeContentPublishingNotification.cs b/Our.Umbraco.MaintenanceMode/NotificationHandlers/Content/FreezeContentPublishingNotification.cs index 6662b6c..57b7a4f 100644 --- a/Our.Umbraco.MaintenanceMode/NotificationHandlers/Content/FreezeContentPublishingNotification.cs +++ b/Our.Umbraco.MaintenanceMode/NotificationHandlers/Content/FreezeContentPublishingNotification.cs @@ -21,7 +21,7 @@ public void Handle(ContentPublishingNotification notification) { if (_backofficeUserAccessor.BackofficeUser == null) return; - if (_maintenanceModeService.Status.Settings.UnfrozenUsers.Contains(_backofficeUserAccessor.BackofficeUser.GetId().ToString())) return; + if (_maintenanceModeService.Status.Settings.UnfrozenUsersList.Contains(_backofficeUserAccessor.BackofficeUser.GetId().ToString())) return; notification.CancelOperation(new EventMessage("Warning", "This site is currently frozen during updates", EventMessageType.Error)); diff --git a/Our.Umbraco.MaintenanceMode/NotificationHandlers/Content/FreezeContentSavingNotification.cs b/Our.Umbraco.MaintenanceMode/NotificationHandlers/Content/FreezeContentSavingNotification.cs index c4cc36c..d63387a 100644 --- a/Our.Umbraco.MaintenanceMode/NotificationHandlers/Content/FreezeContentSavingNotification.cs +++ b/Our.Umbraco.MaintenanceMode/NotificationHandlers/Content/FreezeContentSavingNotification.cs @@ -21,7 +21,7 @@ public void Handle(ContentSavingNotification notification) { if (_backofficeUserAccessor.BackofficeUser == null) return; - if (_maintenanceModeService.Status.Settings.UnfrozenUsers.Contains(_backofficeUserAccessor.BackofficeUser.GetId().ToString())) return; + if (_maintenanceModeService.Status.Settings.UnfrozenUsersList.Contains(_backofficeUserAccessor.BackofficeUser.GetId().ToString())) return; notification.CancelOperation(new EventMessage("Warning", "This site is currently frozen during updates", EventMessageType.Error)); diff --git a/Our.Umbraco.MaintenanceMode/NotificationHandlers/Content/FreezeContentUnpublishingNotification.cs b/Our.Umbraco.MaintenanceMode/NotificationHandlers/Content/FreezeContentUnpublishingNotification.cs index 23c2d1f..69abd11 100644 --- a/Our.Umbraco.MaintenanceMode/NotificationHandlers/Content/FreezeContentUnpublishingNotification.cs +++ b/Our.Umbraco.MaintenanceMode/NotificationHandlers/Content/FreezeContentUnpublishingNotification.cs @@ -21,7 +21,7 @@ public void Handle(ContentUnpublishingNotification notification) { if (_backofficeUserAccessor.BackofficeUser == null) return; - if (_maintenanceModeService.Status.Settings.UnfrozenUsers.Contains(_backofficeUserAccessor.BackofficeUser.GetId().ToString())) return; + if (_maintenanceModeService.Status.Settings.UnfrozenUsersList.Contains(_backofficeUserAccessor.BackofficeUser.GetId().ToString())) return; notification.CancelOperation(new EventMessage("Warning", "This site is currently frozen during updates", EventMessageType.Error)); diff --git a/Our.Umbraco.MaintenanceMode/NotificationHandlers/Media/FreezeMediaDeletingNotification.cs b/Our.Umbraco.MaintenanceMode/NotificationHandlers/Media/FreezeMediaDeletingNotification.cs index 1936772..b5b7341 100644 --- a/Our.Umbraco.MaintenanceMode/NotificationHandlers/Media/FreezeMediaDeletingNotification.cs +++ b/Our.Umbraco.MaintenanceMode/NotificationHandlers/Media/FreezeMediaDeletingNotification.cs @@ -21,7 +21,7 @@ public void Handle(MediaDeletingNotification notification) { if (_backofficeUserAccessor.BackofficeUser == null) return; - if (_maintenanceModeService.Status.Settings.UnfrozenUsers.Contains(_backofficeUserAccessor.BackofficeUser.GetId().ToString())) return; + if (_maintenanceModeService.Status.Settings.UnfrozenUsersList.Contains(_backofficeUserAccessor.BackofficeUser.GetId().ToString())) return; notification.CancelOperation(new EventMessage("Warning", "This site is currently frozen during updates", EventMessageType.Error)); diff --git a/Our.Umbraco.MaintenanceMode/NotificationHandlers/Media/FreezeMediaMovingNotification.cs b/Our.Umbraco.MaintenanceMode/NotificationHandlers/Media/FreezeMediaMovingNotification.cs index bc423af..4b6aadd 100644 --- a/Our.Umbraco.MaintenanceMode/NotificationHandlers/Media/FreezeMediaMovingNotification.cs +++ b/Our.Umbraco.MaintenanceMode/NotificationHandlers/Media/FreezeMediaMovingNotification.cs @@ -21,7 +21,7 @@ public void Handle(MediaMovingNotification notification) { if (_backofficeUserAccessor.BackofficeUser == null) return; - if (_maintenanceModeService.Status.Settings.UnfrozenUsers.Contains(_backofficeUserAccessor.BackofficeUser.GetId().ToString())) return; + if (_maintenanceModeService.Status.Settings.UnfrozenUsersList.Contains(_backofficeUserAccessor.BackofficeUser.GetId().ToString())) return; notification.CancelOperation(new EventMessage("Warning", "This site is currently frozen during updates", EventMessageType.Error)); diff --git a/Our.Umbraco.MaintenanceMode/NotificationHandlers/Media/FreezeMediaMovingToRecycleBinNotification.cs b/Our.Umbraco.MaintenanceMode/NotificationHandlers/Media/FreezeMediaMovingToRecycleBinNotification.cs index 88edc98..a4e7688 100644 --- a/Our.Umbraco.MaintenanceMode/NotificationHandlers/Media/FreezeMediaMovingToRecycleBinNotification.cs +++ b/Our.Umbraco.MaintenanceMode/NotificationHandlers/Media/FreezeMediaMovingToRecycleBinNotification.cs @@ -21,7 +21,7 @@ public void Handle(MediaMovingToRecycleBinNotification notification) { if (_backofficeUserAccessor.BackofficeUser == null) return; - if (_maintenanceModeService.Status.Settings.UnfrozenUsers.Contains(_backofficeUserAccessor.BackofficeUser.GetId().ToString())) return; + if (_maintenanceModeService.Status.Settings.UnfrozenUsersList.Contains(_backofficeUserAccessor.BackofficeUser.GetId().ToString())) return; notification.CancelOperation(new EventMessage("Warning", "This site is currently frozen during updates", EventMessageType.Error)); diff --git a/Our.Umbraco.MaintenanceMode/NotificationHandlers/Media/FreezeMediaSavingNotification.cs b/Our.Umbraco.MaintenanceMode/NotificationHandlers/Media/FreezeMediaSavingNotification.cs index a97afff..4a31cb0 100644 --- a/Our.Umbraco.MaintenanceMode/NotificationHandlers/Media/FreezeMediaSavingNotification.cs +++ b/Our.Umbraco.MaintenanceMode/NotificationHandlers/Media/FreezeMediaSavingNotification.cs @@ -21,7 +21,7 @@ public void Handle(MediaSavingNotification notification) { if (_backofficeUserAccessor.BackofficeUser == null) return; - if (_maintenanceModeService.Status.Settings.UnfrozenUsers.Contains(_backofficeUserAccessor.BackofficeUser.GetId().ToString())) return; + if (_maintenanceModeService.Status.Settings.UnfrozenUsersList.Contains(_backofficeUserAccessor.BackofficeUser.GetId().ToString())) return; notification.CancelOperation(new EventMessage("Warning", "This site is currently frozen during updates", EventMessageType.Error));