only show requested by users to admins + start maintaining a list of users with each request

pull/110/head
Drewster727 9 years ago
parent 5a5512a1cd
commit b8a01b62b9

@ -33,7 +33,7 @@ namespace PlexRequests.Core
public interface IRequestService
{
long AddRequest(RequestedModel model);
bool CheckRequest(int providerId);
RequestedModel CheckRequest(int providerId);
void DeleteRequest(RequestedModel request);
bool UpdateRequest(RequestedModel model);
RequestedModel Get(int id);

@ -58,10 +58,11 @@ namespace PlexRequests.Core
return result ? id : -1;
}
public bool CheckRequest(int providerId)
public RequestedModel CheckRequest(int providerId)
{
var blobs = Repo.GetAll();
return blobs.Any(x => x.ProviderId == providerId);
var blob = blobs.FirstOrDefault(x => x.ProviderId == providerId);
return blob != null ? ByteConverterHelper.ReturnObject<RequestedModel>(blob.Content) : null;
}
public void DeleteRequest(RequestedModel request)

@ -2,6 +2,8 @@
using System.Security.Cryptography;
using Dapper.Contrib.Extensions;
using System.Collections.Generic;
using System.Linq;
namespace PlexRequests.Store
{
@ -18,7 +20,10 @@ namespace PlexRequests.Store
public RequestType Type { get; set; }
public string Status { get; set; }
public bool Approved { get; set; }
[Obsolete("Use RequestedUsers")]
public string RequestedBy { get; set; }
public DateTime RequestedDate { get; set; }
public bool Available { get; set; }
public IssueState Issues { get; set; }
@ -27,6 +32,17 @@ namespace PlexRequests.Store
public int[] SeasonList { get; set; }
public int SeasonCount { get; set; }
public string SeasonsRequested { get; set; }
public List<string> RequestedUsers { get; set; }
public bool UserHasRequested(string username)
{
bool alreadyRequested = !string.IsNullOrEmpty(RequestedBy) && RequestedBy.Equals(username, StringComparison.OrdinalIgnoreCase);
if (!alreadyRequested && RequestedUsers != null && RequestedUsers.Count > 0)
{
alreadyRequested = RequestedUsers.Any(x => x.Equals(username, StringComparison.OrdinalIgnoreCase));
}
return alreadyRequested;
}
}
public enum RequestType

