Add permissions for downloading LeafInput

This commit is contained in:
2020-08-08 21:43:12 -04:00
parent 2716b9bfb4
commit 5dfc65a83a
9 changed files with 109 additions and 51 deletions
+36 -10
View File
@@ -5,6 +5,7 @@ using LeafWeb.Core.Entities;
using LeafWeb.Core.Utility;
using LeafWeb.WebCms.Models;
using LeafWeb.WebCms.Utility;
using Microsoft.Ajax.Utilities;
using Umbraco.Web.Mvc;
namespace LeafWeb.WebCms.Controllers
@@ -29,13 +30,31 @@ namespace LeafWeb.WebCms.Controllers
[MemberAuthorize(AllowGroup = "Authenticated,Administrator")]
public ActionResult Input(int id)
{
return GetInputZip(id);
var leafInput = DataService.GetLeafInput(id);
// check leafinput email matches current user
if (!Permissions.IsCurrentUserAdministrator() &&
!leafInput.DoesBelongToUser(HttpContext.User.Identity.Name))
{
return View("PermissionDenied");
}
return GetInputZip(leafInput);
}
[MemberAuthorize(AllowGroup = "Authenticated,Administrator")]
public ActionResult OutputToUser(int id)
{
return GetOutputZip(id, LeafOutputFileType.ToUser);
var leafInput = DataService.GetLeafInput(id);
// check leafinput email matches current user
if (!Permissions.IsCurrentUserAdministrator() &&
!leafInput.DoesBelongToUser(HttpContext.User.Identity.Name))
{
return View("PermissionDenied");
}
return GetOutputZip(leafInput, LeafOutputFileType.ToUser);
}
[MemberAuthorize(AllowGroup = "Administrator")]
@@ -44,42 +63,49 @@ namespace LeafWeb.WebCms.Controllers
return GetOutputZip(id, LeafOutputFileType.NotToUser);
}
[MemberAuthorize(AllowGroup = "Authenticated,Administrator")]
[MemberAuthorize(AllowGroup = "Administrator")]
public ActionResult OutputCleanedInput(int id)
{
return GetOutputZip(id, LeafOutputFileType.CleanedInput);
}
[MemberAuthorize(AllowGroup = "Authenticated,Administrator")]
[MemberAuthorize(AllowGroup = "Administrator")]
public ActionResult ResultsInputZip(LeafDataQuery query)
{
return GetResults(query, LeafInput.GetInputFilesZip, $"LeafWeb_{DateTime.Now:yyyy-dd-MM--HH-mm-ss}_Input.zip");
}
[MemberAuthorize(AllowGroup = "Authenticated,Administrator")]
[MemberAuthorize(AllowGroup = "Administrator")]
public ActionResult ResultsOutputZip(LeafDataQuery query)
{
return GetResults(query, LeafInput.GetOutputFilesZip_ToUser, $"LeafWeb_{DateTime.Now:yyyy-dd-MM--HH-mm-ss}_Output.zip");
}
private ActionResult GetOutputZip(int id, LeafOutputFileType type)
{
var leafInput = DataService.GetLeafInput(id);
=> GetOutputZip(DataService.GetLeafInput(id), type);
private ActionResult GetOutputZip(LeafInput leafInput, LeafOutputFileType type)
{
if (leafInput == null)
return View("DownloadNotFound");
var zip = leafInput.GetOutputFileZip(type);
var filename = $"{leafInput.Identifier.FilterValidFilename()}_{type}.zip";
var suffix =
type == LeafOutputFileType.ToUser
? "_Output"
: $"_Output_{type}";
var filename = $"{leafInput.Identifier.FilterValidFilename()}{suffix}.zip";
return new FileContentResult(zip, "application/zip") { FileDownloadName = filename };
}
private ActionResult GetInputZip(int id)
{
var leafInput = DataService.GetLeafInput(id);
=> GetInputZip(DataService.GetLeafInput(id));
private ActionResult GetInputZip(LeafInput leafInput)
{
if (leafInput == null)
return View("DownloadNotFound");