diff --git a/PlexRequests.Core/Models/IssuesModel.cs b/PlexRequests.Core/Models/IssuesModel.cs index d616f8d96..1460a4f6b 100644 --- a/PlexRequests.Core/Models/IssuesModel.cs +++ b/PlexRequests.Core/Models/IssuesModel.cs @@ -42,6 +42,7 @@ namespace PlexRequests.Core.Models public List Issues { get; set; } public bool Deleted { get; set; } public RequestType Type { get; set; } + public IssueStatus IssueStatus { get; set; } } public class IssueModel @@ -50,7 +51,6 @@ namespace PlexRequests.Core.Models public string UserReported { get; set; } public IssueState Issue { get; set; } public string AdminNote { get; set; } - public IssueStatus IssueStatus { get; set; } } public enum IssueStatus diff --git a/PlexRequests.Core/Setup.cs b/PlexRequests.Core/Setup.cs index 87e16118e..b01810378 100644 --- a/PlexRequests.Core/Setup.cs +++ b/PlexRequests.Core/Setup.cs @@ -57,13 +57,13 @@ namespace PlexRequests.Core var version = CheckSchema(); if (version > 0) { - if (version > 1700 && version <= 1799) + if (version > 1700 && version <= 1759) { MigrateToVersion1700(); } - if (version > 1800 && version <= 1899) + if (version > 1759 && version <= 1799) { - MigrateToVersion1800(); + MigrateToVersion1760(); } } @@ -183,7 +183,7 @@ namespace PlexRequests.Core /// This includes updating the admin account to have all roles. /// Set the log level to info /// - private void MigrateToVersion1800() + private void MigrateToVersion1760() { try { diff --git a/PlexRequests.UI/Modules/IssuesModule.cs b/PlexRequests.UI/Modules/IssuesModule.cs index dd789c5fc..6cca1c935 100644 --- a/PlexRequests.UI/Modules/IssuesModule.cs +++ b/PlexRequests.UI/Modules/IssuesModule.cs @@ -5,10 +5,14 @@ using System.Threading.Tasks; using Nancy; using Nancy.Responses.Negotiation; +using Nancy.Security; + +using NLog; using PlexRequests.Core; using PlexRequests.Core.Models; using PlexRequests.Core.SettingModels; +using PlexRequests.Helpers; using PlexRequests.Store; using PlexRequests.UI.Models; @@ -23,22 +27,37 @@ namespace PlexRequests.UI.Modules Get["/"] = x => Index(); - Get["/issuecount", true] = async (x, ct) => await IssueCount(); - Get["/{id}", true] = async (x, ct) => await Details(x.id); Post["/issue", true] = async (x, ct) => await ReportIssue((int)Request.Form.requestId, (IssueState)(int)Request.Form.issue, null); + + Get["/inprogress", true] = async (x, ct) => await GetInProgressIssues(IssueStatus.InProgressIssue); + Get["/pending", true] = async (x, ct) => await GetInProgressIssues(IssueStatus.PendingIssue); + Get["/resolved", true] = async (x, ct) => await GetInProgressIssues(IssueStatus.ResolvedIssue); + + Post["/remove", true] = async (x, ct) => await RemoveIssue((int)Request.Form.issueId); + + Get["/issuecount", true] = async (x, ct) => await IssueCount(); + Post["/issuecomment", true] = async (x, ct) => await ReportIssue((int)Request.Form.requestId, IssueState.Other, (string)Request.Form.commentArea); } private IIssueService IssuesService { get; } private IRequestService RequestService { get; } + private static Logger Log = LogManager.GetCurrentClassLogger(); public Negotiator Index() { return View["Index"]; } + private async Task GetInProgressIssues(IssueStatus status) + { + var issues = await IssuesService.GetAllAsync(); + + return Response.AsJson(issues.Where(x => x.IssueStatus == status)); + } + public async Task IssueCount() { var issues = await IssuesService.GetAllAsync(); @@ -52,7 +71,6 @@ namespace PlexRequests.UI.Modules public async Task Details(int id) { - var issue = await IssuesService.GetAsync(id); return issue == null @@ -66,7 +84,6 @@ namespace PlexRequests.UI.Modules var model = new IssueModel { Issue = issue, - IssueStatus = IssueStatus.PendingIssue, UserReported = Username, UserNote = !string.IsNullOrEmpty(comment) ? $"{Username} - {comment}" @@ -95,7 +112,8 @@ namespace PlexRequests.UI.Modules Title = request.Title, PosterUrl = request.PosterPath, RequestId = requestId, - Type = request.Type + Type = request.Type, + IssueStatus = IssueStatus.PendingIssue }; issues.Issues.Add(model); @@ -130,6 +148,24 @@ namespace PlexRequests.UI.Modules return myIssues; } - + private async Task RemoveIssue(int issueId) + { + try + { + this.RequiresClaims(UserClaims.PowerUser); + + await IssuesService.DeleteIssueAsync(issueId); + + return Response.AsJson(new JsonResponseModel {Result = true, Message = "Issue Removed"}); + } + catch (Exception e) + { + Log.Error(e); + return Response.AsJson(new JsonResponseModel { Result = false, Message = "Looks like we couldn't remove the issue. Check the logs!" }); + } + + } + + } }