Skip to content

Commit

Permalink
Merge pull request #1028 from k7hpn/feature/bulk-code-reassignment
Browse files Browse the repository at this point in the history
Upload a list of vendor codes to bulk reassign
  • Loading branch information
k7hpn authored Jul 20, 2023
2 parents 7c541df + 4d52e37 commit eba882b
Show file tree
Hide file tree
Showing 11 changed files with 507 additions and 60 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
- Downloadable ZIP files of badge images for each system from Mission Control
- Ability to attach, remove, or update a certificate (uploaded PDF) to a trigger
- News stand post updates are shown as updated and sorted by update date
- Uploading a list of vendor codes to invalidate them and send participants new ones

### Fixed

Expand Down
71 changes: 71 additions & 0 deletions src/GRA.Controllers/MissionControl/VendorCodesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using GRA.Domain.Service;
using GRA.Utility;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -99,6 +100,72 @@ public static IEnumerable<SelectListItem> ShipDateOptions
}
}

[HttpGet]
[Authorize(Policy = Policy.ManageVendorCodes)]
public IActionResult BulkCodeReassignment()
{
return View();
}

[HttpPost]
[Authorize(Policy = Policy.ManageVendorCodes)]
public async Task<IActionResult> BulkCodeReassignment(string reason, IFormFile textFile)
{
var issues = new List<string>();
if (string.IsNullOrEmpty(reason) || reason.Length > 255)
{
issues.Add("Please supply a reason between 1 and 255 characters.");
ModelState.AddModelError(nameof(reason), "You must supply a reason between 1-255 characters.");
}

if (textFile?.FileName == null
|| (!string.Equals(Path.GetExtension(textFile.FileName), ".txt",
StringComparison.OrdinalIgnoreCase)))
{
issues.Add("You must select a .txt file.");
ModelState.AddModelError(nameof(textFile), "You must select a .txt file.");
}

if (ModelState.ErrorCount == 0)
{
var tempFile = _pathResolver.ResolvePrivateTempFilePath();
_logger.LogInformation("Accepted reassignment import file {UploadFile} as {TempFile}",
textFile.FileName,
tempFile);

using var fileStream = new FileStream(tempFile, FileMode.Create);
await textFile.CopyToAsync(fileStream);

string file = WebUtility.UrlEncode(Path.GetFileName(tempFile));

var jobToken = await _jobService.CreateJobAsync(new Job
{
JobType = JobType.BulkReassignCodes,
SerializedParameters = JsonConvert
.SerializeObject(new JobDetailsVendorCodeBulkReassignment
{
Filename = file,
Reason = reason
})
});

return View("Job", new ViewModel.MissionControl.Shared.JobViewModel
{
CancelUrl = Url.Action(nameof(BulkCodeReassignment)),
JobToken = jobToken.ToString(),
PingSeconds = 5,
SuccessRedirectUrl = "",
SuccessUrl = Url.Action(nameof(BulkCodeReassignment)),
Title = "Loading import..."
});
}
else
{
AlertDanger = string.Join(' ', issues)?.Trim();
return RedirectToAction(nameof(BulkCodeReassignment));
}
}

[HttpGet]
[Authorize(Policy = Policy.ManageVendorCodes)]
public async Task<IActionResult> Configure()
Expand Down Expand Up @@ -612,6 +679,8 @@ public IActionResult LookupPackingSlip(string id)
[HttpPost]
public async Task<IActionResult> ProcessPackingSlip(PackingSlipSummary summary)
{
ArgumentNullException.ThrowIfNull(summary);

if (!UserHasPermission(Permission.ManageVendorCodes)
&& !UserHasPermission(Permission.ReceivePackingSlips))
{
Expand Down Expand Up @@ -917,6 +986,8 @@ await _segmentService.UpdateTextAsync(segmentTextId.Value,
[Authorize(Policy = Policy.ManageVendorCodes)]
public async Task<IActionResult> UpdateConfiguration(ConfigureViewModel viewModel)
{
ArgumentNullException.ThrowIfNull(viewModel);

if (viewModel.VendorCodeType == null)
{
ShowAlertDanger("Could not create empty vendor code type.");
Expand Down
12 changes: 12 additions & 0 deletions src/GRA.Domain.Model/JobDetailsVendorCodeBulkReassignment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.ComponentModel.DataAnnotations;

namespace GRA.Domain.Model
{
public class JobDetailsVendorCodeBulkReassignment
{
public string Filename { get; set; }

[MaxLength(255)]
public string Reason { get; set; }
}
}
3 changes: 2 additions & 1 deletion src/GRA.Domain.Model/JobType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public enum JobType
UpdateEmailAwardStatus,
BranchImport,
SendNewsEmails,
ReceivePackingSlip
ReceivePackingSlip,
BulkReassignCodes
}
}
Loading

0 comments on commit eba882b

Please sign in to comment.