Listview batch publishing on multi language site, publishes all variants #13755 - Fix (#13772)

* Modified PostPublishById to handle content that is culture variant. Added model and modified the javascript function that call the api endpoint.

* Added separate method for publishing with cultures. Added if else statment to js function.

* Moved check for all cultures being published to the top of PostPublishByIdAndCulture. Added parameter to ngDoc. Added Where Query.

(cherry picked from commit 37db3ae3da)
This commit is contained in:
Menno Mout
2023-02-26 14:00:28 +01:00
committed by Sebastiaan Janssen
parent 154021801e
commit 273e7708e5
3 changed files with 88 additions and 12 deletions

View File

@@ -168,8 +168,8 @@ public class ContentController : ContentControllerBase
authorizationService,
contentVersionService,
StaticServiceProvider.Instance.GetRequiredService<ICultureImpactFactory>())
{
}
{
}
public object? Domains { get; private set; }
@@ -1950,6 +1950,7 @@ public class ContentController : ContentControllerBase
}
PublishResult publishResult = _contentService.SaveAndPublish(foundContent, userId: _backofficeSecurityAccessor.BackOfficeSecurity?.GetUserId().Result ?? 0);
if (publishResult.Success == false)
{
var notificationModel = new SimpleNotificationModel();
@@ -1960,6 +1961,56 @@ public class ContentController : ContentControllerBase
return Ok();
}
/// <summary>
/// Publishes a document with a given ID and cultures.
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
/// <remarks>
/// The EnsureUserPermissionForContent attribute will deny access to this method if the current user
/// does not have Publish access to this node.
/// </remarks>
[Authorize(Policy = AuthorizationPolicies.ContentPermissionPublishById)]
public IActionResult PostPublishByIdAndCulture(PublishContent model)
{
var languageCount = _allLangs.Value.Count();
// If there is no culture specified or the cultures specified are equal to the total amount of languages, publish the content in all cultures.
if (model.Cultures == null || !model.Cultures.Any() || model.Cultures.Length == languageCount)
{
return PostPublishById(model.Id);
}
IContent? foundContent = GetObjectFromRequest(() => _contentService.GetById(model.Id));
if (foundContent == null)
{
return HandleContentNotFound(model.Id);
}
var results = new Dictionary<string, PublishResult>();
foreach (var culture in model.Cultures)
{
PublishResult publishResult = _contentService.SaveAndPublish(foundContent, culture, _backofficeSecurityAccessor.BackOfficeSecurity?.GetUserId().Result ?? 0);
results[culture] = publishResult;
}
if (results.Any(x => x.Value.Success == false))
{
var notificationModel = new SimpleNotificationModel();
foreach (var culture in results.Where(x => x.Value.Success == false))
{
AddMessageForPublishStatus(new[] { culture.Value }, notificationModel);
}
return ValidationProblem(notificationModel);
}
return Ok();
}
[HttpDelete]
[HttpPost]
public IActionResult DeleteBlueprint(int id)