Skip to content

Commit

Permalink
Merge pull request #543 from tidusjar/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
tidusjar authored Sep 18, 2016
2 parents 3917ebc + 0f9015f commit 962e663
Show file tree
Hide file tree
Showing 25 changed files with 403 additions and 69 deletions.
2 changes: 1 addition & 1 deletion PlexRequests.Core/UserMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public bool UpdatePassword(string username, string oldPassword, string newPasswo
var passwordMatch = PasswordHasher.VerifyPassword(oldPassword, userToChange.Salt, userToChange.Hash);
if (!passwordMatch)
{
throw new SecurityException("Password does not match");
throw new SecurityException("Incorrect password.");
}

var newSalt = PasswordHasher.GenerateSalt();
Expand Down
1 change: 1 addition & 0 deletions PlexRequests.Helpers.Tests/StringHasherTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ private static IEnumerable<TestCaseData> StringHashData
{
yield return new TestCaseData("hello!").Returns("5a8dd3ad0756a93ded72b823b19dd877").SetName("Hello");
yield return new TestCaseData("0111111").Returns("9549d400a68633435918290085f06293").SetName("Number");
yield return new TestCaseData("tidusjar").Returns("f47201e0103fa37ca82ce5243cebb9c7").SetName("tidusjar");
yield return new TestCaseData("hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!").Returns("26d0d126918fbecfc0fa4a63070d314c")
.SetName("Long string");
}
Expand Down
2 changes: 1 addition & 1 deletion PlexRequests.Helpers.Tests/TypeHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private static IEnumerable<TestCaseData> TypeData
"ProviderId", "ImdbId", "TvDbId", "Overview", "Title", "PosterPath", "ReleaseDate", "Type",
"Status", "Approved", "RequestedBy", "RequestedDate", "Available", "Issues", "OtherMessage", "AdminNote",
"SeasonList", "SeasonCount", "SeasonsRequested", "MusicBrainzId", "RequestedUsers","ArtistName",
"ArtistId","IssueId","Episodes","AllUsers","CanApprove","Id"
"ArtistId","IssueId","Episodes", "Denied", "DeniedReason", "AllUsers","CanApprove","Id",
}).SetName("Requested Model");
}
}
Expand Down
2 changes: 1 addition & 1 deletion PlexRequests.Helpers/StringHasher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static string CalcuateMd5Hash(string input)
{
using (var md5 = MD5.Create())
{
var inputBytes = Encoding.ASCII.GetBytes(input);
var inputBytes = Encoding.UTF8.GetBytes(input);
var hash = md5.ComputeHash(inputBytes);

var sb = new StringBuilder();
Expand Down
10 changes: 7 additions & 3 deletions PlexRequests.Services/Jobs/CouchPotatoCacher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,12 @@ public int[] QueuedIds()
{
var movies = Cache.Get<CouchPotatoMovies>(CacheKeys.CouchPotatoQueued);

var items = movies?.movies?.Select(x => x.info?.tmdb_id).Cast<int>().ToArray();
return items ?? new int[] { };
var items = movies?.movies?.Select(x => x.info?.tmdb_id);
if(items != null)
{
return items.Cast<int>().ToArray();
}
return new int[] { };
}
catch (Exception e)
{
Expand All @@ -107,4 +111,4 @@ public void Execute(IJobExecutionContext context)
Queued();
}
}
}
}
9 changes: 9 additions & 0 deletions PlexRequests.Services/Jobs/PlexAvailabilityChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,18 @@ public bool IsMovieAvailable(PlexMovie[] plexMovies, string title, string year,

public PlexMovie GetMovie(PlexMovie[] plexMovies, string title, string year, string providerId = null)
{
if (plexMovies.Length == 0)
{
return null;
}
var advanced = !string.IsNullOrEmpty(providerId);
foreach (var movie in plexMovies)
{
if (string.IsNullOrEmpty(movie.Title) || string.IsNullOrEmpty(movie.ReleaseYear))
{
continue;
}

if (advanced)
{
if (!string.IsNullOrEmpty(movie.ProviderId) &&
Expand Down
4 changes: 3 additions & 1 deletion PlexRequests.Store/RequestedModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public RequestedModel()
public string Status { get; set; }
public bool Approved { get; set; }

[Obsolete("Use RequestedUsers")]
[Obsolete("Use RequestedUsers")] //TODO remove this obsolete property
public string RequestedBy { get; set; }

public DateTime RequestedDate { get; set; }
Expand All @@ -44,6 +44,8 @@ public RequestedModel()
public string ArtistId { get; set; }
public int IssueId { get; set; }
public List<EpisodesModel> Episodes { get; set; }
public bool Denied { get; set; }
public string DeniedReason { get; set; }

[JsonIgnore]
public List<string> AllUsers
Expand Down
118 changes: 111 additions & 7 deletions PlexRequests.UI/Content/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,17 @@ $('#noteModal').on('show.bs.modal', function (event) {
requestField.val(id); // Add ID to the hidden field
});

// Update deny reason modal
$('#denyReasonModal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget); // Button that triggered the modal
var id = button.data('identifier'); // Extract info from data-* attributes

var modal = $(this);
modal.find('.denySaveReason').val(id); // Add ID to the button
var requestField = modal.find('input');
requestField.val(id); // Add ID to the hidden field
});

// Delete
$(document).on("click", ".delete", function (e) {
e.preventDefault();
Expand Down Expand Up @@ -403,28 +414,85 @@ $(document).on("click", ".delete", function (e) {
// Approve single request
$(document).on("click", ".approve", function (e) {
e.preventDefault();
var $this = $(this);
var $form = $this.parents('form').first();
var $self = $(this);
var $form = $self.parents('form').first();

if ($this.text() === " Loading...") {
if ($self.text() === " Loading...") {
return;
}

loadingButton($this.attr('id'), "success");
loadingButton($self.attr('id'), "success");

approveRequest($form, null, function () {
$("#" + $this.attr('id') + "notapproved").prop("class", "fa fa-check");
$("#" + $self.attr('id') + "notapproved").prop("class", "fa fa-check");


var $group = $this.parent('.btn-split');
var $group = $self.parent('.btn-split');
if ($group.length > 0) {
$group.remove();
}
else {
$this.remove();
$self.remove();
}
});
});

// Deny single request
$(document).on("click", ".deny", function (e) {
e.preventDefault();
var $self = $(this);
var $form = $self.parents('form').first();

if ($self.text() === " Loading...") {
return;
}
loadingButton($self.attr('id')+"deny", "success");

denyRequest($form, function () {
// Remove the form
$("#" + "deny" + $self.attr('id')).remove();
// remove the approve button
var id = $self.attr("custom-button");
$("#" + id).remove();

var $group = $self.parent('.btn-split');
if ($group.length > 0) {
$group.remove();
}
else {
$self.remove();
}
});
});

// Deny single request with reason (modal)
$(document).on("click", ".denySaveReason", function (e) {
var comment = $("#denyReason").val();
e.preventDefault();

var $form = $("#denyReasonForm");
var data = $form.serialize();
data = data + "&reason=" + comment;

$.ajax({
type: $form.prop("method"),
url: $form.prop("action"),
data: data,
dataType: "json",
success: function (response) {
if (checkJsonResponse(response)) {
generateNotify(response.message, "success");
$("#denyReasonModal").modal("hide");
}
},
error: function (e) {
console.log(e);
generateNotify("Something went wrong!", "danger");
}
});
});


$(document).on("click", ".approve-with-quality", function (e) {
e.preventDefault();
var $this = $(this);
Expand Down Expand Up @@ -524,6 +592,35 @@ function approveRequest($form, qualityId, successCallback) {
});
}

function denyRequest($form, successCallback) {

var formData = $form.serialize();
$.ajax({
type: $form.prop('method'),
url: $form.prop('action'),
data: formData,
dataType: "json",
success: function (response) {

if (checkJsonResponse(response)) {
if (response.message) {
generateNotify(response.message, "success");
} else {
generateNotify("Success! Request Approved.", "success");
}

if (successCallback) {
successCallback();
}
}
},
error: function (e) {
console.log(e);
generateNotify("Something went wrong!", "danger");
}
});
}

function mixItUpConfig(activeState) {
var conf = mixItUpDefault;

Expand Down Expand Up @@ -556,6 +653,11 @@ function movieLoad() {
var html = searchTemplate(context);
$ml.append(html);
});


$('.customTooltip').tooltipster({
contentCloning: true
});
}
else {
$ml.html(noResultsHtml.format("movie"));
Expand Down Expand Up @@ -658,6 +760,8 @@ function buildRequestContext(result, type) {
hasQualities: result.qualities && result.qualities.length > 0,
artist: result.artistName,
musicBrainzId: result.musicBrainzId,
denied: result.denied,
deniedReason: result.deniedReason,
};

return context;
Expand Down
3 changes: 2 additions & 1 deletion PlexRequests.UI/Content/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,8 @@ $(function () {
available: result.available,
episodes: result.episodes,
tvFullyAvailable: result.tvFullyAvailable,
url: result.plexUrl
url: result.plexUrl,
tvPartialAvailable : result.tvPartialAvailable
};
return context;
}
Expand Down
59 changes: 51 additions & 8 deletions PlexRequests.UI/Helpers/TvSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
using PlexRequests.Core.SettingModels;
using PlexRequests.Store;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;

using PlexRequests.Helpers.Exceptions;
Expand Down Expand Up @@ -70,7 +71,7 @@ public async Task<SonarrAddSeries> SendToSonarr(SonarrSettings sonarrSettings, R
{
int.TryParse(sonarrSettings.QualityProfile, out qualityProfile);
}

var series = await GetSonarrSeries(sonarrSettings, model.ProviderId);

if (episodeRequest)
Expand All @@ -81,7 +82,7 @@ public async Task<SonarrAddSeries> SendToSonarr(SonarrSettings sonarrSettings, R
// Series Exists
// Request the episodes in the existing series
await RequestEpisodesWithExistingSeries(model, series, sonarrSettings);
return new SonarrAddSeries {title = series.title};
return new SonarrAddSeries { title = series.title };
}


Expand All @@ -93,7 +94,7 @@ public async Task<SonarrAddSeries> SendToSonarr(SonarrSettings sonarrSettings, R

// Get the series that was just added
series = await GetSonarrSeries(sonarrSettings, model.ProviderId);
series.monitored = false; // Un-monitor the series
series.monitored = true; // We want to make sure we are monitoring the series

// Un-monitor all seasons
foreach (var season in series.seasons)
Expand All @@ -113,15 +114,44 @@ public async Task<SonarrAddSeries> SendToSonarr(SonarrSettings sonarrSettings, R

if (series != null)
{
// Monitor the seasons that we have chosen
foreach (var season in series.seasons)
var requestAll = model.SeasonsRequested.Equals("All", StringComparison.CurrentCultureIgnoreCase);
var first = model.SeasonsRequested.Equals("First", StringComparison.CurrentCultureIgnoreCase);
var latest = model.SeasonsRequested.Equals("Latest", StringComparison.CurrentCultureIgnoreCase);

if (model.SeasonList.Any())
{
if (model.SeasonList.Contains(season.seasonNumber))
// Monitor the seasons that we have chosen
foreach (var season in series.seasons)
{
if (model.SeasonList.Contains(season.seasonNumber))
{
season.monitored = true;
}
}
}

if (requestAll)
{
// Monitor all seasons
foreach (var season in series.seasons)
{
season.monitored = true;
}
}

if (first)
{
var firstSeries = series?.seasons?.OrderBy(x => x.seasonNumber)?.FirstOrDefault() ?? new Season();
firstSeries.monitored = true;
}

if (latest)
{
var lastSeries = series?.seasons?.OrderByDescending(x => x.seasonNumber)?.FirstOrDefault() ?? new Season();
lastSeries.monitored = true;
}


// Update the series in sonarr with the new monitored status
SonarrApi.UpdateSeries(series, sonarrSettings.ApiKey, sonarrSettings.FullUri);
await RequestAllEpisodesInASeasonWithExistingSeries(model, series, sonarrSettings);
Expand Down Expand Up @@ -201,7 +231,7 @@ internal async Task RequestAllEpisodesWithExistingSeries(RequestedModel model, S
var tasks = new List<Task>();
foreach (var r in episodes)
{
if(r.monitored || r.hasFile) // If it's already montiored or has the file, there is no point in updating it
if (r.monitored || r.hasFile) // If it's already montiored or has the file, there is no point in updating it
{
continue;
}
Expand Down Expand Up @@ -230,9 +260,22 @@ internal async Task RequestAllEpisodesInASeasonWithExistingSeries(RequestedModel

var internalEpisodeIds = new List<int>();
var tasks = new List<Task>();

var requestedEpisodes = model.Episodes;

foreach (var r in episodes)
{
if (r.hasFile || !model.SeasonList.Contains(r.seasonNumber)) // If it already has the file, there is no point in updating it
if (r.hasFile) // If it already has the file, there is no point in updating it
{
continue;
}
var epComparison = new EpisodesModel
{
EpisodeNumber = r.episodeNumber,
SeasonNumber = r.seasonNumber
};
// Make sure we are looking for the right episode and season
if (!requestedEpisodes.Contains(epComparison))
{
continue;
}
Expand Down
2 changes: 2 additions & 0 deletions PlexRequests.UI/Models/RequestViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,7 @@ public class RequestViewModel
public QualityModel[] Qualities { get; set; }
public string ArtistName { get; set; }
public Store.EpisodesModel[] Episodes { get; set; }
public bool Denied { get; set; }
public string DeniedReason { get; set; }
}
}
Loading

0 comments on commit 962e663

Please sign in to comment.