Newznab providers will be compared based on url, not name.

Built-in Newznab providers cannot be deleted (they would be re-added anyways), nor can the URL be changed.
pull/3113/head
Mark McDowall 13 years ago
parent b7fea36045
commit b930eb0993

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
@ -216,6 +217,7 @@ namespace NzbDrone.Core.Test.ProviderTests
//Assert
var result = db.Fetch<NewznabDefinition>();
result.Should().HaveCount(5);
result.Should().OnlyContain(i => i.BuiltIn);
}
[Test]
@ -236,16 +238,39 @@ namespace NzbDrone.Core.Test.ProviderTests
Mocker.SetConstant(db);
db.Insert(definitions[0]);
db.Insert(definitions[1]);
db.Insert(definitions[2]);
//Act
Mocker.Resolve<NewznabProvider>().InitializeNewznabIndexers(definitions);
//Assert
var result = db.Fetch<NewznabDefinition>();
result.Should().HaveCount(5);
result.Where(d => d.Url == "http://www.nzbdrone.com").Should().HaveCount(3);
result.Where(d => d.Url == "http://www.nzbdrone2.com").Should().HaveCount(2);
result.Should().HaveCount(2);
result.Where(d => d.Url == "http://www.nzbdrone.com").Should().HaveCount(1);
result.Where(d => d.Url == "http://www.nzbdrone2.com").Should().HaveCount(1);
}
[Test]
public void InitializeNewznabIndexers_should_update_matching_indexer_to_be_builtin()
{
//Setup
var definition = Builder<NewznabDefinition>.CreateNew()
.With(d => d.Url = "http://www.nzbdrone2.com")
.With(d => d.BuiltIn = false)
.Build();
var db = TestDbHelper.GetEmptyDatabase();
Mocker.SetConstant(db);
db.Insert(definition);
//Act
Mocker.Resolve<NewznabProvider>().InitializeNewznabIndexers(new List<NewznabDefinition>{ definition });
//Assert
var result = db.Fetch<NewznabDefinition>();
result.Should().HaveCount(1);
result.First().BuiltIn.Should().BeTrue();
}
}
}

@ -107,8 +107,8 @@ namespace NzbDrone.Core
var newznabIndexers = new List<NewznabDefinition>
{
new NewznabDefinition { Enable = false, Name = "Nzbs.org", Url = "http://nzbs.org" },
new NewznabDefinition { Enable = false, Name = "Nzb.su", Url = "http://nzb.su" }
new NewznabDefinition { Enable = false, Name = "Nzbs.org", Url = "https://nzbs.org", BuiltIn = true },
new NewznabDefinition { Enable = false, Name = "Nzb.su", Url = "https://nzb.su", BuiltIn = true }
};
Kernel.Get<NewznabProvider>().InitializeNewznabIndexers(newznabIndexers);

@ -0,0 +1,15 @@
using System.Data;
using Migrator.Framework;
namespace NzbDrone.Core.Datastore.Migrations
{
[Migration(20120504)]
public class Migration20120504 : NzbDroneMigration
{
protected override void MainDbUpgrade()
{
Database.AddColumn("NewznabDefinitions", "BuiltIn", DbType.Boolean, ColumnProperty.Null);
}
}
}

@ -224,6 +224,7 @@
<Compile Include="Datastore\MigrationLogger.cs" />
<Compile Include="Datastore\MigrationsHelper.cs" />
<Compile Include="Datastore\CustomeMapper.cs" />
<Compile Include="Datastore\Migrations\Migration20120504.cs" />
<Compile Include="Datastore\Migrations\Migration20120430.cs" />
<Compile Include="Datastore\Migrations\Migration20120420.cs" />
<Compile Include="Datastore\Migrations\Migration20120228.cs" />
@ -440,7 +441,7 @@
<Compile Include="Providers\MisnamedProvider.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Providers\NewznzbProvider.cs">
<Compile Include="Providers\NewznabProvider.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Providers\NotificationProvider.cs">

@ -70,18 +70,28 @@ namespace NzbDrone.Core.Providers
foreach (var feedProvider in indexers)
{
NewznabDefinition indexerLocal = feedProvider;
if (!currentIndexers.Exists(c => c.Name == indexerLocal.Name))
var currentIndexer = currentIndexers
.SingleOrDefault(c => new Uri(c.Url.ToLower()).Host == new Uri(indexerLocal.Url.ToLower()).Host);
if (currentIndexer == null)
{
var settings = new NewznabDefinition
{
Enable = false,
Name = indexerLocal.Name,
Url = indexerLocal.Url,
ApiKey = indexerLocal.ApiKey
ApiKey = indexerLocal.ApiKey,
BuiltIn = true
};
Save(settings);
}
else
{
currentIndexer.BuiltIn = true;
Save(currentIndexer);
}
}
}

@ -16,5 +16,7 @@ namespace NzbDrone.Core.Repository
public String Url { get; set; }
public String ApiKey { get; set; }
public bool BuiltIn { get; set; }
}
}

@ -13,8 +13,11 @@
<span class="titleText" id="title_@(Model.Id)">
@Model.Name
</span>
<a href="#" id="@Model.Id" class="deleteProvider" onclick="deleteProvider('@(Model.Id)'); return false;">
<img src="../../Content/Images/close.png" alt="Delete" width="22px" height="22px" /></a>
@if(!Model.BuiltIn)
{
<a href="#" id="@Model.Id" class="deleteProvider" onclick="deleteProvider('@(Model.Id)'); return false;">
<img src="../../Content/Images/close.png" alt="Delete" width="22px" height="22px" /></a>
}
</div>
<div class="providerOptions">
@Html.Label("Enabled")
@ -22,9 +25,18 @@
@Html.LabelFor(x => x.Name)
@Html.TextBoxFor(x => x.Name, new {@class = "providerName_textbox"})
@Html.LabelFor(x => x.Url)
@Html.TextBoxFor(m => m.Url)
@if(!Model.BuiltIn)
{
@Html.LabelFor(x => x.Url)
@Html.TextBoxFor(m => m.Url)
}
else
{
@Html.LabelFor(x => x.Url)
@Html.TextBoxFor(m => m.Url, new { disabled = "disabled" })
}
@Html.LabelFor(x => x.ApiKey)
@Html.TextBoxFor(m => m.ApiKey)

Loading…
Cancel
Save