mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-08 14:10:50 -07:00
don't query the session as much in the modules, rely on a variable from the base class and store the username as needed
This commit is contained in:
parent
a028a68a08
commit
a668ea04ec
4 changed files with 29 additions and 15 deletions
|
@ -33,16 +33,30 @@ namespace PlexRequests.UI.Modules
|
||||||
{
|
{
|
||||||
public class BaseModule : NancyModule
|
public class BaseModule : NancyModule
|
||||||
{
|
{
|
||||||
|
private string _username;
|
||||||
|
|
||||||
|
protected string Username
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(_username))
|
||||||
|
{
|
||||||
|
_username = Session[SessionKeys.UsernameKey].ToString();
|
||||||
|
}
|
||||||
|
return _username;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public BaseModule()
|
public BaseModule()
|
||||||
{
|
{
|
||||||
Before += (ctx)=> CheckAuth();
|
Before += (ctx) => CheckAuth();
|
||||||
}
|
}
|
||||||
|
|
||||||
public BaseModule(string modulePath) : base(modulePath)
|
public BaseModule(string modulePath) : base(modulePath)
|
||||||
{
|
{
|
||||||
Before += (ctx) => CheckAuth();
|
Before += (ctx) => CheckAuth();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Response CheckAuth()
|
private Response CheckAuth()
|
||||||
{
|
{
|
||||||
|
|
|
@ -84,7 +84,7 @@ namespace PlexRequests.UI.Modules
|
||||||
var dbMovies = Service.GetAll().Where(x => x.Type == RequestType.Movie);
|
var dbMovies = Service.GetAll().Where(x => x.Type == RequestType.Movie);
|
||||||
if (settings.UsersCanViewOnlyOwnRequests && !isAdmin)
|
if (settings.UsersCanViewOnlyOwnRequests && !isAdmin)
|
||||||
{
|
{
|
||||||
dbMovies = dbMovies.Where(x => x.UserHasRequested(Session[SessionKeys.UsernameKey].ToString()));
|
dbMovies = dbMovies.Where(x => x.UserHasRequested(Username));
|
||||||
}
|
}
|
||||||
|
|
||||||
var viewModel = dbMovies.Select(movie => {
|
var viewModel = dbMovies.Select(movie => {
|
||||||
|
@ -127,7 +127,7 @@ namespace PlexRequests.UI.Modules
|
||||||
var dbTv = Service.GetAll().Where(x => x.Type == RequestType.TvShow);
|
var dbTv = Service.GetAll().Where(x => x.Type == RequestType.TvShow);
|
||||||
if (settings.UsersCanViewOnlyOwnRequests && !isAdmin)
|
if (settings.UsersCanViewOnlyOwnRequests && !isAdmin)
|
||||||
{
|
{
|
||||||
dbTv = dbTv.Where(x => x.UserHasRequested(Session[SessionKeys.UsernameKey].ToString()));
|
dbTv = dbTv.Where(x => x.UserHasRequested(Username));
|
||||||
}
|
}
|
||||||
|
|
||||||
var viewModel = dbTv.Select(tv => {
|
var viewModel = dbTv.Select(tv => {
|
||||||
|
@ -194,7 +194,7 @@ namespace PlexRequests.UI.Modules
|
||||||
}
|
}
|
||||||
originalRequest.Issues = issue;
|
originalRequest.Issues = issue;
|
||||||
originalRequest.OtherMessage = !string.IsNullOrEmpty(comment)
|
originalRequest.OtherMessage = !string.IsNullOrEmpty(comment)
|
||||||
? $"{Session[SessionKeys.UsernameKey]} - {comment}"
|
? $"{Username} - {comment}"
|
||||||
: string.Empty;
|
: string.Empty;
|
||||||
|
|
||||||
|
|
||||||
|
@ -202,7 +202,7 @@ namespace PlexRequests.UI.Modules
|
||||||
|
|
||||||
var model = new NotificationModel
|
var model = new NotificationModel
|
||||||
{
|
{
|
||||||
User = Session[SessionKeys.UsernameKey].ToString(),
|
User = Username,
|
||||||
NotificationType = NotificationType.Issue,
|
NotificationType = NotificationType.Issue,
|
||||||
Title = originalRequest.Title,
|
Title = originalRequest.Title,
|
||||||
DateTime = DateTime.Now,
|
DateTime = DateTime.Now,
|
||||||
|
|
|
@ -187,9 +187,9 @@ namespace PlexRequests.UI.Modules
|
||||||
if (existingRequest != null)
|
if (existingRequest != null)
|
||||||
{
|
{
|
||||||
// check if the current user is already marked as a requester for this movie, if not, add them
|
// 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()))
|
if (!existingRequest.UserHasRequested(Username))
|
||||||
{
|
{
|
||||||
existingRequest.RequestedUsers.Add(Session[SessionKeys.UsernameKey].ToString());
|
existingRequest.RequestedUsers.Add(Username);
|
||||||
RequestService.UpdateRequest(existingRequest);
|
RequestService.UpdateRequest(existingRequest);
|
||||||
}
|
}
|
||||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = settings.UsersCanViewOnlyOwnRequests ? $"{fullMovieName} was successfully added!" : $"{fullMovieName} has already been requested!" });
|
return Response.AsJson(new JsonResponseModel { Result = false, Message = settings.UsersCanViewOnlyOwnRequests ? $"{fullMovieName} was successfully added!" : $"{fullMovieName} has already been requested!" });
|
||||||
|
@ -222,12 +222,12 @@ namespace PlexRequests.UI.Modules
|
||||||
Status = movieInfo.Status,
|
Status = movieInfo.Status,
|
||||||
RequestedDate = DateTime.Now,
|
RequestedDate = DateTime.Now,
|
||||||
Approved = false,
|
Approved = false,
|
||||||
RequestedUsers = new List<string>() { Session[SessionKeys.UsernameKey].ToString() },
|
RequestedUsers = new List<string>() { Username },
|
||||||
Issues = IssueState.None,
|
Issues = IssueState.None,
|
||||||
};
|
};
|
||||||
|
|
||||||
Log.Trace(settings.DumpJson());
|
Log.Trace(settings.DumpJson());
|
||||||
if (!settings.RequireMovieApproval || settings.NoApprovalUserList.Any(x => x.Equals(Session[SessionKeys.UsernameKey].ToString(), StringComparison.OrdinalIgnoreCase)))
|
if (!settings.RequireMovieApproval || settings.NoApprovalUserList.Any(x => x.Equals(Username, StringComparison.OrdinalIgnoreCase)))
|
||||||
{
|
{
|
||||||
var cpSettings = CpService.GetSettings();
|
var cpSettings = CpService.GetSettings();
|
||||||
|
|
||||||
|
@ -325,9 +325,9 @@ namespace PlexRequests.UI.Modules
|
||||||
if (existingRequest != null)
|
if (existingRequest != null)
|
||||||
{
|
{
|
||||||
// check if the current user is already marked as a requester for this show, if not, add them
|
// 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()))
|
if (!existingRequest.UserHasRequested(Username))
|
||||||
{
|
{
|
||||||
existingRequest.RequestedUsers.Add(Session[SessionKeys.UsernameKey].ToString());
|
existingRequest.RequestedUsers.Add(Username);
|
||||||
RequestService.UpdateRequest(existingRequest);
|
RequestService.UpdateRequest(existingRequest);
|
||||||
}
|
}
|
||||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = settings.UsersCanViewOnlyOwnRequests ? $"{fullShowName} was successfully added!" : $"{fullShowName} has already been requested!" });
|
return Response.AsJson(new JsonResponseModel { Result = false, Message = settings.UsersCanViewOnlyOwnRequests ? $"{fullShowName} was successfully added!" : $"{fullShowName} has already been requested!" });
|
||||||
|
@ -358,7 +358,7 @@ namespace PlexRequests.UI.Modules
|
||||||
Status = showInfo.status,
|
Status = showInfo.status,
|
||||||
RequestedDate = DateTime.Now,
|
RequestedDate = DateTime.Now,
|
||||||
Approved = false,
|
Approved = false,
|
||||||
RequestedUsers = new List<string>() { Session[SessionKeys.UsernameKey].ToString() },
|
RequestedUsers = new List<string>() { Username },
|
||||||
Issues = IssueState.None,
|
Issues = IssueState.None,
|
||||||
ImdbId = showInfo.externals?.imdb ?? string.Empty,
|
ImdbId = showInfo.externals?.imdb ?? string.Empty,
|
||||||
SeasonCount = showInfo.seasonCount
|
SeasonCount = showInfo.seasonCount
|
||||||
|
@ -381,7 +381,7 @@ namespace PlexRequests.UI.Modules
|
||||||
|
|
||||||
model.SeasonList = seasonsList.ToArray();
|
model.SeasonList = seasonsList.ToArray();
|
||||||
|
|
||||||
if (!settings.RequireTvShowApproval || settings.NoApprovalUserList.Any(x => x.Equals(Session[SessionKeys.UsernameKey].ToString(), StringComparison.OrdinalIgnoreCase)))
|
if (!settings.RequireTvShowApproval || settings.NoApprovalUserList.Any(x => x.Equals(Username, StringComparison.OrdinalIgnoreCase)))
|
||||||
{
|
{
|
||||||
var sonarrSettings = SonarrService.GetSettings();
|
var sonarrSettings = SonarrService.GetSettings();
|
||||||
var sender = new TvSender(SonarrApi, SickrageApi);
|
var sender = new TvSender(SonarrApi, SickrageApi);
|
||||||
|
|
|
@ -69,7 +69,7 @@ namespace PlexRequests.UI
|
||||||
if (port == -1)
|
if (port == -1)
|
||||||
port = GetStartupPort();
|
port = GetStartupPort();
|
||||||
|
|
||||||
var options = new StartOptions( $"http://+:{port}")
|
var options = new StartOptions(Debugger.IsAttached ? $"http://localhost:{port}" : $"http://+:{port}")
|
||||||
{
|
{
|
||||||
ServerFactory = "Microsoft.Owin.Host.HttpListener"
|
ServerFactory = "Microsoft.Owin.Host.HttpListener"
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue