-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3972 from cisagov/feature/CSET-2773
Implement "Resume Questions" feature
- Loading branch information
Showing
19 changed files
with
421 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
CSETWebApi/CSETWeb_Api/CSETWebCore.Helpers/LastAnsweredHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
//////////////////////////////// | ||
// | ||
// Copyright 2024 Battelle Energy Alliance, LLC | ||
// | ||
// | ||
//////////////////////////////// | ||
using System.Linq; | ||
using CSETWebCore.Model.Question; | ||
using CSETWebCore.DataLayer.Model; | ||
|
||
|
||
namespace CSETWebCore.Helpers | ||
{ | ||
/// <summary> | ||
/// Saves the last-answered question/option. | ||
/// </summary> | ||
public class LastAnsweredHelper | ||
{ | ||
private readonly CSETContext _context; | ||
|
||
|
||
public LastAnsweredHelper(CSETContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Save the group/requirement/question/option so that the user can return to the last question answered | ||
/// on a subsequent rerun of the assessment. | ||
/// </summary> | ||
/// <param name="questionId"></param> | ||
public void Save(int assessmentId, int? userId, Answer ans) | ||
{ | ||
var ac = _context.ASSESSMENT_CONTACTS.Where(x => x.UserId == userId && x.Assessment_Id == assessmentId).FirstOrDefault(); | ||
if (ac == null) | ||
{ | ||
// no contact record - should never happen | ||
return; | ||
} | ||
|
||
|
||
if (ans.QuestionType.ToLower() == "maturity") | ||
{ | ||
// get the question ID if not in the answer | ||
if (ans.QuestionId == 0) | ||
{ | ||
var dbOption = _context.MATURITY_ANSWER_OPTIONS.FirstOrDefault(x => x.Mat_Option_Id == ans.OptionId); | ||
ans.QuestionId = dbOption.Mat_Question_Id; | ||
} | ||
|
||
var dbQuestion = _context.MATURITY_QUESTIONS.Where(x => x.Mat_Question_Id == ans.QuestionId).FirstOrDefault(); | ||
|
||
ac.Last_Q_Answered = $"MG:{dbQuestion.Grouping_Id},MQ:{ans.QuestionId}"; | ||
|
||
if (ans.OptionId != null && ans.OptionId != 0) | ||
{ | ||
ac.Last_Q_Answered += $",MO:{ans.OptionId}"; | ||
} | ||
} | ||
|
||
|
||
if (ans.QuestionType.ToLower() == "requirement") | ||
{ | ||
ac.Last_Q_Answered = $"R:{ans.QuestionId}"; | ||
} | ||
|
||
|
||
if (ans.QuestionType.ToLower() == "question") | ||
{ | ||
ac.Last_Q_Answered = $"Q:{ans.QuestionId}"; | ||
} | ||
|
||
|
||
_context.SaveChanges(); | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
CSETWebApi/CSETWeb_Api/CSETWebCore.Helpers/UserAuthenticationAzure.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using CSETWebCore.DataLayer.Model; | ||
using CSETWebCore.Model.Authentication; | ||
using Microsoft.EntityFrameworkCore; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
//using Microsoft.AspNetCore.Authentication.OpenIdConnect; | ||
|
||
|
||
namespace CSETWebCore.Helpers | ||
{ | ||
public class UserAuthenticationAzure | ||
{ | ||
CSETContext _context; | ||
|
||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="context"></param> | ||
public UserAuthenticationAzure( | ||
CSETContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="login"></param> | ||
/// <returns></returns> | ||
public LoginResponse AuthenticateUser(Login login) | ||
{ | ||
// authenticate against Azure | ||
|
||
|
||
|
||
|
||
// Read directly from the database; UserManager does not read password and salt, in order to keep them more private | ||
var loginUser = _context.USERS.Where(x => x.PrimaryEmail == login.Email).FirstOrDefault(); | ||
|
||
// Build response object | ||
LoginResponse resp = new LoginResponse | ||
{ | ||
UserId = loginUser.UserId, | ||
Email = login.Email, | ||
Lang = loginUser.Lang, | ||
UserFirstName = loginUser.FirstName, | ||
UserLastName = loginUser.LastName, | ||
IsSuperUser = loginUser.IsSuperUser, | ||
ResetRequired = loginUser.PasswordResetRequired, | ||
ExportExtension = IOHelper.GetExportFileExtension(login.Scope), | ||
ImportExtensions = IOHelper.GetImportFileExtensions(login.Scope), | ||
LinkerTime = new BuildNumberHelper().GetLinkerTime(), | ||
IsFirstLogin = loginUser.IsFirstLogin | ||
}; | ||
|
||
return resp; | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
CSETWebApi/CSETWeb_Api/CSETWebCore.Model/Contact/Bookmark.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace CSETWebCore.Model.Contact | ||
{ | ||
public class BookmarkRequest | ||
{ | ||
public string Bookmark { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.