Small tweaks to the Request Page

pull/733/head
Jamie.Rees 8 years ago
parent b7d4a9c2be
commit a2639375fb

@ -20,8 +20,8 @@ namespace PlexRequests.Core
Response HasPermissionsRedirect(Permissions perm, NancyContext context, string routeName, HttpStatusCode code);
Func<NancyContext, Response> HttpStatusCodeIfNot(HttpStatusCode statusCode, Func<NancyContext, bool> test);
bool IsLoggedIn(NancyContext context);
bool IsNormalUser(NancyContext context);
bool IsPlexUser(NancyContext context);
bool IsNormalUser(IUserIdentity user);
bool IsPlexUser(IUserIdentity user);
bool HasPermissions(string userName, Permissions perm);
/// <summary>

@ -65,15 +65,15 @@ namespace PlexRequests.Core
return realUser || plexUser;
}
public bool IsPlexUser(NancyContext context)
public bool IsPlexUser(IUserIdentity user)
{
var plexUser = PlexUsers.GetUserByUsername(context.CurrentUser.UserName);
var plexUser = PlexUsers.GetUserByUsername(user.UserName);
return plexUser != null;
}
public bool IsNormalUser(NancyContext context)
public bool IsNormalUser(IUserIdentity user)
{
var dbUser = UserRepository.GetUserByUsername(context.CurrentUser.UserName);
var dbUser = UserRepository.GetUserByUsername(user.UserName);
return dbUser != null;
}

