This commit is contained in:
2020-12-23 15:42:39 +00:00
parent c0a90fffb0
commit 22ac0d9189
3 changed files with 69 additions and 27 deletions

View File

@@ -187,6 +187,7 @@ namespace AyaNova.Api.Controllers
[AllowAnonymous] [AllowAnonymous]
public async Task<IActionResult> SubSet([FromRoute] long id, [FromBody] List<string> inObj) public async Task<IActionResult> SubSet([FromRoute] long id, [FromBody] List<string> inObj)
{ {
//## NOTE: This route is ONLY used at present for the reset password form at the client
if (serverState.IsClosed) if (serverState.IsClosed)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason)); return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
var l = await TranslationBiz.GetSpecifiedTranslationSubsetStaticAsync(inObj, id); var l = await TranslationBiz.GetSpecifiedTranslationSubsetStaticAsync(inObj, id);

View File

@@ -465,7 +465,7 @@ namespace AyaNova.Biz
//////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////
// NOTIFICATION PROCESSING // NOTIFICATION PROCESSING
// //
public async Task HandlePotentialNotificationEvent(AyaEvent ayaEvent, ICoreBizObjectModel proposedObj, ICoreBizObjectModel currentObj=null) public async Task HandlePotentialNotificationEvent(AyaEvent ayaEvent, ICoreBizObjectModel proposedObj, ICoreBizObjectModel currentObj = null)
{ {
ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger<ReviewBiz>(); ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger<ReviewBiz>();
if (ServerBootConfig.SEEDING) return; if (ServerBootConfig.SEEDING) return;
@@ -501,6 +501,8 @@ namespace AyaNova.Biz
} }
{ {
var eventNameTranslated = await TranslationBiz.GetTranslationForUserStaticAsync("ReviewOverDue", r.UserId);
NotifyEvent n = new NotifyEvent() NotifyEvent n = new NotifyEvent()
{ {
EventType = NotifyEventType.GeneralNotification, EventType = NotifyEventType.GeneralNotification,
@@ -508,7 +510,7 @@ namespace AyaNova.Biz
ObjectId = proposedObj.Id, ObjectId = proposedObj.Id,
AyaType = AyaType.Review, AyaType = AyaType.Review,
NotifySubscriptionId = userNotifySub.Id, NotifySubscriptionId = userNotifySub.Id,
Name = "LT:ReviewOverDue - " + proposedObj.Name, Name = $"{eventNameTranslated} - {proposedObj.Name}",
EventDate = r.DueDate EventDate = r.DueDate
}; };
await ct.NotifyEvent.AddAsync(n); await ct.NotifyEvent.AddAsync(n);
@@ -517,6 +519,7 @@ namespace AyaNova.Biz
if (supervisorNotifySub != null) if (supervisorNotifySub != null)
{ {
var eventNameTranslated = await TranslationBiz.GetTranslationForUserStaticAsync("ReviewOverDue", r.AssignedByUserId);
NotifyEvent n = new NotifyEvent() NotifyEvent n = new NotifyEvent()
{ {
EventType = NotifyEventType.GeneralNotification, EventType = NotifyEventType.GeneralNotification,
@@ -524,7 +527,7 @@ namespace AyaNova.Biz
ObjectId = proposedObj.Id, ObjectId = proposedObj.Id,
AyaType = AyaType.Review, AyaType = AyaType.Review,
NotifySubscriptionId = supervisorNotifySub.Id, NotifySubscriptionId = supervisorNotifySub.Id,
Name = "LT:ReviewOverDue - " + proposedObj.Name, Name = $"{eventNameTranslated} - {proposedObj.Name}",
EventDate = r.DueDate EventDate = r.DueDate
}; };
await ct.NotifyEvent.AddAsync(n); await ct.NotifyEvent.AddAsync(n);

View File

@@ -12,7 +12,7 @@ namespace AyaNova.Biz
internal class TranslationBiz : BizObject internal class TranslationBiz : BizObject
{ {
internal TranslationBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles userRoles) internal TranslationBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles userRoles)
{ {
@@ -20,7 +20,7 @@ namespace AyaNova.Biz
UserId = currentUserId; UserId = currentUserId;
UserTranslationId = userTranslationId; UserTranslationId = userTranslationId;
CurrentUserRoles = userRoles; CurrentUserRoles = userRoles;
BizType = AyaType.Translation; BizType = AyaType.Translation;
} }
internal static TranslationBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext = null) internal static TranslationBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext = null)
@@ -335,7 +335,7 @@ namespace AyaNova.Biz
// Get subset for specified translation ID // Get subset for specified translation ID
// called from controller and Used when user is not logged in // called from controller and Used when user is not logged in
// e.g. when resetting their password // e.g. when resetting their password
// // ## NOTE: NO other use for this other than the reset password at this point
internal static async Task<List<KeyValuePair<string, string>>> GetSpecifiedTranslationSubsetStaticAsync(List<string> param, long translationId) internal static async Task<List<KeyValuePair<string, string>>> GetSpecifiedTranslationSubsetStaticAsync(List<string> param, long translationId)
{ {
#if (DEBUG) #if (DEBUG)
@@ -371,6 +371,43 @@ namespace AyaNova.Biz
} }
} }
/////////////////////////////////////////////////////////////////
// Get subset for specified user (looks up translation id) statically
// called from internal code (e.g. notification processing)
//
internal static async Task<Dictionary<string, string>> GetSubsetForUserStaticAsync(List<string> param, long userId)
{
long translationId = ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID;
using (AyContext ct = ServiceProviderProvider.DBContext)
{
translationId = await ct.UserOptions.AsNoTracking().Where(z => z.UserId == userId).Select(z => z.TranslationId).SingleAsync();
}
return await GetSubsetStaticAsync(param, translationId);
}
/////////////////////////////////////////////////////////////////
// Get single item for specified user (looks up translation id) statically
// called from internal code (e.g. notification processing)
//
internal static async Task<string> GetTranslationForUserStaticAsync(string translationKey, long userId)
{
long translationId = ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID;
using (AyContext ct = ServiceProviderProvider.DBContext)
{
translationId = await ct.UserOptions.AsNoTracking().Where(z => z.UserId == userId).Select(z => z.TranslationId).SingleAsync();
}
var param = new List<string>() { translationKey };
var ret = await GetSubsetStaticAsync(param, translationId);
if (ret.Count > 0) return ret[translationKey];
return $"??{translationKey}";
}
//used by internal notification and other processes i.e. "Server" in all languages for server based notifications //used by internal notification and other processes i.e. "Server" in all languages for server based notifications
internal static async Task<Dictionary<long, string>> GetAllTranslationsForKey(string translationKey) internal static async Task<Dictionary<long, string>> GetAllTranslationsForKey(string translationKey)
{ {
@@ -394,28 +431,29 @@ namespace AyaNova.Biz
} }
/// <summary> //DEPRECATED
/// Get the value of the key provided in the default translation chosen // /// <summary>
/// </summary> // /// Get the value of the key provided in the default translation chosen
/// <param name="key"></param> // /// </summary>
/// <returns></returns> // /// <param name="key"></param>
internal static async Task<string> GetDefaultTranslationAsync(string key) // /// <returns></returns>
{ // internal static async Task<string> GetDefaultTranslationAsync(string key)
if (string.IsNullOrWhiteSpace(key)) // {
return "ERROR: GetDefaultTranslation NO KEY VALUE SPECIFIED"; // if (string.IsNullOrWhiteSpace(key))
#if (DEBUG) // return "ERROR: GetDefaultTranslation NO KEY VALUE SPECIFIED";
TrackRequestedKey(key); // #if (DEBUG)
#endif // TrackRequestedKey(key);
using (AyContext ct = ServiceProviderProvider.DBContext) // #endif
return await ct.TranslationItem.Where(z => z.TranslationId == ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID && z.Key == key).Select(z => z.Display).AsNoTracking().FirstOrDefaultAsync(); // using (AyContext ct = ServiceProviderProvider.DBContext)
} // return await ct.TranslationItem.Where(z => z.TranslationId == ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID && z.Key == key).Select(z => z.Display).AsNoTracking().FirstOrDefaultAsync();
// }
//Get all stock keys that are valid (used for key coverage reporting) // //Get all stock keys that are valid (used for key coverage reporting)
internal static async Task<List<string>> GetKeyListAsync() // internal static async Task<List<string>> GetKeyListAsync()
{ // {
using (AyContext ct = ServiceProviderProvider.DBContext) // using (AyContext ct = ServiceProviderProvider.DBContext)
return await ct.TranslationItem.Where(z => z.TranslationId == 1).OrderBy(z => z.Key).Select(z => z.Key).AsNoTracking().ToListAsync(); // return await ct.TranslationItem.Where(z => z.TranslationId == 1).OrderBy(z => z.Key).Select(z => z.Key).AsNoTracking().ToListAsync();
} // }