From 313eed96b9ab929afeccde4e9572422d9cc1eeb2 Mon Sep 17 00:00:00 2001 From: kjac Date: Mon, 27 Mar 2023 07:55:55 +0200 Subject: [PATCH] Revert "Add content notifications API" This reverts commit 8202879ba75be28c6b1531a12fac74b13d3f7e33. --- .../Document/NotificationsController.cs | 31 --------------- .../Document/UpdateNotificationsController.cs | 37 ------------------ .../DocumentBuilderExtensions.cs | 1 - ...DocumentNotificationPresentationFactory.cs | 39 ------------------- ...DocumentNotificationPresentationFactory.cs | 9 ----- .../DocumentNotificationsResponseModel.cs | 8 ---- ...UpdateDocumentNotificationsRequestModel.cs | 6 --- 7 files changed, 131 deletions(-) delete mode 100644 src/Umbraco.Cms.Api.Management/Controllers/Document/NotificationsController.cs delete mode 100644 src/Umbraco.Cms.Api.Management/Controllers/Document/UpdateNotificationsController.cs delete mode 100644 src/Umbraco.Cms.Api.Management/Factories/DocumentNotificationPresentationFactory.cs delete mode 100644 src/Umbraco.Cms.Api.Management/Factories/IDocumentNotificationPresentationFactory.cs delete mode 100644 src/Umbraco.Cms.Api.Management/ViewModels/Document/DocumentNotificationsResponseModel.cs delete mode 100644 src/Umbraco.Cms.Api.Management/ViewModels/Document/UpdateDocumentNotificationsRequestModel.cs diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Document/NotificationsController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Document/NotificationsController.cs deleted file mode 100644 index e5917d0a07..0000000000 --- a/src/Umbraco.Cms.Api.Management/Controllers/Document/NotificationsController.cs +++ /dev/null @@ -1,31 +0,0 @@ -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Umbraco.Cms.Api.Management.Factories; -using Umbraco.Cms.Api.Management.ViewModels.Document; -using Umbraco.Cms.Core.Models; -using Umbraco.Cms.Core.Services; - -namespace Umbraco.Cms.Api.Management.Controllers.Document; - -public class NotificationsController : DocumentControllerBase -{ - private readonly IContentEditingService _contentEditingService; - private readonly IDocumentNotificationPresentationFactory _documentNotificationPresentationFactory; - - public NotificationsController(IContentEditingService contentEditingService, IDocumentNotificationPresentationFactory documentNotificationPresentationFactory) - { - _contentEditingService = contentEditingService; - _documentNotificationPresentationFactory = documentNotificationPresentationFactory; - } - - [HttpGet("{key:guid}/notifications")] - [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] - [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task Notifications(Guid key) - { - IContent? content = await _contentEditingService.GetAsync(key); - return content != null - ? Ok(await _documentNotificationPresentationFactory.CreateNotificationModelsAsync(content)) - : DocumentNotFound(); - } -} diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Document/UpdateNotificationsController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Document/UpdateNotificationsController.cs deleted file mode 100644 index 1fc558e369..0000000000 --- a/src/Umbraco.Cms.Api.Management/Controllers/Document/UpdateNotificationsController.cs +++ /dev/null @@ -1,37 +0,0 @@ -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Umbraco.Cms.Api.Management.ViewModels.Document; -using Umbraco.Cms.Core.Models; -using Umbraco.Cms.Core.Security; -using Umbraco.Cms.Core.Services; - -namespace Umbraco.Cms.Api.Management.Controllers.Document; - -public class UpdateNotificationsController : DocumentControllerBase -{ - private readonly IContentEditingService _contentEditingService; - private readonly INotificationService _notificationService; - private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor; - - public UpdateNotificationsController(IContentEditingService contentEditingService, INotificationService notificationService, IBackOfficeSecurityAccessor backOfficeSecurityAccessor) - { - _contentEditingService = contentEditingService; - _notificationService = notificationService; - _backOfficeSecurityAccessor = backOfficeSecurityAccessor; - } - - [HttpPut("{key:guid}/notifications")] - [ProducesResponseType(StatusCodes.Status200OK)] - [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task UpdateNotifications(Guid key, UpdateDocumentNotificationsRequestModel updateModel) - { - IContent? content = await _contentEditingService.GetAsync(key); - if (content == null) - { - return DocumentNotFound(); - } - - _notificationService.SetNotifications(_backOfficeSecurityAccessor.BackOfficeSecurity?.CurrentUser, content, updateModel.SubscribedActionIds); - return await Task.FromResult(Ok()); - } -} diff --git a/src/Umbraco.Cms.Api.Management/DependencyInjection/DocumentBuilderExtensions.cs b/src/Umbraco.Cms.Api.Management/DependencyInjection/DocumentBuilderExtensions.cs index 9b16d23022..604626cfc9 100644 --- a/src/Umbraco.Cms.Api.Management/DependencyInjection/DocumentBuilderExtensions.cs +++ b/src/Umbraco.Cms.Api.Management/DependencyInjection/DocumentBuilderExtensions.cs @@ -11,7 +11,6 @@ internal static class DocumentBuilderExtensions internal static IUmbracoBuilder AddDocuments(this IUmbracoBuilder builder) { builder.Services.AddTransient(); - builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); diff --git a/src/Umbraco.Cms.Api.Management/Factories/DocumentNotificationPresentationFactory.cs b/src/Umbraco.Cms.Api.Management/Factories/DocumentNotificationPresentationFactory.cs deleted file mode 100644 index 549163df91..0000000000 --- a/src/Umbraco.Cms.Api.Management/Factories/DocumentNotificationPresentationFactory.cs +++ /dev/null @@ -1,39 +0,0 @@ -using Umbraco.Cms.Api.Management.ViewModels.Document; -using Umbraco.Cms.Core.Actions; -using Umbraco.Cms.Core.Models; -using Umbraco.Cms.Core.Security; -using Umbraco.Cms.Core.Services; - -namespace Umbraco.Cms.Api.Management.Factories; - -internal sealed class DocumentNotificationPresentationFactory : IDocumentNotificationPresentationFactory -{ - private readonly ActionCollection _actionCollection; - private readonly INotificationService _notificationService; - private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor; - - public DocumentNotificationPresentationFactory(ActionCollection actionCollection, INotificationService notificationService, IBackOfficeSecurityAccessor backOfficeSecurityAccessor) - { - _actionCollection = actionCollection; - _notificationService = notificationService; - _backOfficeSecurityAccessor = backOfficeSecurityAccessor; - } - - public async Task> CreateNotificationModelsAsync(IContent content) - { - var subscribedActionIds = _notificationService - .GetUserNotifications(_backOfficeSecurityAccessor.BackOfficeSecurity?.CurrentUser, content.Path)? - .Select(n => n.Action) - .ToArray() - ?? Array.Empty(); - - var availableActionIds = _actionCollection.Where(a => a.ShowInNotifier).Select(a => a.Letter.ToString()).ToArray(); - - return await Task.FromResult( - availableActionIds.Select(actionId => new DocumentNotificationResponseModel - { - ActionId = actionId, - Subscribed = subscribedActionIds.Contains(actionId) - }).ToArray()); - } -} diff --git a/src/Umbraco.Cms.Api.Management/Factories/IDocumentNotificationPresentationFactory.cs b/src/Umbraco.Cms.Api.Management/Factories/IDocumentNotificationPresentationFactory.cs deleted file mode 100644 index ee0325eff5..0000000000 --- a/src/Umbraco.Cms.Api.Management/Factories/IDocumentNotificationPresentationFactory.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Umbraco.Cms.Api.Management.ViewModels.Document; -using Umbraco.Cms.Core.Models; - -namespace Umbraco.Cms.Api.Management.Factories; - -public interface IDocumentNotificationPresentationFactory -{ - Task> CreateNotificationModelsAsync(IContent content); -} diff --git a/src/Umbraco.Cms.Api.Management/ViewModels/Document/DocumentNotificationsResponseModel.cs b/src/Umbraco.Cms.Api.Management/ViewModels/Document/DocumentNotificationsResponseModel.cs deleted file mode 100644 index b3ae3b8f6e..0000000000 --- a/src/Umbraco.Cms.Api.Management/ViewModels/Document/DocumentNotificationsResponseModel.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Umbraco.Cms.Api.Management.ViewModels.Document; - -public class DocumentNotificationResponseModel -{ - public required string ActionId { get; set; } - - public required bool Subscribed { get; set; } -} diff --git a/src/Umbraco.Cms.Api.Management/ViewModels/Document/UpdateDocumentNotificationsRequestModel.cs b/src/Umbraco.Cms.Api.Management/ViewModels/Document/UpdateDocumentNotificationsRequestModel.cs deleted file mode 100644 index 35b9938fc3..0000000000 --- a/src/Umbraco.Cms.Api.Management/ViewModels/Document/UpdateDocumentNotificationsRequestModel.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Umbraco.Cms.Api.Management.ViewModels.Document; - -public class UpdateDocumentNotificationsRequestModel -{ - public required string[] SubscribedActionIds { get; set; } -}