|
|
@ -1,4 +1,8 @@ |
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
|
|
using System; |
|
|
|
|
|
using System.ComponentModel; |
|
|
|
|
|
using System.Globalization; |
|
|
|
|
|
using System.Linq.Expressions; |
|
|
using Volo.Abp.Users; |
|
|
using Volo.Abp.Users; |
|
|
|
|
|
|
|
|
namespace LINGYUN.Abp.DataProtection.Keywords; |
|
|
namespace LINGYUN.Abp.DataProtection.Keywords; |
|
|
@ -7,9 +11,22 @@ public class DataAccessCurrentUserContributor : IDataAccessKeywordContributor |
|
|
public const string Name = "@CurrentUser"; |
|
|
public const string Name = "@CurrentUser"; |
|
|
public string Keyword => Name; |
|
|
public string Keyword => Name; |
|
|
|
|
|
|
|
|
public object Contribute(DataAccessKeywordContributorContext context) |
|
|
public Expression Contribute(DataAccessKeywordContributorContext context) |
|
|
{ |
|
|
{ |
|
|
var currentUser = context.ServiceProvider.GetRequiredService<ICurrentUser>(); |
|
|
var currentUser = context.ServiceProvider.GetRequiredService<ICurrentUser>(); |
|
|
return currentUser.Id; |
|
|
|
|
|
|
|
|
var userId = CastTo(currentUser.Id, context.ConversionType); |
|
|
|
|
|
|
|
|
|
|
|
// entity.Where(x => x.CreatorId == CurrentUser.Id);
|
|
|
|
|
|
return Expression.Constant(userId, context.ConversionType); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static object CastTo(object value, Type conversionType) |
|
|
|
|
|
{ |
|
|
|
|
|
if (conversionType == typeof(Guid) || conversionType == typeof(Guid?)) |
|
|
|
|
|
{ |
|
|
|
|
|
return TypeDescriptor.GetConverter(conversionType).ConvertFromInvariantString(value.ToString()!)!; |
|
|
|
|
|
} |
|
|
|
|
|
return Convert.ChangeType(value, conversionType, CultureInfo.InvariantCulture); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|