revise opt-in tags

This commit is contained in:
Luke Pulverenti 2015-02-09 01:56:45 -05:00
parent d5c4655361
commit f03f2346f3
12 changed files with 16 additions and 89 deletions

View File

@ -74,7 +74,7 @@ namespace MediaBrowser.Controller.Channels
return false; return false;
} }
protected override bool IsTagFilterEnforced(TagFilterMode mode) protected override bool IsAllowTagFilterEnforced()
{ {
return false; return false;
} }

View File

@ -1080,31 +1080,14 @@ namespace MediaBrowser.Controller.Entities
if (hasTags != null) if (hasTags != null)
{ {
if (user.Policy.TagFilters.Any(i => !IsTagFilterAccepted(hasTags, i))) var policy = user.Policy;
if (policy.BlockedTags.Any(i => hasTags.Tags.Contains(i, StringComparer.OrdinalIgnoreCase)))
{ {
return false; return false;
} }
} if (policy.AllowedTags.Length > 0 && IsAllowTagFilterEnforced())
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 (policy.AllowedTags.Any(i => !hasTags.Tags.Contains(i, StringComparer.OrdinalIgnoreCase)))
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 false;
} }
@ -1114,7 +1097,7 @@ namespace MediaBrowser.Controller.Entities
return true; return true;
} }
protected virtual bool IsTagFilterEnforced(TagFilterMode mode) protected virtual bool IsAllowTagFilterEnforced()
{ {
return true; return true;
} }

View File

@ -80,7 +80,7 @@ namespace MediaBrowser.Controller.Entities
} }
} }
protected override bool IsTagFilterEnforced(TagFilterMode mode) protected override bool IsAllowTagFilterEnforced()
{ {
if (this is ICollectionFolder) if (this is ICollectionFolder)
{ {

View File

@ -1181,12 +1181,6 @@
<Compile Include="..\MediaBrowser.Model\Users\PinRedeemResult.cs"> <Compile Include="..\MediaBrowser.Model\Users\PinRedeemResult.cs">
<Link>Users\PinRedeemResult.cs</Link> <Link>Users\PinRedeemResult.cs</Link>
</Compile> </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"> <Compile Include="..\MediaBrowser.Model\Users\UserAction.cs">
<Link>Users\UserAction.cs</Link> <Link>Users\UserAction.cs</Link>
</Compile> </Compile>

View File

@ -1140,12 +1140,6 @@
<Compile Include="..\MediaBrowser.Model\Users\PinRedeemResult.cs"> <Compile Include="..\MediaBrowser.Model\Users\PinRedeemResult.cs">
<Link>Users\PinRedeemResult.cs</Link> <Link>Users\PinRedeemResult.cs</Link>
</Compile> </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"> <Compile Include="..\MediaBrowser.Model\Users\UserAction.cs">
<Link>Users\UserAction.cs</Link> <Link>Users\UserAction.cs</Link>
</Compile> </Compile>

View File

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

View File

@ -1,9 +0,0 @@

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

View File

@ -1,9 +0,0 @@

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

View File

@ -29,6 +29,7 @@ namespace MediaBrowser.Model.Users
public int? MaxParentalRating { get; set; } public int? MaxParentalRating { get; set; }
public string[] BlockedTags { get; set; } public string[] BlockedTags { get; set; }
public string[] AllowedTags { get; set; }
public bool EnableUserPreferenceAccess { get; set; } public bool EnableUserPreferenceAccess { get; set; }
public AccessSchedule[] AccessSchedules { get; set; } public AccessSchedule[] AccessSchedules { get; set; }
public UnratedItem[] BlockUnratedItems { get; set; } public UnratedItem[] BlockUnratedItems { get; set; }
@ -59,8 +60,6 @@ namespace MediaBrowser.Model.Users
public string[] EnabledFolders { get; set; } public string[] EnabledFolders { get; set; }
public bool EnableAllFolders { get; set; } public bool EnableAllFolders { get; set; }
public TagFilter[] TagFilters { get; set; }
public UserPolicy() public UserPolicy()
{ {
EnableLiveTvManagement = true; EnableLiveTvManagement = true;
@ -68,6 +67,8 @@ namespace MediaBrowser.Model.Users
EnableLiveTvAccess = true; EnableLiveTvAccess = true;
EnableSharedDeviceControl = true; EnableSharedDeviceControl = true;
BlockedTags = new string[] { };
AllowedTags = new string[] { };
BlockUnratedItems = new UnratedItem[] { }; BlockUnratedItems = new UnratedItem[] { };
EnableUserPreferenceAccess = true; EnableUserPreferenceAccess = true;
@ -84,8 +85,6 @@ namespace MediaBrowser.Model.Users
EnableAllDevices = true; EnableAllDevices = true;
EnableContentDownloading = true; EnableContentDownloading = true;
TagFilters = new TagFilter[] { };
} }
} }
} }

