Files
Umbraco-CMS/src/Umbraco.Core/Configuration/ContentSettingsExtensions.cs

33 lines
1.5 KiB
C#
Raw Normal View History

using System.Linq;
using Umbraco.Cms.Core.Configuration.Models;
2017-05-30 10:50:09 +02:00
namespace Umbraco.Extensions
2017-05-30 10:50:09 +02:00
{
public static class ContentSettingsExtensions
2017-05-30 10:50:09 +02:00
{
/// <summary>
/// Determines if file extension is allowed for upload based on (optional) white list and black list
/// held in settings.
/// Allow upload if extension is whitelisted OR if there is no whitelist and extension is NOT blacklisted.
/// </summary>
public static bool IsFileAllowedForUpload(this ContentSettings contentSettings, string extension)
2017-05-30 10:50:09 +02:00
{
2020-03-12 15:30:22 +01:00
return contentSettings.AllowedUploadFiles.Any(x => x.InvariantEquals(extension)) ||
(contentSettings.AllowedUploadFiles.Any() == false &&
contentSettings.DisallowedUploadFiles.Any(x => x.InvariantEquals(extension)) == false);
2017-05-30 10:50:09 +02:00
}
/// <summary>
/// Gets the auto-fill configuration for a specified property alias.
/// </summary>
2020-03-12 15:30:22 +01:00
/// <param name="contentSettings"></param>
/// <param name="propertyTypeAlias">The property type alias.</param>
/// <returns>The auto-fill configuration for the specified property alias, or null.</returns>
public static ImagingAutoFillUploadField? GetConfig(this ContentSettings contentSettings, string propertyTypeAlias)
{
var autoFillConfigs = contentSettings.Imaging.AutoFillImageProperties;
return autoFillConfigs?.FirstOrDefault(x => x.Alias == propertyTypeAlias);
}
2017-05-30 10:50:09 +02:00
}
2017-07-20 11:21:28 +02:00
}