Skip to content

Commit

Permalink
https://github.com/umbraco/Umbraco-CMS/issues/16443
Browse files Browse the repository at this point in the history
Also ensure master templates cannot be deleted
  • Loading branch information
bergmania committed Nov 15, 2024
1 parent 46f48e8 commit a75f310
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ protected IActionResult TemplateOperationStatusResult(TemplateOperationStatus st
.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()),
_ => StatusCode(StatusCodes.Status500InternalServerError, problemDetailsBuilder
.WithTitle("Unknown template operation status.")
.Build()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ public enum TemplateOperationStatus
DuplicateAlias,
TemplateNotFound,
MasterTemplateNotFound,
CircularMasterTemplateReference
CircularMasterTemplateReference,
MasterTemplateCannotBeDeleted,
}
6 changes: 6 additions & 0 deletions src/Umbraco.Core/Services/TemplateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,12 @@ private void Audit(AuditType type, int userId, int objectId, string? entityType)
return Attempt.FailWithStatus<ITemplate?, TemplateOperationStatus>(TemplateOperationStatus.TemplateNotFound, null);
}

if (template.IsMasterTemplate)
{
scope.Complete();
return Attempt.FailWithStatus<ITemplate?, TemplateOperationStatus>(TemplateOperationStatus.MasterTemplateCannotBeDeleted, null);
}

EventMessages eventMessages = EventMessagesFactory.Get();
var deletingNotification = new TemplateDeletingNotification(template, eventMessages);
if (scope.Notifications.PublishCancelable(deletingNotification))
Expand Down

0 comments on commit a75f310

Please sign in to comment.