added an allow mode filter for tags

This commit is contained in:
Luke Pulverenti
2015-02-09 01:17:11 -05:00
parent ac68e0ba41
commit 01828f19a7
15 changed files with 119 additions and 10 deletions

View File

@@ -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;
}
}
}

View File

@@ -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>

View File

@@ -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>