@ -16,10 +16,13 @@ var base = $('#baseUrl').text();
var tvLoaded = false;
var albumLoaded = false;
var isAdmin = $('#isAdmin').val();
var defaultFiler = isAdmin == 'True' ? '.approved-fase' : 'all';
var mixItUpDefault = {
animation: { enable: true },
load: {
filter: '.approved-false',
filter: defaultFiler,
sort: 'requestorder:desc'
},
layout: {
@ -259,7 +262,7 @@ $('#deleteMusic').click(function (e) {
});
// filtering/sorting
$('.filter,.sort', '.dropdown-menu').click(function (e) {
$('.filter', '.dropdown-menu').click(function (e) {
var $this = $(this);
$('.fa-check-square', $this.parents('.dropdown-menu:first')).removeClass('fa-check-square').addClass('fa-square-o');
$this.children('.fa').first().removeClass('fa-square-o').addClass('fa-check-square');
@ -268,6 +271,12 @@ $('.filter,.sort', '.dropdown-menu').click(function (e) {
}).fadeIn();
});
$('.sort', '.dropdown-menu').click(function (e) {
var $this = $(this);
$('.fa-check-square', $this.parents('.dropdown-menu:first')).removeClass('fa-check-square').addClass('fa-square-o');
$this.children('.fa').first().removeClass('fa-square-o').addClass('fa-check-square');
});
// Report Issue
$(document).on("click", ".dropdownIssue", function (e) {

@ -26,12 +26,9 @@
#endregion
using Nancy;
using Nancy.Linker;
using Nancy.Security;
using Nancy.ViewEngines.Razor;
using Ninject;
using PlexRequests.Helpers.Permissions;
using PlexRequests.Store.Repository;
using ISecurityExtensions = PlexRequests.Core.ISecurityExtensions;
namespace PlexRequests.UI.Helpers
@ -50,14 +47,14 @@ namespace PlexRequests.UI.Helpers
private static ISecurityExtensions _security;
public static bool HasAnyPermission(this HtmlHelpers helper, int permission, bool authenticated = true)
public static bool HasAnyPermission(this HtmlHelpers helper, bool authenticated = true, params Permissions[] permission)
{
if (authenticated)
{
return helper.CurrentUser.IsAuthenticated()
&& Security.HasPermissions(helper.CurrentUser, (Permissions) permission);
&& Security.HasAnyPermissions(helper.CurrentUser, permission);
}
return Security.HasPermissions(helper.CurrentUser, (Permissions)permission);
return Security.HasAnyPermissions(helper.CurrentUser, permission);
}
public static bool DoesNotHavePermission(this HtmlHelpers helper, int permission)
@ -67,12 +64,21 @@ namespace PlexRequests.UI.Helpers
public static bool IsAdmin(this HtmlHelpers helper, bool isAuthenticated = true)
{
return HasAnyPermission(helper, (int) Permissions.Administrator, isAuthenticated);
return HasAnyPermission(helper, isAuthenticated, Permissions.Administrator);
}
public static bool IsLoggedIn(this HtmlHelpers helper, NancyContext context)
{
return Security.IsLoggedIn(context);
}
public static bool IsPlexUser(this HtmlHelpers helper)
{
return Security.IsPlexUser(helper.CurrentUser);
}
public static bool IsNormalUser(this HtmlHelpers helper)
{
return Security.IsNormalUser(helper.CurrentUser);
}
}
}

@ -11,7 +11,7 @@
formAction = "/" + baseUrl.ToHtmlString();
}
var isAdmin = Html.HasAnyPermission((int)Permissions.Administrator) || Html.HasAnyPermission((int)Permissions.ManageRequests);
var isAdmin = Html.HasAnyPermission(true, Permissions.Administrator) || Html.HasAnyPermission(Permissions.ManageRequests);
}
<h1>Details</h1>

@ -1,19 +1,22 @@
@using Nancy.Security
@using Nancy.Security
@using PlexRequests.Helpers.Permissions
@using PlexRequests.UI.Helpers
@using PlexRequests.UI.Resources
@{
var baseUrl = Html.GetBaseUrl();
var formAction = string.Empty;
var isAdmin = Html.HasAnyPermission(true, Permissions.Administrator, Permissions.ManageRequests);
if (!string.IsNullOrEmpty(baseUrl.ToHtmlString()))
{
formAction = "/" + baseUrl.ToHtmlString();
}
}
<div>
<div hidden="hidden" id="isAdmin" value="@isAdmin"></div>
<h1>@UI.Requests_Title</h1>
<h4>@UI.Requests_Paragraph</h4>
<br />
<br/>
<!-- Nav tabs -->
<ul id="nav-tabs" class="nav nav-tabs" role="tablist">
@ -30,7 +33,7 @@
<li role="presentation"><a href="#MusicTab" aria-controls="profile" role="tab" data-toggle="tab"><i class="fa fa-music"></i> @UI.Requests_AlbumsTabTitle</a></li>
}
</ul>
<br />
<br/>
<!-- Tab panes -->
<div class="tab-content contentList">
@ -38,38 +41,59 @@
<div class="col-sm-12">
<div class="pull-right">
<div class="btn-group btn-group-separated">
@if (Context.CurrentUser.IsAuthenticated()) //TODO replace with IsAdmin
@if (isAdmin)
{
@if (Model.SearchForMovies)
{
<button id="deleteMovies" class="btn btn-warning-outline delete-category" type="submit"><i class="fa fa-trash"></i> @UI.Requests_DeleteMovies</button>
<button id="approveMovies" class="btn btn-success-outline approve-category" type="submit"><i class="fa fa-plus"></i> @UI.Requests_ApproveMovies</button>
}
{
<button id="deleteMovies" class="btn btn-warning-outline delete-category" type="submit"><i class="fa fa-trash"></i> @UI.Requests_DeleteMovies</button>
<button id="approveMovies" class="btn btn-success-outline approve-category" type="submit"><i class="fa fa-plus"></i> @UI.Requests_ApproveMovies</button>
}
@if (Model.SearchForTvShows)
{
<button id="deleteTVShows" class="btn btn-warning-outline delete-category" type="submit" style="display: none;"><i class="fa fa-trash"></i> @UI.Requests_DeleteTVShows</button>
<button id="approveTVShows" class="btn btn-success-outline approve-category" type="submit" style="display: none;"><i class="fa fa-plus"></i> @UI.Requests_ApproveTvShows</button>
}
{
<button id="deleteTVShows" class="btn btn-warning-outline delete-category" type="submit" style="display: none;"><i class="fa fa-trash"></i> @UI.Requests_DeleteTVShows</button>
<button id="approveTVShows" class="btn btn-success-outline approve-category" type="submit" style="display: none;"><i class="fa fa-plus"></i> @UI.Requests_ApproveTvShows</button>
}
@if (Model.SearchForMusic)
{
<button id="deleteMusic" class="btn btn-warning-outline delete-category" type="submit" style="display: none;"><i class="fa fa-trash"></i> @UI.Requests_DeleteMusic</button>
<button id="approveMusic" class="btn btn-success-outline approve-category" type="submit" style="display: none;"><i class="fa fa-plus"></i> @UI.Requests_ApproveMusic</button>
}
{
<button id="deleteMusic" class="btn btn-warning-outline delete-category" type="submit" style="display: none;"><i class="fa fa-trash"></i> @UI.Requests_DeleteMusic</button>
<button id="approveMusic" class="btn btn-success-outline approve-category" type="submit" style="display: none;"><i class="fa fa-plus"></i> @UI.Requests_ApproveMusic</button>
}
}
</div>
<div class="btn-group">
<a href="#" class="btn btn-primary-outline dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
<span id="filterText">@UI.Requests_Filter_NotApproved</span>
@if (isAdmin)
{
<span id="filterText">@UI.Requests_Filter_NotApproved</span>
}
else
{
<span id="filterText">@UI.Requests_Filter_All</span>
}
<i class="fa fa-filter"></i>
</a>
<ul class="dropdown-menu">
<li><a href="#" class="filter" data-filter="all"><i class="fa fa-square-o"></i> @UI.Requests_Filter_All</a></li>
<li><a href="#" class="filter" data-filter=".approved-true"><i class="fa fa-square-o"></i> @UI.Requests_Filter_Approved</a></li>
<li><a href="#" class="filter" data-filter=".approved-false"><i class="fa fa-check-square"></i> @UI.Requests_Filter_NotApproved</a></li>
<li><a href="#" class="filter" data-filter=".available-true"><i class="fa fa-square-o"></i> @UI.Requests_Filter_Available</a></li>
@if (!isAdmin)
{
<li><a href="#" class="filter" data-filter="all"><i class="fa fa-check-square"></i> @UI.Requests_Filter_All</a></li>
}
else
{
<li><a href="#" class="filter" data-filter="all"><i class="fa fa-square-o"></i> @UI.Requests_Filter_All</a></li>
}
<li><a href="#" class="filter" data-filter=".approved-true"><i class="fa fa-square-o"></i> @UI.Requests_Filter_Approved</a></li>
@if (isAdmin)
{
<li><a href="#" class="filter" data-filter=".approved-false"><i class="fa fa-check-square"></i> @UI.Requests_Filter_NotApproved</a></li>
}
else
{
<li><a href="#" class="filter" data-filter=".approved-false"><i class="fa fa-square-o"></i> @UI.Requests_Filter_NotApproved</a></li>
}
<li><a href="#" class="filter" data-filter=".available-true"><i class="fa fa-square-o"></i> @UI.Requests_Filter_Available</a></li>
<li><a href="#" class="filter" data-filter=".available-false"><i class="fa fa-square-o"></i> @UI.Requests_Filter_NotAvailable</a></li>
<li><a href="#" class="filter" data-filter=".released-true"><i class="fa fa-square-o"></i> @UI.Requests_Filter_Released</a></li>
<li><a href="#" class="filter" data-filter=".released-false"><i class="fa fa-square-o"></i> @UI.Requests_Filter_NotReleased</a></li>
<li><a href="#" class="filter" data-filter=".released-true"><i class="fa fa-square-o"></i> @UI.Requests_Filter_Released</a></li>
<li><a href="#" class="filter" data-filter=".released-false"><i class="fa fa-square-o"></i> @UI.Requests_Filter_NotReleased</a></li>
</ul>
</div>
<div class="btn-group">
@ -78,23 +102,23 @@
<i class="fa fa-sort"></i>
</a>
<ul class="dropdown-menu">
<li><a href="#" class="sort" data-sort="requestorder:desc"><i class="fa fa-check-square"></i> @UI.Requests_Order_LatestRequests</a></li>
<li><a href="#" class="sort" data-sort="requestorder:asc"><i class="fa fa-square-o"></i> @UI.Requests_Order_OldestRequests</a></li>
<li><a href="#" class="sort" data-sort="releaseorder:desc"><i class="fa fa-square-o"></i> @UI.Requests_Order_LatestReleases</a></li>
<li><a href="#" class="sort" data-sort="releaseorder:asc"><i class="fa fa-square-o"></i> @UI.Requests_Order_OldestReleases</a></li>
<li><a href="#" class="sort" data-sort="requestorder:desc"><i class="fa fa-check-square"></i> @UI.Requests_Order_LatestRequests</a></li>
<li><a href="#" class="sort" data-sort="requestorder:asc"><i class="fa fa-square-o"></i> @UI.Requests_Order_OldestRequests</a></li>
<li><a href="#" class="sort" data-sort="releaseorder:desc"><i class="fa fa-square-o"></i> @UI.Requests_Order_LatestReleases</a></li>
<li><a href="#" class="sort" data-sort="releaseorder:asc"><i class="fa fa-square-o"></i> @UI.Requests_Order_OldestReleases</a></li>
</ul>
</div>
</div>
</div>
</div>
@if (Model.SearchForMovies)
{
{
<!-- Movie tab -->
<div role="tabpanel" class="tab-pane active" id="MoviesTab">
<br />
<br />
<br/>
<br/>
<!-- Movie content -->
<div id="movieList">
</div>
@ -102,12 +126,12 @@
}
@if (Model.SearchForTvShows)
{
{
<!-- TV tab -->
<div role="tabpanel" class="tab-pane" id="TvShowTab">
<br />
<br />
<br/>
<br/>
<!-- TV content -->
<div id="tvList">
</div>
@ -115,12 +139,12 @@
}
@if (Model.SearchForMusic)
{
{
<!-- Music tab -->
<div role="tabpanel" class="tab-pane" id="MusicTab">
<br />
<br />
<br/>
<br/>
<!-- TV content -->
<div id="musicList">
</div>
@ -168,9 +192,14 @@
<a href="http://www.imdb.com/title/{{imdb}}/" target="_blank">
<h4 class="request-title">{{title}} ({{year}})</h4>
</a>
<span class="label label-success">{{status}}</span>
</div>
<br />
{{#if_eq type "tv"}}
<span>@UI.Search_TV_Show_Status: </span>
{{else}}
<span>@UI.Search_Movie_Status: </span>
{{/if_eq}}
<span class="label label-success">{{status}}</span>
{{#if denied}}
<div>
Denied: <i style="color:red;" class="fa fa-check"></i>

@ -69,7 +69,7 @@
</li>
}
@*@if (Context.Request.Session[SessionKeys.UsernameKey] != null && !Context.CurrentUser.IsAuthenticated())*@
else if (Context.CurrentUser != null && Context.CurrentUser.IsAuthenticated()) // Logged in but not admin
else if (Html.IsNormalUser()) // Logged in but not admin
{
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-user"></i> @UI.Layout_Welcome @Context.CurrentUser.UserName <span class="caret"></span></a>
@ -79,6 +79,16 @@
</ul>
</li>
}
else if (Html.IsPlexUser()) // Logged in but not admin
{
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-user"></i> @UI.Layout_Welcome @Context.CurrentUser.UserName <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><a href="@url/logout"><i class="fa fa-sign-out"></i> @UI.Layout_Logout</a></li>
</ul>
</li>
}
<li class="dropdown">

Loading…
Cancel
Save