Align .editorconfig files
When debugging only app.Services.GetRequiredService<IPCRBService>(); Injected AppSettings instead of using GetEnvironmentVariable at Services level Get ready to use VSCode IDE
This commit is contained in:
@ -44,7 +44,7 @@ public class ApprovalService : IApprovalService {
|
||||
queryBuilder.Append($"values ({approval.IssueID}, '{approval.RoleName}', '{approval.SubRole}', {approval.UserID}, ");
|
||||
queryBuilder.Append($"{approval.SubRoleID}, 0, '{approval.AssignedDate.ToString("yyyy-MM-dd HH:mm:ss")}', ");
|
||||
queryBuilder.Append($"3, 0, {approval.Step}, {approval.TaskID});");
|
||||
|
||||
|
||||
int rowsCreated = await _dalService.ExecuteAsync(queryBuilder.ToString());
|
||||
|
||||
if (rowsCreated <= 0) throw new Exception("Unable to insert approval in database");
|
||||
@ -63,7 +63,7 @@ public class ApprovalService : IApprovalService {
|
||||
if (issueId <= 0) throw new ArgumentException($"{issueId} is not a valid issue ID");
|
||||
|
||||
IEnumerable<Approval>? approvals = new List<Approval>();
|
||||
|
||||
|
||||
if (!bypassCache)
|
||||
approvals = _cache.Get<IEnumerable<Approval>>($"approvals{issueId}");
|
||||
|
||||
@ -78,7 +78,7 @@ public class ApprovalService : IApprovalService {
|
||||
|
||||
foreach (Approval approval in approvals) {
|
||||
int successfulUpdates = 0;
|
||||
|
||||
|
||||
User? user = await _userService.GetUserByUserId(approval.UserID);
|
||||
if (user is not null) {
|
||||
approval.User = user;
|
||||
@ -86,11 +86,11 @@ public class ApprovalService : IApprovalService {
|
||||
}
|
||||
|
||||
if (approval.ItemStatus < 0)
|
||||
approval.StatusMessage = "Denied";
|
||||
approval.StatusMessage = "Denied";
|
||||
if (approval.ItemStatus == 0)
|
||||
approval.StatusMessage = "Assigned";
|
||||
approval.StatusMessage = "Assigned";
|
||||
if (approval.ItemStatus > 0)
|
||||
approval.StatusMessage = "Approved";
|
||||
approval.StatusMessage = "Approved";
|
||||
}
|
||||
|
||||
_cache.Set($"approvals{issueId}", approvals, DateTimeOffset.Now.AddMinutes(5));
|
||||
@ -107,7 +107,7 @@ public class ApprovalService : IApprovalService {
|
||||
try {
|
||||
_logger.LogInformation($"Attempting to get role ID by name");
|
||||
|
||||
if (string.IsNullOrWhiteSpace(roleName))
|
||||
if (string.IsNullOrWhiteSpace(roleName))
|
||||
throw new ArgumentException("Role name cannot be null or empty");
|
||||
|
||||
int roleId = _cache.Get<int>($"role{roleName}");
|
||||
@ -170,7 +170,7 @@ public class ApprovalService : IApprovalService {
|
||||
if (subRoleId <= 0) throw new ArgumentException($"{subRoleId} is not a valid sub role ID");
|
||||
|
||||
List<User>? members = _cache.Get<List<User>>($"approvalMembers{subRoleId}");
|
||||
|
||||
|
||||
if (members is null || members.Count() <= 0) {
|
||||
IEnumerable<int>? memberIds = _cache.Get<IEnumerable<int>>($"approvalMemberIds{subRoleId}");
|
||||
|
||||
@ -211,7 +211,7 @@ public class ApprovalService : IApprovalService {
|
||||
if (userId <= 0) throw new ArgumentException($"{userId} is not a valid user ID");
|
||||
|
||||
IEnumerable<Approval>? approvals = null;
|
||||
|
||||
|
||||
if (!bypassCache) approvals = _cache.Get<IEnumerable<Approval>>($"approvalMembers{userId}");
|
||||
|
||||
if (approvals is null) {
|
||||
@ -317,4 +317,4 @@ public class ApprovalService : IApprovalService {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ using System.Security.Principal;
|
||||
using System.Text;
|
||||
|
||||
using MesaFabApproval.API.Services;
|
||||
using MesaFabApproval.Models;
|
||||
using MesaFabApproval.Shared.Models;
|
||||
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
@ -30,17 +31,13 @@ public class AuthenticationService : IAuthenticationService {
|
||||
private readonly string _jwtAudience;
|
||||
private readonly string _jwtKey;
|
||||
|
||||
public AuthenticationService(ILogger<AuthenticationService> logger, IMemoryCache cache, IUserService userService) {
|
||||
public AuthenticationService(ILogger<AuthenticationService> logger, IMemoryCache cache, IUserService userService, AppSettings appSettings) {
|
||||
_logger = logger ?? throw new ArgumentNullException("ILogger not injected");
|
||||
_cache = cache ?? throw new ArgumentNullException("IMemoryCache not injected");
|
||||
_userService = userService ?? throw new ArgumentNullException("IUserService not injected");
|
||||
|
||||
_jwtIssuer = Environment.GetEnvironmentVariable("FabApprovalJwtIssuer") ??
|
||||
throw new ArgumentNullException("FabApprovalJwtIssuer environment variable not found");
|
||||
_jwtAudience = Environment.GetEnvironmentVariable("FabApprovalJwtAudience") ??
|
||||
throw new ArgumentNullException("FabApprovalJwtAudience environment variable not found");
|
||||
_jwtKey = Environment.GetEnvironmentVariable("FabApprovalJwtKey") ??
|
||||
throw new ArgumentNullException("FabApprovalJwtKey environment variable not found");
|
||||
_jwtKey = appSettings.JwtKey;
|
||||
_jwtIssuer = appSettings.JwtIssuer;
|
||||
_jwtAudience = appSettings.JwtAudience;
|
||||
}
|
||||
|
||||
public async Task<LoginResult> AuthenticateUser(AuthAttempt login) {
|
||||
@ -59,7 +56,7 @@ public class AuthenticationService : IAuthenticationService {
|
||||
|
||||
if (user is null) {
|
||||
user = await _userService.GetUserByLoginId(login.LoginID);
|
||||
|
||||
|
||||
_cache.Set<User>($"user{login.LoginID}", user, DateTimeOffset.Now.AddDays(1));
|
||||
}
|
||||
|
||||
@ -77,8 +74,8 @@ public class AuthenticationService : IAuthenticationService {
|
||||
};
|
||||
} else {
|
||||
return new LoginResult() {
|
||||
IsAuthenticated= false,
|
||||
AuthTokens = new() {
|
||||
IsAuthenticated = false,
|
||||
AuthTokens = new() {
|
||||
JwtToken = "",
|
||||
RefreshToken = ""
|
||||
},
|
||||
@ -105,7 +102,7 @@ public class AuthenticationService : IAuthenticationService {
|
||||
if (user.IsManager) roles.Add("manager");
|
||||
if (user.IsAdmin) roles.Add("admin");
|
||||
|
||||
AuthAttempt authAttempt = new() {
|
||||
AuthAttempt authAttempt = new() {
|
||||
LoginID = user.LoginID,
|
||||
};
|
||||
|
||||
@ -132,7 +129,7 @@ public class AuthenticationService : IAuthenticationService {
|
||||
|
||||
byte[] key = Encoding.ASCII.GetBytes(_jwtKey);
|
||||
|
||||
List<Claim> claims = new() {
|
||||
List<Claim> claims = new() {
|
||||
new Claim(nameof(authAttempt.LoginID), authAttempt.LoginID)
|
||||
};
|
||||
|
||||
@ -171,7 +168,7 @@ public class AuthenticationService : IAuthenticationService {
|
||||
|
||||
_cache.Set<List<string>>(authAttempt.LoginID, refreshTokensForUser, DateTimeOffset.Now.AddHours(4));
|
||||
|
||||
return new AuthTokens {
|
||||
return new AuthTokens {
|
||||
JwtToken = jwt,
|
||||
RefreshToken = refreshToken
|
||||
};
|
||||
@ -251,4 +248,4 @@ public class AuthenticationService : IAuthenticationService {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -43,4 +43,4 @@ public class CAService : ICAService {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -35,4 +35,4 @@ public class CustomerService : ICustomerService {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -86,4 +86,4 @@ public class DalService : IDalService {
|
||||
|
||||
return rowsAffected;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
using System.Data;
|
||||
|
||||
using MesaFabApproval.Models;
|
||||
|
||||
using Microsoft.Data.SqlClient;
|
||||
|
||||
namespace MesaFabApproval.API.Services;
|
||||
@ -11,12 +13,10 @@ public interface IDbConnectionService {
|
||||
public class DbConnectionService : IDbConnectionService {
|
||||
private readonly string _dbConnectionString;
|
||||
|
||||
public DbConnectionService() {
|
||||
_dbConnectionString = Environment.GetEnvironmentVariable("FabApprovalDbConnectionString") ??
|
||||
throw new ArgumentNullException("FabApprovalDbConnectionString environment variable not found");
|
||||
public DbConnectionService(AppSettings appSettings) {
|
||||
_dbConnectionString = appSettings.DbConnectionString;
|
||||
}
|
||||
|
||||
public IDbConnection GetConnection() {
|
||||
return new SqlConnection(_dbConnectionString);
|
||||
}
|
||||
}
|
||||
public IDbConnection GetConnection() =>
|
||||
new SqlConnection(_dbConnectionString);
|
||||
}
|
@ -43,4 +43,4 @@ public class ECNService : IECNService {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ using System.Net.Mail;
|
||||
using System.Text;
|
||||
|
||||
using MesaFabApproval.API.Utilities;
|
||||
using MesaFabApproval.Models;
|
||||
using MesaFabApproval.Shared.Models;
|
||||
using MesaFabApproval.Shared.Utilities;
|
||||
|
||||
@ -51,17 +52,16 @@ public class MRBService : IMRBService {
|
||||
IMemoryCache cache,
|
||||
IUserService userService,
|
||||
IApprovalService approvalService,
|
||||
ISmtpService smtpService) {
|
||||
ISmtpService smtpService,
|
||||
AppSettings appSettings) {
|
||||
_logger = logger ?? throw new ArgumentNullException("ILogger not injected");
|
||||
_dalService = dalService ?? throw new ArgumentNullException("IDalService not injected");
|
||||
_cache = cache ?? throw new ArgumentNullException("IMemoryCache not injected");
|
||||
_userService = userService ?? throw new ArgumentNullException("IUserService not injected");
|
||||
_approvalService = approvalService ?? throw new ArgumentNullException("IApprovalService not injected");
|
||||
_smtpService = smtpService ?? throw new ArgumentNullException("ISmtpService not injected");
|
||||
_siteBaseUrl = Environment.GetEnvironmentVariable("NewFabApprovalBaseUrl") ??
|
||||
throw new ArgumentNullException("FabApprovalBaseUrl environment variable not found");
|
||||
_mrbAttachmentPath = Environment.GetEnvironmentVariable("FabApprovalMrbAttachmentPath") ??
|
||||
throw new ArgumentNullException("FabApprovalMrbAttachmentPath environment variable not found");
|
||||
_siteBaseUrl = appSettings.SiteBaseUrl;
|
||||
_mrbAttachmentPath = appSettings.MrbAttachmentPath;
|
||||
}
|
||||
public async Task CreateNewMRB(MRB mrb) {
|
||||
try {
|
||||
@ -100,7 +100,7 @@ public class MRBService : IMRBService {
|
||||
if (rowsCreated <= 0) throw new Exception("Unable to create new MRB");
|
||||
|
||||
mrb = await GetMRBByTitle(mrb.Title, true);
|
||||
|
||||
|
||||
_cache.Set($"mrb{mrb.MRBNumber}", mrb, DateTimeOffset.Now.AddHours(1));
|
||||
_cache.Set($"mrb{mrb.Title}", mrb, DateTimeOffset.Now.AddHours(1));
|
||||
|
||||
@ -160,7 +160,7 @@ public class MRBService : IMRBService {
|
||||
_cache.Set("mrbNumbers", mrbNumbers);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
} catch (Exception ex) {
|
||||
_logger.LogError($"Unable to determine if {number} is a valid MRB#, because {ex.Message}");
|
||||
@ -205,7 +205,7 @@ public class MRBService : IMRBService {
|
||||
if (string.IsNullOrWhiteSpace(title)) throw new ArgumentException("Title cannot be null or empty");
|
||||
|
||||
MRB? mrb = null;
|
||||
|
||||
|
||||
if (!bypassCache) mrb = _cache.Get<MRB>($"mrb{title}");
|
||||
|
||||
if (mrb is null) {
|
||||
@ -275,7 +275,7 @@ public class MRBService : IMRBService {
|
||||
IEnumerable<MRB>? allMrbs = _cache.Get<IEnumerable<MRB>>("allMrbs");
|
||||
if (allMrbs is not null) {
|
||||
List<MRB> mrbList = allMrbs.ToList();
|
||||
mrbList.RemoveAll(m => m.MRBNumber ==mrb.MRBNumber);
|
||||
mrbList.RemoveAll(m => m.MRBNumber == mrb.MRBNumber);
|
||||
mrbList.Add(mrb);
|
||||
_cache.Set("allMrbs", mrbList, DateTimeOffset.Now.AddHours(1));
|
||||
}
|
||||
@ -302,7 +302,6 @@ public class MRBService : IMRBService {
|
||||
|
||||
if (rowsAffected <= 0) throw new Exception("Unable to create MRB action in database");
|
||||
|
||||
|
||||
} catch (Exception ex) {
|
||||
_logger.LogError($"An exception occurred when attempting to create new MRB action. Exception: {ex.Message}");
|
||||
throw;
|
||||
@ -316,7 +315,7 @@ public class MRBService : IMRBService {
|
||||
if (mrbNumber <= 0) throw new ArgumentException($"{mrbNumber} is not a valid MRB number");
|
||||
|
||||
IEnumerable<MRBAction>? mrbActions = null;
|
||||
|
||||
|
||||
if (!bypassCache)
|
||||
_cache.Get<IEnumerable<MRBAction>>($"mrbActions{mrbNumber}");
|
||||
|
||||
@ -542,7 +541,7 @@ public class MRBService : IMRBService {
|
||||
foreach (MRBAction action in await GetMRBActionsForMRB(mrbNumber, false)) {
|
||||
string sql = $"select * from MRBActionAttachment where ActionID = {action.ActionID};";
|
||||
|
||||
IEnumerable<MRBActionAttachment> newAttachments =
|
||||
IEnumerable<MRBActionAttachment> newAttachments =
|
||||
(await _dalService.QueryAsync<MRBActionAttachment>(sql)).ToList();
|
||||
|
||||
attachments.AddRange(newAttachments);
|
||||
@ -574,7 +573,7 @@ public class MRBService : IMRBService {
|
||||
|
||||
int rowsDeleted = await _dalService.ExecuteAsync(sql);
|
||||
|
||||
if (rowsDeleted <= 0)
|
||||
if (rowsDeleted <= 0)
|
||||
throw new Exception($"No attachments found in the database with attachment ID {attachment.AttachmentID}");
|
||||
} catch (Exception ex) {
|
||||
_logger.LogError($"An exception occurred when attempting to delete an attachment. Exception: {ex.Message}");
|
||||
@ -781,7 +780,7 @@ public class MRBService : IMRBService {
|
||||
|
||||
sw.Write(sw.NewLine);
|
||||
|
||||
foreach (DataRow dr in dt.Rows) {
|
||||
foreach (DataRow dr in dt.Rows) {
|
||||
for (int i = 0; i < dt.Columns.Count; i++) {
|
||||
if (!Convert.IsDBNull(dr[i])) {
|
||||
string? value = dr[i].ToString();
|
||||
@ -838,7 +837,7 @@ public class MRBService : IMRBService {
|
||||
string convertFromPart = string.Empty;
|
||||
string convertToCustomer = string.Empty;
|
||||
string convertToPart = string.Empty;
|
||||
|
||||
|
||||
string[] convertFrom = action.ConvertFrom.Split(" ");
|
||||
if (convertFrom.Length > 1) {
|
||||
convertFromCustomer = convertFrom[0];
|
||||
@ -936,4 +935,4 @@ public class MRBService : IMRBService {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ using System.Net.Mail;
|
||||
using System.Text;
|
||||
|
||||
using MesaFabApproval.API.Utilities;
|
||||
using MesaFabApproval.Models;
|
||||
using MesaFabApproval.Shared.Models;
|
||||
using MesaFabApproval.Shared.Utilities;
|
||||
|
||||
@ -54,18 +55,17 @@ public class PCRBService : IPCRBService {
|
||||
IMemoryCache cache,
|
||||
IUserService userService,
|
||||
IApprovalService approvalService,
|
||||
ISmtpService smtpService) {
|
||||
ISmtpService smtpService,
|
||||
AppSettings appSettings) {
|
||||
_logger = logger ?? throw new ArgumentNullException("ILogger not injected");
|
||||
_dalService = dalService ?? throw new ArgumentNullException("IDalService not injected");
|
||||
_cache = cache ?? throw new ArgumentNullException("IMemoryCache not injected");
|
||||
_userService = userService ?? throw new ArgumentNullException("IUserService not injected");
|
||||
_pcrbAttachmentPath = Environment.GetEnvironmentVariable("FabApprovalPcrbAttachmentPath") ??
|
||||
throw new ArgumentNullException("FabApprovalPcrbAttachmentPath environment variable not found");
|
||||
_approvalService = approvalService ??
|
||||
throw new ArgumentNullException("IApprovalService not injected");
|
||||
_smtpService = smtpService ?? throw new ArgumentNullException("ISmtpService not injected");
|
||||
_siteBaseUrl = Environment.GetEnvironmentVariable("NewFabApprovalBaseUrl") ??
|
||||
throw new ArgumentNullException("FabApprovalBaseUrl environment variable not found");
|
||||
_siteBaseUrl = appSettings.SiteBaseUrl;
|
||||
_pcrbAttachmentPath = appSettings.PcrbAttachmentPath;
|
||||
}
|
||||
|
||||
public async Task CreateNewPCRB(PCRB pcrb) {
|
||||
@ -295,7 +295,7 @@ public class PCRBService : IPCRBService {
|
||||
|
||||
IEnumerable<PCRBAttachment>? attachments = null;
|
||||
|
||||
if (!bypassCache)
|
||||
if (!bypassCache)
|
||||
attachments = _cache.Get<IEnumerable<PCRBAttachment>>($"pcrbAttachments{planNumber}");
|
||||
|
||||
if (attachments is null) {
|
||||
@ -609,7 +609,7 @@ public class PCRBService : IPCRBService {
|
||||
|
||||
IEnumerable<Approval> approvals = await _approvalService.GetApprovalsForIssueId(pcrb.PlanNumber, true);
|
||||
|
||||
List<Approval> approvalsNeedingNotification = approvals.Where(a => a.Step == pcrb.CurrentStep &&
|
||||
List<Approval> approvalsNeedingNotification = approvals.Where(a => a.Step == pcrb.CurrentStep &&
|
||||
a.NotifyDate <= DateTimeUtilities.MIN_DT &&
|
||||
a.AssignedDate > DateTimeUtilities.MIN_DT).ToList();
|
||||
|
||||
@ -764,4 +764,4 @@ public class PCRBService : IPCRBService {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,10 @@
|
||||
using MesaFabApproval.API.Clients;
|
||||
using System.Net.Mail;
|
||||
|
||||
using MesaFabApproval.API.Clients;
|
||||
using MesaFabApproval.Models;
|
||||
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
|
||||
using System.Net.Mail;
|
||||
|
||||
namespace MesaFabApproval.API.Services;
|
||||
|
||||
public interface ISmtpService {
|
||||
@ -15,13 +16,12 @@ public class SmtpService : ISmtpService {
|
||||
private readonly ISmtpClientWrapper _smtpClient;
|
||||
private readonly bool _shouldSendEmail;
|
||||
|
||||
public SmtpService(ILogger<SmtpService> logger, ISmtpClientWrapper smtpClient) {
|
||||
public SmtpService(ILogger<SmtpService> logger, ISmtpClientWrapper smtpClient, AppSettings appSettings) {
|
||||
_logger = logger ??
|
||||
throw new ArgumentNullException("ILogger not injected");
|
||||
_smtpClient = smtpClient ??
|
||||
throw new ArgumentNullException("SmtpClient not injected");
|
||||
if (!Boolean.TryParse(Environment.GetEnvironmentVariable("FabApprovalShouldSendEmail"), out _shouldSendEmail))
|
||||
throw new ArgumentNullException("FabApprovalShouldSendEmail environment variable not found");
|
||||
_shouldSendEmail = appSettings.ShouldSendEmail;
|
||||
}
|
||||
|
||||
public async Task<bool> SendEmail(IEnumerable<MailAddress> recipients,
|
||||
@ -32,7 +32,7 @@ public class SmtpService : ISmtpService {
|
||||
if (ccRecipients is null) throw new ArgumentNullException("ccRecipients cannot be null!");
|
||||
if (subject.IsNullOrEmpty()) throw new ArgumentNullException("subject cannot be null or empty!");
|
||||
if (body.IsNullOrEmpty()) throw new ArgumentNullException("body cannot be null or empty!");
|
||||
|
||||
|
||||
return await Task.Run(() => {
|
||||
int maxRetries = 3;
|
||||
int backoffSeconds = 30;
|
||||
@ -76,4 +76,4 @@ public class SmtpService : ISmtpService {
|
||||
return messageWasSent;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -144,4 +144,4 @@ public class UserService : IUserService {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user