251 changed files with 6049 additions and 442 deletions
@ -0,0 +1,48 @@ |
|||||
|
using Microsoft.EntityFrameworkCore.Diagnostics; |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Linq.Expressions; |
||||
|
using System.Reflection; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Data; |
||||
|
|
||||
|
namespace LINGYUN.Abp.DataProtection.EntityFrameworkCore; |
||||
|
public class DataProtectionQueryExpressionInterceptor : IQueryExpressionInterceptor |
||||
|
{ |
||||
|
public Expression QueryCompilationStarting(Expression queryExpression, QueryExpressionEventData eventData) |
||||
|
{ |
||||
|
return new DataProtectionExpressionVisitor().Visit(queryExpression); |
||||
|
} |
||||
|
|
||||
|
public class DataProtectionExpressionVisitor : ExpressionVisitor |
||||
|
{ |
||||
|
private readonly static MethodInfo WhereMethodInfo = typeof(Queryable).GetMethod(nameof(Queryable.Where)); |
||||
|
private readonly IDataFilter _dataFilter; |
||||
|
|
||||
|
protected override Expression VisitMethodCall(MethodCallExpression node) |
||||
|
{ |
||||
|
//if (_dataFilter.IsEnabled<IDataProtection>())
|
||||
|
//{
|
||||
|
// var methodInfo = node!.Method;
|
||||
|
// if (methodInfo.DeclaringType == typeof(Queryable)
|
||||
|
// && methodInfo.Name == nameof(Queryable.Select)
|
||||
|
// && methodInfo.GetParameters().Length == 2)
|
||||
|
// {
|
||||
|
// var sourceType = node.Type.GetGenericArguments()[0];
|
||||
|
// var lambdaExpression = (LambdaExpression)((UnaryExpression)node.Arguments[1]).Operand;
|
||||
|
// var entityParameterExpression = lambdaExpression.Parameters[0];
|
||||
|
// var test = Expression.Call(
|
||||
|
// method: WhereMethodInfo.MakeGenericMethod(sourceType, typeof(bool)),
|
||||
|
// arg0: base.VisitMethodCall(node),
|
||||
|
// arg1: Expression.Lambda(typeof(Func<,>).MakeGenericType(entityParameterExpression.Type, typeof(bool)),
|
||||
|
// Expression.Property(entityParameterExpression, nameof(IDataProtection.Owner)),
|
||||
|
// true));
|
||||
|
// return test;
|
||||
|
// }
|
||||
|
//}
|
||||
|
return base.VisitMethodCall(node); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,41 @@ |
|||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
using Microsoft.EntityFrameworkCore.Diagnostics; |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Auditing; |
||||
|
using Volo.Abp.Domain.Entities; |
||||
|
using Volo.Abp.EntityFrameworkCore; |
||||
|
|
||||
|
namespace LINGYUN.Abp.DataProtection.EntityFrameworkCore; |
||||
|
public class DataProtectionSaveChangesInterceptor : SaveChangesInterceptor |
||||
|
{ |
||||
|
private readonly static EntityState[] _protectedStates = |
||||
|
[ |
||||
|
EntityState.Modified, |
||||
|
EntityState.Detached, |
||||
|
]; |
||||
|
public async override ValueTask<InterceptionResult<int>> SavingChangesAsync( |
||||
|
DbContextEventData eventData, |
||||
|
InterceptionResult<int> result, |
||||
|
CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
if (eventData.Context != null && eventData.Context is IAbpEfCoreDbContext) |
||||
|
{ |
||||
|
// 存在资源所属者的实体将被检查访问权限
|
||||
|
var changeEntires = eventData.Context.ChangeTracker.Entries<IMayHaveCreator>() |
||||
|
.Where(e => _protectedStates.Contains(e.State)) |
||||
|
.Where(e => e.Entity.CreatorId.HasValue); |
||||
|
|
||||
|
foreach (var changeEntity in changeEntires) |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
// return InterceptionResult<int>.SuppressWithResult(0);
|
||||
|
return await base.SavingChangesAsync(eventData, result, cancellationToken); |
||||
|
} |
||||
|
} |
||||
File diff suppressed because it is too large
@ -0,0 +1,94 @@ |
|||||
|
using Microsoft.EntityFrameworkCore.Migrations; |
||||
|
|
||||
|
#nullable disable |
||||
|
|
||||
|
namespace LY.MicroService.Applications.Single.EntityFrameworkCore.Migrations |
||||
|
{ |
||||
|
/// <inheritdoc />
|
||||
|
public partial class UpgradeAbpFrameworkTo800 : Migration |
||||
|
{ |
||||
|
/// <inheritdoc />
|
||||
|
protected override void Up(MigrationBuilder migrationBuilder) |
||||
|
{ |
||||
|
migrationBuilder.RenameColumn( |
||||
|
name: "Type", |
||||
|
table: "OpenIddictApplications", |
||||
|
newName: "ClientType"); |
||||
|
|
||||
|
migrationBuilder.AddColumn<string>( |
||||
|
name: "ApplicationType", |
||||
|
table: "OpenIddictApplications", |
||||
|
type: "varchar(50)", |
||||
|
maxLength: 50, |
||||
|
nullable: true) |
||||
|
.Annotation("MySql:CharSet", "utf8mb4"); |
||||
|
|
||||
|
migrationBuilder.AddColumn<string>( |
||||
|
name: "JsonWebKeySet", |
||||
|
table: "OpenIddictApplications", |
||||
|
type: "longtext", |
||||
|
nullable: true) |
||||
|
.Annotation("MySql:CharSet", "utf8mb4"); |
||||
|
|
||||
|
migrationBuilder.AddColumn<string>( |
||||
|
name: "Settings", |
||||
|
table: "OpenIddictApplications", |
||||
|
type: "longtext", |
||||
|
nullable: true) |
||||
|
.Annotation("MySql:CharSet", "utf8mb4"); |
||||
|
|
||||
|
migrationBuilder.AlterColumn<string>( |
||||
|
name: "EntityId", |
||||
|
table: "AbpEntityChanges", |
||||
|
type: "varchar(128)", |
||||
|
maxLength: 128, |
||||
|
nullable: true, |
||||
|
oldClrType: typeof(string), |
||||
|
oldType: "varchar(128)", |
||||
|
oldMaxLength: 128) |
||||
|
.Annotation("MySql:CharSet", "utf8mb4") |
||||
|
.OldAnnotation("MySql:CharSet", "utf8mb4"); |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc />
|
||||
|
protected override void Down(MigrationBuilder migrationBuilder) |
||||
|
{ |
||||
|
migrationBuilder.DropColumn( |
||||
|
name: "ApplicationType", |
||||
|
table: "OpenIddictApplications"); |
||||
|
|
||||
|
migrationBuilder.DropColumn( |
||||
|
name: "JsonWebKeySet", |
||||
|
table: "OpenIddictApplications"); |
||||
|
|
||||
|
migrationBuilder.DropColumn( |
||||
|
name: "Settings", |
||||
|
table: "OpenIddictApplications"); |
||||
|
|
||||
|
migrationBuilder.RenameColumn( |
||||
|
name: "ClientType", |
||||
|
table: "OpenIddictApplications", |
||||
|
newName: "Type"); |
||||
|
|
||||
|
migrationBuilder.UpdateData( |
||||
|
table: "AbpEntityChanges", |
||||
|
keyColumn: "EntityId", |
||||
|
keyValue: null, |
||||
|
column: "EntityId", |
||||
|
value: ""); |
||||
|
|
||||
|
migrationBuilder.AlterColumn<string>( |
||||
|
name: "EntityId", |
||||
|
table: "AbpEntityChanges", |
||||
|
type: "varchar(128)", |
||||
|
maxLength: 128, |
||||
|
nullable: false, |
||||
|
oldClrType: typeof(string), |
||||
|
oldType: "varchar(128)", |
||||
|
oldMaxLength: 128, |
||||
|
oldNullable: true) |
||||
|
.Annotation("MySql:CharSet", "utf8mb4") |
||||
|
.OldAnnotation("MySql:CharSet", "utf8mb4"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue