-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathTemplateControllerBase.cs
More file actions
64 lines (60 loc) · 3.61 KB
/
TemplateControllerBase.cs
File metadata and controls
64 lines (60 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Api.Common.Builders;
using Umbraco.Cms.Api.Management.Routing;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Services.OperationStatus;
using Umbraco.Cms.Web.Common.Authorization;
namespace Umbraco.Cms.Api.Management.Controllers.Template;
[VersionedApiBackOfficeRoute(Constants.UdiEntityType.Template)]
[ApiExplorerSettings(GroupName = nameof(Constants.UdiEntityType.Template))]
[Authorize(Policy = AuthorizationPolicies.TreeAccessTemplates)]
public class TemplateControllerBase : ManagementApiControllerBase
{
protected IActionResult TemplateOperationStatusResult(TemplateOperationStatus status) =>
OperationStatusResult(status, problemDetailsBuilder => status switch
{
TemplateOperationStatus.TemplateNotFound => TemplateNotFound(),
TemplateOperationStatus.InvalidAlias => BadRequest(problemDetailsBuilder
.WithTitle("Invalid alias")
.WithDetail("The template alias is not valid.")
.Build()),
TemplateOperationStatus.CancelledByNotification => BadRequest(problemDetailsBuilder
.WithTitle("Cancelled by notification")
.WithDetail("A notification handler prevented the template operation.")
.Build()),
TemplateOperationStatus.DuplicateAlias => BadRequest(problemDetailsBuilder
.WithTitle("Duplicate alias")
.WithDetail("A template with that alias already exists.")
.Build()),
TemplateOperationStatus.CircularMasterTemplateReference => BadRequest(problemDetailsBuilder
.WithTitle("Invalid master template")
.WithDetail("The master template referenced in the template leads to a circular reference.")
.Build()),
TemplateOperationStatus.MasterTemplateNotFound => BadRequest(problemDetailsBuilder
.WithTitle("Master template not found")
.WithDetail("The master template referenced in the template was not found.")
.Build()),
TemplateOperationStatus.MasterTemplateCannotBeDeleted => BadRequest(problemDetailsBuilder
.WithTitle("Master template cannot be deleted")
.WithDetail("The master templates cannot be deleted. Please ensure the template is not a master template before you delete.")
.Build()),
TemplateOperationStatus.NotAllowedInProductionMode => BadRequest(problemDetailsBuilder
.WithTitle("Not allowed in production mode")
.WithDetail("Template modifications are not allowed when running in production mode.")
.Build()),
TemplateOperationStatus.ContentChangeNotAllowedInProductionMode => BadRequest(problemDetailsBuilder
.WithTitle("Content change not allowed in production mode")
.WithDetail("Template content changes are not allowed when running in production mode. Metadata updates are permitted.")
.Build()),
_ => StatusCode(StatusCodes.Status500InternalServerError, problemDetailsBuilder
.WithTitle("Unknown template operation status.")
.Build()),
});
protected IActionResult TemplateNotFound()
=> OperationStatusResult(TemplateOperationStatus.TemplateNotFound, TemplateNotFound);
protected IActionResult TemplateNotFound(ProblemDetailsBuilder problemDetailsBuilder) => NotFound(problemDetailsBuilder
.WithTitle("The template could not be found")
.Build());
}