Browse Source

Remove License define; Adapt PermissionChecker

HOME 2 years ago
parent
commit
f6b571b4ac

+ 5 - 5
VCommonCoreExample/AppServices/Session/SessionService.cs

@@ -3,11 +3,11 @@ using System;
 using System.Linq;
 using VCommon.Security;
 using VCommon.VApplication.Authorization;
-using VCommon.VApplication.Linq.Expressions.Dynamic;
 using VCommon.VApplication.Security;
 using VCommon.VOpenApi.VAspNetCore;
 using VCommonCoreExample.AppServices.Basic;
 using VCommonCoreExample.AppServices.Session.Dto;
+using VCommonCoreExample.Authorization;
 using VCommonCoreExample.Caching;
 using VCommonCoreExample.Caching.Models;
 using VCommonCoreExample.DataStore;
@@ -30,13 +30,13 @@ namespace VCommonCoreExample.AppServices.Session
     {
         private readonly UserStore _userStore;
         private readonly SessionCache _sessionCache;
-        private readonly IPermissionManager _permissionManager;
+        private readonly PermissionProvider _permissionProvider;
 
-        public SessionService(UserStore userStore, SessionCache sessionCache, IPermissionManager permissionManager)
+        public SessionService(UserStore userStore, SessionCache sessionCache, PermissionProvider permissionProvider)
         {
             _userStore = userStore;
             _sessionCache = sessionCache;
-            _permissionManager = permissionManager;
+            _permissionProvider = permissionProvider;
         }
 
         public string Login(SessionLoginInput input)
@@ -104,7 +104,7 @@ namespace VCommonCoreExample.AppServices.Session
                 TenantId = tid,
                 UserId = uid,
                 UserName = usr.Name,
-                Permissions = _permissionManager.GetUserPermissionCodes(VSession.TenantId, VSession.GetUserId()),
+                Permissions = _permissionProvider.GetUserPermissionCodes(VSession.TenantId, VSession.GetUserId()),
                 //Setting = new Dictionary<string, object>(), //TODO: UserProfileService Setting
             };
         }

+ 6 - 6
VCommonCoreExample/AppServices/System/Roles/RoleService.cs

