This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
@@ -52,12 +53,8 @@ namespace AyaNova.Api.Controllers
|
||||
public async Task<IActionResult> GetList([FromRoute] string enumkey)
|
||||
{
|
||||
if (serverState.IsClosed)
|
||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
|
||||
long TranslationId = UserTranslationIdFromContext.Id(HttpContext.Items);
|
||||
|
||||
var ret = await GetEnumList(enumkey, TranslationId);
|
||||
|
||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
var ret = await GetEnumList(enumkey, UserTranslationIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
|
||||
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>();
|
||||
@@ -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
|
||||
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())
|
||||
{
|
||||
//this is intended primarily for developers, not for UI facing so no need to localize or pretty it up
|
||||
@@ -459,9 +535,9 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["ContractOverrideTypePriceDiscount"], Id = (long)ContractOverrideType.PriceDiscount });
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["ContractOverrideTypeMarkup"], Id = (long)ContractOverrideType.CostMarkup });
|
||||
//this is not a valid setting, not sure why it's there
|
||||
// ReturnList.Add(new NameIdItem() { Name = "-", Id = (long)ContractOverrideType.NotSet });
|
||||
|
||||
//this is not a valid setting, not sure why it's there
|
||||
// ReturnList.Add(new NameIdItem() { Name = "-", Id = (long)ContractOverrideType.NotSet });
|
||||
|
||||
}
|
||||
//#################################################################################################################
|
||||
//################### NEW HERE DO NOT FORGET TO ADD TO LISTS AVAILABLE ABOVE AS WELL ##############################
|
||||
|
||||
Reference in New Issue
Block a user