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
|
||||
{
|
||||
private string _username;
|
||||
|
||||
protected string Username
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(_username))
|
||||
{
|
||||
_username = Session[SessionKeys.UsernameKey].ToString();
|
||||
}
|
||||
return _username;
|
||||
}
|
||||
}
|
||||
|
||||
public BaseModule()
|
||||
{
|
||||
Before += (ctx)=> CheckAuth();
|
||||
Before += (ctx) => CheckAuth();
|
||||
}
|
||||
|
||||
public BaseModule(string modulePath) : base(modulePath)
|
||||
{
|
||||
Before += (ctx) => CheckAuth();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private Response CheckAuth()
|
||||
{
|
||||
|
|
|
@ -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.UserHasRequested(Session[SessionKeys.UsernameKey].ToString()));
|
||||
dbMovies = dbMovies.Where(x => x.UserHasRequested(Username));
|
||||
}
|
||||
|
||||
var viewModel = dbMovies.Select(movie => {
|
||||
|
@ -127,7 +127,7 @@ namespace PlexRequests.UI.Modules
|
|||
var dbTv = Service.GetAll().Where(x => x.Type == RequestType.TvShow);
|
||||
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 => {
|
||||
|
@ -194,7 +194,7 @@ namespace PlexRequests.UI.Modules
|
|||
}
|
||||
originalRequest.Issues = issue;
|
||||
originalRequest.OtherMessage = !string.IsNullOrEmpty(comment)
|
||||
? $"{Session[SessionKeys.UsernameKey]} - {comment}"
|
||||
? $"{Username} - {comment}"
|
||||
: string.Empty;
|
||||
|
||||
|
||||
|
@ -202,7 +202,7 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
var model = new NotificationModel
|
||||
{
|
||||
User = Session[SessionKeys.UsernameKey].ToString(),
|
||||
User = Username,
|
||||
NotificationType = NotificationType.Issue,
|
||||
Title = originalRequest.Title,
|
||||
DateTime = DateTime.Now,
|
||||
|
|
|
@ -187,9 +187,9 @@ namespace PlexRequests.UI.Modules
|
|||
if (existingRequest != null)
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
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,
|
||||
RequestedDate = DateTime.Now,
|
||||
Approved = false,
|
||||
RequestedUsers = new List<string>() { Session[SessionKeys.UsernameKey].ToString() },
|
||||
RequestedUsers = new List<string>() { Username },
|
||||
Issues = IssueState.None,
|
||||
};
|
||||
|
||||
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();
|
||||
|
||||
|
@ -325,9 +325,9 @@ namespace PlexRequests.UI.Modules
|
|||
if (existingRequest != null)
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
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,
|
||||
RequestedDate = DateTime.Now,
|
||||
Approved = false,
|
||||
RequestedUsers = new List<string>() { Session[SessionKeys.UsernameKey].ToString() },
|
||||
RequestedUsers = new List<string>() { Username },
|
||||
Issues = IssueState.None,
|
||||
ImdbId = showInfo.externals?.imdb ?? string.Empty,
|
||||
SeasonCount = showInfo.seasonCount
|
||||
|
@ -381,7 +381,7 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
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 sender = new TvSender(SonarrApi, SickrageApi);
|
||||
|
|
|
@ -69,7 +69,7 @@ namespace PlexRequests.UI
|
|||
if (port == -1)
|
||||
port = GetStartupPort();
|
||||
|
||||
var options = new StartOptions( $"http://+:{port}")
|
||||
var options = new StartOptions(Debugger.IsAttached ? $"http://localhost:{port}" : $"http://+:{port}")
|
||||
{
|
||||
ServerFactory = "Microsoft.Owin.Host.HttpListener"
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue