Merge branch 'netcore/netcore' into feature/8651-config-options-patten

# Conflicts:
#	src/Umbraco.Tests.Common/Builders/GlobalSettingsBuilder.cs
#	src/Umbraco.Tests/TEMP/DatabaseContextTests.sdf
#	src/Umbraco.Web.BackOffice/Controllers/ImagesController.cs
This commit is contained in:
Andy Butland
2020-08-27 09:03:01 +02:00
979 changed files with 9486 additions and 4278 deletions

View File

@@ -177,6 +177,10 @@ namespace Umbraco.Web.BackOffice.Controllers
"mediaApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl<MediaController>(
controller => controller.GetRootMedia())
},
{
"iconApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl<IconController>(
controller => controller.GetIcon(""))
},
{
"imagesApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl<ImagesController>(
controller => controller.GetBigThumbnail(""))

View File

@@ -3,8 +3,6 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.Mime;
using System.Text;
using System.Threading.Tasks;
@@ -13,30 +11,25 @@ using System.Xml.Linq;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Configuration;
using Umbraco.Core.Dictionary;
using Umbraco.Core.Hosting;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Editors;
using Umbraco.Core.Packaging;
using Umbraco.Core.Persistence;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Scoping;
using Umbraco.Core.Services;
using Umbraco.Core.Strings;
using Umbraco.Web.Models;
using Umbraco.Web.Models.ContentEditing;
using Umbraco.Web.WebApi.Filters;
using Constants = Umbraco.Core.Constants;
using Umbraco.Core.Mapping;
using Umbraco.Web.BackOffice.Filters;
using Umbraco.Web.Common.Attributes;
using Umbraco.Web.Common.Exceptions;
using Umbraco.Web.Editors;
using Umbraco.Web.Routing;
using Umbraco.Web.Security;
using ContentType = Umbraco.Core.Models.ContentType;
using Umbraco.Core.Configuration.Models;
@@ -141,6 +134,12 @@ namespace Umbraco.Web.BackOffice.Controllers
return _contentTypeService.HasContentNodes(id);
}
/// <summary>
/// Gets the document type a given id
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[DetermineAmbiguousActionByPassingParameters]
public DocumentTypeDisplay GetById(int id)
{
var ct = _contentTypeService.Get(id);
@@ -153,6 +152,46 @@ namespace Umbraco.Web.BackOffice.Controllers
return dto;
}
/// <summary>
/// Gets the document type a given guid
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[DetermineAmbiguousActionByPassingParameters]
public DocumentTypeDisplay GetById(Guid id)
{
var contentType = _contentTypeService.Get(id);
if (contentType == null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
var dto = _umbracoMapper.Map<IContentType, DocumentTypeDisplay>(contentType);
return dto;
}
/// <summary>
/// Gets the document type a given udi
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[DetermineAmbiguousActionByPassingParameters]
public DocumentTypeDisplay GetById(Udi id)
{
var guidUdi = id as GuidUdi;
if (guidUdi == null)
throw new HttpResponseException(HttpStatusCode.NotFound);
var contentType = _contentTypeService.Get(guidUdi.Guid);
if (contentType == null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
var dto = _umbracoMapper.Map<IContentType, DocumentTypeDisplay>(contentType);
return dto;
}
/// <summary>
/// Deletes a document type with a given ID
/// </summary>

View File

@@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Linq;
using System.Net.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Mapping;
@@ -131,7 +131,7 @@ namespace Umbraco.Web.BackOffice.Controllers
}
}
/// <summary>
/// <summary>
/// Gets a dictionary item by id
/// </summary>
/// <param name="id">
@@ -143,10 +143,58 @@ namespace Umbraco.Web.BackOffice.Controllers
/// <exception cref="HttpResponseException">
/// Returns a not found response when dictionary item does not exist
/// </exception>
[DetermineAmbiguousActionByPassingParameters]
public ActionResult<DictionaryDisplay> GetById(int id)
{
var dictionary = _localizationService.GetDictionaryItemById(id);
if (dictionary == null)
return NotFound();
return _umbracoMapper.Map<IDictionaryItem, DictionaryDisplay>(dictionary);
}
/// <summary>
/// Gets a dictionary item by guid
/// </summary>
/// <param name="id">
/// The id.
/// </param>
/// <returns>
/// The <see cref="DictionaryDisplay"/>.
/// </returns>
/// <exception cref="HttpResponseException">
/// Returns a not found response when dictionary item does not exist
/// </exception>
[DetermineAmbiguousActionByPassingParameters]
public ActionResult<DictionaryDisplay> GetById(Guid id)
{
var dictionary = _localizationService.GetDictionaryItemById(id);
if (dictionary == null)
return NotFound();
return _umbracoMapper.Map<IDictionaryItem, DictionaryDisplay>(dictionary);
}
/// <summary>
/// Gets a dictionary item by udi
/// </summary>
/// <param name="id">
/// The id.
/// </param>
/// <returns>
/// The <see cref="DictionaryDisplay"/>.
/// </returns>
/// <exception cref="HttpResponseException">
/// Returns a not found response when dictionary item does not exist
/// </exception>
[DetermineAmbiguousActionByPassingParameters]
public ActionResult<DictionaryDisplay> GetById(Udi id)
{
var guidUdi = id as GuidUdi;
if (guidUdi == null)
return NotFound();
var dictionary = _localizationService.GetDictionaryItemById(guidUdi.Guid);
if (dictionary == null)
return NotFound();
@@ -224,19 +272,30 @@ namespace Umbraco.Web.BackOffice.Controllers
/// </returns>
public IEnumerable<DictionaryOverviewDisplay> GetList()
{
var list = new List<DictionaryOverviewDisplay>();
var items = _localizationService.GetDictionaryItemDescendants(null).ToArray();
var list = new List<DictionaryOverviewDisplay>(items.Length);
const int level = 0;
foreach (var dictionaryItem in _localizationService.GetRootDictionaryItems().OrderBy(ItemSort()))
// recursive method to build a tree structure from the flat structure returned above
void BuildTree(int level = 0, Guid? parentId = null)
{
var item = _umbracoMapper.Map<IDictionaryItem, DictionaryOverviewDisplay>(dictionaryItem);
item.Level = 0;
list.Add(item);
var children = items.Where(t => t.ParentId == parentId).ToArray();
if(children.Any() == false)
{
return;
}
GetChildItemsForList(dictionaryItem, level + 1, list);
foreach(var child in children.OrderBy(ItemSort()))
{
var display = _umbracoMapper.Map<IDictionaryItem, DictionaryOverviewDisplay>(child);
display.Level = level;
list.Add(display);
BuildTree(level + 1, child.Key);
}
}
BuildTree();
return list;
}

View File

@@ -0,0 +1,111 @@
using System.Collections.Generic;
using System.Linq;
using Umbraco.Web.Models;
using System.IO;
using Umbraco.Core;
using Ganss.XSS;
using Umbraco.Core.Configuration;
using Umbraco.Core.Hosting;
using Umbraco.Web.BackOffice.Controllers;
using Umbraco.Web.Common.Attributes;
using Umbraco.Web.Common.Filters;
namespace Umbraco.Web.Editors
{
[PluginController("UmbracoApi")]
public class IconController : UmbracoAuthorizedApiController
{
private readonly IHostingEnvironment _hostingEnvironment;
private readonly IGlobalSettings _globalSettings;
public IconController(
IHostingEnvironment hostingEnvironment,
IGlobalSettings globalSettings)
{
_hostingEnvironment = hostingEnvironment;
_globalSettings = globalSettings;
}
/// <summary>
/// Gets an IconModel containing the icon name and SvgString according to an icon name found at the global icons path
/// </summary>
/// <param name="iconName"></param>
/// <returns></returns>
[DetermineAmbiguousActionByPassingParameters]
public IconModel GetIcon(string iconName)
{
return string.IsNullOrWhiteSpace(iconName)
? null
: CreateIconModel(iconName.StripFileExtension(),
_hostingEnvironment.MapPathWebRoot($"{_globalSettings.IconsPath}/{iconName}.svg"));
}
/// <summary>
/// Gets an IconModel using values from a FileInfo model
/// </summary>
/// <param name="fileInfo"></param>
/// <returns></returns>
[DetermineAmbiguousActionByPassingParameters]
public IconModel GetIcon(FileInfo fileInfo)
{
return fileInfo == null || string.IsNullOrWhiteSpace(fileInfo.Name)
? null
: CreateIconModel(fileInfo.Name.StripFileExtension(), fileInfo.FullName);
}
/// <summary>
/// Gets a list of all svg icons found at at the global icons path.
/// </summary>
/// <returns></returns>
public List<IconModel> GetAllIcons()
{
var icons = new List<IconModel>();
var directory = new DirectoryInfo(_hostingEnvironment.MapPathWebRoot($"{_globalSettings.IconsPath}/"));
var iconNames = directory.GetFiles("*.svg");
iconNames.OrderBy(f => f.Name).ToList().ForEach(iconInfo =>
{
var icon = GetIcon(iconInfo);
if (icon != null)
{
icons.Add(icon);
}
});
return icons;
}
/// <summary>
/// Gets an IconModel containing the icon name and SvgString
/// </summary>
/// <param name="iconName"></param>
/// <param name="iconPath"></param>
/// <returns></returns>
private IconModel CreateIconModel(string iconName, string iconPath)
{
var sanitizer = new HtmlSanitizer();
sanitizer.AllowedAttributes.UnionWith(Core.Constants.SvgSanitizer.Attributes);
sanitizer.AllowedCssProperties.UnionWith(Core.Constants.SvgSanitizer.Attributes);
sanitizer.AllowedTags.UnionWith(Core.Constants.SvgSanitizer.Tags);
try
{
var svgContent = System.IO.File.ReadAllText(iconPath);
var sanitizedString = sanitizer.Sanitize(svgContent);
var svg = new IconModel
{
Name = iconName,
SvgString = sanitizedString
};
return svg;
}
catch
{
return null;
}
}
}
}

View File

@@ -23,7 +23,10 @@ namespace Umbraco.Web.BackOffice.Controllers
private readonly ContentSettings _contentSettings;
private readonly IImageUrlGenerator _imageUrlGenerator;
public ImagesController(IMediaFileSystem mediaFileSystem, IOptions<ContentSettings> contentSettings, IImageUrlGenerator imageUrlGenerator)
public ImagesController(
IMediaFileSystem mediaFileSystem,
IOptions<ContentSettings> contentSettings,
IImageUrlGenerator imageUrlGenerator)
{
_mediaFileSystem = mediaFileSystem;
_contentSettings = contentSettings.Value;
@@ -67,7 +70,6 @@ namespace Umbraco.Web.BackOffice.Controllers
try
{
imageLastModified = _mediaFileSystem.GetLastModified(imagePath);
}
catch (Exception)
{
@@ -78,7 +80,14 @@ namespace Umbraco.Web.BackOffice.Controllers
}
var rnd = imageLastModified.HasValue ? $"&rnd={imageLastModified:yyyyMMddHHmmss}" : null;
var imageUrl = _imageUrlGenerator.GetImageUrl(new ImageUrlGenerationOptions(imagePath) { UpScale = false, Width = width, AnimationProcessMode = "first", ImageCropMode = ImageCropMode.Max, CacheBusterValue = rnd });
var imageUrl = _imageUrlGenerator.GetImageUrl(new ImageUrlGenerationOptions(imagePath)
{
UpScale = false,
Width = width,
AnimationProcessMode = "first",
ImageCropMode = ImageCropMode.Max,
CacheBusterValue = rnd
});
return new RedirectResult(imageUrl, false);
}
@@ -94,20 +103,30 @@ namespace Umbraco.Web.BackOffice.Controllers
/// <param name="animationProcessMode"></param>
/// <param name="mode"></param>
/// <param name="upscale"></param>
/// <param name="cacheBusterValue"></param>
/// <param name="crop"></param>
/// <param name="center"></param>
/// <returns></returns>
/// <remarks>
/// If there is no media, image property or image file is found then this will return not found.
/// </remarks>
public string GetProcessedImageUrl(string imagePath,
int? width = null,
int? height = null,
int? focalPointLeft = null,
int? focalPointTop = null,
string animationProcessMode = "first",
int? width = null,
int? height = null,
decimal? focalPointLeft = null,
decimal? focalPointTop = null,
string animationProcessMode = "first",
ImageCropMode mode = ImageCropMode.Max,
bool upscale = false,
string cacheBusterValue = "")
{
bool upscale = false,
string cacheBusterValue = "",
decimal? cropX1 = null,
decimal? cropX2 = null,
decimal? cropY1 = null,
decimal? cropY2 = null
)
{
var options = new ImageUrlGenerationOptions(imagePath)
{
AnimationProcessMode = animationProcessMode,
@@ -116,13 +135,35 @@ namespace Umbraco.Web.BackOffice.Controllers
ImageCropMode = mode,
UpScale = upscale,
Width = width,
Crop = (cropX1.HasValue && cropX2.HasValue && cropY1.HasValue && cropY2.HasValue) ? new ImageUrlGenerationOptions.CropCoordinates(cropX1.Value, cropY1.Value, cropX2.Value, cropY2.Value) : null,
FocalPoint = new ImageUrlGenerationOptions.FocalPointPosition(focalPointTop.GetValueOrDefault(0.5m), focalPointLeft.GetValueOrDefault(0.5m)),
};
if (focalPointLeft.HasValue && focalPointTop.HasValue)
{
options.FocalPoint = new ImageUrlGenerationOptions.FocalPointPosition(focalPointTop.Value, focalPointLeft.Value);
options.FocalPoint =
new ImageUrlGenerationOptions.FocalPointPosition(focalPointTop.Value, focalPointLeft.Value);
}
return _imageUrlGenerator.GetImageUrl(options);
}
public class FocalPointPositionModel
{
public decimal Left { get; set; }
public decimal Top { get; set; }
}
/// <summary>
/// The bounds of the crop within the original image, in whatever units the registered
/// IImageUrlGenerator uses, typically a percentage between 0 and 100.
/// </summary>
public class CropCoordinatesModel
{
public decimal X1 { get; set; }
public decimal Y1 { get; set; }
public decimal X2 { get; set;}
public decimal Y2 { get; set;}
}
}
}

