@@ -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<DocumentNotificationResponseModel>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> Notifications(Guid key)
|
||||
{
|
||||
IContent? content = await _contentEditingService.GetAsync(key);
|
||||
return content != null
|
||||
? Ok(await _documentNotificationPresentationFactory.CreateNotificationModelsAsync(content))
|
||||
: DocumentNotFound();
|
||||
}
|
||||
}
|
||||
@@ -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<IActionResult> 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());
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,6 @@ internal static class DocumentBuilderExtensions
|
||||
internal static IUmbracoBuilder AddDocuments(this IUmbracoBuilder builder)
|
||||
{
|
||||
builder.Services.AddTransient<IDocumentPresentationFactory, DocumentPresentationFactory>();
|
||||
builder.Services.AddTransient<IDocumentNotificationPresentationFactory, DocumentNotificationPresentationFactory>();
|
||||
builder.Services.AddTransient<IContentUrlFactory, ContentUrlFactory>();
|
||||
builder.Services.AddTransient<IDocumentEditingPresentationFactory, DocumentEditingPresentationFactory>();
|
||||
|
||||
|
||||
@@ -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<IEnumerable<DocumentNotificationResponseModel>> CreateNotificationModelsAsync(IContent content)
|
||||
{
|
||||
var subscribedActionIds = _notificationService
|
||||
.GetUserNotifications(_backOfficeSecurityAccessor.BackOfficeSecurity?.CurrentUser, content.Path)?
|
||||
.Select(n => n.Action)
|
||||
.ToArray()
|
||||
?? Array.Empty<string>();
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -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<IEnumerable<DocumentNotificationResponseModel>> CreateNotificationModelsAsync(IContent content);
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
namespace Umbraco.Cms.Api.Management.ViewModels.Document;
|
||||
|
||||
public class UpdateDocumentNotificationsRequestModel
|
||||
{
|
||||
public required string[] SubscribedActionIds { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user