Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
inlguy committed Jan 7, 2022
2 parents 8617638 + 4cd16ca commit 595e442
Show file tree
Hide file tree
Showing 58 changed files with 2,620 additions and 553,798 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ public void DetermineFeaturesFromData(ref AssessmentDetail assessment)
/// <param name="assessment"></param>
/// <returns></returns>
public int SaveAssessmentDetail(int assessmentId, AssessmentDetail assessment)
{
{
string app_code = _tokenManager.Payload(Constants.Constants.Token_Scope);

// Add or update the ASSESSMENTS record
Expand All @@ -410,7 +410,7 @@ public int SaveAssessmentDetail(int assessmentId, AssessmentDetail assessment)

dbAssessment.Assessment_Id = assessmentId;
dbAssessment.AssessmentCreatedDate = assessment.CreatedDate;
dbAssessment.AssessmentCreatorId = assessment.CreatorId;
dbAssessment.AssessmentCreatorId = assessment.CreatorId == 0 ? null:assessment.CreatorId;
dbAssessment.Assessment_Date = assessment.AssessmentDate ?? DateTime.Now;
dbAssessment.LastAccessedDate = assessment.LastModifiedDate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public ContactDetail CreateAndAddContactToAssessment(ContactCreateParameters new
UserCreateResponse resp = _userBusiness.CheckUserExists(userDetail);
if (!resp.IsExisting)
{
resp = _userBusiness.CreateUser(userDetail);
resp = _userBusiness.CreateUser(userDetail, _context);

// Send this brand-new user an email with their temporary password (if they have an email)
if (!string.IsNullOrEmpty(userDetail.Email))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,14 @@ public List<ResourceNode> Search(string term, bool isResourceDocs, bool isProcur
string resourceType = lucDoc.Get(FieldNames.RESOURCE_TYPE);
ResourceTypeEnum resourceTypeEnum = (ResourceTypeEnum)System.Enum.Parse(typeof(ResourceTypeEnum), resourceType, true);
ResourceNode resDoc = GetDoc(docId, resourceTypeEnum);
resDoc.Score = doc.Score;
if (resDoc != null)
{
resDoc.Score = doc.Score;
listResourceDocuments.Add(resDoc);
}
}
return listResourceDocuments.OrderBy(x => x.HeadingTitle).OrderByDescending(x => x.DatePublished).OrderByDescending(x=>x.Score).ToList();

return listResourceDocuments.OrderBy(x => x.HeadingTitle).OrderByDescending(x => x.DatePublished).OrderByDescending(x => x.Score).ToList();
}
catch (Exception)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public UserBusiness(CSETContext context, IPasswordHash password)
/// to create a user.
/// </summary>
/// <returns></returns>
public UserCreateResponse CreateUser(UserDetail userDetail)
public UserCreateResponse CreateUser(UserDetail userDetail, CSETContext tmpContext)
{
// see if this user already exists
UserDetail existingUser = this.GetUserDetail(userDetail.Email);
Expand Down Expand Up @@ -60,10 +60,10 @@ public UserCreateResponse CreateUser(UserDetail userDetail)
IsSuperUser = false,
PasswordResetRequired = true
};
_context.USERS.Add(u);
tmpContext.USERS.Add(u);
try
{
_context.SaveChanges();
tmpContext.SaveChanges();
}
catch (Microsoft.EntityFrameworkCore.DbUpdateException ex)
{
Expand All @@ -74,7 +74,7 @@ public UserCreateResponse CreateUser(UserDetail userDetail)
}
//TODO: Add logging
Console.WriteLine(ex);
_context.USERS.Remove(u);
tmpContext.USERS.Remove(u);
}

UserCreateResponse resp = new UserCreateResponse
Expand Down
17 changes: 10 additions & 7 deletions CSETWebApi/CSETWeb_Api/CSETWebCore.Helpers/TokenManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public class TokenManager : ITokenManager
private readonly IConfiguration _configuration;

private CSETContext _context;
private string secret = null;
private static string secret = null;
private static object myLockObject = new object();

/// <summary>
/// Creates an instance of TokenManager and populates it with
Expand Down Expand Up @@ -324,12 +325,14 @@ public string GetSecret()
return secret;
}


secret = "";
lock (secret)
lock (myLockObject)
{
var inst = _context.INSTALLATION
.OrderByDescending(i => i.Generated_UTC).OrderBy(i => i.Installation_ID).FirstOrDefault();
if (secret != null)
{
return secret;
}

var inst = _context.INSTALLATION.OrderBy(i => i.Installation_ID).FirstOrDefault();
if (inst != null)
{
secret = inst.JWT_Secret;
Expand Down Expand Up @@ -360,7 +363,7 @@ public string GetSecret()
};
_context.INSTALLATION.Add(installRec);

_context.SaveChangesAsync();
_context.SaveChanges();
secret = newSecret;
return newSecret;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public bool CreateUserSendEmail(CreateUser info)
FirstName = info.FirstName,
LastName = info.LastName
};
UserCreateResponse userCreateResponse = _userBusiness.CreateUser(ud);
UserCreateResponse userCreateResponse = _userBusiness.CreateUser(ud,_context);

_context.USER_SECURITY_QUESTIONS.Add(new USER_SECURITY_QUESTIONS()
{
Expand Down
131 changes: 68 additions & 63 deletions CSETWebApi/CSETWeb_Api/CSETWebCore.Helpers/UserAuthentication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,12 @@ public LoginResponse Authenticate(Login login)
/// </summary>
/// <param name="login"></param>
/// <returns></returns>
public LoginResponse AuthenticateStandalone(Login login)
public LoginResponse AuthenticateStandalone(Login login, ITokenManager tokenManager)
{
int? assessmentId = ((TokenManager)tokenManager).GetAssessmentId();

assessmentId = assessmentId == 0 ? null : assessmentId;

int userIdSO = 100;
string primaryEmailSO = "";

Expand All @@ -96,91 +100,92 @@ public LoginResponse AuthenticateStandalone(Login login)
return null;
}

//TODO: Make work multi-platform
string name = WindowsIdentity.GetCurrent().Name;
name = string.IsNullOrWhiteSpace(name) ? "Local" : name;
primaryEmailSO = name;
//check for legacy default email for local installation and set to new standard
var userOrg = _context.USERS.Where(x => x.PrimaryEmail == primaryEmailSO + "@myorg.org").FirstOrDefault();
if (userOrg != null)
{
string tmp = userOrg.PrimaryEmail.Split('@')[0];
userOrg.PrimaryEmail = tmp;
if (_context.USERS.Where(x => x.PrimaryEmail == tmp).FirstOrDefault() == null)
_context.SaveChanges();
primaryEmailSO = userOrg.PrimaryEmail;
}
using (CSETContext tmpcontext = new CSETContext()) {
//TODO: Make work multi-platform
string name = WindowsIdentity.GetCurrent().Name;
name = string.IsNullOrWhiteSpace(name) ? "Local" : name;
primaryEmailSO = name;
//check for legacy default email for local installation and set to new standard
var userOrg = tmpcontext.USERS.Where(x => x.PrimaryEmail == primaryEmailSO + "@myorg.org").FirstOrDefault();
if (userOrg != null)
{
string tmp = userOrg.PrimaryEmail.Split('@')[0];
userOrg.PrimaryEmail = tmp;
if (tmpcontext.USERS.Where(x => x.PrimaryEmail == tmp).FirstOrDefault() == null)
tmpcontext.SaveChanges();
primaryEmailSO = userOrg.PrimaryEmail;
}

var user = _context.USERS.Where(x => x.PrimaryEmail == primaryEmailSO).FirstOrDefault();
if (user == null)
{
UserDetail ud = new UserDetail()
var user = tmpcontext.USERS.Where(x => x.PrimaryEmail == primaryEmailSO).FirstOrDefault();
if (user == null)
{
Email = primaryEmailSO,
FirstName = name,
LastName = ""
};
UserCreateResponse userCreateResponse = _userBusiness.CreateUser(ud);

_context.SaveChanges();
//update the userid 1 to the new user
var tempu = _context.USERS.Where(x => x.PrimaryEmail == primaryEmailSO).FirstOrDefault();
if (tempu != null)
userIdSO = tempu.UserId;
determineIfUpgradedNeededAndDoSo(userIdSO);
}
else
{
userIdSO = user.UserId;
}
UserDetail ud = new UserDetail()
{
Email = primaryEmailSO,
FirstName = name,
LastName = ""
};
UserCreateResponse userCreateResponse = _userBusiness.CreateUser(ud,tmpcontext);

tmpcontext.SaveChanges();
//update the userid 1 to the new user
var tempu = tmpcontext.USERS.Where(x => x.PrimaryEmail == primaryEmailSO).FirstOrDefault();
if (tempu != null)
userIdSO = tempu.UserId;
determineIfUpgradedNeededAndDoSo(userIdSO,tmpcontext);
}
else
{
userIdSO = user.UserId;
}

if (string.IsNullOrEmpty(primaryEmailSO))
{
return null;
}
if (string.IsNullOrEmpty(primaryEmailSO))
{
return null;
}


// Generate a token for this user
string token = _transactionSecurity.GenerateToken(userIdSO, login.TzOffset, -1, null, null, login.Scope);
// Generate a token for this user
string token = _transactionSecurity.GenerateToken(userIdSO, login.TzOffset, -1, assessmentId, null, login.Scope);

// Build response object
LoginResponse resp = new LoginResponse
{
Token = token,
Email = primaryEmailSO,
UserFirstName = name,
UserLastName = "",
IsSuperUser = false,
ResetRequired = false,
ExportExtension = IOHelper.GetExportFileExtension(login.Scope),
ImportExtensions = IOHelper.GetImportFileExtensions(login.Scope),
LinkerTime = new BuildNumberHelper().GetLinkerTime()
};
// Build response object
LoginResponse resp = new LoginResponse
{
Token = token,
Email = primaryEmailSO,
UserFirstName = name,
UserLastName = "",
IsSuperUser = false,
ResetRequired = false,
UserId = userIdSO,
ExportExtension = IOHelper.GetExportFileExtension(login.Scope),
ImportExtensions = IOHelper.GetImportFileExtensions(login.Scope),
LinkerTime = new BuildNumberHelper().GetLinkerTime()
};


return resp;
return resp;
}
}

private bool IsUpgraded = false;

public void determineIfUpgradedNeededAndDoSo(int newuserID)
public void determineIfUpgradedNeededAndDoSo(int newuserID, CSETContext tmpContext)
{
//look to see if the localuser exists
//if so then get that user id and changes all
if (!IsUpgraded)
{
var user = _context.USERS.Where(x => x.PrimaryEmail == "localuser").FirstOrDefault();
var user = tmpContext.USERS.Where(x => x.PrimaryEmail == "localuser").FirstOrDefault();
if (user != null)
{
var contacts = _context.ASSESSMENT_CONTACTS.Where(x => x.UserId == user.UserId).ToList();
var contacts = tmpContext.ASSESSMENT_CONTACTS.Where(x => x.UserId == user.UserId).ToList();
if(contacts.Any())
for (int i = 0; i < contacts.Count(); i++)
contacts[i].UserId = newuserID;

_context.ASSESSMENT_CONTACTS.UpdateRange(contacts);
_context.SaveChanges();


tmpContext.ASSESSMENT_CONTACTS.UpdateRange(contacts);
tmpContext.SaveChanges();
}
}
IsUpgraded = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using System;
using CSETWebCore.DataLayer.Model;
using CSETWebCore.Model.Authentication;

namespace CSETWebCore.Interfaces.Helpers
{
public interface IUserAuthentication
{
LoginResponse Authenticate(Login login);
LoginResponse AuthenticateStandalone(Login login);
void determineIfUpgradedNeededAndDoSo(int newuserID);
LoginResponse AuthenticateStandalone(Login login, ITokenManager tokenManager);
void determineIfUpgradedNeededAndDoSo(int newuserID, CSETContext tmpContext);
bool IsLocalInstallation(String app_code);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using CSETWebCore.Model.Contact;
using CSETWebCore.DataLayer.Model;
using CSETWebCore.Model.Contact;
using CSETWebCore.Model.User;

namespace CSETWebCore.Interfaces.User
{
public interface IUserBusiness
{
UserCreateResponse CreateUser(UserDetail userDetail);
UserCreateResponse CreateUser(UserDetail userDetail, CSETContext tmpContext);
void UpdateUser(int userid, string PrimaryEmail, CreateUser user);
UserDetail GetUserDetail(string email);
CreateUser GetUserInfo(int userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

}


@{ RenderContactInformation(); }

<div class="container-fluid">
@{ RenderContactInformation(); }
</div>


<style>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
var totalDistribution = Model.CRRScores.FullAnswerDistrib();
var totalBarChartInput = new BarChartInput() { Height = 50, Width = 110 };
totalBarChartInput.AnswerCounts = new List<int>
{ totalDistribution.Green, totalDistribution.Yellow, totalDistribution.Red };
{ totalDistribution.Green, totalDistribution.Yellow, totalDistribution.Red };
var totalBarChart = new ScoreBarChart(totalBarChartInput);

}
@Html.Raw(totalBarChart.ToString())

</div>
<div class="row" style="padding: 0;">
<div class="col" style="padding: 0;">
<h5 class="appendix-label">CRR Summary</h5>
</div>
</div>
Expand All @@ -59,7 +59,7 @@
@Html.Raw(legend.ToString())
</div>
</div>
<div class="row header" style="border-top: 1px solid black;">
<div class="row header" style="border-top: 1px solid black; padding: 0;">
<div style="width: 60%;">
<b>MIL-1 Performed</b>
<br />
Expand Down Expand Up @@ -124,11 +124,11 @@
foreach (XElement domain in XDocument.Root.Elements())
{
var domainScores = Model.CRRScores.DomainAnswerDistrib(domain.Attribute("abbreviation").Value);
var barChartInput = new BarChartInput() { Height = 50, Width = 75 };
var barChartInput = new BarChartInput() { Height = 45, Width = 75 };
barChartInput.AnswerCounts = new List<int> { domainScores.Green, domainScores.Yellow, domainScores.Red };
var barChart = new ScoreBarChart(barChartInput);

<div class="row" style="border-top: 1px solid black;">
<div class="row" style="border-top: 0.5px solid black;">
<div class="col-1" style="width: 15%; padding: 0 0.25rem 0 0;">
<div class="row">
<div style="font-size: 0.7rem; font-weight: bold;">
Expand Down Expand Up @@ -212,7 +212,7 @@
.header div {
padding: 0;
font-size: 8px;
font-size: 7.5px;
padding: 0.1rem;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public override void Execute(SqlConnection conn)
RunFile(Path.Combine(this.applicationPath, @"VersionUpgrader\SQL\1034_to_1100.sql"), conn);
RunFile(Path.Combine(this.applicationPath, @"VersionUpgrader\SQL\1034_to_1100_data.sql"), conn);
RunFile(Path.Combine(this.applicationPath, @"VersionUpgrader\SQL\1034_to_1100_data2.sql"), conn);
RunFile(Path.Combine(this.applicationPath, @"VersionUpgrader\SQL\1034_to_1100_data3.sql"), conn);
RunFile(Path.Combine(this.applicationPath, @"VersionUpgrader\SQL\Move_Child_Questions_Content_to_Parent.sql"), conn);
this.UpgradeToVersionLocalDB(conn, myVersion);
}
Expand Down
Loading

0 comments on commit 595e442

Please sign in to comment.