@@ -39,12 +39,12 @@ namespace VCommonCoreExample.AppServices.System.Roles
 
     public class RoleService : DbTableAppServiceBase<Role>, IRoleService
     {
-        private readonly IPermissionManager _permissionManager;
+        private readonly PermissionProvider _permissionProvider;
         private readonly AuthCache _authCache;
 
-        public RoleService(IPermissionManager permissionManager, AuthCache authCache)
+        public RoleService(PermissionProvider permissionProvider, AuthCache authCache)
         {
-            _permissionManager = permissionManager;
+            _permissionProvider = permissionProvider;
             _authCache = authCache;
         }
 
@@ -65,7 +65,7 @@ namespace VCommonCoreExample.AppServices.System.Roles
 
         public RoleFormPrepOutput FormPrep(Guid? input)
         {
-            var tree = _permissionManager.GetPermissionTreeOutput(VSession.Side);
+            var tree = _permissionProvider.GetPermissionTreeOutput(VSession.Side);
 
             var treeOutput = TreeCopy.CreateFrom<PermissionNodeOutput, ElTreeNode, string, string>(tree,
                 (k, v, c) => new ElTreeNode { Key = k, Label = v, Children = c.ToArray() },
@@ -86,7 +86,7 @@ namespace VCommonCoreExample.AppServices.System.Roles
         {
             foreach (var s in input.PermissionSet)
             {
-                if (false == _permissionManager.ValidPermission(s)) throw new VFriendlyException($"无效的权限代码:{s}");
+                if (false == _permissionProvider.ValidPermission(s)) throw new VFriendlyException($"无效的权限代码:{s}");
             }
 
             var repo = GetRepository();
@@ -103,7 +103,7 @@ namespace VCommonCoreExample.AppServices.System.Roles
         {
             foreach (var s in input.PermissionSet)
             {
-                if (false == _permissionManager.ValidPermission(s)) throw new VFriendlyException($"无效的权限代码:{s}");
+                if (false == _permissionProvider.ValidPermission(s)) throw new VFriendlyException($"无效的权限代码:{s}");
             }
 
             var repo = GetRepository();

+ 20 - 0
VCommonCoreExample/Authorization/PermissionChecker.cs

@@ -0,0 +1,20 @@
+using System;
+using VCommon.Ioc;
+using VCommon.VApplication.Authorization;
+
+namespace VCommonCoreExample.Authorization
+{
+    public class PermissionChecker : ISingletonIocClass, IPermissionChecker
+    {
+        private readonly PermissionProvider _provider;
+
+        public PermissionChecker(PermissionProvider provider)
+        {
+            _provider = provider;
+        }
+        public bool CheckPermission(Guid? tenantId, Guid userId, params string[] hasAnyPermission)
+        {
+            return _provider.CheckPermission(tenantId, userId, hasAnyPermission);
+        }
+    }
+}

+ 1 - 9
VCommonCoreExample/Authorization/PermissionCodes.cs

@@ -16,15 +16,7 @@
                 public const string Delete = EntryTenant + "." + nameof(Delete);
             }
 
-            //public static class License
-            //{
-            //    public const string EntryLicense = EntryPlatform + "." + nameof(License);
-
-            //    public const string Query = EntryLicense + "." + nameof(Query);
-            //    public const string Create = EntryLicense + "." + nameof(Create);
-            //    public const string Update = EntryLicense + "." + nameof(Update);
-            //    public const string Delete = EntryLicense + "." + nameof(Delete);
-            //}
+      
         }
 
         public static class System

+ 2 - 2
VCommonCoreExample/Authorization/PermissionManager.cs

@@ -8,14 +8,14 @@ using VCommonCoreExample.Configuration;
 
 namespace VCommonCoreExample.Authorization
 {
-    public class PermissionManager : ISingletonIocClass, IPermissionManager
+    public class PermissionProvider : ISingletonIocClass
     {
         private readonly AuthCache _authCache;
 
         private readonly PermissionTree _tree;
         private readonly HashSet<string> _allPermissionCodes;
 
-        public PermissionManager(AuthCache authCache)
+        public PermissionProvider(AuthCache authCache)
         {
             _authCache = authCache;
             _tree = new PermissionTree();

+ 0 - 23
VCommonCoreExample/Entity/License.cs

@@ -1,23 +0,0 @@
-using System;
-using VCommon.VApplication.Dto;
-using VCommon.VEntity;
-
-namespace VCommonCoreExample.Entity
-{
-    public class License : VEntityBase, IHaveName, ISoftDelete, IFullAuditEntity
-    {
-        public string Name { get; set; }
-
-        /// <summary>
-        /// 权限集合 JSON Array
-        /// </summary>
-        public string PermissionSet { get; set; }
-
-        public bool IsAbolish { get; set; }
-
-        public DateTime CreationTime { get; set; }
-        public Guid CreationUserId { get; set; }
-        public DateTime? LastModificationTime { get; set; }
-        public Guid? LastModificationUserId { get; set; }
-    }
-}

+ 0 - 2
VCommonCoreExample/EntityFrameworkCore/ExampleDbContext.cs

@@ -8,8 +8,6 @@ namespace VCommonCoreExample.EntityFrameworkCore
 {
     public class ExampleDbContext : VAppDbContextBase
     {
-        public DbSet<License> Licenses { get; set; }
-
         public DbSet<Organization> Organizations { get; set; }
 
         public DbSet<Role> Roles { get; set; }

+ 1 - 32
VCommonCoreExample/Migrations/20210724080721_CreateDatabase.Designer.cs

@@ -9,7 +9,7 @@ using VCommonCoreExample.EntityFrameworkCore;
 namespace VCommonCoreExample.Migrations
 {
     [DbContext(typeof(ExampleDbContext))]
-    [Migration("20210724080721_CreateDatabase")]
+    [Migration("20210805095921_CreateDatabase")]
     partial class CreateDatabase
     {
         protected override void BuildTargetModel(ModelBuilder modelBuilder)
@@ -19,37 +19,6 @@ namespace VCommonCoreExample.Migrations
                 .HasAnnotation("Relational:MaxIdentifierLength", 64)
                 .HasAnnotation("ProductVersion", "5.0.7");
 
-            modelBuilder.Entity("VCommonCoreExample.Entity.License", b =>
-                {
-                    b.Property<Guid>("Id")
-                        .HasColumnType("char(36)");
-
-                    b.Property<DateTime>("CreationTime")
-                        .HasColumnType("datetime(6)");
-
-                    b.Property<Guid>("CreationUserId")
-                        .HasColumnType("char(36)");
-
-                    b.Property<bool>("IsAbolish")
-                        .HasColumnType("tinyint(1)");
-
-                    b.Property<DateTime?>("LastModificationTime")
-                        .HasColumnType("datetime(6)");
-
-                    b.Property<Guid?>("LastModificationUserId")
-                        .HasColumnType("char(36)");
-
-                    b.Property<string>("Name")
-                        .HasColumnType("longtext");
-
-                    b.Property<string>("PermissionSet")
-                        .HasColumnType("longtext");
-
-                    b.HasKey("Id");
-
-                    b.ToTable("Licenses");
-                });
-
             modelBuilder.Entity("VCommonCoreExample.Entity.Organization", b =>
                 {
                     b.Property<Guid>("Id")

+ 0 - 24
VCommonCoreExample/Migrations/20210724080721_CreateDatabase.cs

@@ -11,27 +11,6 @@ namespace VCommonCoreExample.Migrations
                 .Annotation("MySql:CharSet", "utf8mb4");
 
             migrationBuilder.CreateTable(
-                name: "Licenses",
-                columns: table => new
-                {
-                    Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
-                    Name = table.Column<string>(type: "longtext", nullable: true)
-                        .Annotation("MySql:CharSet", "utf8mb4"),
-                    PermissionSet = table.Column<string>(type: "longtext", nullable: true)
-                        .Annotation("MySql:CharSet", "utf8mb4"),
-                    IsAbolish = table.Column<bool>(type: "tinyint(1)", nullable: false),
-                    CreationTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
-                    CreationUserId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
-                    LastModificationTime = table.Column<DateTime>(type: "datetime(6)", nullable: true),
-                    LastModificationUserId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci")
-                },
-                constraints: table =>
-                {
-                    table.PrimaryKey("PK_Licenses", x => x.Id);
-                })
-                .Annotation("MySql:CharSet", "utf8mb4");
-
-            migrationBuilder.CreateTable(
                 name: "Organizations",
                 columns: table => new
                 {
@@ -179,9 +158,6 @@ namespace VCommonCoreExample.Migrations
         protected override void Down(MigrationBuilder migrationBuilder)
         {
             migrationBuilder.DropTable(
-                name: "Licenses");
-
-            migrationBuilder.DropTable(
                 name: "Organizations");
 
             migrationBuilder.DropTable(

+ 0 - 31
VCommonCoreExample/Migrations/ExampleDbContextModelSnapshot.cs

@@ -17,37 +17,6 @@ namespace VCommonCoreExample.Migrations
                 .HasAnnotation("Relational:MaxIdentifierLength", 64)
                 .HasAnnotation("ProductVersion", "5.0.7");
 
-            modelBuilder.Entity("VCommonCoreExample.Entity.License", b =>
-                {
-                    b.Property<Guid>("Id")
-                        .HasColumnType("char(36)");
-
-                    b.Property<DateTime>("CreationTime")
-                        .HasColumnType("datetime(6)");
-
-                    b.Property<Guid>("CreationUserId")
-                        .HasColumnType("char(36)");
-
-                    b.Property<bool>("IsAbolish")
-                        .HasColumnType("tinyint(1)");
-
-                    b.Property<DateTime?>("LastModificationTime")
-                        .HasColumnType("datetime(6)");
-
-                    b.Property<Guid?>("LastModificationUserId")
-                        .HasColumnType("char(36)");
-
-                    b.Property<string>("Name")
-                        .HasColumnType("longtext");
-
-                    b.Property<string>("PermissionSet")
-                        .HasColumnType("longtext");
-
-                    b.HasKey("Id");
-
-                    b.ToTable("Licenses");
-                });
-
             modelBuilder.Entity("VCommonCoreExample.Entity.Organization", b =>
                 {
                     b.Property<Guid>("Id")