From 15fae2639724f90bbc5f6f867dd6619fb7579e03 Mon Sep 17 00:00:00 2001 From: TidusJar Date: Sun, 15 May 2016 23:01:17 -0400 Subject: [PATCH] More work on the user management --- PlexRequests.UI/Helpers/BaseUrlHelper.cs | 2 +- .../Models/UserManagementUsersViewModel.cs | 20 +++++++++++ PlexRequests.UI/Modules/ApprovalModule.cs | 16 ++------- PlexRequests.UI/Modules/SearchModule.cs | 8 ++--- .../Modules/UserManagementModule.cs | 11 ++++++ PlexRequests.UI/PlexRequests.UI.csproj | 1 + PlexRequests.UI/Views/Admin/Logs.cshtml | 2 +- .../Views/UserManagement/Index.cshtml | 36 ++++++++++++++++++- 8 files changed, 75 insertions(+), 21 deletions(-) create mode 100644 PlexRequests.UI/Models/UserManagementUsersViewModel.cs diff --git a/PlexRequests.UI/Helpers/BaseUrlHelper.cs b/PlexRequests.UI/Helpers/BaseUrlHelper.cs index c9a3e30f2..4071f00d8 100644 --- a/PlexRequests.UI/Helpers/BaseUrlHelper.cs +++ b/PlexRequests.UI/Helpers/BaseUrlHelper.cs @@ -95,7 +95,7 @@ namespace PlexRequests.UI.Helpers return helper.Raw(sb.ToString()); } - public static IHtmlString LoadLogsAssets(this HtmlHelpers helper) + public static IHtmlString LoadTableAssets(this HtmlHelpers helper) { var sb = new StringBuilder(); var assetLocation = GetBaseUrl(); diff --git a/PlexRequests.UI/Models/UserManagementUsersViewModel.cs b/PlexRequests.UI/Models/UserManagementUsersViewModel.cs new file mode 100644 index 000000000..66bc9974e --- /dev/null +++ b/PlexRequests.UI/Models/UserManagementUsersViewModel.cs @@ -0,0 +1,20 @@ +using System; + +namespace PlexRequests.UI +{ + public class UserManagementUsersViewModel + { + public string Username{get;set;} + public string Claims{get;set;} + public int Id {get;set;} + public string Alias {get;set;} + public UserType Type { get; set;} + } + + public enum UserType + { + PlexUser, + LocalUser + } +} + diff --git a/PlexRequests.UI/Modules/ApprovalModule.cs b/PlexRequests.UI/Modules/ApprovalModule.cs index e6cb97c06..d74431eb8 100644 --- a/PlexRequests.UI/Modules/ApprovalModule.cs +++ b/PlexRequests.UI/Modules/ApprovalModule.cs @@ -50,7 +50,7 @@ namespace PlexRequests.UI.Modules ISettingsService sonarrSettings, ISickRageApi srApi, ISettingsService srSettings, ISettingsService hpSettings, IHeadphonesApi hpApi) : base("approval") { - this.RequiresAuthentication(); + this.RequiresClaims(UserClaims.Admin, UserClaims.PowerUser); Service = service; CpService = cpService; @@ -88,10 +88,7 @@ namespace PlexRequests.UI.Modules private Response Approve(int requestId, string qualityId) { Log.Info("approving request {0}", requestId); - if (!Context.CurrentUser.IsAuthenticated()) - { - return Response.AsJson(new JsonResponseModel { Result = false, Message = "You are not an Admin, so you cannot approve any requests." }); - } + // Get the request from the DB var request = Service.Get(requestId); @@ -258,10 +255,6 @@ namespace PlexRequests.UI.Modules private Response ApproveAllMovies() { - if (!Context.CurrentUser.IsAuthenticated()) - { - return Response.AsJson(new JsonResponseModel { Result = false, Message = "You are not an Admin, so you cannot approve any requests." }); - } var requests = Service.GetAll().Where(x => x.CanApprove && x.Type == RequestType.Movie); var requestedModels = requests as RequestedModel[] ?? requests.ToArray(); @@ -312,11 +305,6 @@ namespace PlexRequests.UI.Modules /// private Response ApproveAll() { - if (!Context.CurrentUser.IsAuthenticated()) - { - return Response.AsJson(new JsonResponseModel { Result = false, Message = "You are not an Admin, so you cannot approve any requests." }); - } - var requests = Service.GetAll().Where(x => x.CanApprove); var requestedModels = requests as RequestedModel[] ?? requests.ToArray(); if (!requestedModels.Any()) diff --git a/PlexRequests.UI/Modules/SearchModule.cs b/PlexRequests.UI/Modules/SearchModule.cs index 39b58dd59..4ef08002b 100644 --- a/PlexRequests.UI/Modules/SearchModule.cs +++ b/PlexRequests.UI/Modules/SearchModule.cs @@ -500,7 +500,7 @@ namespace PlexRequests.UI.Modules RequestService.AddRequest(model); - if (ShouldSendNotification) { + if (ShouldSendNotification()) { var notificationModel = new NotificationModel { Title = model.Title, User = Username, @@ -525,7 +525,7 @@ namespace PlexRequests.UI.Modules Log.Info("Adding movie to database (No approval required)"); RequestService.AddRequest(model); - if (ShouldSendNotification) { + if (ShouldSendNotification()) { var notificationModel = new NotificationModel { Title = model.Title, User = Username, @@ -660,7 +660,7 @@ namespace PlexRequests.UI.Modules Log.Debug("Adding tv to database requests (No approval required & Sonarr)"); RequestService.AddRequest(model); - if (ShouldSendNotification) { + if (ShouldSendNotification()) { var notify1 = new NotificationModel { Title = model.Title, User = Username, @@ -686,7 +686,7 @@ namespace PlexRequests.UI.Modules model.Approved = true; Log.Debug("Adding tv to database requests (No approval required & SickRage)"); RequestService.AddRequest(model); - if (ShouldSendNotification) { + if (ShouldSendNotification()) { var notify2 = new NotificationModel { Title = model.Title, User = Username, diff --git a/PlexRequests.UI/Modules/UserManagementModule.cs b/PlexRequests.UI/Modules/UserManagementModule.cs index 0e7bd1c02..eeed0db69 100644 --- a/PlexRequests.UI/Modules/UserManagementModule.cs +++ b/PlexRequests.UI/Modules/UserManagementModule.cs @@ -10,6 +10,7 @@ using PlexRequests.Core; using PlexRequests.UI.Models; using PlexRequests.UI.Modules; using PlexRequests.Helpers; +using System.Collections.Generic; namespace PlexRequests.UI @@ -32,6 +33,16 @@ namespace PlexRequests.UI public Response LoadUsers() { var users = UserMapper.GetUsers (); + var model = new List(); + foreach (var user in users) { + model.Add (new UserManagementUsersViewModel { + //Claims = ByteConverterHelper.ReturnObject(user.Claims), + Claims = "test", + Id = user.Id, + Username = user.UserName, + //Type = UserType.LocalUser + }); + } return Response.AsJson (users); } } diff --git a/PlexRequests.UI/PlexRequests.UI.csproj b/PlexRequests.UI/PlexRequests.UI.csproj index f0683968d..d78195670 100644 --- a/PlexRequests.UI/PlexRequests.UI.csproj +++ b/PlexRequests.UI/PlexRequests.UI.csproj @@ -201,6 +201,7 @@ + diff --git a/PlexRequests.UI/Views/Admin/Logs.cshtml b/PlexRequests.UI/Views/Admin/Logs.cshtml index ed32d6552..9fc58d202 100644 --- a/PlexRequests.UI/Views/Admin/Logs.cshtml +++ b/PlexRequests.UI/Views/Admin/Logs.cshtml @@ -1,6 +1,6 @@ @using PlexRequests.UI.Helpers @Html.Partial("_Sidebar") -@Html.LoadLogsAssets() +@Html.LoadTableAssets() @{ var baseUrl = Html.GetBaseUrl(); diff --git a/PlexRequests.UI/Views/UserManagement/Index.cshtml b/PlexRequests.UI/Views/UserManagement/Index.cshtml index f2e3b9d54..3df2a104d 100644 --- a/PlexRequests.UI/Views/UserManagement/Index.cshtml +++ b/PlexRequests.UI/Views/UserManagement/Index.cshtml @@ -1,4 +1,5 @@ @using PlexRequests.UI.Helpers +@Html.LoadTableAssets() @{ var baseUrl = Html.GetBaseUrl().ToHtmlString(); var url = string.Empty; @@ -11,4 +12,37 @@

User Management

- \ No newline at end of file + +
+
+
+ + + + + + + + + +
IdUsernamePermissions
+
+ + \ No newline at end of file