mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-21 17:44:43 +01:00
added an allow mode filter for tags
This commit is contained in:
@@ -5,6 +5,7 @@ using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Model.Users;
|
||||
|
||||
namespace MediaBrowser.Controller.Channels
|
||||
{
|
||||
@@ -72,5 +73,10 @@ namespace MediaBrowser.Controller.Channels
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
protected override bool IsTagFilterEnforced(TagFilterMode mode)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1080,7 +1080,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
|
||||
if (hasTags != null)
|
||||
{
|
||||
if (user.Policy.BlockedTags.Any(i => hasTags.Tags.Contains(i, StringComparer.OrdinalIgnoreCase)))
|
||||
if (user.Policy.TagFilters.Any(i => !IsTagFilterAccepted(hasTags, i)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -1089,6 +1089,36 @@ namespace MediaBrowser.Controller.Entities
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool IsTagFilterAccepted(IHasTags hasTags, TagFilter filter)
|
||||
{
|
||||
if (IsTagFilterEnforced(filter.Mode))
|
||||
{
|
||||
if (filter.Mode == TagFilterMode.Block)
|
||||
{
|
||||
// If content has the tag, it's not allowed
|
||||
if (hasTags.Tags.Contains(filter.Tag, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (filter.Mode == TagFilterMode.Allow)
|
||||
{
|
||||
// If content doesn't have the tag, it's not allowed
|
||||
if (!hasTags.Tags.Contains(filter.Tag, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected virtual bool IsTagFilterEnforced(TagFilterMode mode)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the block unrated value.
|
||||
/// </summary>
|
||||
|
||||
@@ -14,6 +14,7 @@ using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Model.Users;
|
||||
|
||||
namespace MediaBrowser.Controller.Entities
|
||||
{
|
||||
@@ -79,6 +80,19 @@ namespace MediaBrowser.Controller.Entities
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool IsTagFilterEnforced(TagFilterMode mode)
|
||||
{
|
||||
if (this is ICollectionFolder)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this is UserView)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether this instance is physical root.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user