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>

View File

@ -15,11 +15,11 @@ namespace MediaBrowser.Dlna.Profiles
Name = "Xbox 360";
// Required according to above
ModelName = "Windows Media Connect";
ModelName = "Windows Media Player Sharing";
ModelNumber = "12.0";
FriendlyName = "${HostName} : 1 : Windows Media Connect";
FriendlyName = "${HostName} : 1";
ModelUrl = "http://www.microsoft.com/";
Manufacturer = "Microsoft Corporation";

View File

@ -8,10 +8,10 @@
<HttpHeaderInfo name="User-Agent" value="Xenon" match="Substring" />
</Headers>
</Identification>
<FriendlyName>${HostName} : 1 : Windows Media Connect</FriendlyName>
<FriendlyName>${HostName} : 1</FriendlyName>
<Manufacturer>Microsoft Corporation</Manufacturer>
<ManufacturerUrl>http://www.microsoft.com/</ManufacturerUrl>
<ModelName>Windows Media Connect</ModelName>
<ModelName>Windows Media Player Sharing</ModelName>
<ModelDescription>Media Browser</ModelDescription>
<ModelNumber>12.0</ModelNumber>
<ModelUrl>http://www.microsoft.com/</ModelUrl>

View File

@ -1181,6 +1181,12 @@
<Compile Include="..\MediaBrowser.Model\Users\PinRedeemResult.cs">
<Link>Users\PinRedeemResult.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Users\TagFilter.cs">
<Link>Users\TagFilter.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Users\TagFilterMode.cs">
<Link>Users\TagFilterMode.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Users\UserAction.cs">
<Link>Users\UserAction.cs</Link>
</Compile>

View File

@ -1140,6 +1140,12 @@
<Compile Include="..\MediaBrowser.Model\Users\PinRedeemResult.cs">
<Link>Users\PinRedeemResult.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Users\TagFilter.cs">
<Link>Users\TagFilter.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Users\TagFilterMode.cs">
<Link>Users\TagFilterMode.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Users\UserAction.cs">
<Link>Users\UserAction.cs</Link>
</Compile>

View File

@ -433,6 +433,8 @@
<Compile Include="Users\ForgotPasswordAction.cs" />
<Compile Include="Users\ForgotPasswordResult.cs" />
<Compile Include="Users\PinRedeemResult.cs" />
<Compile Include="Users\TagFilter.cs" />
<Compile Include="Users\TagFilterMode.cs" />
<Compile Include="Users\UserAction.cs" />
<Compile Include="Users\UserActionType.cs" />
<Compile Include="Users\UserPolicy.cs" />

View File

@ -0,0 +1,9 @@

namespace MediaBrowser.Model.Users
{
public class TagFilter
{
public string Tag { get; set; }
public TagFilterMode Mode { get; set; }
}
}

View File

@ -0,0 +1,9 @@

namespace MediaBrowser.Model.Users
{
public enum TagFilterMode
{
Block = 0,
Allow = 1
}
}

View File

@ -58,6 +58,8 @@ namespace MediaBrowser.Model.Users
public string[] EnabledFolders { get; set; }
public bool EnableAllFolders { get; set; }
public TagFilter[] TagFilters { get; set; }
public UserPolicy()
{
@ -66,7 +68,6 @@ namespace MediaBrowser.Model.Users
EnableLiveTvAccess = true;
EnableSharedDeviceControl = true;
BlockedTags = new string[] { };
BlockUnratedItems = new UnratedItem[] { };
EnableUserPreferenceAccess = true;
@ -83,6 +84,8 @@ namespace MediaBrowser.Model.Users
EnableAllDevices = true;
EnableContentDownloading = true;
TagFilters = new TagFilter[] { };
}
}
}

View File

@ -168,6 +168,7 @@ namespace MediaBrowser.Server.Implementations.Library
foreach (var user in users)
{
await DoPolicyMigration(user).ConfigureAwait(false);
await DoBlockedTagMigration(user).ConfigureAwait(false);
}
// If there are no local users with admin rights, make them all admins
@ -346,6 +347,25 @@ namespace MediaBrowser.Server.Implementations.Library
}
}
private async Task DoBlockedTagMigration(User user)
{
if (user.Policy.BlockedTags != null)
{
user.Policy.TagFilters = user.Policy
.BlockedTags
.Select(i => new TagFilter
{
Tag = i,
Mode = TagFilterMode.Block
})
.ToArray();
user.Policy.BlockedTags = null;
await UpdateUserPolicy(user, user.Policy, false);
}
}
public UserDto GetUserDto(User user, string remoteEndPoint = null)
{
if (user == null)

View File

@ -276,7 +276,7 @@
"ButtonStart": "Start",
"HeaderChannels": "Channels",
"HeaderMediaFolders": "Media Folders",
"HeaderBlockItemsWithNoRating": "Block items with no rating information:",
"HeaderBlockItemsWithNoRating": "Block content with no rating information:",
"OptionBlockOthers": "Others",
"OptionBlockTvShows": "TV Shows",
"OptionBlockTrailers": "Trailers",

View File

@ -1356,8 +1356,10 @@
"HeaderVideoTypes": "Video Types",
"HeaderYears": "Years",
"HeaderAddTag": "Add Tag",
"LabelBlockItemsWithTags": "Block items with tags:",
"LabelBlockOrAllowItemsWithTags": "Block or allow content with tags:",
"LabelTag": "Tag:",
"OptionBlockItemWithTag": "Block all content with this tag",
"OptionAllowItemWithTag": "Allow only content with this tag",
"LabelEnableSingleImageInDidlLimit": "Limit to single embedded image",
"LabelEnableSingleImageInDidlLimitHelp": "Some devices will not render properly if multiple images are embedded within Didl.",
"TabActivity": "Activity",
@ -1368,5 +1370,7 @@
"NameSeasonNumber": "Season {0}",
"LabelNewUserNameHelp": "Usernames can contain letters (a-z), numbers (0-9), dashes (-), underscores (_), apostrophes ('), and periods (.)",
"TabJobs": "Jobs",
"TabSyncJobs": "Sync Jobs"
"TabSyncJobs": "Sync Jobs",
"LabelTagFilterMode": "Mode:",
"LabelTagFilterAllowModeHelp": "If used as part of a deeply nested folder structure, content that is tagged with this mechanism will require parent folders to be tagged as well."
}

View File

@ -90,7 +90,7 @@
<Content Include="dashboard-ui\css\images\server.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\css\images\splash.png">
<Content Include="dashboard-ui\css\images\splash.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\css\images\tour\dashboard\help.png">