Skip to content

Commit

Permalink
fix: finalerrors (#897)
Browse files Browse the repository at this point in the history
* Get more details

* It's wrong

* fix: put it all back
  • Loading branch information
jaybeeelsdon authored Dec 12, 2024
1 parent d7a0774 commit bd365b2
Show file tree
Hide file tree
Showing 11 changed files with 256 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Data-Egress-API/Controllers/DataEgressController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public async Task<BoolReturn> AddNewDataEgress(EgressSubmission submission)
}
catch (Exception ex)
{
Log.Error(ex.ToString());
Log.Error(ex,"{Function} Sending email error", "AddNewDataEgress");
}

return new BoolReturn() { Result = true };
Expand Down
15 changes: 14 additions & 1 deletion src/Data-Egress-API/Repositories/DbContexts/DataInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,20 @@ public void SeedAllInOneData(string password)
_dbContext.SaveChanges();
}


if (!_dbContext.KeycloakCredentials.Any(x => x.CredentialType == CredentialType.Egress))
{


_dbContext.KeycloakCredentials.Add(new KeycloakCredentials()
{
UserName = "globaladminuser",
CredentialType = CredentialType.Egress,
PasswordEnc = _encDecHelper.Encrypt(password)
});
_dbContext.SaveChanges();
}




}
Expand Down
47 changes: 47 additions & 0 deletions src/Data-Egress-UI/Controllers/DataEgressCredentialsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using BL.Models;
using BL.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using BL.Models.APISimpleTypeReturns;

