diff --git a/aspnet-core/LINGYUN.MicroService.sln b/aspnet-core/LINGYUN.MicroService.sln index d8bd1f324..af232f52f 100644 --- a/aspnet-core/LINGYUN.MicroService.sln +++ b/aspnet-core/LINGYUN.MicroService.sln @@ -205,9 +205,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.FileManagement. EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Platform.HttpApi.Host", "services\platform\LINGYUN.Platform.HttpApi.Host\LINGYUN.Platform.HttpApi.Host.csproj", "{372123C3-3AFD-42C8-BB80-778322EA72C3}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.IdentityServer.Domain", "modules\identityServer\LINGYUN.Abp.IdentityServer.Domain\LINGYUN.Abp.IdentityServer.Domain.csproj", "{F359AAA1-C854-444A-88F2-1C0D8A07F864}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.IdentityServer.Domain", "modules\identityServer\LINGYUN.Abp.IdentityServer.Domain\LINGYUN.Abp.IdentityServer.Domain.csproj", "{F359AAA1-C854-444A-88F2-1C0D8A07F864}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.IdentityServer.EntityFrameworkCore", "modules\identityServer\LINGYUN.Abp.IdentityServer.EntityFrameworkCore\LINGYUN.Abp.IdentityServer.EntityFrameworkCore.csproj", "{5D0ED1FC-3A7C-4531-9512-832E73AD9555}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.IdentityServer.EntityFrameworkCore", "modules\identityServer\LINGYUN.Abp.IdentityServer.EntityFrameworkCore\LINGYUN.Abp.IdentityServer.EntityFrameworkCore.csproj", "{5D0ED1FC-3A7C-4531-9512-832E73AD9555}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.Identity.Domain", "modules\identity\LINGYUN.Abp.Identity.Domain\LINGYUN.Abp.Identity.Domain.csproj", "{2BF7FB73-0C62-4ECF-99F0-0583855D2777}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.Identity.EntityFrameworkCore", "modules\identity\LINGYUN.Abp.Identity.EntityFrameworkCore\LINGYUN.Abp.Identity.EntityFrameworkCore.csproj", "{6FE7E243-2D99-4567-8786-6C9283D608EF}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -555,6 +559,14 @@ Global {5D0ED1FC-3A7C-4531-9512-832E73AD9555}.Debug|Any CPU.Build.0 = Debug|Any CPU {5D0ED1FC-3A7C-4531-9512-832E73AD9555}.Release|Any CPU.ActiveCfg = Release|Any CPU {5D0ED1FC-3A7C-4531-9512-832E73AD9555}.Release|Any CPU.Build.0 = Release|Any CPU + {2BF7FB73-0C62-4ECF-99F0-0583855D2777}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2BF7FB73-0C62-4ECF-99F0-0583855D2777}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2BF7FB73-0C62-4ECF-99F0-0583855D2777}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2BF7FB73-0C62-4ECF-99F0-0583855D2777}.Release|Any CPU.Build.0 = Release|Any CPU + {6FE7E243-2D99-4567-8786-6C9283D608EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6FE7E243-2D99-4567-8786-6C9283D608EF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6FE7E243-2D99-4567-8786-6C9283D608EF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6FE7E243-2D99-4567-8786-6C9283D608EF}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -660,6 +672,8 @@ Global {372123C3-3AFD-42C8-BB80-778322EA72C3} = {E5D1B78A-1A8F-4D52-BF99-A4A863ADE898} {F359AAA1-C854-444A-88F2-1C0D8A07F864} = {0439B173-F41E-4CE0-A44A-CCB70328F272} {5D0ED1FC-3A7C-4531-9512-832E73AD9555} = {0439B173-F41E-4CE0-A44A-CCB70328F272} + {2BF7FB73-0C62-4ECF-99F0-0583855D2777} = {52B5D4F7-237B-4E0A-A167-68442164F70A} + {6FE7E243-2D99-4567-8786-6C9283D608EF} = {52B5D4F7-237B-4E0A-A167-68442164F70A} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C95FDF91-16F2-4A8B-A4BE-0E62D1B66718} diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Dto/IdentityRoleAddOrRemoveOrganizationUnitDto.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Dto/IdentityRoleAddOrRemoveOrganizationUnitDto.cs new file mode 100644 index 000000000..195331e60 --- /dev/null +++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Dto/IdentityRoleAddOrRemoveOrganizationUnitDto.cs @@ -0,0 +1,11 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace LINGYUN.Abp.Identity +{ + public class IdentityRoleAddOrRemoveOrganizationUnitDto + { + [Required] + public Guid[] OrganizationUnitIds { get; set; } + } +} diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Dto/IdentityUserOrganizationUnitUpdateDto.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Dto/IdentityUserOrganizationUnitUpdateDto.cs new file mode 100644 index 000000000..f04c8cb36 --- /dev/null +++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Dto/IdentityUserOrganizationUnitUpdateDto.cs @@ -0,0 +1,11 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace LINGYUN.Abp.Identity +{ + public class IdentityUserOrganizationUnitUpdateDto + { + [Required] + public Guid[] OrganizationUnitIds { get; set; } + } +} diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IIdentityRoleAppService.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IIdentityRoleAppService.cs new file mode 100644 index 000000000..d70796824 --- /dev/null +++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IIdentityRoleAppService.cs @@ -0,0 +1,13 @@ +using System; +using System.Threading.Tasks; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Application.Services; + +namespace LINGYUN.Abp.Identity +{ + public interface IIdentityRoleAppService : IApplicationService + { + Task> GetOrganizationUnitsAsync(Guid id); + Task SetOrganizationUnitsAsync(Guid id, IdentityRoleAddOrRemoveOrganizationUnitDto input); + } +} diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IIdentityUserAppService.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IIdentityUserAppService.cs new file mode 100644 index 000000000..b21116f4f --- /dev/null +++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IIdentityUserAppService.cs @@ -0,0 +1,13 @@ +using System; +using System.Threading.Tasks; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Application.Services; + +namespace LINGYUN.Abp.Identity +{ + public interface IIdentityUserAppService : IApplicationService + { + Task> GetOrganizationUnitsAsync(Guid id); + Task UpdateOrganizationUnitsAsync(Guid id, IdentityUserOrganizationUnitUpdateDto input); + } +} diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IOrganizationUnitAppService.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IOrganizationUnitAppService.cs index 9991efcc2..15c9bc56f 100644 --- a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IOrganizationUnitAppService.cs +++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IOrganizationUnitAppService.cs @@ -1,5 +1,4 @@ using System; -using System.ComponentModel.DataAnnotations; using System.Threading.Tasks; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; @@ -27,13 +26,5 @@ namespace LINGYUN.Abp.Identity Task> GetRolesAsync(OrganizationUnitGetRoleByPagedDto input); Task> GetUsersAsync(OrganizationUnitGetUserDto input); - - Task AddRoleAsync(OrganizationUnitDtoAddOrRemoveRoleDto input); - - Task RemoveRoleAsync(OrganizationUnitDtoAddOrRemoveRoleDto input); - - Task AddUserAsync(OrganizationUnitDtoAddOrRemoveUserDto input); - - Task RemoveUserAsync(OrganizationUnitDtoAddOrRemoveUserDto input); } } diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IdentityPermissionDefinitionProvider.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IdentityPermissionDefinitionProvider.cs index 38a6dbb28..3d4787326 100644 --- a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IdentityPermissionDefinitionProvider.cs +++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IdentityPermissionDefinitionProvider.cs @@ -11,6 +11,18 @@ namespace LINGYUN.Abp.Identity var identityGroup = context.GetGroupOrNull(Volo.Abp.Identity.IdentityPermissions.GroupName); if (identityGroup != null) { + var userPermission = identityGroup.GetPermissionOrNull(Volo.Abp.Identity.IdentityPermissions.Users.Default); + if (userPermission != null) + { + userPermission.AddChild(IdentityPermissions.Users.ManageOrganizationUnits, L("Permission:ManageOrganizationUnits")); + } + + var rolePermission = identityGroup.GetPermissionOrNull(Volo.Abp.Identity.IdentityPermissions.Roles.Default); + if (rolePermission != null) + { + rolePermission.AddChild(IdentityPermissions.Roles.ManageOrganizationUnits, L("Permission:ManageOrganizationUnits")); + } + var origanizationUnitPermission = identityGroup.AddPermission(IdentityPermissions.OrganizationUnits.Default, L("Permission:OrganizationUnitManagement")); origanizationUnitPermission.AddChild(IdentityPermissions.OrganizationUnits.Create, L("Permission:Create")); origanizationUnitPermission.AddChild(IdentityPermissions.OrganizationUnits.Update, L("Permission:Edit")); diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IdentityPermissions.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IdentityPermissions.cs index 1200ce27a..3fc7ae408 100644 --- a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IdentityPermissions.cs +++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/IdentityPermissions.cs @@ -4,6 +4,16 @@ namespace LINGYUN.Abp.Identity { public class IdentityPermissions { + public static class Roles + { + public const string ManageOrganizationUnits = Volo.Abp.Identity.IdentityPermissions.Roles.Default + ".ManageOrganizationUnits"; + } + + public static class Users + { + public const string ManageOrganizationUnits = Volo.Abp.Identity.IdentityPermissions.Users.Default + ".ManageOrganizationUnits"; + } + public static class OrganizationUnits { public const string Default = Volo.Abp.Identity.IdentityPermissions.GroupName + ".OrganizationUnits"; diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Localization/en.json b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Localization/en.json index f1c21169c..54f80defc 100644 --- a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Localization/en.json +++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Localization/en.json @@ -3,6 +3,7 @@ "texts": { "Permission:OrganizationUnitManagement": "Organization unit management", "Permission:ChangeRoles": "Change roles", - "Permission:ChangeUsers": "Change users" + "Permission:ChangeUsers": "Change users", + "Permission:ManageOrganizationUnits": "Management organization units" } } \ No newline at end of file diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Localization/zh-Hans.json b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Localization/zh-Hans.json index 69bbbb26b..dba0b9432 100644 --- a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Localization/zh-Hans.json +++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application.Contracts/LINGYUN/Abp/Identity/Localization/zh-Hans.json @@ -3,6 +3,7 @@ "texts": { "Permission:OrganizationUnitManagement": "组织机构管理", "Permission:ChangeRoles": "更改角色", - "Permission:ChangeUsers": "更改用户" + "Permission:ChangeUsers": "更改用户", + "Permission:ManageOrganizationUnits": "管理组织机构" } } \ No newline at end of file diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN.Abp.Identity.Application.csproj b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN.Abp.Identity.Application.csproj index fbb9fc057..4269ad7ba 100644 --- a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN.Abp.Identity.Application.csproj +++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN.Abp.Identity.Application.csproj @@ -11,6 +11,7 @@ + diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/IdentityRoleAppService.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/IdentityRoleAppService.cs new file mode 100644 index 000000000..07460784c --- /dev/null +++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/IdentityRoleAppService.cs @@ -0,0 +1,53 @@ +using Microsoft.AspNetCore.Authorization; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Identity; + +namespace LINGYUN.Abp.Identity +{ + [Authorize(IdentityPermissions.Roles.ManageOrganizationUnits)] + public class IdentityRoleAppService : IdentityAppServiceBase, IIdentityRoleAppService + { + protected IIdentityRoleRepository IdentityRoleRepository { get; } + protected OrganizationUnitManager OrganizationUnitManager { get; } + protected IOrganizationUnitRepository OrganizationUnitRepository { get; } + public IdentityRoleAppService( + IIdentityRoleRepository roleRepository, + OrganizationUnitManager organizationUnitManager) + { + OrganizationUnitManager = organizationUnitManager; + IdentityRoleRepository = roleRepository; + } + + public virtual async Task> GetOrganizationUnitsAsync(Guid id) + { + var origanizationUnits = await IdentityRoleRepository.GetOrganizationUnitsAsync(id); + + return new ListResultDto( + ObjectMapper.Map, List>(origanizationUnits)); + } + + public virtual async Task SetOrganizationUnitsAsync(Guid id, IdentityRoleAddOrRemoveOrganizationUnitDto input) + { + var origanizationUnits = await IdentityRoleRepository.GetOrganizationUnitsAsync(id, true); + + var notInRoleOuIds = input.OrganizationUnitIds.Where(ouid => !origanizationUnits.Any(ou => ou.Id.Equals(ouid))); + + foreach (var ouId in notInRoleOuIds) + { + await OrganizationUnitManager.AddRoleToOrganizationUnitAsync(id, ouId); + } + + var removeRoleOriganzationUnits = origanizationUnits.Where(ou => !input.OrganizationUnitIds.Contains(ou.Id)); + foreach (var origanzationUnit in removeRoleOriganzationUnits) + { + origanzationUnit.RemoveRole(id); + } + + await CurrentUnitOfWork.SaveChangesAsync(); + } + } +} diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/IdentityUserAppService.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/IdentityUserAppService.cs new file mode 100644 index 000000000..090a950fc --- /dev/null +++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/IdentityUserAppService.cs @@ -0,0 +1,39 @@ +using Microsoft.AspNetCore.Authorization; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Identity; + +namespace LINGYUN.Abp.Identity +{ + [Authorize(IdentityPermissions.Users.ManageOrganizationUnits)] + public class IdentityUserAppService : IdentityAppServiceBase, IIdentityUserAppService + { + protected IdentityUserManager UserManager { get; } + public IdentityUserAppService( + IdentityUserManager userManager) + { + UserManager = userManager; + } + + public virtual async Task> GetOrganizationUnitsAsync(Guid id) + { + var user = await UserManager.GetByIdAsync(id); + + var origanizationUnits = await UserManager.GetOrganizationUnitsAsync(user); + + return new ListResultDto( + ObjectMapper.Map, List>(origanizationUnits)); + } + + public virtual async Task UpdateOrganizationUnitsAsync(Guid id, IdentityUserOrganizationUnitUpdateDto input) + { + var user = await UserManager.GetByIdAsync(id); + + await UserManager.SetOrganizationUnitsAsync(user, input.OrganizationUnitIds); + + await CurrentUnitOfWork.SaveChangesAsync(); + } + } +} diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/OrganizationUnitAppService.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/OrganizationUnitAppService.cs index 17bb80e91..f825d0567 100644 --- a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/OrganizationUnitAppService.cs +++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Application/LINGYUN/Abp/Identity/OrganizationUnitAppService.cs @@ -146,53 +146,5 @@ namespace LINGYUN.Abp.Identity return ObjectMapper.Map(origanizationUnit); } - - [Authorize(IdentityPermissions.OrganizationUnits.ManageRoles)] - public virtual async Task AddRoleAsync(OrganizationUnitDtoAddOrRemoveRoleDto input) - { - var origanizationUnit = await OrganizationUnitRepository.GetAsync(input.Id); - if (!origanizationUnit.IsInRole(input.RoleId)) - { - origanizationUnit.AddRole(input.RoleId); - await OrganizationUnitManager.UpdateAsync(origanizationUnit); - await CurrentUnitOfWork.SaveChangesAsync(); - } - } - - [Authorize(IdentityPermissions.OrganizationUnits.ManageRoles)] - public virtual async Task RemoveRoleAsync(OrganizationUnitDtoAddOrRemoveRoleDto input) - { - var origanizationUnit = await OrganizationUnitRepository.GetAsync(input.Id); - if (origanizationUnit.IsInRole(input.RoleId)) - { - origanizationUnit.RemoveRole(input.RoleId); - await OrganizationUnitManager.UpdateAsync(origanizationUnit); - await CurrentUnitOfWork.SaveChangesAsync(); - } - } - - [Authorize(IdentityPermissions.OrganizationUnits.ManageUsers)] - public virtual async Task AddUserAsync(OrganizationUnitDtoAddOrRemoveUserDto input) - { - var identityUser = await UserRepository.GetAsync(input.UserId); - var origanizationUnit = await OrganizationUnitRepository.GetAsync(input.Id); - if (!identityUser.IsInOrganizationUnit(input.Id)) - { - await UserManager.AddToOrganizationUnitAsync(identityUser, origanizationUnit); - await CurrentUnitOfWork.SaveChangesAsync(); - } - } - - [Authorize(IdentityPermissions.OrganizationUnits.ManageUsers)] - public virtual async Task RemoveUserAsync(OrganizationUnitDtoAddOrRemoveUserDto input) - { - var identityUser = await UserRepository.GetAsync(input.UserId); - var origanizationUnit = await OrganizationUnitRepository.GetAsync(input.Id); - if (identityUser.IsInOrganizationUnit(input.Id)) - { - await UserManager.RemoveFromOrganizationUnitAsync(identityUser, origanizationUnit); - await CurrentUnitOfWork.SaveChangesAsync(); - } - } } } diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Domain/LINGYUN.Abp.Identity.Domain.csproj b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Domain/LINGYUN.Abp.Identity.Domain.csproj new file mode 100644 index 000000000..8a6916da6 --- /dev/null +++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Domain/LINGYUN.Abp.Identity.Domain.csproj @@ -0,0 +1,12 @@ + + + + netstandard2.0 + + + + + + + + diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Domain/LINGYUN/Abp/Identity/AbpIdentityDomainModule.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Domain/LINGYUN/Abp/Identity/AbpIdentityDomainModule.cs new file mode 100644 index 000000000..9004ff3f5 --- /dev/null +++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Domain/LINGYUN/Abp/Identity/AbpIdentityDomainModule.cs @@ -0,0 +1,9 @@ +using Volo.Abp.Modularity; + +namespace LINGYUN.Abp.Identity +{ + [DependsOn(typeof(Volo.Abp.Identity.AbpIdentityDomainModule))] + public class AbpIdentityDomainModule : AbpModule + { + } +} diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Domain/LINGYUN/Abp/Identity/IIdentityRoleRepository.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Domain/LINGYUN/Abp/Identity/IIdentityRoleRepository.cs new file mode 100644 index 000000000..38ccc0d18 --- /dev/null +++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Domain/LINGYUN/Abp/Identity/IIdentityRoleRepository.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using Volo.Abp.Identity; + +namespace LINGYUN.Abp.Identity +{ + public interface IIdentityRoleRepository : Volo.Abp.Identity.IIdentityRoleRepository + { + Task> GetOrganizationUnitsAsync( + Guid id, + bool includeDetails = false, + CancellationToken cancellationToken = default); + + Task> GetRolesInOrganizationUnitAsync( + Guid organizationUnitId, + CancellationToken cancellationToken = default + ); + Task> GetRolesInOrganizationsListAsync( + List organizationUnitIds, + CancellationToken cancellationToken = default + ); + + Task> GetRolesInOrganizationUnitWithChildrenAsync( + string code, + CancellationToken cancellationToken = default + ); + } +} diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.EntityFrameworkCore/LINGYUN.Abp.Identity.EntityFrameworkCore.csproj b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.EntityFrameworkCore/LINGYUN.Abp.Identity.EntityFrameworkCore.csproj new file mode 100644 index 000000000..0853f4327 --- /dev/null +++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.EntityFrameworkCore/LINGYUN.Abp.Identity.EntityFrameworkCore.csproj @@ -0,0 +1,16 @@ + + + + netstandard2.0 + + + + + + + + + + + + diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.EntityFrameworkCore/LINGYUN/Abp/Identity/EntityFrameworkCore/AbpIdentityEntityFrameworkCoreModule.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.EntityFrameworkCore/LINGYUN/Abp/Identity/EntityFrameworkCore/AbpIdentityEntityFrameworkCoreModule.cs new file mode 100644 index 000000000..ed033f359 --- /dev/null +++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.EntityFrameworkCore/LINGYUN/Abp/Identity/EntityFrameworkCore/AbpIdentityEntityFrameworkCoreModule.cs @@ -0,0 +1,20 @@ +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Identity; +using Volo.Abp.Identity.EntityFrameworkCore; +using Volo.Abp.Modularity; + +namespace LINGYUN.Abp.Identity.EntityFrameworkCore +{ + [DependsOn(typeof(LINGYUN.Abp.Identity.AbpIdentityDomainModule))] + [DependsOn(typeof(Volo.Abp.Identity.EntityFrameworkCore.AbpIdentityEntityFrameworkCoreModule))] + public class AbpIdentityEntityFrameworkCoreModule : AbpModule + { + public override void ConfigureServices(ServiceConfigurationContext context) + { + context.Services.AddAbpDbContext(options => + { + options.AddRepository(); + }); + } + } +} diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.EntityFrameworkCore/LINGYUN/Abp/Identity/EntityFrameworkCore/EfCoreIdentityRoleRepository.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.EntityFrameworkCore/LINGYUN/Abp/Identity/EntityFrameworkCore/EfCoreIdentityRoleRepository.cs new file mode 100644 index 000000000..245d0fac9 --- /dev/null +++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.EntityFrameworkCore/LINGYUN/Abp/Identity/EntityFrameworkCore/EfCoreIdentityRoleRepository.cs @@ -0,0 +1,70 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Internal; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Dynamic.Core; +using System.Threading; +using System.Threading.Tasks; +using Volo.Abp.EntityFrameworkCore; +using Volo.Abp.Identity; +using Volo.Abp.Identity.EntityFrameworkCore; + +namespace LINGYUN.Abp.Identity.EntityFrameworkCore +{ + public class EfCoreIdentityRoleRepository : Volo.Abp.Identity.EntityFrameworkCore.EfCoreIdentityRoleRepository, IIdentityRoleRepository + { + public EfCoreIdentityRoleRepository( + IDbContextProvider dbContextProvider) + : base(dbContextProvider) + { + } + + public virtual async Task> GetOrganizationUnitsAsync( + Guid id, + bool includeDetails = false, + CancellationToken cancellationToken = default) + { + var query = from roleOU in DbContext.Set() + join ou in DbContext.OrganizationUnits.IncludeDetails(includeDetails) on roleOU.OrganizationUnitId equals ou.Id + where roleOU.RoleId == id + select ou; + + return await query.ToListAsync(GetCancellationToken(cancellationToken)); + } + + public virtual async Task> GetRolesInOrganizationsListAsync( + List organizationUnitIds, + CancellationToken cancellationToken = default) + { + var query = from roleOu in DbContext.Set() + join user in DbSet on roleOu.RoleId equals user.Id + where organizationUnitIds.Contains(roleOu.OrganizationUnitId) + select user; + return await query.ToListAsync(GetCancellationToken(cancellationToken)); + } + + public virtual async Task> GetRolesInOrganizationUnitAsync( + Guid organizationUnitId, + CancellationToken cancellationToken = default) + { + var query = from roleOu in DbContext.Set() + join user in DbSet on roleOu.RoleId equals user.Id + where roleOu.OrganizationUnitId == organizationUnitId + select user; + return await query.ToListAsync(GetCancellationToken(cancellationToken)); + } + + public virtual async Task> GetRolesInOrganizationUnitWithChildrenAsync( + string code, + CancellationToken cancellationToken = default) + { + var query = from roleOU in DbContext.Set() + join user in DbSet on roleOU.RoleId equals user.Id + join ou in DbContext.Set() on roleOU.OrganizationUnitId equals ou.Id + where ou.Code.StartsWith(code) + select user; + return await query.ToListAsync(GetCancellationToken(cancellationToken)); + } + } +} diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.HttpApi/LINGYUN/Abp/Identity/IIdentityRoleController.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.HttpApi/LINGYUN/Abp/Identity/IIdentityRoleController.cs new file mode 100644 index 000000000..38e4a6730 --- /dev/null +++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.HttpApi/LINGYUN/Abp/Identity/IIdentityRoleController.cs @@ -0,0 +1,38 @@ +using Microsoft.AspNetCore.Mvc; +using System; +using System.Threading.Tasks; +using Volo.Abp; +using Volo.Abp.Application.Dtos; +using Volo.Abp.AspNetCore.Mvc; +using Volo.Abp.Identity; + +namespace LINGYUN.Abp.Identity +{ + [RemoteService(true, Name = IdentityRemoteServiceConsts.RemoteServiceName)] + [Area("identity")] + [ControllerName("Role")] + [Route("api/identity/roles")] + public class IIdentityRoleController : AbpController, IIdentityRoleAppService + { + protected IIdentityRoleAppService RoleAppService { get; } + public IIdentityRoleController( + IIdentityRoleAppService roleAppService) + { + RoleAppService = roleAppService; + } + + [HttpGet] + [Route("organization-units/{id}")] + public virtual async Task> GetOrganizationUnitsAsync(Guid id) + { + return await RoleAppService.GetOrganizationUnitsAsync(id); + } + + [HttpPut] + [Route("organization-units/{id}")] + public virtual async Task SetOrganizationUnitsAsync(Guid id, IdentityRoleAddOrRemoveOrganizationUnitDto input) + { + await RoleAppService.SetOrganizationUnitsAsync(id, input); + } + } +} diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.HttpApi/LINGYUN/Abp/Identity/IIdentityUserController.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.HttpApi/LINGYUN/Abp/Identity/IIdentityUserController.cs new file mode 100644 index 000000000..6a904521d --- /dev/null +++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.HttpApi/LINGYUN/Abp/Identity/IIdentityUserController.cs @@ -0,0 +1,38 @@ +using Microsoft.AspNetCore.Mvc; +using System; +using System.Threading.Tasks; +using Volo.Abp; +using Volo.Abp.Application.Dtos; +using Volo.Abp.AspNetCore.Mvc; +using Volo.Abp.Identity; + +namespace LINGYUN.Abp.Identity +{ + [RemoteService(true, Name = IdentityRemoteServiceConsts.RemoteServiceName)] + [Area("identity")] + [ControllerName("User")] + [Route("api/identity/users")] + public class IIdentityUserController : AbpController, IIdentityUserAppService + { + protected IIdentityUserAppService UserAppService { get; } + public IIdentityUserController( + IIdentityUserAppService userAppService) + { + UserAppService = userAppService; + } + + [HttpGet] + [Route("organization-units/{id}")] + public virtual async Task> GetOrganizationUnitsAsync(Guid id) + { + return await UserAppService.GetOrganizationUnitsAsync(id); + } + + [HttpPut] + [Route("organization-units/{id}")] + public virtual async Task UpdateOrganizationUnitsAsync(Guid id, IdentityUserOrganizationUnitUpdateDto input) + { + await UserAppService.UpdateOrganizationUnitsAsync(id, input); + } + } +} diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.HttpApi/LINGYUN/Abp/Identity/OrganizationUnitController.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.HttpApi/LINGYUN/Abp/Identity/OrganizationUnitController.cs index 0a106b8e7..5ebc3f1b7 100644 --- a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.HttpApi/LINGYUN/Abp/Identity/OrganizationUnitController.cs +++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.HttpApi/LINGYUN/Abp/Identity/OrganizationUnitController.cs @@ -1,6 +1,5 @@ using Microsoft.AspNetCore.Mvc; using System; -using System.ComponentModel.DataAnnotations; using System.Threading.Tasks; using Volo.Abp; using Volo.Abp.Application.Dtos; @@ -23,20 +22,6 @@ namespace LINGYUN.Abp.Identity OrganizationUnitAppService = organizationUnitAppService; } - [HttpPost] - [Route("management-roles")] - public virtual async Task AddRoleAsync(OrganizationUnitDtoAddOrRemoveRoleDto input) - { - await OrganizationUnitAppService.AddRoleAsync(input); - } - - [HttpPost] - [Route("management-users")] - public virtual async Task AddUserAsync(OrganizationUnitDtoAddOrRemoveUserDto input) - { - await OrganizationUnitAppService.AddUserAsync(input); - } - [HttpPost] public virtual async Task CreateAsync(OrganizationUnitCreateDto input) { @@ -112,20 +97,6 @@ namespace LINGYUN.Abp.Identity await OrganizationUnitAppService.MoveAsync(id, input); } - [HttpDelete] - [Route("management-roles")] - public virtual async Task RemoveRoleAsync(OrganizationUnitDtoAddOrRemoveRoleDto input) - { - await OrganizationUnitAppService.RemoveRoleAsync(input); - } - - [HttpDelete] - [Route("management-users")] - public virtual async Task RemoveUserAsync(OrganizationUnitDtoAddOrRemoveUserDto input) - { - await OrganizationUnitAppService.RemoveUserAsync(input); - } - [HttpPut] [Route("{id}")] public virtual async Task UpdateAsync(Guid id, OrganizationUnitUpdateDto input) diff --git a/aspnet-core/services/admin/LINGYUN.BackendAdminApp.Host/BackendAdminHostModule.cs b/aspnet-core/services/admin/LINGYUN.BackendAdminApp.Host/BackendAdminHostModule.cs index fbccd7cc5..dcb6e577c 100644 --- a/aspnet-core/services/admin/LINGYUN.BackendAdminApp.Host/BackendAdminHostModule.cs +++ b/aspnet-core/services/admin/LINGYUN.BackendAdminApp.Host/BackendAdminHostModule.cs @@ -77,7 +77,7 @@ namespace LINGYUN.BackendAdmin typeof(AbpTenantManagementApplicationModule), typeof(AbpTenantManagementHttpApiModule), typeof(AbpEntityFrameworkCoreMySQLModule), - typeof(AbpIdentityEntityFrameworkCoreModule), + typeof(LINGYUN.Abp.Identity.EntityFrameworkCore.AbpIdentityEntityFrameworkCoreModule), typeof(AbpIdentityServerEntityFrameworkCoreModule), typeof(AbpTenantManagementEntityFrameworkCoreModule), typeof(AbpSettingManagementEntityFrameworkCoreModule), diff --git a/aspnet-core/services/admin/LINGYUN.BackendAdminApp.Host/LINGYUN.BackendAdminApp.Host.csproj b/aspnet-core/services/admin/LINGYUN.BackendAdminApp.Host/LINGYUN.BackendAdminApp.Host.csproj index cc8830e45..b68c8b473 100644 --- a/aspnet-core/services/admin/LINGYUN.BackendAdminApp.Host/LINGYUN.BackendAdminApp.Host.csproj +++ b/aspnet-core/services/admin/LINGYUN.BackendAdminApp.Host/LINGYUN.BackendAdminApp.Host.csproj @@ -64,6 +64,7 @@ + diff --git a/vueJs/src/api/organizationunit.ts b/vueJs/src/api/organizationunit.ts index 231af13ac..b48a0adb7 100644 --- a/vueJs/src/api/organizationunit.ts +++ b/vueJs/src/api/organizationunit.ts @@ -24,7 +24,7 @@ export default class OrganizationUnitService { */ public static getRootOrganizationUnits() { const _url = '/api/identity/organization-units/root-node' - return ApiService.Get>(_url, serviceUrl) + return ApiService.Get>(_url, serviceUrl) } /** diff --git a/vueJs/src/api/roles.ts b/vueJs/src/api/roles.ts index cc2334a31..6b6468910 100644 --- a/vueJs/src/api/roles.ts +++ b/vueJs/src/api/roles.ts @@ -1,5 +1,6 @@ import { pagerFormat } from '@/utils/index' import ApiService from './serviceBase' +import { OrganizationUnit } from './organizationunit' import { ListResultDto, PagedAndSortedResultRequestDto, PagedResultDto } from './types' const IdentityServiceUrl = process.env.VUE_APP_BASE_API @@ -25,6 +26,16 @@ export default class RoleService { return ApiService.Get(_url, IdentityServiceUrl) } + public static getRoleOrganizationUnits(roleId: string) { + const _url = '/api/identity/roles/organization-units/' + roleId + return ApiService.Get>(_url, IdentityServiceUrl); + } + + public static changeRoleOrganizationUnits(roleId: string, payload: ChangeRoleOrganizationUnitDto) { + const _url = '/api/identity/roles/organization-units/' + roleId + return ApiService.Put(_url, payload, IdentityServiceUrl); + } + public static createRole(input: CreateRoleDto) { return ApiService.Post('/api/identity/roles', input, IdentityServiceUrl) } @@ -75,3 +86,7 @@ export class UpdateRoleDto extends RoleBaseDto { this.isPublic = true } } + +export class ChangeRoleOrganizationUnitDto { + organizationUnitIds = new Array() +} diff --git a/vueJs/src/api/users.ts b/vueJs/src/api/users.ts index a9470ef63..f3466b8a6 100644 --- a/vueJs/src/api/users.ts +++ b/vueJs/src/api/users.ts @@ -1,7 +1,9 @@ import qs from 'querystring' import { pagerFormat } from '@/utils/index' import { PagedAndSortedResultRequestDto, FullAuditedEntityDto, PagedResultDto } from '@/api/types' +import { OrganizationUnit } from './organizationunit' import ApiService from './serviceBase' +import { ListResultDto } from './types' const IdentityServiceUrl = process.env.VUE_APP_BASE_API const IdentityServerUrl = process.env.VUE_APP_BASE_IDENTITY_SERVER @@ -58,6 +60,16 @@ export default class UserApiService { return ApiService.Get(_url, IdentityServiceUrl) } + public static getUserOrganizationUnits(userId: string) { + const _url = '/api/identity/users/organization-units/' + userId + return ApiService.Get>(_url, IdentityServiceUrl); + } + + public static changeUserOrganizationUnits(roleId: string, payload: ChangeUserOrganizationUnitDto) { + const _url = '/api/identity/users/organization-units/' + roleId + return ApiService.Put(_url, payload, IdentityServiceUrl); + } + public static setUserRoles(userId: string, roles: string[]) { let _url = '/api/identity/users' _url += '/' + userId @@ -440,3 +452,7 @@ export interface IUserRole { /** 并发令牌 */ concurrencyStamp: string | undefined } + +export class ChangeUserOrganizationUnitDto { + organizationUnitIds = new Array() +} diff --git a/vueJs/src/components/OrganizationUnitTree/index.vue b/vueJs/src/components/OrganizationUnitTree/index.vue new file mode 100644 index 000000000..e835f9739 --- /dev/null +++ b/vueJs/src/components/OrganizationUnitTree/index.vue @@ -0,0 +1,108 @@ + + + + + diff --git a/vueJs/src/lang/zh.ts b/vueJs/src/lang/zh.ts index 2c5e712fb..ae59d3473 100644 --- a/vueJs/src/lang/zh.ts +++ b/vueJs/src/lang/zh.ts @@ -250,6 +250,7 @@ export default { roleList: '角色列表', hasRoles: '已有角色', permission: '分配权限', + organizationUnits: '组织机构', password: '用户密码', confirmPassword: '确认用户密码', pleaseInputName: '请输入用户名称', @@ -261,6 +262,7 @@ export default { pleaseConfirmPassword: '请再次输入用户密码' }, roles: { + basic: '基本信息', refreshList: '刷新列表', id: '角色标识', name: '角色名称', @@ -284,7 +286,9 @@ export default { roleHasBeenSetDefault: '{name} 已设置为默认角色!', createRoleSuccess: '角色 {name} 添加成功!', pleaseInputRoleName: '请输入角色名称', - roleNameIsRequired: '角色名称不能为空!' + roleNameIsRequired: '角色名称不能为空!', + organizationUnits: '组织机构', + updateRoleSuccess: '角色 {name} 修改成功!' }, operaActions: '操作方法', queryFilter: '查询过滤', diff --git a/vueJs/src/views/admin/apigateway/global.vue b/vueJs/src/views/admin/apigateway/global.vue index 981449eff..d863c9860 100644 --- a/vueJs/src/views/admin/apigateway/global.vue +++ b/vueJs/src/views/admin/apigateway/global.vue @@ -115,7 +115,6 @@ :label="$t('operaActions')" align="center" width="250px" - fixed="right" >