This commit is contained in:
@@ -355,12 +355,11 @@ namespace AyaNova
|
||||
var ct = context.RequestServices.GetService<AyContext>();
|
||||
|
||||
//get the user record
|
||||
var u = ct.User.AsNoTracking().Where(a => a.Id == userId).Select(m => new { roles = m.Roles, name = m.Name, id = m.Id, localeId = m.LocaleId, tzOffset = m.UserOptions.TimeZoneOffset }).First();
|
||||
var u = ct.User.AsNoTracking().Where(a => a.Id == userId).Select(m => new { roles = m.Roles, name = m.Name, id = m.Id, localeId = m.LocaleId }).First();
|
||||
context.Request.HttpContext.Items["AY_ROLES"] = u.roles;
|
||||
context.Request.HttpContext.Items["AY_USERNAME"] = u.name;
|
||||
context.Request.HttpContext.Items["AY_USER_ID"] = u.id;
|
||||
context.Request.HttpContext.Items["AY_LOCALE_ID"] = u.localeId;
|
||||
context.Request.HttpContext.Items["AY_USER_TZ_OFFSET"] = u.tzOffset;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace AyaNova.Biz
|
||||
internal AyaType BizType { get; set; }
|
||||
internal AyaNova.Models.AyContext ct { get; set; }
|
||||
internal long UserId { get; set; }
|
||||
internal long UserLocaleId { get; set; }
|
||||
internal long UserLocaleId { get; set; }
|
||||
internal AuthorizationRoles CurrentUserRoles { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -3,13 +3,15 @@ using System;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace AyaNova.Biz
|
||||
{
|
||||
public static class FilterSqlCriteriaBuilder
|
||||
{
|
||||
//"SELECT *, xmin FROM AWIDGET name Like 'BoolDataFilterTest%' AND active = true AND "
|
||||
public static string DataFilterToSQLCriteria(AyaNova.Models.DataFilter dataFilter, FilterOptions filterOptions, decimal timeZoneOffset)
|
||||
public static string DataFilterToSQLCriteria(AyaNova.Models.DataFilter dataFilter, FilterOptions filterOptions, long userId)
|
||||
{
|
||||
|
||||
if (string.IsNullOrWhiteSpace(dataFilter.Filter))
|
||||
@@ -38,7 +40,7 @@ namespace AyaNova.Biz
|
||||
|
||||
var dataType = filterOptions.Flds.Find(x => x.Fld == fld).Type;
|
||||
|
||||
sb.Append(DataFilterToColumnCriteria(fld, dataType, opType, val, tagList, timeZoneOffset));
|
||||
sb.Append(DataFilterToColumnCriteria(fld, dataType, opType, val, tagList, userId));
|
||||
if (i < FilterArray.Count - 1)
|
||||
{
|
||||
sb.Append(" AND ");
|
||||
@@ -51,7 +53,7 @@ namespace AyaNova.Biz
|
||||
/// <summary>
|
||||
/// Translate DataFilter to Postgres friendly SQL criteria
|
||||
/// </summary>
|
||||
private static string DataFilterToColumnCriteria(string sColumn, string sDataType, string sOperator, string sValue, List<string> sTags, decimal timeZoneOffset)//, bool IsCompound)
|
||||
private static string DataFilterToColumnCriteria(string sColumn, string sDataType, string sOperator, string sValue, List<string> sTags, long userId)//, bool IsCompound)
|
||||
{
|
||||
bool TagFilter = sTags.Count < 0;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
@@ -274,11 +276,20 @@ namespace AyaNova.Biz
|
||||
//suitable for the database to handle as all database dates are in UTC
|
||||
//Local display and parsing will be considered a CLIENT issue at all times
|
||||
|
||||
//HOWEVER, if it's a relative date filter TOKEN like "nextMonth" then the users time zone offset will be taken into consideration
|
||||
|
||||
//So this is the core date time to work off of
|
||||
DateTime RelativeNow=DateTime.Now;
|
||||
|
||||
|
||||
if (sValue.StartsWith("{[") && sValue.EndsWith("]}"))
|
||||
{
|
||||
//Need to adjust RelativeNow to users time frame
|
||||
//Fetch useroptions object and relative time offset
|
||||
AyaNova.Models.AyContext ct = AyaNova.Util.ServiceProviderProvider.DBContext;
|
||||
var u = ct.User.AsNoTracking().Where(a => a.Id == userId).Select(m => new { roles = m.Roles, name = m.Name, id = m.Id, localeId = m.LocaleId }).First();
|
||||
|
||||
|
||||
#region Build criteria for date RANGE TOKEN specified
|
||||
//Used as the basis point
|
||||
System.DateTime dtAfter;
|
||||
|
||||
@@ -186,7 +186,7 @@ namespace AyaNova.Biz
|
||||
var TheFilter = await ct.DataFilter.FirstOrDefaultAsync(x => x.Id == pagingOptions.DataFilterId);
|
||||
|
||||
//BUILD WHERE AND APPEND IT
|
||||
q = q + FilterSqlCriteriaBuilder.DataFilterToSQLCriteria(TheFilter, WidgetBiz.FilterOptions());
|
||||
q = q + FilterSqlCriteriaBuilder.DataFilterToSQLCriteria(TheFilter, WidgetBiz.FilterOptions(), UserId);
|
||||
|
||||
//TESTING:
|
||||
//LOG THE CRIT AND QUERY
|
||||
|
||||
Reference in New Issue
Block a user