Skip to content

Commit

Permalink
#15195 Fixed issue with media not cached correct (#15196)
Browse files Browse the repository at this point in the history
  • Loading branch information
bergmania committed Nov 14, 2023
1 parent 151fcce commit df4cd63
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
7 changes: 6 additions & 1 deletion src/Umbraco.Core/Services/UserServiceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ namespace Umbraco.Extensions;
public static class UserServiceExtensions
{
public static EntityPermission? GetPermissions(this IUserService userService, IUser? user, string path)
{
return userService.GetAllPermissions(user, path).FirstOrDefault();
}

public static EntityPermissionCollection GetAllPermissions(this IUserService userService, IUser? user, string path)
{
var ids = path.Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries)
.Select(x =>
Expand All @@ -23,7 +28,7 @@ public static class UserServiceExtensions
" could not be parsed into an array of integers or the path was empty");
}

return userService.GetPermissions(user, ids[^1]).FirstOrDefault();
return userService.GetPermissions(user, ids[^1]);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public IEnumerable<ContentNodeKit> GetAllContentSources()
IContentCacheDataSerializer serializer =
_contentCacheDataSerializerFactory.Create(ContentCacheDataSerializerEntityType.Document);

IEnumerable<ContentSourceDto> dtos = GetContentNodeDtos(sql);
IEnumerable<ContentSourceDto> dtos = GetContentNodeDtos(sql, Constants.ObjectTypes.Document);

foreach (ContentSourceDto row in dtos)
{
Expand All @@ -242,7 +242,7 @@ public IEnumerable<ContentNodeKit> GetBranchContentSources(int id)
IContentCacheDataSerializer serializer =
_contentCacheDataSerializerFactory.Create(ContentCacheDataSerializerEntityType.Document);

IEnumerable<ContentSourceDto> dtos = GetContentNodeDtos(sql);
IEnumerable<ContentSourceDto> dtos = GetContentNodeDtos(sql, Constants.ObjectTypes.Document);

foreach (ContentSourceDto row in dtos)
{
Expand All @@ -265,7 +265,7 @@ public IEnumerable<ContentNodeKit> GetTypeContentSources(IEnumerable<int>? ids)
IContentCacheDataSerializer serializer =
_contentCacheDataSerializerFactory.Create(ContentCacheDataSerializerEntityType.Document);

IEnumerable<ContentSourceDto> dtos = GetContentNodeDtos(sql);
IEnumerable<ContentSourceDto> dtos = GetContentNodeDtos(sql, Constants.ObjectTypes.Document);

foreach (ContentSourceDto row in dtos)
{
Expand Down Expand Up @@ -301,7 +301,7 @@ public IEnumerable<ContentNodeKit> GetAllMediaSources()
IContentCacheDataSerializer serializer =
_contentCacheDataSerializerFactory.Create(ContentCacheDataSerializerEntityType.Media);

IEnumerable<ContentSourceDto> dtos = GetContentNodeDtos(sql);
IEnumerable<ContentSourceDto> dtos = GetContentNodeDtos(sql, Constants.ObjectTypes.Media);

foreach (ContentSourceDto row in dtos)
{
Expand All @@ -319,7 +319,7 @@ public IEnumerable<ContentNodeKit> GetBranchMediaSources(int id)
IContentCacheDataSerializer serializer =
_contentCacheDataSerializerFactory.Create(ContentCacheDataSerializerEntityType.Media);

IEnumerable<ContentSourceDto> dtos = GetContentNodeDtos(sql);
IEnumerable<ContentSourceDto> dtos = GetContentNodeDtos(sql, Constants.ObjectTypes.Media);

foreach (ContentSourceDto row in dtos)
{
Expand All @@ -342,7 +342,7 @@ public IEnumerable<ContentNodeKit> GetTypeMediaSources(IEnumerable<int> ids)
IContentCacheDataSerializer serializer =
_contentCacheDataSerializerFactory.Create(ContentCacheDataSerializerEntityType.Media);

IEnumerable<ContentSourceDto> dtos = GetContentNodeDtos(sql);
IEnumerable<ContentSourceDto> dtos = GetContentNodeDtos(sql, Constants.ObjectTypes.Media);

foreach (ContentSourceDto row in dtos)
{
Expand Down Expand Up @@ -990,7 +990,7 @@ private ContentNodeKit CreateMediaNodeKit(ContentSourceDto dto, IContentCacheDat
return s;
}

private IEnumerable<ContentSourceDto> GetContentNodeDtos(Sql<ISqlContext> sql)
private IEnumerable<ContentSourceDto> GetContentNodeDtos(Sql<ISqlContext> sql, Guid nodeObjectType)
{
// We need to page here. We don't want to iterate over every single row in one connection cuz this can cause an SQL Timeout.
// We also want to read with a db reader and not load everything into memory, QueryPaged lets us do that.
Expand All @@ -1000,7 +1000,7 @@ private IEnumerable<ContentSourceDto> GetContentNodeDtos(Sql<ISqlContext> sql)
{
// Use a more efficient COUNT query
Sql<ISqlContext>? sqlCountQuery = SqlContentSourcesCount()
.Append(SqlObjectTypeNotTrashed(SqlContext, Constants.ObjectTypes.Document));
.Append(SqlObjectTypeNotTrashed(SqlContext, nodeObjectType));

Sql<ISqlContext>? sqlCount =
SqlContext.Sql("SELECT COUNT(*) FROM (").Append(sqlCountQuery).Append(") npoco_tbl");
Expand Down
8 changes: 4 additions & 4 deletions src/Umbraco.Web.BackOffice/Controllers/ContentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2337,11 +2337,11 @@ public ActionResult<DomainSave> PostSaveLanguageAndDomains(DomainSave model)
return NotFound("There is no content node with id {model.NodeId}.");
}

EntityPermission? permission =
_userService.GetPermissions(_backofficeSecurityAccessor.BackOfficeSecurity?.CurrentUser, node.Path);
// Validate permissions on node
var permissions = _userService.GetAllPermissions(_backofficeSecurityAccessor.BackOfficeSecurity?.CurrentUser, node.Path);


if (permission?.AssignedPermissions.Contains(ActionAssignDomain.ActionLetter.ToString(), StringComparer.Ordinal) == false)
if (permissions.Any(x =>
x.AssignedPermissions.Contains(ActionAssignDomain.ActionLetter.ToString(), StringComparer.Ordinal) && x.EntityId == node.Id) == false)
{
HttpContext.SetReasonPhrase("Permission Denied.");
return BadRequest("You do not have permission to assign domains on that node.");
Expand Down

0 comments on commit df4cd63

Please sign in to comment.