Merge branch 'leekelleher-U4-337' into 7.3.0
Conflicts: src/Umbraco.Core/Umbraco.Core.csproj
This commit is contained in:
@@ -212,6 +212,10 @@ namespace Umbraco.Web.Editors
|
||||
"packageInstallApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl<PackageInstallController>(
|
||||
controller => controller.Fetch(string.Empty))
|
||||
},
|
||||
{
|
||||
"relationApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl<RelationController>(
|
||||
controller => controller.GetById(0))
|
||||
},
|
||||
{
|
||||
"rteApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl<RichTextPreValueController>(
|
||||
controller => controller.GetConfiguration())
|
||||
|
||||
67
src/Umbraco.Web/Editors/RelationController.cs
Normal file
67
src/Umbraco.Web/Editors/RelationController.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Web.Http;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.WebApi.Filters;
|
||||
using Constants = Umbraco.Core.Constants;
|
||||
|
||||
namespace Umbraco.Web.Editors
|
||||
{
|
||||
[PluginController("UmbracoApi")]
|
||||
[UmbracoApplicationAuthorizeAttribute(Constants.Applications.Content)]
|
||||
public class RelationController : ContentControllerBase
|
||||
{
|
||||
public RelationController()
|
||||
: this(UmbracoContext.Current)
|
||||
{
|
||||
}
|
||||
|
||||
public RelationController(UmbracoContext umbracoContext)
|
||||
: base(umbracoContext)
|
||||
{
|
||||
}
|
||||
|
||||
public IRelation GetById(int id)
|
||||
{
|
||||
return Services.RelationService.GetById(id);
|
||||
}
|
||||
|
||||
[EnsureUserPermissionForContent("childId")]
|
||||
public IEnumerable<IRelation> GetByChildId(int childId, string relationTypeAlias = "")
|
||||
{
|
||||
var relations = Services.RelationService.GetByChildId(childId);
|
||||
|
||||
if (relations == null)
|
||||
{
|
||||
throw new HttpResponseException(HttpStatusCode.NotFound);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(relationTypeAlias))
|
||||
{
|
||||
return relations.Where(x => x.RelationType.Alias.InvariantEquals(relationTypeAlias));
|
||||
}
|
||||
|
||||
return relations;
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
[HttpPost]
|
||||
public HttpResponseMessage DeleteById(int id)
|
||||
{
|
||||
var foundRelation = GetObjectFromRequest(() => Services.RelationService.GetById(id));
|
||||
|
||||
if (foundRelation == null)
|
||||
{
|
||||
return HandleContentNotFound(id, false);
|
||||
}
|
||||
|
||||
Services.RelationService.Delete(foundRelation);
|
||||
|
||||
return Request.CreateResponse(HttpStatusCode.OK);
|
||||
}
|
||||
}
|
||||
}
|
||||
65
src/Umbraco.Web/Strategies/RelateOnTrashHandler.cs
Normal file
65
src/Umbraco.Web/Strategies/RelateOnTrashHandler.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Auditing;
|
||||
using Umbraco.Core.Events;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Services;
|
||||
|
||||
namespace Umbraco.Web.Strategies
|
||||
{
|
||||
public sealed class RelateOnTrashHandler : ApplicationEventHandler
|
||||
{
|
||||
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
|
||||
{
|
||||
ContentService.Moved += ContentService_Moved;
|
||||
ContentService.Trashed += ContentService_Trashed;
|
||||
}
|
||||
|
||||
private void ContentService_Moved(IContentService sender, MoveEventArgs<IContent> e)
|
||||
{
|
||||
foreach (var item in e.MoveInfoCollection.Where(x => x.OriginalPath.Contains(Constants.System.RecycleBinContent.ToInvariantString())))
|
||||
{
|
||||
var relationService = ApplicationContext.Current.Services.RelationService;
|
||||
var relationTypeAlias = Constants.Conventions.RelationTypes.RelateParentDocumentOnDeleteAlias;
|
||||
var relations = relationService.GetByChildId(item.Entity.Id);
|
||||
|
||||
foreach (var relation in relations.Where(x => x.RelationType.Alias.InvariantEquals(relationTypeAlias)))
|
||||
{
|
||||
relationService.Delete(relation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ContentService_Trashed(IContentService sender, MoveEventArgs<IContent> e)
|
||||
{
|
||||
var relationService = ApplicationContext.Current.Services.RelationService;
|
||||
var relationTypeAlias = Constants.Conventions.RelationTypes.RelateParentDocumentOnDeleteAlias;
|
||||
var relationType = relationService.GetRelationTypeByAlias(relationTypeAlias);
|
||||
|
||||
// check that the relation-type exists, if not, then recreate it
|
||||
if (relationType == null)
|
||||
{
|
||||
var documentObjectType = new Guid(Constants.ObjectTypes.Document);
|
||||
var relationTypeName = Constants.Conventions.RelationTypes.RelateParentDocumentOnDeleteName;
|
||||
|
||||
relationType = new RelationType(documentObjectType, documentObjectType, relationTypeAlias, relationTypeName);
|
||||
relationService.Save(relationType);
|
||||
}
|
||||
|
||||
foreach (var item in e.MoveInfoCollection)
|
||||
{
|
||||
var originalPath = item.OriginalPath.ToDelimitedList();
|
||||
var originalParentId = originalPath.Count > 2
|
||||
? int.Parse(originalPath[originalPath.Count - 2])
|
||||
: Constants.System.Root;
|
||||
|
||||
// Add a relation for the item being deleted, so that we can know the original parent for if we need to restore later
|
||||
var relation = new Relation(originalParentId, item.Entity.Id, relationType);
|
||||
relationService.Save(relation);
|
||||
|
||||
Audit.Add(AuditTypes.Delete, string.Format("Trashed content with Id: '{0}' related to original parent content with Id: '{1}'", item.Entity.Id, originalParentId), item.Entity.WriterId, item.Entity.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -177,6 +177,7 @@ namespace Umbraco.Web.Trees
|
||||
if (item.Path.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries).Contains(RecycleBinId.ToInvariantString()))
|
||||
{
|
||||
nodeMenu.DefaultMenuAlias = null;
|
||||
nodeMenu.Items.Insert(2, new MenuItem(ActionRestore.Instance, ui.Text("actions", ActionRestore.Instance.Alias)));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -310,6 +310,7 @@
|
||||
<Compile Include="Editors\EntityControllerConfigurationAttribute.cs" />
|
||||
<Compile Include="Editors\ImagesController.cs" />
|
||||
<Compile Include="Editors\PackageInstallController.cs" />
|
||||
<Compile Include="Editors\RelationController.cs" />
|
||||
<Compile Include="Editors\CanvasDesignerController.cs" />
|
||||
<Compile Include="Editors\UserController.cs" />
|
||||
<Compile Include="GridTemplateExtensions.cs" />
|
||||
@@ -495,6 +496,7 @@
|
||||
<Compile Include="Mvc\UmbracoVirtualNodeRouteHandler.cs" />
|
||||
<Compile Include="Routing\CustomRouteUrlProvider.cs" />
|
||||
<Compile Include="Routing\UrlProviderExtensions.cs" />
|
||||
<Compile Include="Strategies\RelateOnTrashHandler.cs" />
|
||||
<Compile Include="Strategies\Migrations\ClearCsrfCookiesAfterUpgrade.cs" />
|
||||
<Compile Include="Strategies\Migrations\ClearMediaXmlCacheForDeletedItemsAfterUpgrade.cs" />
|
||||
<Compile Include="Strategies\Migrations\EnsureListViewDataTypeIsCreated.cs" />
|
||||
|
||||
Reference in New Issue
Block a user