Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/v10/dev' into v11/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
bergmania committed Dec 20, 2023
2 parents 923c98a + ec91c47 commit 851e060
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/Umbraco.Web.BackOffice/Controllers/ContentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,7 @@ public PagedResult<ContentItemBasic<ContentPropertyBasic>> GetChildren(
/// <param name="contentId">The content id to copy</param>
/// <param name="name">The name of the blueprint</param>
/// <returns></returns>
[Authorize(Policy = AuthorizationPolicies.ContentPermissionCreateBlueprintFromId)]
[HttpPost]
public ActionResult<SimpleNotificationModel> CreateBlueprintFromContent(
[FromQuery] int contentId,
Expand Down Expand Up @@ -881,8 +882,9 @@ private bool EnsureUniqueName(string? name, IContent? content, string modelName)
/// <summary>
/// Saves content
/// </summary>
[Authorize(Policy = AuthorizationPolicies.TreeAccessDocumentTypes)]
[FileUploadCleanupFilter]
[ContentSaveValidation]
[ContentSaveValidation(skipUserAccessValidation:true)] // skip user access validation because we "only" require Settings access to create new blueprints from scratch
public async Task<ActionResult<ContentItemDisplay<ContentVariantDisplay>?>?> PostSaveBlueprint(
[ModelBinder(typeof(BlueprintItemBinder))] ContentItemSave contentItem)
{
Expand Down Expand Up @@ -2077,6 +2079,7 @@ public IActionResult PostPublishByIdAndCulture(PublishContent model)
return Ok();
}

[Authorize(Policy = AuthorizationPolicies.TreeAccessDocumentTypes)]
[HttpDelete]
[HttpPost]
public IActionResult DeleteBlueprint(int id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public LanguageController(ILocalizationService localizationService, IUmbracoMapp
/// </summary>
/// <returns></returns>
[HttpGet]
[Authorize(Policy = AuthorizationPolicies.SectionAccessContent)]
public IEnumerable<Language>? GetAllLanguages()
{
IEnumerable<ILanguage> allLanguages = _localizationService.GetAllLanguages();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ private static void CreatePolicies(AuthorizationOptions options, string backOffi
policy.Requirements.Add(new ContentPermissionsQueryStringRequirement(ActionDelete.ActionLetter));
});

options.AddPolicy(AuthorizationPolicies.ContentPermissionCreateBlueprintFromId, policy =>
{
policy.AuthenticationSchemes.Add(backOfficeAuthenticationScheme);
policy.Requirements.Add(
new ContentPermissionsQueryStringRequirement(ActionCreateBlueprintFromContent.ActionLetter, "contentId"));
});

options.AddPolicy(AuthorizationPolicies.BackOfficeAccess, policy =>
{
policy.AuthenticationSchemes.Add(backOfficeAuthenticationScheme);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ namespace Umbraco.Cms.Web.BackOffice.Filters;
/// </summary>
internal sealed class ContentSaveValidationAttribute : TypeFilterAttribute
{
public ContentSaveValidationAttribute() : base(typeof(ContentSaveValidationFilter)) =>
public ContentSaveValidationAttribute(bool skipUserAccessValidation = false)
: base(typeof(ContentSaveValidationFilter))
{
Order = -3000; // More important than ModelStateInvalidFilter.FilterOrder

Arguments = new object[] { skipUserAccessValidation };
}

private sealed class ContentSaveValidationFilter : IAsyncActionFilter
{
Expand All @@ -32,6 +35,7 @@ private sealed class ContentSaveValidationFilter : IAsyncActionFilter
private readonly ILocalizationService _localizationService;
private readonly ILoggerFactory _loggerFactory;
private readonly IPropertyValidationService _propertyValidationService;
private readonly bool _skipUserAccessValidation;


public ContentSaveValidationFilter(
Expand All @@ -40,7 +44,8 @@ public ContentSaveValidationFilter(
IPropertyValidationService propertyValidationService,
IAuthorizationService authorizationService,
IBackOfficeSecurityAccessor backOfficeSecurityAccessor,
ILocalizationService localizationService)
ILocalizationService localizationService,
bool skipUserAccessValidation)
{
_loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
_contentService = contentService ?? throw new ArgumentNullException(nameof(contentService));
Expand All @@ -49,6 +54,7 @@ public ContentSaveValidationFilter(
_authorizationService = authorizationService;
_backOfficeSecurityAccessor = backOfficeSecurityAccessor;
_localizationService = localizationService;
_skipUserAccessValidation = skipUserAccessValidation;
}

public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
Expand Down Expand Up @@ -88,7 +94,7 @@ private async Task OnActionExecutingAsync(ActionExecutingContext context)
return;
}

if (!await ValidateUserAccessAsync(model, context))
if (_skipUserAccessValidation is false && await ValidateUserAccessAsync(model, context) is false)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static class AuthorizationPolicies
public const string ContentPermissionProtectById = nameof(ContentPermissionProtectById);
public const string ContentPermissionBrowseById = nameof(ContentPermissionBrowseById);
public const string ContentPermissionDeleteById = nameof(ContentPermissionDeleteById);
public const string ContentPermissionCreateBlueprintFromId = nameof(ContentPermissionCreateBlueprintFromId);

public const string MediaPermissionByResource = nameof(MediaPermissionByResource);
public const string MediaPermissionPathById = nameof(MediaPermissionPathById);
Expand Down

0 comments on commit 851e060

Please sign in to comment.