This commit is contained in:
2021-03-16 23:55:36 +00:00
parent ead4a22e16
commit 9c98eaff09
7 changed files with 133 additions and 24 deletions

View File

@@ -1,4 +1,5 @@
using System; using System;
using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Routing;
@@ -53,11 +54,7 @@ namespace AyaNova.Api.Controllers
{ {
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 ret = await GetEnumList(enumkey, UserTranslationIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
long TranslationId = UserTranslationIdFromContext.Id(HttpContext.Items);
var ret = await GetEnumList(enumkey, TranslationId);
return Ok(ApiOkResponse.Response(ret)); return Ok(ApiOkResponse.Response(ret));
} }
@@ -95,7 +92,7 @@ namespace AyaNova.Api.Controllers
public static async Task<List<NameIdItem>> GetEnumList(string enumKey, long translationId) public static async Task<List<NameIdItem>> GetEnumList(string enumKey, long translationId, AuthorizationRoles userRoles)
{ {
List<string> TranslationKeysToFetch = new List<string>(); List<string> TranslationKeysToFetch = new List<string>();
@@ -116,7 +113,7 @@ namespace AyaNova.Api.Controllers
} }
} }
else if (keyNameInLowerCase == "core") else if (keyNameInLowerCase == "coreall")
{ {
//core biz objects for UI facing purposes such as search form limit to object type etc //core biz objects for UI facing purposes such as search form limit to object type etc
var values = Enum.GetValues(typeof(AyaType)); var values = Enum.GetValues(typeof(AyaType));
@@ -147,6 +144,85 @@ namespace AyaNova.Api.Controllers
} }
} }
} }
else if (keyNameInLowerCase == "coreview")//all core objects user can read
{
//core biz objects for UI facing purposes such as search form limit to object type etc
var rawvalues = Enum.GetValues(typeof(AyaType));
List<AyaType> allowedValues = new List<AyaType>();
foreach (AyaType t in rawvalues)
{
if (Authorized.HasReadFullRole(userRoles, t))
allowedValues.Add(t);
}
foreach (AyaType t in allowedValues)
{
if (t.HasAttribute(typeof(CoreBizObjectAttribute)))
{
TranslationKeysToFetch.Add(t.ToString());
}
}
var LT = await TranslationBiz.GetSubsetStaticAsync(TranslationKeysToFetch, translationId);
foreach (AyaType t in allowedValues)
{
if (t.HasAttribute(typeof(CoreBizObjectAttribute)))
{
var tName = t.ToString();
string name = string.Empty;
if (LT.ContainsKey(tName))
{
name = LT[tName];
}
else
{
name = tName;
}
ReturnList.Add(new NameIdItem() { Name = name, Id = (long)t });
}
}
}
else if (keyNameInLowerCase == "coreedit")//all core objects current user can edit
{
//core biz objects for UI facing purposes such as search form limit to object type etc
var rawvalues = Enum.GetValues(typeof(AyaType));
List<AyaType> allowedValues = new List<AyaType>();
foreach (AyaType t in rawvalues)
{
if (Authorized.HasModifyRole(userRoles, t))
allowedValues.Add(t);
}
foreach (AyaType t in allowedValues)
{
if (t.HasAttribute(typeof(CoreBizObjectAttribute)))
{
TranslationKeysToFetch.Add(t.ToString());
}
}
var LT = await TranslationBiz.GetSubsetStaticAsync(TranslationKeysToFetch, translationId);
foreach (AyaType t in allowedValues)
{
if (t.HasAttribute(typeof(CoreBizObjectAttribute)))
{
var tName = t.ToString();
string name = string.Empty;
if (LT.ContainsKey(tName))
{
name = LT[tName];
}
else
{
name = tName;
}
ReturnList.Add(new NameIdItem() { Name = name, Id = (long)t });
}
}
}
else if (keyNameInLowerCase == StringUtil.TrimTypeName(typeof(AyaType).ToString()).ToLowerInvariant()) else if (keyNameInLowerCase == StringUtil.TrimTypeName(typeof(AyaType).ToString()).ToLowerInvariant())
{ {
//this is intended primarily for developers, not for UI facing so no need to localize or pretty it up //this is intended primarily for developers, not for UI facing so no need to localize or pretty it up
@@ -459,8 +535,8 @@ namespace AyaNova.Api.Controllers
ReturnList.Add(new NameIdItem() { Name = LT["ContractOverrideTypePriceDiscount"], Id = (long)ContractOverrideType.PriceDiscount }); ReturnList.Add(new NameIdItem() { Name = LT["ContractOverrideTypePriceDiscount"], Id = (long)ContractOverrideType.PriceDiscount });
ReturnList.Add(new NameIdItem() { Name = LT["ContractOverrideTypeMarkup"], Id = (long)ContractOverrideType.CostMarkup }); ReturnList.Add(new NameIdItem() { Name = LT["ContractOverrideTypeMarkup"], Id = (long)ContractOverrideType.CostMarkup });
//this is not a valid setting, not sure why it's there //this is not a valid setting, not sure why it's there
// ReturnList.Add(new NameIdItem() { Name = "-", Id = (long)ContractOverrideType.NotSet }); // ReturnList.Add(new NameIdItem() { Name = "-", Id = (long)ContractOverrideType.NotSet });
} }
//################################################################################################################# //#################################################################################################################

