Skip to content

Commit 87b2153

Browse files
Adds support for retrieval of data type references when data type is routed using a GUID (#19184)
* Adds support for retrieval of data type references when data type is routed using a GUID. * Fixed typos in comments. * Use IIdKeyMap to resolve ID instead of fetching datatype * Use IDKeyMap instead --------- Co-authored-by: mole <[email protected]>
1 parent 0fc5b2a commit 87b2153

File tree

1 file changed

+55
-9
lines changed

1 file changed

+55
-9
lines changed

src/Umbraco.Web.BackOffice/Controllers/DataTypeController.cs

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1-
using System;
2-
using System.Collections.Generic;
31
using System.Data;
4-
using System.Linq;
52
using System.Net.Mime;
63
using System.Text;
74
using Microsoft.AspNetCore.Authorization;
85
using Microsoft.AspNetCore.Mvc;
96
using Microsoft.Extensions.DependencyInjection;
107
using Microsoft.Extensions.Options;
11-
using NPoco;
128
using Umbraco.Cms.Core;
139
using Umbraco.Cms.Core.Configuration.Models;
1410
using Umbraco.Cms.Core.DependencyInjection;
1511
using Umbraco.Cms.Core.Mapping;
1612
using Umbraco.Cms.Core.Models;
1713
using Umbraco.Cms.Core.Models.ContentEditing;
14+
using Umbraco.Cms.Core.Models.Entities;
1815
using Umbraco.Cms.Core.PropertyEditors;
1916
using Umbraco.Cms.Core.Security;
2017
using Umbraco.Cms.Core.Serialization;
@@ -37,6 +34,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
3734
[PluginController(Constants.Web.Mvc.BackOfficeApiArea)]
3835
[Authorize(Policy = AuthorizationPolicies.TreeAccessDocumentsOrDocumentTypes)]
3936
[ParameterSwapControllerActionSelector(nameof(GetById), "id", typeof(int), typeof(Guid), typeof(Udi))]
37+
[ParameterSwapControllerActionSelector(nameof(GetReferences), "id", typeof(int), typeof(Guid))]
4038
public class DataTypeController : BackOfficeNotificationsController
4139
{
4240
private readonly PropertyEditorCollection _propertyEditors;
@@ -51,6 +49,7 @@ public class DataTypeController : BackOfficeNotificationsController
5149
private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor;
5250
private readonly IConfigurationEditorJsonSerializer _serializer;
5351
private readonly IDataTypeUsageService _dataTypeUsageService;
52+
private readonly IIdKeyMap _idKeyMap;
5453

5554
[Obsolete("Use constructor that takes IDataTypeUsageService, scheduled for removal in V12")]
5655
public DataTypeController(
@@ -77,11 +76,12 @@ public DataTypeController(
7776
localizedTextService,
7877
backOfficeSecurityAccessor,
7978
serializer,
80-
StaticServiceProvider.Instance.GetRequiredService<IDataTypeUsageService>())
79+
StaticServiceProvider.Instance.GetRequiredService<IDataTypeUsageService>(),
80+
StaticServiceProvider.Instance.GetRequiredService<IIdKeyMap>())
8181
{
8282
}
8383

84-
[ActivatorUtilitiesConstructor]
84+
[Obsolete("Use constructor that takes IDataTypeUsageService, scheduled for removal in V17")]
8585
public DataTypeController(
8686
PropertyEditorCollection propertyEditors,
8787
IDataTypeService dataTypeService,
@@ -95,6 +95,38 @@ public DataTypeController(
9595
IBackOfficeSecurityAccessor backOfficeSecurityAccessor,
9696
IConfigurationEditorJsonSerializer serializer,
9797
IDataTypeUsageService dataTypeUsageService)
98+
: this(
99+
propertyEditors,
100+
dataTypeService,
101+
contentSettings,
102+
umbracoMapper,
103+
propertyEditorCollection,
104+
contentTypeService,
105+
mediaTypeService,
106+
memberTypeService,
107+
localizedTextService,
108+
backOfficeSecurityAccessor,
109+
serializer,
110+
dataTypeUsageService,
111+
StaticServiceProvider.Instance.GetRequiredService<IIdKeyMap>())
112+
{
113+
}
114+
115+
[ActivatorUtilitiesConstructor]
116+
public DataTypeController(
117+
PropertyEditorCollection propertyEditors,
118+
IDataTypeService dataTypeService,
119+
IOptionsSnapshot<ContentSettings> contentSettings,
120+
IUmbracoMapper umbracoMapper,
121+
PropertyEditorCollection propertyEditorCollection,
122+
IContentTypeService contentTypeService,
123+
IMediaTypeService mediaTypeService,
124+
IMemberTypeService memberTypeService,
125+
ILocalizedTextService localizedTextService,
126+
IBackOfficeSecurityAccessor backOfficeSecurityAccessor,
127+
IConfigurationEditorJsonSerializer serializer,
128+
IDataTypeUsageService dataTypeUsageService,
129+
IIdKeyMap entityService)
98130
{
99131
_propertyEditors = propertyEditors ?? throw new ArgumentNullException(nameof(propertyEditors));
100132
_dataTypeService = dataTypeService ?? throw new ArgumentNullException(nameof(dataTypeService));
@@ -108,6 +140,7 @@ public DataTypeController(
108140
_backOfficeSecurityAccessor = backOfficeSecurityAccessor ?? throw new ArgumentNullException(nameof(backOfficeSecurityAccessor));
109141
_serializer = serializer ?? throw new ArgumentNullException(nameof(serializer));
110142
_dataTypeUsageService = dataTypeUsageService ?? throw new ArgumentNullException(nameof(dataTypeUsageService));
143+
_idKeyMap = entityService ?? throw new ArgumentNullException(nameof(entityService));
111144
}
112145

113146
/// <summary>
@@ -421,10 +454,10 @@ public IActionResult PostRenameContainer(int id, string name)
421454
}
422455

423456
/// <summary>
424-
/// Returns the references (usages) for the data type
457+
/// Returns the references (usages) for the data type.
425458
/// </summary>
426-
/// <param name="id"></param>
427-
/// <returns></returns>
459+
/// <param name="id">Data type's integer Id.</param>
460+
[HttpGet]
428461
public DataTypeReferences GetReferences(int id)
429462
{
430463
var result = new DataTypeReferences();
@@ -462,6 +495,19 @@ public DataTypeReferences GetReferences(int id)
462495
return result;
463496
}
464497

498+
/// <summary>
499+
/// Returns the references (usages) for the data type.
500+
/// </summary>
501+
/// <param name="id">Data type's key.</param>
502+
[HttpGet]
503+
public DataTypeReferences GetReferences(Guid id)
504+
{
505+
Attempt<int> dataType = _idKeyMap.GetIdForKey(id, UmbracoObjectTypes.DataType);
506+
return dataType.Success
507+
? GetReferences(dataType.Result)
508+
: new DataTypeReferences();
509+
}
510+
465511
[HttpGet]
466512
public ActionResult<DataTypeHasValuesDisplay> HasValues(int id)
467513
{

0 commit comments

Comments
 (0)