namespace Data_Egress_UI.Controllers
{
[Authorize(Roles = "data-egress-admin")]
public class DataEgressCredentialsController : Controller
{
private readonly IDataEgressClientHelper _clientHelper;
public DataEgressCredentialsController(IDataEgressClientHelper client)
{
_clientHelper = client;
}
[HttpGet]
public async Task<IActionResult> UpdateCredentialsAsync()
{
var valid = await _clientHelper.CallAPIWithoutModel<BoolReturn>("/api/TreCredentials/EgressCheckCredentialsAreValid");
return View(new KeycloakCredentials()
{ Valid = valid.Result });
}
[HttpPost]
public async Task<IActionResult> UpdateCredentials(KeycloakCredentials credentials)
{
if (ModelState.IsValid)
{
var result =
await _clientHelper.CallAPI<KeycloakCredentials, KeycloakCredentials>(
"/api/TreCredentials/EgressUpdateCredentials", credentials);
if (result.Valid)
{
return RedirectToAction("Index", "Home");
}
else
{
return View(credentials);
}
}
else
{
return View(credentials);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
@model BL.Models.KeycloakCredentials
<div class="container-lg p-4">
<h1 class="fs-3 mb-0">Update Tre Credentials</h1>
<hr class="d-flex my-4">
<div class="d-flex align-items-center justify-content-between mb-4">
<div>
@if (!Model.Valid)
{
<h2 class="fs-5">Egress Credentials are missing or invalid. Please update</h2>
}
</div>
</div>
<div class="row">
<div class="col-md-4">
@using (Html.BeginForm("UpdateCredentials", "DataEgressCredentials", FormMethod.Post, new { id = "frmMain" }))
{
@Html.AntiForgeryToken()
@Html.HiddenFor(m => m.Id)
<div class="form-group">
@Html.LabelFor(m => m.UserName)
@Html.TextBoxFor(x => x.UserName, new { @class = "form-control show-tick noBottomMargin" })
@Html.ValidationMessageFor(m => m.UserName)
</div>
<div class="form-group">
@Html.LabelFor(m => m.PasswordEnc)
@Html.PasswordFor(x => x.PasswordEnc, new { @class = "form-control show-tick noBottomMargin" })
@Html.ValidationMessageFor(m => m.PasswordEnc)
</div>
<div class="form-group">
@Html.LabelFor(m => m.ConfirmPassword)
@Html.PasswordFor(x => x.ConfirmPassword, new { @class = "form-control show-tick noBottomMargin" })
@Html.ValidationMessageFor(m => m.ConfirmPassword)
</div>
<div class="mt-4">
<button type="submit" class="btn btn-sm btn-primary">Update Credentials</button>
</div>
}
</div>
</div>
</div>
4 changes: 3 additions & 1 deletion src/Data-Egress-UI/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="TreCredentials" asp-action="UpdateCredentials">Update Tre Credentials</a>
</li>

<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="DataEgressCredentials" asp-action="UpdateCredentials">Update Egress Credentials</a>
</li>
<li class="mobile-account-nav">
<hr class="mobile-account-nav dropdown-divider" />
</li>
Expand Down
40 changes: 40 additions & 0 deletions src/TRE-API/Controllers/TRECredentialsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using BL.Models;
using BL.Models.APISimpleTypeReturns;
using BL.Models.Settings;
using BL.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Serilog;
using TRE_API.Repositories.DbContexts;
using TRE_API.Services;
namespace TRE_API.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class TRECredentialsController : Controller
{
private readonly ApplicationDbContext _DbContext;
private readonly IEncDecHelper _encDecHelper;
private readonly KeycloakTokenHelper _keycloakTokenHelper;
public TRECredentialsController(ApplicationDbContext applicationDbContext, IEncDecHelper encDec, SubmissionKeyCloakSettings keycloakSettings)
{
_encDecHelper = encDec;
_DbContext = applicationDbContext;
_keycloakTokenHelper = new KeycloakTokenHelper(keycloakSettings.BaseUrl, keycloakSettings.ClientId,
keycloakSettings.ClientSecret, keycloakSettings.Proxy, keycloakSettings.ProxyAddresURL, keycloakSettings.DemoMode);
}
[Authorize(Roles = "dare-tre-admin")]
[HttpGet("CheckCredentialsAreValid")]
public async Task<BoolReturn> CheckCredentialsAreValidAsync()
{
return await ControllerHelpers.CheckCredentialsAreValid(_keycloakTokenHelper, _encDecHelper, _DbContext, CredentialType.Tre);
}
[Authorize(Roles = "dare-tre-admin")]
[HttpPost("UpdateCredentials")]
public async Task<KeycloakCredentials> UpdateCredentials(KeycloakCredentials creds)
{
creds = await ControllerHelpers.UpdateCredentials(creds, _keycloakTokenHelper, _DbContext, _encDecHelper, CredentialType.Tre, "dare-tre-admin");
return creds;
}
}
}
13 changes: 13 additions & 0 deletions src/TRE-API/Repositories/DbContexts/DataInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ public void SeedAllInOneData(string password)
_dbContext.SaveChanges();
}

if (!_dbContext.KeycloakCredentials.Any(x => x.CredentialType == CredentialType.Tre))
{


_dbContext.KeycloakCredentials.Add(new KeycloakCredentials()
{
UserName = "globaladminuser",
CredentialType = CredentialType.Tre,
PasswordEnc = _encDecHelper.Encrypt(password)
});
_dbContext.SaveChanges();
}

if (!_dbContext.KeycloakCredentials.Any(x => x.CredentialType == CredentialType.Egress))
{

Expand Down
16 changes: 8 additions & 8 deletions src/TRE-API/Services/SubmissionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,14 @@ public void SimulateSubmissionProcessing(Submission submission)
{


UpdateStatusForTre(submission.ToString(), StatusType.SendingSubmissionToHutch, "");
UpdateStatusForTre(submission.ToString(), StatusType.WaitingForCrate, "");
UpdateStatusForTre(submission.ToString(), StatusType.ValidatingCrate, "");
UpdateStatusForTre(submission.ToString(), StatusType.FetchingWorkflow, "");
UpdateStatusForTre(submission.ToString(), StatusType.StagingWorkflow, "");
UpdateStatusForTre(submission.ToString(), StatusType.ExecutingWorkflow, "");
UpdateStatusForTre(submission.ToString(), StatusType.PreparingOutputs, "");
UpdateStatusForTre(submission.ToString(), StatusType.TransferredForDataOut, "");
UpdateStatusForTre(submission.Id.ToString(), StatusType.SendingSubmissionToHutch, "");
UpdateStatusForTre(submission.Id.ToString(), StatusType.WaitingForCrate, "");
UpdateStatusForTre(submission.Id.ToString(), StatusType.ValidatingCrate, "");
UpdateStatusForTre(submission.Id.ToString(), StatusType.FetchingWorkflow, "");
UpdateStatusForTre(submission.Id.ToString(), StatusType.StagingWorkflow, "");
UpdateStatusForTre(submission.Id.ToString(), StatusType.ExecutingWorkflow, "");
UpdateStatusForTre(submission.Id.ToString(), StatusType.PreparingOutputs, "");
UpdateStatusForTre(submission.Id.ToString(), StatusType.TransferredForDataOut, "");

Uri uri = new Uri(submission.DockerInputLocation);
string fileName = Path.GetFileName(uri.LocalPath);
Expand Down
43 changes: 43 additions & 0 deletions src/TRE-UI/Controllers/TRECredentialsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using BL.Models;
using BL.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using BL.Models.APISimpleTypeReturns;
using TRE_UI.Services;
namespace TRE_UI.Controllers
{
[Authorize(Roles = "dare-tre-admin")]
public class TRECredentialsController : Controller
{
private readonly ITREClientHelper _clientHelper;
public TRECredentialsController(ITREClientHelper client)
{
_clientHelper = client;
}
[HttpGet]
public async Task<IActionResult> UpdateCredentialsAsync()
{
return View(await ControllerHelpers.CheckCredentialsAreValid("TRECredentials", _clientHelper));

}
[HttpPost]

public async Task<IActionResult> UpdateCredentials(KeycloakCredentials credentials)
{
if (await ControllerHelpers.UpdateCredentials("TRECredentials", _clientHelper, ModelState,
credentials))
{
return RedirectToAction("Index", "Home");
}
else
{
return View(credentials);
}

}




}
}
4 changes: 3 additions & 1 deletion src/TRE-UI/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="DataEgressCredentials" asp-action="UpdateCredentials">Update Data Egress Credentials</a>
</li>

<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="TRECredentials" asp-action="UpdateCredentials">Update TRE Credentials</a>
</li>
<li class="mobile-account-nav">
<hr class="mobile-account-nav dropdown-divider" />
</li>
Expand Down
44 changes: 44 additions & 0 deletions src/TRE-UI/Views/TRECredentials/UpdateCredentials.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
@model BL.Models.KeycloakCredentials
@{
ViewData["Title"] = "TRE Credentials";
}
<div class="container-lg p-4">
<h1 class="fs-3 mb-0">TRE Credentials</h1>
<hr class="d-flex my-4">
<div class="d-flex align-items-center justify-content-between mb-4">
<div>
@if (!Model.Valid)
{
<h2 class="fs-5">TRE Credentials are missing or invalid. Please update</h2>
}
</div>
</div>
<div class="row">
<div class="col-md-4">
@using (Html.BeginForm("UpdateCredentials", "TRECredentials", FormMethod.Post, new { id = "frmMain" }))
{
@Html.AntiForgeryToken()
@Html.HiddenFor(m => m.Id)

<div class="form-group">
@Html.LabelFor(m => m.UserName, new { @class = "form-label" })
@Html.TextBoxFor(x => x.UserName, new { @class = "form-control show-tick" })
@Html.ValidationMessageFor(m => m.UserName)
</div>
<div class="form-group">
@Html.LabelFor(m => m.PasswordEnc, new { @class = "form-label" })
@Html.PasswordFor(x => x.PasswordEnc, new { @class = "form-control show-tick noBottomMargin" })
@Html.ValidationMessageFor(m => m.PasswordEnc)
</div>
<div class="form-group">
@Html.LabelFor(m => m.ConfirmPassword, new { @class = "form-label" })
@Html.PasswordFor(x => x.ConfirmPassword, new { @class = "form-control show-tick noBottomMargin" })
@Html.ValidationMessageFor(m => m.ConfirmPassword)
</div>
<div class="mt-4">
<button type="submit" class="btn btn-sm btn-primary">Save Credentials</button>
</div>
}
</div>
</div>
</div>

0 comments on commit bd365b2

Please sign in to comment.