@ -433,7 +433,7 @@ function buildRequestContext(result, type) {
releaseDate: result.releaseDate,
releaseDateTicks: result.releaseDateTicks,
approved: result.approved,
requestedBy: result.requestedBy,
requestedUsers: result.requestedUsers ? result.requestedUsers.join(', ') : '',
requestedDate: result.requestedDate,
requestedDateTicks: result.requestedDateTicks,
available: result.available,

@ -41,7 +41,7 @@ namespace PlexRequests.UI.Models
public RequestType Type { get; set; }
public string Status { get; set; }
public bool Approved { get; set; }
public string RequestedBy { get; set; }
public string[] RequestedUsers { get; set; }
public string RequestedDate { get; set; }
public long RequestedDateTicks { get; set; }
public string ReleaseYear { get; set; }

@ -84,7 +84,7 @@ namespace PlexRequests.UI.Modules
var dbMovies = Service.GetAll().Where(x => x.Type == RequestType.Movie);
if (settings.UsersCanViewOnlyOwnRequests && !isAdmin)
{
dbMovies = dbMovies.Where(x => x.RequestedBy.Equals(Session[SessionKeys.UsernameKey].ToString(), StringComparison.OrdinalIgnoreCase));
dbMovies = dbMovies.Where(x => x.UserHasRequested(Session[SessionKeys.UsernameKey].ToString()));
}
var viewModel = dbMovies.Select(movie => new RequestViewModel
@ -102,7 +102,7 @@ namespace PlexRequests.UI.Modules
Approved = movie.Available || movie.Approved,
Title = movie.Title,
Overview = movie.Overview,
RequestedBy = movie.RequestedBy,
RequestedUsers = isAdmin ? movie.RequestedUsers.ToArray() : new string[] { },
ReleaseYear = movie.ReleaseDate.Year.ToString(),
Available = movie.Available,
Admin = isAdmin,
@ -121,7 +121,7 @@ namespace PlexRequests.UI.Modules
var dbTv = Service.GetAll().Where(x => x.Type == RequestType.TvShow);
if (settings.UsersCanViewOnlyOwnRequests && !isAdmin)
{
dbTv = dbTv.Where(x => x.RequestedBy.Equals(Session[SessionKeys.UsernameKey].ToString(), StringComparison.OrdinalIgnoreCase));
dbTv = dbTv.Where(x => x.UserHasRequested(Session[SessionKeys.UsernameKey].ToString()));
}
var viewModel = dbTv.Select(tv => new RequestViewModel
@ -139,7 +139,7 @@ namespace PlexRequests.UI.Modules
Approved = tv.Available || tv.Approved,
Title = tv.Title,
Overview = tv.Overview,
RequestedBy = tv.RequestedBy,
RequestedUsers = isAdmin ? tv.RequestedUsers.ToArray() : new string[] { },
ReleaseYear = tv.ReleaseDate.Year.ToString(),
Available = tv.Available,
Admin = isAdmin,

@ -179,11 +179,20 @@ namespace PlexRequests.UI.Modules
Log.Trace(movieInfo.DumpJson);
//#if !DEBUG
var settings = PrService.GetSettings();
// check if the movie has already been requested
Log.Info("Requesting movie with id {0}", movieId);
if (RequestService.CheckRequest(movieId))
var existingRequest = RequestService.CheckRequest(movieId);
if (existingRequest != null)
{
Log.Trace("movie with id {0} exists", movieId);
return Response.AsJson(new JsonResponseModel { Result = false, Message = $"{fullMovieName} has already been requested!" });
// check if the current user is already marked as a requester for this movie, if not, add them
if (!existingRequest.UserHasRequested(Session[SessionKeys.UsernameKey].ToString()))
{
existingRequest.RequestedUsers.Add(Session[SessionKeys.UsernameKey].ToString());
RequestService.UpdateRequest(existingRequest);
}
return Response.AsJson(new JsonResponseModel { Result = false, Message = settings.UsersCanViewOnlyOwnRequests ? $"{fullMovieName} was successfully added!" : $"{fullMovieName} has already been requested!" });
}
Log.Debug("movie with id {0} doesnt exists", movieId);
@ -213,12 +222,10 @@ namespace PlexRequests.UI.Modules
Status = movieInfo.Status,
RequestedDate = DateTime.Now,
Approved = false,
RequestedBy = Session[SessionKeys.UsernameKey].ToString(),
RequestedUsers = new List<string>() { Session[SessionKeys.UsernameKey].ToString() },
Issues = IssueState.None,
};
var settings = PrService.GetSettings();
Log.Trace(settings.DumpJson());
if (!settings.RequireMovieApproval || settings.NoApprovalUserList.Any(x => x.Equals(Session[SessionKeys.UsernameKey].ToString(), StringComparison.OrdinalIgnoreCase)))
{
@ -310,9 +317,20 @@ namespace PlexRequests.UI.Modules
string fullShowName = $"{showInfo.name} ({firstAir.Year})";
//#if !DEBUG
if (RequestService.CheckRequest(showId))
var settings = PrService.GetSettings();
// check if the show has already been requested
Log.Info("Requesting tv show with id {0}", showId);
var existingRequest = RequestService.CheckRequest(showId);
if (existingRequest != null)
{
return Response.AsJson(new JsonResponseModel { Result = false, Message = $"{fullShowName} has already been requested!" });
// check if the current user is already marked as a requester for this show, if not, add them
if (!existingRequest.UserHasRequested(Session[SessionKeys.UsernameKey].ToString()))
{
existingRequest.RequestedUsers.Add(Session[SessionKeys.UsernameKey].ToString());
RequestService.UpdateRequest(existingRequest);
}
return Response.AsJson(new JsonResponseModel { Result = false, Message = settings.UsersCanViewOnlyOwnRequests ? $"{fullShowName} was successfully added!" : $"{fullShowName} has already been requested!" });
}
try
@ -340,7 +358,7 @@ namespace PlexRequests.UI.Modules
Status = showInfo.status,
RequestedDate = DateTime.Now,
Approved = false,
RequestedBy = Session[SessionKeys.UsernameKey].ToString(),
RequestedUsers = new List<string>() { Session[SessionKeys.UsernameKey].ToString() },
Issues = IssueState.None,
ImdbId = showInfo.externals?.imdb ?? string.Empty,
SeasonCount = showInfo.seasonCount
@ -363,7 +381,6 @@ namespace PlexRequests.UI.Modules
model.SeasonList = seasonsList.ToArray();
var settings = PrService.GetSettings();
if (!settings.RequireTvShowApproval || settings.NoApprovalUserList.Any(x => x.Equals(Session[SessionKeys.UsernameKey].ToString(), StringComparison.OrdinalIgnoreCase)))
{
var sonarrSettings = SonarrService.GetSettings();

@ -140,7 +140,7 @@
{{#if_eq type "tv"}}
<div>Series Requested: {{seriesRequested}}</div>
{{/if_eq}}
<div>Requested By: {{requestedBy}}</div>
<div>Requested By: {{requestedUsers}}</div>
<div>Requested Date: {{requestedDate}}</div>
<div id="issueArea{{requestId}}">
{{#if otherMessage}}

Loading…
Cancel
Save