2020-09-22 15:06:03 +02:00
|
|
|
|
using System.Linq;
|
2021-02-18 11:06:02 +01:00
|
|
|
|
using Umbraco.Cms.Core.Configuration.Models;
|
2017-05-30 10:50:09 +02:00
|
|
|
|
|
2021-02-18 11:06:02 +01:00
|
|
|
|
namespace Umbraco.Extensions
|
2017-05-30 10:50:09 +02:00
|
|
|
|
{
|
2020-08-20 22:18:50 +01: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>
|
2020-08-20 22:18:50 +01:00
|
|
|
|
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
|
|
|
|
}
|
2018-08-29 01:15:46 +10: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>
|
2018-08-29 01:15:46 +10:00
|
|
|
|
/// <param name="propertyTypeAlias">The property type alias.</param>
|
|
|
|
|
|
/// <returns>The auto-fill configuration for the specified property alias, or null.</returns>
|
2021-12-16 13:44:20 +01:00
|
|
|
|
public static ImagingAutoFillUploadField? GetConfig(this ContentSettings contentSettings, string propertyTypeAlias)
|
2018-08-29 01:15:46 +10:00
|
|
|
|
{
|
2020-08-24 09:29:40 +02:00
|
|
|
|
var autoFillConfigs = contentSettings.Imaging.AutoFillImageProperties;
|
2018-08-29 01:15:46 +10:00
|
|
|
|
return autoFillConfigs?.FirstOrDefault(x => x.Alias == propertyTypeAlias);
|
|
|
|
|
|
}
|
2017-05-30 10:50:09 +02:00
|
|
|
|
}
|
2017-07-20 11:21:28 +02:00
|
|
|
|
}
|