View File

@@ -494,7 +494,10 @@ MULTIPLE discount / markup ITEMS
var orderedList = from id in batch join z in batchResults on id equals z.Id select z; var orderedList = from id in batch join z in batchResults on id equals z.Id select z;
//cache enum list //cache enum list
var ContractOverrideTypeEnumList = await AyaNova.Api.Controllers.EnumListController.GetEnumList(StringUtil.TrimTypeName(typeof(ContractOverrideType).ToString()), UserTranslationId); var ContractOverrideTypeEnumList = await AyaNova.Api.Controllers.EnumListController.GetEnumList(
StringUtil.TrimTypeName(typeof(ContractOverrideType).ToString()),
UserTranslationId,
CurrentUserRoles);
//cache translations needed //cache translations needed
var PreTrans = await TranslationBiz.GetSubsetStaticAsync(new List<string> { "TimeSpanDays", "TimeSpanHours", "TimeSpanMinutes", "TimeSpanSeconds" }, UserTranslationId); var PreTrans = await TranslationBiz.GetSubsetStaticAsync(new List<string> { "TimeSpanDays", "TimeSpanHours", "TimeSpanMinutes", "TimeSpanSeconds" }, UserTranslationId);
foreach (Contract w in orderedList) foreach (Contract w in orderedList)
@@ -513,9 +516,14 @@ MULTIPLE discount / markup ITEMS
private async Task PopulateVizFields(Contract o, List<NameIdItem> contractOverrideTypeEnumList = null, Dictionary<string, string> preTrans = null) private async Task PopulateVizFields(Contract o, List<NameIdItem> contractOverrideTypeEnumList = null, Dictionary<string, string> preTrans = null)
{ {
if (contractOverrideTypeEnumList == null) if (contractOverrideTypeEnumList == null)
contractOverrideTypeEnumList = await AyaNova.Api.Controllers.EnumListController.GetEnumList(StringUtil.TrimTypeName(typeof(ContractOverrideType).ToString()), UserTranslationId); contractOverrideTypeEnumList = await AyaNova.Api.Controllers.EnumListController.GetEnumList(
StringUtil.TrimTypeName(typeof(ContractOverrideType).ToString()),
UserTranslationId,
CurrentUserRoles);
if (preTrans == null) if (preTrans == null)
await TranslationBiz.GetSubsetStaticAsync(new List<string> { "TimeSpanDays", "TimeSpanHours", "TimeSpanMinutes", "TimeSpanSeconds" }, UserTranslationId); await TranslationBiz.GetSubsetStaticAsync(
new List<string> { "TimeSpanDays", "TimeSpanHours", "TimeSpanMinutes", "TimeSpanSeconds" },
UserTranslationId);
if (o.ResponseTime == TimeSpan.Zero) if (o.ResponseTime == TimeSpan.Zero)
o.ResponseTimeViz = string.Empty; o.ResponseTimeViz = string.Empty;

View File

@@ -333,8 +333,14 @@ namespace AyaNova.Biz
//cache frequent viz data //cache frequent viz data
//usertypes //usertypes
var CustomerServiceRequestStatusEnumList = await AyaNova.Api.Controllers.EnumListController.GetEnumList(StringUtil.TrimTypeName(typeof(CustomerServiceRequestStatus).ToString()), UserTranslationId); var CustomerServiceRequestStatusEnumList = await AyaNova.Api.Controllers.EnumListController.GetEnumList(
var CustomerServiceRequestPriorityEnumList = await AyaNova.Api.Controllers.EnumListController.GetEnumList(StringUtil.TrimTypeName(typeof(CustomerServiceRequestPriority).ToString()), UserTranslationId); StringUtil.TrimTypeName(typeof(CustomerServiceRequestStatus).ToString()),
UserTranslationId,
CurrentUserRoles);
var CustomerServiceRequestPriorityEnumList = await AyaNova.Api.Controllers.EnumListController.GetEnumList(
StringUtil.TrimTypeName(typeof(CustomerServiceRequestPriority).ToString()),
UserTranslationId,
CurrentUserRoles);
foreach (CustomerServiceRequest w in orderedList) foreach (CustomerServiceRequest w in orderedList)

View File

@@ -277,7 +277,10 @@ namespace AyaNova.Biz
var orderedList = from id in batch join z in batchResults on id equals z.Id select z; var orderedList = from id in batch join z in batchResults on id equals z.Id select z;
//cache frequent viz data //cache frequent viz data
var AyaTypesEnumList = await AyaNova.Api.Controllers.EnumListController.GetEnumList(StringUtil.TrimTypeName(typeof(AyaType).ToString()), UserTranslationId); var AyaTypesEnumList = await AyaNova.Api.Controllers.EnumListController.GetEnumList(
StringUtil.TrimTypeName(typeof(AyaType).ToString()),
UserTranslationId,
CurrentUserRoles);
using (var command = ct.Database.GetDbConnection().CreateCommand()) using (var command = ct.Database.GetDbConnection().CreateCommand())
{ {
ct.Database.OpenConnection(); ct.Database.OpenConnection();

View File

@@ -887,7 +887,10 @@ namespace AyaNova.Biz
//cache frequent viz data //cache frequent viz data
//usertypes //usertypes
var UserTypesEnumList = await AyaNova.Api.Controllers.EnumListController.GetEnumList(StringUtil.TrimTypeName(typeof(UserType).ToString()), UserTranslationId); var UserTypesEnumList = await AyaNova.Api.Controllers.EnumListController.GetEnumList(
StringUtil.TrimTypeName(typeof(UserType).ToString()),
UserTranslationId,
CurrentUserRoles);
//foreach (User w in orderedList) //foreach (User w in orderedList)
foreach (var w in orderedList) foreach (var w in orderedList)

View File

@@ -368,7 +368,10 @@ namespace AyaNova.Biz
//cache frequent viz data //cache frequent viz data
//usertypes //usertypes
var UserTypesEnumList = await AyaNova.Api.Controllers.EnumListController.GetEnumList(StringUtil.TrimTypeName(typeof(UserType).ToString()), UserTranslationId); var UserTypesEnumList = await AyaNova.Api.Controllers.EnumListController.GetEnumList(
StringUtil.TrimTypeName(typeof(UserType).ToString()),
UserTranslationId,
CurrentUserRoles);
foreach (Widget w in orderedList) foreach (Widget w in orderedList)
{ {

View File

@@ -116,9 +116,11 @@ namespace AyaNova.Biz
var usersNeedingTranslations = events.Where(z => z.NotifySubscription.DeliveryMethod != NotifyDeliveryMethod.App && z.User.Active).Select(z => z.NotifySubscription.UserId).ToList().Distinct(); var usersNeedingTranslations = events.Where(z => z.NotifySubscription.DeliveryMethod != NotifyDeliveryMethod.App && z.User.Active).Select(z => z.NotifySubscription.UserId).ToList().Distinct();
foreach (long userid in usersNeedingTranslations) foreach (long userid in usersNeedingTranslations)
{ {
long transId = (await ct.UserOptions.SingleAsync(z => z.UserId == userid)).TranslationId; var usr = await ct.User.AsNoTracking().Include(z => z.UserOptions).SingleAsync(z => z.Id == userid);
long transId = usr.UserOptions.TranslationId;
_UserTranslationIdCache.Add(userid, transId); _UserTranslationIdCache.Add(userid, transId);
await CacheTranslations(transId); await CacheTranslations(transId, usr.Roles);
} }
//cache all translations of the word "Server" for server notifications //cache all translations of the word "Server" for server notifications
_ServerTheWordTranslations = await TranslationBiz.GetAllTranslationsForKey("Server"); _ServerTheWordTranslations = await TranslationBiz.GetAllTranslationsForKey("Server");
@@ -193,13 +195,21 @@ namespace AyaNova.Biz
} }
//cache any translations required for email notification //cache any translations required for email notification
private static async Task CacheTranslations(long translationId) private static async Task CacheTranslations(long translationId, AuthorizationRoles roles)
{ {
if (!_NotifyEventTypeTransCache.ContainsKey(translationId)) if (!_NotifyEventTypeTransCache.ContainsKey(translationId))
_NotifyEventTypeTransCache.Add(translationId, await AyaNova.Api.Controllers.EnumListController.GetEnumList("NotifyEventType", translationId)); _NotifyEventTypeTransCache.Add(translationId, await AyaNova.Api.Controllers.EnumListController.GetEnumList(
"NotifyEventType",
translationId,
roles));
if (!_AyaTypeTypeTransCache.ContainsKey(translationId)) if (!_AyaTypeTypeTransCache.ContainsKey(translationId))
_AyaTypeTypeTransCache.Add(translationId, await AyaNova.Api.Controllers.EnumListController.GetEnumList("AyaType", translationId)); _AyaTypeTypeTransCache.Add(
translationId,
await AyaNova.Api.Controllers.EnumListController.GetEnumList(
"AyaType",
translationId,
roles));
} }