More work on the user management

pull/226/head
TidusJar 9 years ago
parent d44612217a
commit 15fae26397

@ -95,7 +95,7 @@ namespace PlexRequests.UI.Helpers
return helper.Raw(sb.ToString()); return helper.Raw(sb.ToString());
} }
public static IHtmlString LoadLogsAssets(this HtmlHelpers helper) public static IHtmlString LoadTableAssets(this HtmlHelpers helper)
{ {
var sb = new StringBuilder(); var sb = new StringBuilder();
var assetLocation = GetBaseUrl(); var assetLocation = GetBaseUrl();

@ -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
}
}

@ -50,7 +50,7 @@ namespace PlexRequests.UI.Modules
ISettingsService<SonarrSettings> sonarrSettings, ISickRageApi srApi, ISettingsService<SickRageSettings> srSettings, ISettingsService<SonarrSettings> sonarrSettings, ISickRageApi srApi, ISettingsService<SickRageSettings> srSettings,
ISettingsService<HeadphonesSettings> hpSettings, IHeadphonesApi hpApi) : base("approval") ISettingsService<HeadphonesSettings> hpSettings, IHeadphonesApi hpApi) : base("approval")
{ {
this.RequiresAuthentication(); this.RequiresClaims(UserClaims.Admin, UserClaims.PowerUser);
Service = service; Service = service;
CpService = cpService; CpService = cpService;
@ -88,10 +88,7 @@ namespace PlexRequests.UI.Modules
private Response Approve(int requestId, string qualityId) private Response Approve(int requestId, string qualityId)
{ {
Log.Info("approving request {0}", requestId); 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 // Get the request from the DB
var request = Service.Get(requestId); var request = Service.Get(requestId);
@ -258,10 +255,6 @@ namespace PlexRequests.UI.Modules
private Response ApproveAllMovies() 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 requests = Service.GetAll().Where(x => x.CanApprove && x.Type == RequestType.Movie);
var requestedModels = requests as RequestedModel[] ?? requests.ToArray(); var requestedModels = requests as RequestedModel[] ?? requests.ToArray();
@ -312,11 +305,6 @@ namespace PlexRequests.UI.Modules
/// <returns></returns> /// <returns></returns>
private Response ApproveAll() 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 requests = Service.GetAll().Where(x => x.CanApprove);
var requestedModels = requests as RequestedModel[] ?? requests.ToArray(); var requestedModels = requests as RequestedModel[] ?? requests.ToArray();
if (!requestedModels.Any()) if (!requestedModels.Any())

@ -500,7 +500,7 @@ namespace PlexRequests.UI.Modules
RequestService.AddRequest(model); RequestService.AddRequest(model);
if (ShouldSendNotification) { if (ShouldSendNotification()) {
var notificationModel = new NotificationModel { var notificationModel = new NotificationModel {
Title = model.Title, Title = model.Title,
User = Username, User = Username,
@ -525,7 +525,7 @@ namespace PlexRequests.UI.Modules
Log.Info("Adding movie to database (No approval required)"); Log.Info("Adding movie to database (No approval required)");
RequestService.AddRequest(model); RequestService.AddRequest(model);
if (ShouldSendNotification) { if (ShouldSendNotification()) {
var notificationModel = new NotificationModel { var notificationModel = new NotificationModel {
Title = model.Title, Title = model.Title,
User = Username, User = Username,
@ -660,7 +660,7 @@ namespace PlexRequests.UI.Modules
Log.Debug("Adding tv to database requests (No approval required & Sonarr)"); Log.Debug("Adding tv to database requests (No approval required & Sonarr)");
RequestService.AddRequest(model); RequestService.AddRequest(model);
if (ShouldSendNotification) { if (ShouldSendNotification()) {
var notify1 = new NotificationModel { var notify1 = new NotificationModel {
Title = model.Title, Title = model.Title,
User = Username, User = Username,
@ -686,7 +686,7 @@ namespace PlexRequests.UI.Modules
model.Approved = true; model.Approved = true;
Log.Debug("Adding tv to database requests (No approval required & SickRage)"); Log.Debug("Adding tv to database requests (No approval required & SickRage)");
RequestService.AddRequest(model); RequestService.AddRequest(model);
if (ShouldSendNotification) { if (ShouldSendNotification()) {
var notify2 = new NotificationModel { var notify2 = new NotificationModel {
Title = model.Title, Title = model.Title,
User = Username, User = Username,

@ -10,6 +10,7 @@ using PlexRequests.Core;
using PlexRequests.UI.Models; using PlexRequests.UI.Models;
using PlexRequests.UI.Modules; using PlexRequests.UI.Modules;
using PlexRequests.Helpers; using PlexRequests.Helpers;
using System.Collections.Generic;
namespace PlexRequests.UI namespace PlexRequests.UI
@ -32,6 +33,16 @@ namespace PlexRequests.UI
public Response LoadUsers() public Response LoadUsers()
{ {
var users = UserMapper.GetUsers (); var users = UserMapper.GetUsers ();
var model = new List<UserManagementUsersViewModel>();
foreach (var user in users) {
model.Add (new UserManagementUsersViewModel {
//Claims = ByteConverterHelper.ReturnObject<string[]>(user.Claims),
Claims = "test",
Id = user.Id,
Username = user.UserName,
//Type = UserType.LocalUser
});
}
return Response.AsJson (users); return Response.AsJson (users);
} }
} }

@ -201,6 +201,7 @@
</Content> </Content>
<Compile Include="Modules\ApiModule.cs" /> <Compile Include="Modules\ApiModule.cs" />
<Compile Include="Models\ApiModel.cs" /> <Compile Include="Models\ApiModel.cs" />
<Compile Include="Models\UserManagementUsersViewModel.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="Content\bootstrap.min.js"> <Content Include="Content\bootstrap.min.js">

@ -1,6 +1,6 @@
@using PlexRequests.UI.Helpers @using PlexRequests.UI.Helpers
@Html.Partial("_Sidebar") @Html.Partial("_Sidebar")
@Html.LoadLogsAssets() @Html.LoadTableAssets()
@{ @{
var baseUrl = Html.GetBaseUrl(); var baseUrl = Html.GetBaseUrl();

@ -1,4 +1,5 @@
@using PlexRequests.UI.Helpers @using PlexRequests.UI.Helpers
@Html.LoadTableAssets()
@{ @{
var baseUrl = Html.GetBaseUrl().ToHtmlString(); var baseUrl = Html.GetBaseUrl().ToHtmlString();
var url = string.Empty; var url = string.Empty;
@ -11,4 +12,37 @@
<h2>User Management</h2> <h2>User Management</h2>
<button class="btn btn-success-outline" type="submit">Create User <div class="fa fa-plus"/></button> <button class="btn btn-success-outline" type="submit">Create User <div class="fa fa-plus"/></button>
<br>
<br>
<fieldset>
<table id="example" class="table table-striped table-hover table-responsive">
<thead>
<tr>
<th>Id</th>
<th>Username</th>
<th>Permissions</th>
</tr>
</thead>
</table>
</fieldset>
<script>
var baseUrl = '@Html.GetBaseUrl()';
var url = createBaseUrl(baseUrl, "usermanagement/users");
$('#example').DataTable({
"ajax": url,
"columns": [
{ "data": "id" },
{ "data": "username" },
{ "data": "claims" },
//{ "data": "type" }
],
"order": [[1, "desc"]]
});
</script>
Loading…
Cancel
Save