View File

@@ -98,6 +98,13 @@ namespace Umbraco.Web.BackOffice.Controllers
};
}
public IEnumerable<AuditLog> GetLog(AuditType logType, DateTime? sinceDate = null)
{
var result = _auditService.GetLogs(Enum<AuditType>.Parse(logType.ToString()), sinceDate);
var mapped = _umbracoMapper.MapEnumerable<IAuditItem, AuditLog>(result);
return mapped;
}
private IEnumerable<AuditLog> MapAvatarsAndNames(IEnumerable<AuditLog> items)
{
var mappedItems = items.ToList();

View File

@@ -159,15 +159,15 @@ namespace Umbraco.Web.BackOffice.Controllers
[DetermineAmbiguousActionByPassingParameters]
public MediaItemDisplay GetById(int id)
{
var foundContent = GetObjectFromRequest(() => _mediaService.GetById(id));
var foundMedia = GetObjectFromRequest(() => _mediaService.GetById(id));
if (foundContent == null)
if (foundMedia == null)
{
HandleContentNotFound(id);
//HandleContentNotFound will throw an exception
return null;
}
return _umbracoMapper.Map<MediaItemDisplay>(foundContent);
return _umbracoMapper.Map<MediaItemDisplay>(foundMedia);
}
/// <summary>
@@ -180,15 +180,15 @@ namespace Umbraco.Web.BackOffice.Controllers
[DetermineAmbiguousActionByPassingParameters]
public MediaItemDisplay GetById(Guid id)
{
var foundContent = GetObjectFromRequest(() => _mediaService.GetById(id));
var foundMedia = GetObjectFromRequest(() => _mediaService.GetById(id));
if (foundContent == null)
if (foundMedia == null)
{
HandleContentNotFound(id);
//HandleContentNotFound will throw an exception
return null;
}
return _umbracoMapper.Map<MediaItemDisplay>(foundContent);
return _umbracoMapper.Map<MediaItemDisplay>(foundMedia);
}
/// <summary>
@@ -799,10 +799,13 @@ namespace Umbraco.Web.BackOffice.Controllers
var total = long.MaxValue;
while (page * pageSize < total)
{
var children = _mediaService.GetPagedChildren(mediaId, page, pageSize, out total,
var children = _mediaService.GetPagedChildren(mediaId, page++, pageSize, out total,
_sqlContext.Query<IMedia>().Where(x => x.Name == nameToFind));
foreach (var c in children)
return c; //return first one if any are found
var match = children.FirstOrDefault(c => c.ContentType.Alias == contentTypeAlias);
if (match != null)
{
return match;
}
}
return null;
}

View File

@@ -71,6 +71,12 @@ namespace Umbraco.Web.BackOffice.Controllers
public int GetCount() => _contentTypeService.Count();
/// <summary>
/// Gets the media type a given id
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[DetermineAmbiguousActionByPassingParameters]
[UmbracoTreeAuthorize(Constants.Trees.MediaTypes, Constants.Trees.Media)]
public MediaTypeDisplay GetById(int id)
{
@@ -84,6 +90,48 @@ namespace Umbraco.Web.BackOffice.Controllers
return dto;
}
/// <summary>
/// Gets the media type a given guid
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[DetermineAmbiguousActionByPassingParameters]
[UmbracoTreeAuthorize(Constants.Trees.MediaTypes, Constants.Trees.Media)]
public MediaTypeDisplay GetById(Guid id)
{
var mediaType = _mediaTypeService.Get(id);
if (mediaType == null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
var dto = _umbracoMapper.Map<IMediaType, MediaTypeDisplay>(mediaType);
return dto;
}
/// <summary>
/// Gets the media type a given udi
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[DetermineAmbiguousActionByPassingParameters]
[UmbracoTreeAuthorize(Constants.Trees.MediaTypes, Constants.Trees.Media)]
public MediaTypeDisplay GetById(Udi id)
{
var guidUdi = id as GuidUdi;
if (guidUdi == null)
throw new HttpResponseException(HttpStatusCode.NotFound);
var mediaType = _mediaTypeService.Get(guidUdi.Guid);
if (mediaType == null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
var dto = _umbracoMapper.Map<IMediaType, MediaTypeDisplay>(mediaType);
return dto;
}
/// <summary>
/// Deletes a media type with a given ID
/// </summary>

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Core;
using Umbraco.Core.Mapping;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
@@ -37,6 +38,12 @@ namespace Umbraco.Web.BackOffice.Controllers
localizedTextService ?? throw new ArgumentNullException(nameof(localizedTextService));
}
/// <summary>
/// Gets the member group json for the member group id
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[DetermineAmbiguousActionByPassingParameters]
public MemberGroupDisplay GetById(int id)
{
var memberGroup = _memberGroupService.GetById(id);
@@ -49,6 +56,45 @@ namespace Umbraco.Web.BackOffice.Controllers
return dto;
}
/// <summary>
/// Gets the member group json for the member group guid
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[DetermineAmbiguousActionByPassingParameters]
public MemberGroupDisplay GetById(Guid id)
{
var memberGroup = _memberGroupService.GetById(id);
if (memberGroup == null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
return _umbracoMapper.Map<IMemberGroup, MemberGroupDisplay>(memberGroup);
}
/// <summary>
/// Gets the member group json for the member group udi
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[DetermineAmbiguousActionByPassingParameters]
public MemberGroupDisplay GetById(Udi id)
{
var guidUdi = id as GuidUdi;
if (guidUdi == null)
throw new HttpResponseException(HttpStatusCode.NotFound);
var memberGroup = _memberGroupService.GetById(guidUdi.Guid);
if (memberGroup == null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
return _umbracoMapper.Map<IMemberGroup, MemberGroupDisplay>(memberGroup);
}
public IEnumerable<MemberGroupDisplay> GetByIds([FromQuery]int[] ids)
{
return _memberGroupService.GetByIds(ids)

View File

@@ -64,7 +64,13 @@ namespace Umbraco.Web.Editors
localizedTextService ?? throw new ArgumentNullException(nameof(localizedTextService));
}
/// <summary>
/// Gets the member type a given id
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[UmbracoTreeAuthorize(Constants.Trees.MemberTypes)]
[DetermineAmbiguousActionByPassingParameters]
public MemberTypeDisplay GetById(int id)
{
var ct = _memberTypeService.Get(id);
@@ -78,7 +84,49 @@ namespace Umbraco.Web.Editors
}
/// <summary>
/// Deletes a document type with a given ID
/// Gets the member type a given guid
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[UmbracoTreeAuthorize(Constants.Trees.MemberTypes)]
[DetermineAmbiguousActionByPassingParameters]
public MemberTypeDisplay GetById(Guid id)
{
var memberType = _memberTypeService.Get(id);
if (memberType == null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
var dto = _umbracoMapper.Map<IMemberType, MemberTypeDisplay>(memberType);
return dto;
}
/// <summary>
/// Gets the member type a given udi
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[UmbracoTreeAuthorize(Constants.Trees.MemberTypes)]
[DetermineAmbiguousActionByPassingParameters]
public MemberTypeDisplay GetById(Udi id)
{
var guidUdi = id as GuidUdi;
if (guidUdi == null)
throw new HttpResponseException(HttpStatusCode.NotFound);
var memberType = _memberTypeService.Get(guidUdi.Guid);
if (memberType == null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
var dto = _umbracoMapper.Map<IMemberType, MemberTypeDisplay>(memberType);
return dto;
}
/// <summary>
/// Deletes a document type with a given id
/// </summary>
/// <param name="id"></param>
/// <returns></returns>

View File

@@ -49,6 +49,7 @@ namespace Umbraco.Web.BackOffice.Controllers
/// </summary>
/// <param name="id">The relation type ID.</param>
/// <returns>Returns the <see cref="RelationTypeDisplay"/>.</returns>
[DetermineAmbiguousActionByPassingParameters]
public RelationTypeDisplay GetById(int id)
{
var relationType = _relationService.GetRelationTypeById(id);
@@ -63,6 +64,42 @@ namespace Umbraco.Web.BackOffice.Controllers
return display;
}
/// <summary>
/// Gets a relation type by guid
/// </summary>
/// <param name="id">The relation type ID.</param>
/// <returns>Returns the <see cref="RelationTypeDisplay"/>.</returns>
[DetermineAmbiguousActionByPassingParameters]
public RelationTypeDisplay GetById(Guid id)
{
var relationType = _relationService.GetRelationTypeById(id);
if (relationType == null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
return _umbracoMapper.Map<IRelationType, RelationTypeDisplay>(relationType);
}
/// <summary>
/// Gets a relation type by udi
/// </summary>
/// <param name="id">The relation type ID.</param>
/// <returns>Returns the <see cref="RelationTypeDisplay"/>.</returns>
[DetermineAmbiguousActionByPassingParameters]
public RelationTypeDisplay GetById(Udi id)
{
var guidUdi = id as GuidUdi;
if (guidUdi == null)
throw new HttpResponseException(HttpStatusCode.NotFound);
var relationType = _relationService.GetRelationTypeById(guidUdi.Guid);
if (relationType == null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
return _umbracoMapper.Map<IRelationType, RelationTypeDisplay>(relationType);
}
public PagedResult<RelationDisplay> GetPagedResults(int id, int pageNumber = 1, int pageSize = 100)
{

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Core;
using Umbraco.Core.IO;
using Umbraco.Core.Mapping;
using Umbraco.Core.Models;
@@ -55,10 +56,11 @@ namespace Umbraco.Web.BackOffice.Controllers
}
/// <summary>
/// Gets the content json for the content id
/// Gets the template json for the template id
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[DetermineAmbiguousActionByPassingParameters]
public TemplateDisplay GetById(int id)
{
var template = _fileService.GetTemplate(id);
@@ -68,6 +70,43 @@ namespace Umbraco.Web.BackOffice.Controllers
return _umbracoMapper.Map<ITemplate, TemplateDisplay>(template);
}
/// <summary>
/// Gets the template json for the template guid
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[DetermineAmbiguousActionByPassingParameters]
public TemplateDisplay GetById(Guid id)
{
var template = _fileService.GetTemplate(id);
if (template == null)
throw new HttpResponseException(HttpStatusCode.NotFound);
return _umbracoMapper.Map<ITemplate, TemplateDisplay>(template);
}
/// <summary>
/// Gets the template json for the template udi
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[DetermineAmbiguousActionByPassingParameters]
public TemplateDisplay GetById(Udi id)
{
var guidUdi = id as GuidUdi;
if (guidUdi == null)
throw new HttpResponseException(HttpStatusCode.NotFound);
var template = _fileService.GetTemplate(guidUdi.Guid);
if (template == null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
return _umbracoMapper.Map<ITemplate, TemplateDisplay>(template);
}
/// <summary>
/// Deletes a template with a given ID
/// </summary>

View File

@@ -95,7 +95,11 @@ namespace Umbraco.Web.BackOffice.Controllers
QueryExpression = queryExpression.ToString(),
ResultCount = results.Count,
ExecutionTime = timer.ElapsedMilliseconds,
SampleResults = results.Take(20).Select(x => new TemplateQueryResult { Icon = "icon-file", Name = x.Name })
SampleResults = results.Take(20).Select(x => new TemplateQueryResult
{
Icon = "icon-document",
Name = x.Name
})
};
}

View File

@@ -28,6 +28,7 @@ using Umbraco.Core.Services;
using Umbraco.Core.Strings;
using Umbraco.Extensions;
using Umbraco.Web.BackOffice.Filters;
using Umbraco.Web.BackOffice.ModelBinders;
using Umbraco.Web.BackOffice.Security;
using Umbraco.Web.Common.ActionResults;
using Umbraco.Web.Common.Attributes;
@@ -235,6 +236,33 @@ namespace Umbraco.Web.BackOffice.Controllers
return result;
}
/// <summary>
/// Get users by integer ids
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
[TypeFilter(typeof(OutgoingEditorModelEventAttribute))]
[AdminUsersAuthorize]
public IEnumerable<UserDisplay> GetByIds([FromJsonPath]int[] ids)
{
if (ids == null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
if (ids.Length == 0)
return Enumerable.Empty<UserDisplay>();
var users = _userService.GetUsersById(ids);
if (users == null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
var result = _umbracoMapper.MapEnumerable<IUser, UserDisplay>(users);
return result;
}
/// <summary>
/// Returns a paged users collection
/// </summary>