Skip to content
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
using Asp.Versioning;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Api.Management.Extensions;
using Umbraco.Cms.Api.Management.ViewModels.PartialView;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Core.Mapping;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Security;
Expand All @@ -21,21 +25,39 @@ public class CreatePartialViewController : PartialViewControllerBase
private readonly IPartialViewService _partialViewService;
private readonly IUmbracoMapper _umbracoMapper;
private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor;
private readonly IOptions<RuntimeSettings> _runtimeSettings;

/// <summary>
/// Initializes a new instance of the <see cref="CreatePartialViewController"/> class with the specified services.
/// </summary>
/// <param name="partialViewService">The service used to manage partial views.</param>
/// <param name="umbracoMapper">The mapper used for Umbraco model mapping.</param>
/// <param name="backOfficeSecurityAccessor">Provides access to back office security information.</param>
/// <param name="runtimeSettings">The runtime configuration settings.</param>
[ActivatorUtilitiesConstructor]
public CreatePartialViewController(
IPartialViewService partialViewService,
IUmbracoMapper umbracoMapper,
IBackOfficeSecurityAccessor backOfficeSecurityAccessor)
IBackOfficeSecurityAccessor backOfficeSecurityAccessor,
IOptions<RuntimeSettings> runtimeSettings)
{
_partialViewService = partialViewService;
_umbracoMapper = umbracoMapper;
_backOfficeSecurityAccessor = backOfficeSecurityAccessor;
_runtimeSettings = runtimeSettings;
}

[Obsolete("Use the constructor with all parameters. Scheduled for removal in Umbraco 19.")]
public CreatePartialViewController(
IPartialViewService partialViewService,
IUmbracoMapper umbracoMapper,
IBackOfficeSecurityAccessor backOfficeSecurityAccessor)
: this(
partialViewService,
umbracoMapper,
backOfficeSecurityAccessor,
StaticServiceProvider.Instance.GetRequiredService<IOptions<RuntimeSettings>>())
{
}