View File

@ -168,7 +168,6 @@ namespace MediaBrowser.Server.Implementations.Library
foreach (var user in users) foreach (var user in users)
{ {
await DoPolicyMigration(user).ConfigureAwait(false); await DoPolicyMigration(user).ConfigureAwait(false);
await DoBlockedTagMigration(user).ConfigureAwait(false);
} }
// If there are no local users with admin rights, make them all admins // If there are no local users with admin rights, make them all admins
@ -347,25 +346,6 @@ 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) public UserDto GetUserDto(User user, string remoteEndPoint = null)
{ {
if (user == null) if (user == null)
@ -1036,4 +1016,4 @@ namespace MediaBrowser.Server.Implementations.Library
} }
} }
} }
} }

View File

@ -727,7 +727,5 @@
"SyncJobItemStatusSynced": "Synced", "SyncJobItemStatusSynced": "Synced",
"SyncJobItemStatusFailed": "Failed", "SyncJobItemStatusFailed": "Failed",
"SyncJobItemStatusRemovedFromDevice": "Removed from device", "SyncJobItemStatusRemovedFromDevice": "Removed from device",
"SyncJobItemStatusCancelled": "Cancelled", "SyncJobItemStatusCancelled": "Cancelled"
"MessageBlockContentWithThisTag": "Block all content with this tag",
"MessageAllowContentWithThisTag": "Allow only content with this tag"
} }

View File

@ -1356,10 +1356,9 @@
"HeaderVideoTypes": "Video Types", "HeaderVideoTypes": "Video Types",
"HeaderYears": "Years", "HeaderYears": "Years",
"HeaderAddTag": "Add Tag", "HeaderAddTag": "Add Tag",
"LabelBlockOrAllowItemsWithTags": "Block or allow content with tags:", "LabelBlockContentWithTags": "Block content with tags:",
"LabelAllowContentWithTags": "Allow only content with tags:",
"LabelTag": "Tag:", "LabelTag": "Tag:",
"OptionBlockItemWithTag": "Block all content with this tag",
"OptionAllowItemWithTag": "Allow only content with this tag",
"LabelEnableSingleImageInDidlLimit": "Limit to single embedded image", "LabelEnableSingleImageInDidlLimit": "Limit to single embedded image",
"LabelEnableSingleImageInDidlLimitHelp": "Some devices will not render properly if multiple images are embedded within Didl.", "LabelEnableSingleImageInDidlLimitHelp": "Some devices will not render properly if multiple images are embedded within Didl.",
"TabActivity": "Activity", "TabActivity": "Activity",
@ -1372,5 +1371,5 @@
"TabJobs": "Jobs", "TabJobs": "Jobs",
"TabSyncJobs": "Sync Jobs", "TabSyncJobs": "Sync Jobs",
"LabelTagFilterMode": "Mode:", "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." "LabelTagFilterAllowModeHelp": "If allowed tags are used as part of a deeply nested folder structure, content that is tagged will require parent folders to be tagged as well."
} }