Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tidusjar committed Jun 3, 2016
1 parent e7aba8a commit 9d48810
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 11 deletions.
2 changes: 1 addition & 1 deletion PlexRequests.Core/Models/IssuesModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public IssuesModel()
public List<IssueModel> Issues { get; set; }
public bool Deleted { get; set; }
public RequestType Type { get; set; }
public IssueStatus IssueStatus { get; set; }
}

public class IssueModel
Expand All @@ -50,7 +51,6 @@ public class IssueModel
public string UserReported { get; set; }
public IssueState Issue { get; set; }
public string AdminNote { get; set; }
public IssueStatus IssueStatus { get; set; }
}

public enum IssueStatus
Expand Down
8 changes: 4 additions & 4 deletions PlexRequests.Core/Setup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ public string SetupDb(string urlBase)
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();
}
}

Expand Down Expand Up @@ -183,7 +183,7 @@ public void MigrateToVersion1700()
/// <para>This includes updating the admin account to have all roles.</para>
/// <para>Set the log level to info</para>
/// </summary>
private void MigrateToVersion1800()
private void MigrateToVersion1760()
{
try
{
Expand Down
48 changes: 42 additions & 6 deletions PlexRequests.UI/Modules/IssuesModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@

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;

Expand All @@ -23,22 +27,37 @@ public IssuesModule(ISettingsService<PlexRequestSettings> pr, IIssueService issu

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<Response> GetInProgressIssues(IssueStatus status)
{
var issues = await IssuesService.GetAllAsync();

return Response.AsJson(issues.Where(x => x.IssueStatus == status));
}

public async Task<Response> IssueCount()
{
var issues = await IssuesService.GetAllAsync();
Expand All @@ -52,7 +71,6 @@ public async Task<Response> IssueCount()

public async Task<Negotiator> Details(int id)
{

var issue = await IssuesService.GetAsync(id);

return issue == null
Expand All @@ -66,7 +84,6 @@ private async Task<Response> ReportIssue(int requestId, IssueState issue, string
var model = new IssueModel
{
Issue = issue,
IssueStatus = IssueStatus.PendingIssue,
UserReported = Username,
UserNote = !string.IsNullOrEmpty(comment)
? $"{Username} - {comment}"
Expand Down Expand Up @@ -95,7 +112,8 @@ private async Task<Response> ReportIssue(int requestId, IssueState issue, string
Title = request.Title,
PosterUrl = request.PosterPath,
RequestId = requestId,
Type = request.Type
Type = request.Type,
IssueStatus = IssueStatus.PendingIssue
};
issues.Issues.Add(model);

Expand Down Expand Up @@ -130,6 +148,24 @@ where i.UserReported.Equals(Username, StringComparison.CurrentCultureIgnoreCase)

return myIssues;
}

private async Task<Response> 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!" });
}

}


}
}

0 comments on commit 9d48810

Please sign in to comment.