diff --git a/src/Umbraco.Core/Models/PublishNotificationSaveOptions.cs b/src/Umbraco.Core/Models/PublishNotificationSaveOptions.cs
new file mode 100644
index 0000000000..f49e7f30d6
--- /dev/null
+++ b/src/Umbraco.Core/Models/PublishNotificationSaveOptions.cs
@@ -0,0 +1,28 @@
+namespace Umbraco.Cms.Core.Models;
+
+///
+/// Specifies options for publishing notifcations when saving.
+///
+[Flags]
+public enum PublishNotificationSaveOptions
+{
+ ///
+ /// Do not publish any notifications.
+ ///
+ None = 0,
+
+ ///
+ /// Only publish the saving notification.
+ ///
+ Saving = 1,
+
+ ///
+ /// Only publish the saved notification.
+ ///
+ Saved = 2,
+
+ ///
+ /// Publish all the notifications.
+ ///
+ All = Saving | Saved,
+}
diff --git a/src/Umbraco.Core/Services/IMembershipMemberService.cs b/src/Umbraco.Core/Services/IMembershipMemberService.cs
index 99e64a3686..ee77aedcf7 100644
--- a/src/Umbraco.Core/Services/IMembershipMemberService.cs
+++ b/src/Umbraco.Core/Services/IMembershipMemberService.cs
@@ -135,6 +135,14 @@ public interface IMembershipMemberService : IService
/// or to Save
void Save(T entity);
+ ///
+ /// Saves an
+ ///
+ /// An can be of type or
+ /// or to Save
+ /// Enum for deciding which notifications to publish.
+ void Save(T entity, PublishNotificationSaveOptions publishNotificationSaveOptions) => Save(entity);
+
///
/// Saves a list of objects
///
diff --git a/src/Umbraco.Core/Services/MemberService.cs b/src/Umbraco.Core/Services/MemberService.cs
index 493ab313a7..b405519616 100644
--- a/src/Umbraco.Core/Services/MemberService.cs
+++ b/src/Umbraco.Core/Services/MemberService.cs
@@ -743,7 +743,9 @@ namespace Umbraco.Cms.Core.Services
public void SetLastLogin(string username, DateTime date) => throw new NotImplementedException();
///
- public void Save(IMember member)
+ public void Save(IMember member) => Save(member, PublishNotificationSaveOptions.All);
+
+ public void Save(IMember member, PublishNotificationSaveOptions publishNotificationSaveOptions)
{
// trimming username and email to make sure we have no trailing space
member.Username = member.Username.Trim();
@@ -752,11 +754,15 @@ namespace Umbraco.Cms.Core.Services
EventMessages evtMsgs = EventMessagesFactory.Get();
using ICoreScope scope = ScopeProvider.CreateCoreScope();
- var savingNotification = new MemberSavingNotification(member, evtMsgs);
- if (scope.Notifications.PublishCancelable(savingNotification))
+ MemberSavingNotification? savingNotification = null;
+ if (publishNotificationSaveOptions.HasFlag(PublishNotificationSaveOptions.Saving))
{
- scope.Complete();
- return;
+ savingNotification = new MemberSavingNotification(member, evtMsgs);
+ if (scope.Notifications.PublishCancelable(savingNotification))
+ {
+ scope.Complete();
+ return;
+ }
}
if (string.IsNullOrWhiteSpace(member.Name))
@@ -768,7 +774,13 @@ namespace Umbraco.Cms.Core.Services
_memberRepository.Save(member);
- scope.Notifications.Publish(new MemberSavedNotification(member, evtMsgs).WithStateFrom(savingNotification));
+ if (publishNotificationSaveOptions.HasFlag(PublishNotificationSaveOptions.Saved))
+ {
+ scope.Notifications.Publish(
+ savingNotification is null
+ ? new MemberSavedNotification(member, evtMsgs)
+ : new MemberSavedNotification(member, evtMsgs).WithStateFrom(savingNotification));
+ }
Audit(AuditType.Save, 0, member.Id);
diff --git a/src/Umbraco.Infrastructure/Security/MemberUserStore.cs b/src/Umbraco.Infrastructure/Security/MemberUserStore.cs
index 4e4b43f509..a9c7dc5f2a 100644
--- a/src/Umbraco.Infrastructure/Security/MemberUserStore.cs
+++ b/src/Umbraco.Infrastructure/Security/MemberUserStore.cs
@@ -110,7 +110,7 @@ public class MemberUserStore : UmbracoUserStore x.CreateMember(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()))
.Returns(mockMember);
- _mockMemberService.Setup(x => x.Save(mockMember));
+ _mockMemberService.Setup(x => x.Save(mockMember, PublishNotificationSaveOptions.Saving));
// act
var identityResult = await sut.CreateAsync(fakeUser, CancellationToken.None);
@@ -132,7 +132,7 @@ public class MemberUserStoreTests
Assert.IsTrue(!identityResult.Errors.Any());
_mockMemberService.Verify(x =>
x.CreateMember(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()));
- _mockMemberService.Verify(x => x.Save(mockMember));
+ _mockMemberService.Verify(x => x.Save(mockMember, PublishNotificationSaveOptions.Saving));
}
[Test]