/// <summary>
Expand All @@ -55,6 +77,11 @@ public async Task<IActionResult> Create(
CancellationToken cancellationToken,
CreatePartialViewRequestModel requestModel)
{
if (_runtimeSettings.Value.Mode == RuntimeMode.Production)
{
return PartialViewOperationStatusResult(PartialViewOperationStatus.NotAllowedInProductionMode);
}
Comment thread
AndyButland marked this conversation as resolved.
Outdated

PartialViewCreateModel createModel = _umbracoMapper.Map<PartialViewCreateModel>(requestModel)!;
Attempt<IPartialView?, PartialViewOperationStatus> createAttempt = await _partialViewService.CreateAsync(createModel, CurrentUserKey(_backOfficeSecurityAccessor));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
using Asp.Versioning;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Api.Management.Extensions;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Core.Security;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Services.OperationStatus;
Expand All @@ -16,18 +20,34 @@ public class DeletePartialViewController : PartialViewControllerBase
{
private readonly IPartialViewService _partialViewService;
private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor;
private readonly IOptions<RuntimeSettings> _runtimeSettings;

/// <summary>
/// Initializes a new instance of the <see cref="DeletePartialViewController"/> class, responsible for handling requests to delete partial views.
/// </summary>
/// <param name="partialViewService">Service used to manage partial views.</param>
/// <param name="backOfficeSecurityAccessor">Accessor for back office security context.</param>
/// <param name="runtimeSettings">The runtime configuration settings.</param>
[ActivatorUtilitiesConstructor]
public DeletePartialViewController(
IPartialViewService partialViewService,
IBackOfficeSecurityAccessor backOfficeSecurityAccessor)
IBackOfficeSecurityAccessor backOfficeSecurityAccessor,
IOptions<RuntimeSettings> runtimeSettings)
{
_partialViewService = partialViewService;
_backOfficeSecurityAccessor = backOfficeSecurityAccessor;
_runtimeSettings = runtimeSettings;
}

[Obsolete("Use the constructor with all parameters. Scheduled for removal in Umbraco 19.")]
public DeletePartialViewController(
IPartialViewService partialViewService,
IBackOfficeSecurityAccessor backOfficeSecurityAccessor)
: this(
partialViewService,
backOfficeSecurityAccessor,
StaticServiceProvider.Instance.GetRequiredService<IOptions<RuntimeSettings>>())
{
}

[HttpDelete("{*path}")]
Expand All @@ -39,6 +59,11 @@ public DeletePartialViewController(
[EndpointDescription("Deletes a partial view identified by the provided Id.")]
public async Task<IActionResult> Delete(CancellationToken cancellationToken, string path)
{
if (_runtimeSettings.Value.Mode == RuntimeMode.Production)
{
return PartialViewOperationStatusResult(PartialViewOperationStatus.NotAllowedInProductionMode);
}
Comment thread
AndyButland marked this conversation as resolved.
Outdated

path = DecodePath(path).VirtualPathToSystemPath();
PartialViewOperationStatus operationStatus = await _partialViewService.DeleteAsync(path, CurrentUserKey(_backOfficeSecurityAccessor));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
using Asp.Versioning;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Api.Management.Extensions;
using Umbraco.Cms.Api.Management.ViewModels.PartialView;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Core.Mapping;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Security;
Expand All @@ -21,18 +25,39 @@ public class RenamePartialViewController : PartialViewControllerBase
private readonly IPartialViewService _partialViewService;
private readonly IUmbracoMapper _umbracoMapper;
private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor;
private readonly IOptions<RuntimeSettings> _runtimeSettings;

/// <summary>
/// Initializes a new instance of the <see cref="RenamePartialViewController"/> class.
/// </summary>
/// <param name="partialViewService">Service used to manage and manipulate partial views.</param>
/// <param name="backOfficeSecurityAccessor">Accessor for back office security context and authentication.</param>
/// <param name="umbracoMapper">Mapper used to convert between Umbraco domain models and API models.</param>
public RenamePartialViewController(IPartialViewService partialViewService, IBackOfficeSecurityAccessor backOfficeSecurityAccessor, IUmbracoMapper umbracoMapper)
/// <param name="runtimeSettings">The runtime configuration settings.</param>
[ActivatorUtilitiesConstructor]
public RenamePartialViewController(
IPartialViewService partialViewService,
IBackOfficeSecurityAccessor backOfficeSecurityAccessor,
IUmbracoMapper umbracoMapper,
IOptions<RuntimeSettings> runtimeSettings)
{
_partialViewService = partialViewService;
_backOfficeSecurityAccessor = backOfficeSecurityAccessor;
_umbracoMapper = umbracoMapper;
_runtimeSettings = runtimeSettings;
}

[Obsolete("Use the constructor with all parameters. Scheduled for removal in Umbraco 19.")]
public RenamePartialViewController(
IPartialViewService partialViewService,
IBackOfficeSecurityAccessor backOfficeSecurityAccessor,
IUmbracoMapper umbracoMapper)
: this(
partialViewService,
backOfficeSecurityAccessor,
umbracoMapper,
StaticServiceProvider.Instance.GetRequiredService<IOptions<RuntimeSettings>>())
{
}

/// <summary>
Expand Down Expand Up @@ -61,6 +86,11 @@ public async Task<IActionResult> Rename(
string path,
RenamePartialViewRequestModel requestModel)
{
if (_runtimeSettings.Value.Mode == RuntimeMode.Production)
{
return PartialViewOperationStatusResult(PartialViewOperationStatus.NotAllowedInProductionMode);
}
Comment thread
AndyButland marked this conversation as resolved.
Outdated

PartialViewRenameModel renameModel = _umbracoMapper.Map<PartialViewRenameModel>(requestModel)!;

path = DecodePath(path).VirtualPathToSystemPath();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
using Asp.Versioning;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Api.Management.Extensions;
using Umbraco.Cms.Api.Management.ViewModels.PartialView;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Core.Mapping;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Security;
Expand All @@ -21,21 +25,39 @@ public class UpdatePartialViewController : PartialViewControllerBase
private readonly IPartialViewService _partialViewService;
private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor;
private readonly IUmbracoMapper _mapper;
private readonly IOptions<RuntimeSettings> _runtimeSettings;

/// <summary>
/// Initializes a new instance of the <see cref="UpdatePartialViewController"/> class, which handles requests for updating partial views in the Umbraco backoffice.
/// </summary>
/// <param name="partialViewService">Service used to manage partial view files.</param>
/// <param name="backOfficeSecurityAccessor">Accessor for back office security context.</param>
/// <param name="mapper">The Umbraco object mapper for mapping between models.</param>
/// <param name="runtimeSettings">The runtime configuration settings.</param>
[ActivatorUtilitiesConstructor]
public UpdatePartialViewController(
IPartialViewService partialViewService,
IBackOfficeSecurityAccessor backOfficeSecurityAccessor,
IUmbracoMapper mapper)
IUmbracoMapper mapper,
IOptions<RuntimeSettings> runtimeSettings)
{
_partialViewService = partialViewService;
_backOfficeSecurityAccessor = backOfficeSecurityAccessor;
_mapper = mapper;
_runtimeSettings = runtimeSettings;
}

[Obsolete("Use the constructor with all parameters. Scheduled for removal in Umbraco 19.")]
public UpdatePartialViewController(
IPartialViewService partialViewService,
IBackOfficeSecurityAccessor backOfficeSecurityAccessor,
IUmbracoMapper mapper)
: this(
partialViewService,
backOfficeSecurityAccessor,
mapper,
StaticServiceProvider.Instance.GetRequiredService<IOptions<RuntimeSettings>>())
{
}

/// <summary>
Expand All @@ -57,6 +79,11 @@ public async Task<IActionResult> Update(
string path,
UpdatePartialViewRequestModel updateViewModel)
{
if (_runtimeSettings.Value.Mode == RuntimeMode.Production)
{
return PartialViewOperationStatusResult(PartialViewOperationStatus.NotAllowedInProductionMode);
}
Comment thread
AndyButland marked this conversation as resolved.
Outdated

path = DecodePath(path).VirtualPathToSystemPath();
PartialViewUpdateModel updateModel = _mapper.Map<PartialViewUpdateModel>(updateViewModel)!;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
using Asp.Versioning;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Api.Management.ViewModels.Template;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Security;
using Umbraco.Cms.Core.Services;
Expand All @@ -18,18 +22,34 @@ public class CreateTemplateController : TemplateControllerBase
{
private readonly ITemplateService _templateService;
private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor;
private readonly IOptions<RuntimeSettings> _runtimeSettings;

/// <summary>
/// Initializes a new instance of the <see cref="CreateTemplateController"/> class.
/// </summary>
/// <param name="templateService">An instance of <see cref="ITemplateService"/> used to manage templates.</param>
/// <param name="backOfficeSecurityAccessor">An instance of <see cref="IBackOfficeSecurityAccessor"/> used to access back office security information.</param>
/// <param name="runtimeSettings">The runtime configuration settings.</param>
[ActivatorUtilitiesConstructor]
public CreateTemplateController(
ITemplateService templateService,
IBackOfficeSecurityAccessor backOfficeSecurityAccessor)
IBackOfficeSecurityAccessor backOfficeSecurityAccessor,
IOptions<RuntimeSettings> runtimeSettings)
{
_templateService = templateService;
_backOfficeSecurityAccessor = backOfficeSecurityAccessor;
_runtimeSettings = runtimeSettings;
}

[Obsolete("Use the constructor with all parameters. Scheduled for removal in Umbraco 19.")]
public CreateTemplateController(
ITemplateService templateService,
IBackOfficeSecurityAccessor backOfficeSecurityAccessor)
: this(
templateService,
backOfficeSecurityAccessor,
StaticServiceProvider.Instance.GetRequiredService<IOptions<RuntimeSettings>>())
{
}

/// <summary>
Expand All @@ -47,6 +67,11 @@ public CreateTemplateController(
[EndpointDescription("Creates a new template with the configuration specified in the request model.")]
public async Task<IActionResult> Create(CancellationToken cancellationToken, CreateTemplateRequestModel requestModel)
{
if (_runtimeSettings.Value.Mode == RuntimeMode.Production)
{
return TemplateOperationStatusResult(TemplateOperationStatus.NotAllowedInProductionMode);
}
Comment thread
AndyButland marked this conversation as resolved.

Attempt<ITemplate, TemplateOperationStatus> result = await _templateService.CreateAsync(
requestModel.Name,
requestModel.Alias,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
using Asp.Versioning;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Security;
using Umbraco.Cms.Core.Services;
Expand All @@ -17,16 +21,34 @@ public class DeleteTemplateController : TemplateControllerBase
{
private readonly ITemplateService _templateService;
private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor;
private readonly IOptions<RuntimeSettings> _runtimeSettings;

/// <summary>
/// Initializes a new instance of the <see cref="DeleteTemplateController"/> class, responsible for handling template deletion operations.
/// </summary>
/// <param name="templateService">The service used to manage templates.</param>
/// <param name="backOfficeSecurityAccessor">Provides access to back office security features.</param>
public DeleteTemplateController(ITemplateService templateService, IBackOfficeSecurityAccessor backOfficeSecurityAccessor)
/// <param name="runtimeSettings">The runtime configuration settings.</param>
[ActivatorUtilitiesConstructor]
public DeleteTemplateController(
ITemplateService templateService,
IBackOfficeSecurityAccessor backOfficeSecurityAccessor,
IOptions<RuntimeSettings> runtimeSettings)
{
_templateService = templateService;
_backOfficeSecurityAccessor = backOfficeSecurityAccessor;
_runtimeSettings = runtimeSettings;
}

[Obsolete("Use the constructor with all parameters. Scheduled for removal in Umbraco 19.")]
public DeleteTemplateController(
ITemplateService templateService,
IBackOfficeSecurityAccessor backOfficeSecurityAccessor)
: this(
templateService,
backOfficeSecurityAccessor,
StaticServiceProvider.Instance.GetRequiredService<IOptions<RuntimeSettings>>())
{
}

/// <summary>
Expand All @@ -44,6 +66,11 @@ public DeleteTemplateController(ITemplateService templateService, IBackOfficeSec
[EndpointDescription("Deletes a template identified by the provided Id.")]
public async Task<IActionResult> Delete(CancellationToken cancellationToken, Guid id)
{
if (_runtimeSettings.Value.Mode == RuntimeMode.Production)
{
return TemplateOperationStatusResult(TemplateOperationStatus.NotAllowedInProductionMode);
}
Comment thread
AndyButland marked this conversation as resolved.

Attempt<ITemplate?, TemplateOperationStatus> result = await _templateService.DeleteAsync(id, CurrentUserKey(_backOfficeSecurityAccessor));
return result.Success
? Ok()
Expand Down
Loading
Loading