Skip to content

Commit

Permalink
improve publishing filter to also work with default-in only
Browse files Browse the repository at this point in the history
  • Loading branch information
iJungleboy committed Jul 4, 2024
1 parent 419b014 commit 23ed823
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ToSic.Eav.DataSources/DataSources/App/AppRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace ToSic.Eav.DataSources;

/// <summary>
/// The App Root is the entry point for all data. It takes it's data from a hidden AppState Cache.
/// The App Root is the entry point for all data. It takes its data from a hidden AppState Cache.
/// It's implemented as a DataSource so that other DataSources can easily attach to it. <br/>
/// This is also the object returned as the root in any query.
/// </summary>
Expand Down
27 changes: 22 additions & 5 deletions ToSic.Eav.DataSources/DataSources/Security/PublishingFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,31 @@ public PublishingFilter(MyServices services, IContextResolverUserPermissions use

private IImmutableList<IEntity> PublishingFilterList()
{
var showDraftsAsSet = ShowDrafts;
var showDraftsSetting = ShowDrafts;
var l = Log.Fn<IImmutableList<IEntity>>();
var finalShowDrafts = showDraftsAsSet
var finalShowDrafts = showDraftsSetting
?? _userPermissions.UserPermissions()?.ShowDraftData
?? QueryConstants.ParamsShowDraftsDefault;
var outStreamName = finalShowDrafts ? StreamDraftsName : StreamPublishedName;
var result = In[outStreamName].List.ToImmutableList();
return l.Return(result, $"showDraftSet:'{showDraftsAsSet}'; final:{finalShowDrafts}; stream: {outStreamName}; count: {result.Count}");
var inStreamName = finalShowDrafts
? StreamDraftsName
: StreamPublishedName;

// Standard / old case: if the inputs already have the correct streams, use them.
if (In.TryGetValue(inStreamName, out var inStream))
{
var result = inStream.List.ToImmutableList();
return l.Return(result, $"Show Draft setting:'{showDraftsSetting}'; final:{finalShowDrafts}; stream: {inStreamName}; count: {result.Count}");
}

if (In.TryGetValue(StreamDefaultName, out var inDefault))
{
var filtered = finalShowDrafts
? inDefault.List.ToImmutableList()
: inDefault.List.Where(e => e.IsPublished).ToImmutableList();
return l.Return(filtered, $"Refiltering the Default; setting:'{showDraftsSetting}'; final:{finalShowDrafts}; stream: {StreamDefaultName}; count: {filtered.Count}");
}

return l.ReturnAsError(Error.TryGetInFailed(name: $"{inStreamName}/{StreamDefaultName}"));
}

}

0 comments on commit 23ed823

Please sign in to comment.