mirror of https://github.com/abpframework/abp
parent
3638c7e77c
commit
fd016c759c
@ -0,0 +1,2 @@
|
||||
# abp-permissionmanagement
|
||||
Permission management module for ABP framework.
|
@ -0,0 +1,16 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Version>0.3.0</Version>
|
||||
<NoWarn>$(NoWarn);CS1591</NoWarn>
|
||||
<PackageIconUrl>http://www.aspnetboilerplate.com/images/abp_nupkg.png</PackageIconUrl>
|
||||
<PackageProjectUrl>http://abp.io</PackageProjectUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<RepositoryUrl>https://github.com/volosoft/abp/</RepositoryUrl>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="SourceLink.Create.CommandLine" Version="2.8.1" PrivateAssets="All" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="..\..\common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<AssemblyName>Volo.Abp.PermissionManagement.Application.Contracts</AssemblyName>
|
||||
<PackageId>Volo.Abp.PermissionManagement.Application.Contracts</PackageId>
|
||||
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
|
||||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
|
||||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
|
||||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
|
||||
<RootNamespace />
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Volo.Abp.PermissionManagement.Domain.Shared\Volo.Abp.PermissionManagement.Domain.Shared.csproj" />
|
||||
|
||||
<ProjectReference Include="..\..\..\abp\src\Volo.Abp.Authorization\Volo.Abp.Authorization.csproj" />
|
||||
<ProjectReference Include="..\..\..\abp\src\Volo.Abp.Ddd.Application\Volo.Abp.Ddd.Application.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="..\..\common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<AssemblyName>Volo.Abp.PermissionManagement.Application</AssemblyName>
|
||||
<PackageId>Volo.Abp.PermissionManagement.Application</PackageId>
|
||||
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
|
||||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
|
||||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
|
||||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
|
||||
<RootNamespace />
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Volo.Abp.PermissionManagement.Application.Contracts\Volo.Abp.PermissionManagement.Application.Contracts.csproj" />
|
||||
<ProjectReference Include="..\Volo.Abp.PermissionManagement.Domain\Volo.Abp.PermissionManagement.Domain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="..\..\common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<AssemblyName>Volo.Abp.PermissionManagement.Domain.Shared</AssemblyName>
|
||||
<PackageId>Volo.Abp.PermissionManagement.Domain.Shared</PackageId>
|
||||
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
|
||||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
|
||||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
|
||||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
|
||||
<RootNamespace />
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\abp\src\Volo.Abp.Core\Volo.Abp.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,25 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="..\..\common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<AssemblyName>Volo.Abp.PermissionManagement.Domain</AssemblyName>
|
||||
<PackageId>Volo.Abp.PermissionManagement.Domain</PackageId>
|
||||
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
|
||||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
|
||||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
|
||||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
|
||||
<RootNamespace />
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Volo.Abp.PermissionManagement.Domain.Shared\Volo.Abp.PermissionManagement.Domain.Shared.csproj" />
|
||||
|
||||
<ProjectReference Include="..\..\..\abp\src\Volo.Abp.Authorization\Volo.Abp.Authorization.csproj" />
|
||||
<ProjectReference Include="..\..\..\abp\src\Volo.Abp.Caching\Volo.Abp.Caching.csproj" />
|
||||
<ProjectReference Include="..\..\..\abp\src\Volo.Abp.Ddd.Domain\Volo.Abp.Ddd.Domain.csproj" />
|
||||
<ProjectReference Include="..\..\..\abp\src\Volo.Abp.Json\Volo.Abp.Json.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="..\..\common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<AssemblyName>Volo.Abp.PermissionManagement.EntityFrameworkCore</AssemblyName>
|
||||
<PackageId>Volo.Abp.PermissionManagement.EntityFrameworkCore</PackageId>
|
||||
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
|
||||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
|
||||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
|
||||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
|
||||
<RootNamespace />
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Volo.Abp.PermissionManagement.Domain\Volo.Abp.PermissionManagement.Domain.csproj" />
|
||||
|
||||
<ProjectReference Include="..\..\..\abp\src\Volo.Abp.EntityFrameworkCore\Volo.Abp.EntityFrameworkCore.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="..\..\common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<AssemblyName>Volo.Abp.PermissionManagement.MongoDB</AssemblyName>
|
||||
<PackageId>Volo.Abp.PermissionManagement.MongoDB</PackageId>
|
||||
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
|
||||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
|
||||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
|
||||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
|
||||
<RootNamespace />
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Volo.Abp.PermissionManagement.Domain\Volo.Abp.PermissionManagement.Domain.csproj" />
|
||||
|
||||
<ProjectReference Include="..\..\..\abp\src\Volo.Abp.MongoDB\Volo.Abp.MongoDB.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
"culture": "en",
|
||||
"texts": {
|
||||
"Permissions": "Permissions"
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
@page
|
||||
@using Microsoft.AspNetCore.Mvc.Localization
|
||||
@using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Modal
|
||||
@using Volo.Abp.PermissionManagement.Web.Localization.Resources.AbpPermissionManagement
|
||||
@using Volo.Abp.PermissionManagement.Web.Pages.AbpPermissionManagement
|
||||
@model PermissionManagementModal
|
||||
@inject IHtmlLocalizer<AbpPermissionManagementResource> L
|
||||
@{
|
||||
Layout = null;
|
||||
}
|
||||
<form method="post" asp-page="/AbpPermissionManagement/PermissionManagementModal" data-script-class="abp.modals.PermissionManagement">
|
||||
|
||||
<abp-modal size="Large">
|
||||
|
||||
<abp-modal-header title="@(L["Permissions"].Value) - @Model.EntityDisplayName"></abp-modal-header>
|
||||
|
||||
<abp-modal-body>
|
||||
|
||||
<input asp-for="@Model.ProviderKey" />
|
||||
<input asp-for="@Model.ProviderName" />
|
||||
|
||||
<abp-row>
|
||||
<abp-column size-sm="_4">
|
||||
<div class="nav flex-column nav-pills" id="v-pills-tab" role="tablist" aria-orientation="vertical">
|
||||
@for (var i = 0; i < Model.Groups.Count; i++)
|
||||
{
|
||||
<a class="nav-link @(i == 0 ? "active" : "")" id="v-pills-tab-@Model.Groups[i].GetNormalizedGroupName()" data-toggle="pill" href="#v-pills-@Model.Groups[i].GetNormalizedGroupName()" role="tab" aria-controls="v-pills-@Model.Groups[i].GetNormalizedGroupName()" aria-selected="false">@Model.Groups[i].DisplayName</a>
|
||||
}
|
||||
</div>
|
||||
</abp-column>
|
||||
<abp-column size-sm="_8">
|
||||
<div class="tab-content" id="v-pills-tabContent">
|
||||
@for (var i = 0; i < Model.Groups.Count; i++)
|
||||
{
|
||||
<div class="tab-pane fade @(i == 0 ? "show active" : "")" id="v-pills-@Model.Groups[i].GetNormalizedGroupName()" role="tabpanel" aria-labelledby="v-pills-tab-@Model.Groups[i].GetNormalizedGroupName()">
|
||||
@for (var j = 0; j < Model.Groups[i].Permissions.Count; j++)
|
||||
{
|
||||
<abp-input asp-for="@Model.Groups[i].Permissions[j].IsGranted"
|
||||
label="@Model.Groups[i].Permissions[j].GetShownName(Model.ProviderName)"
|
||||
disabled="@Model.Groups[i].Permissions[j].IsDisabled(Model.ProviderName)"
|
||||
data-permission-name="@Model.Groups[i].Permissions[j].Name"
|
||||
data-parent-name="@(Model.Groups[i].Permissions[j].ParentName ?? "")"
|
||||
style="margin-left: @(Model.Groups[i].Permissions[j].Depth * 20)px" />
|
||||
<input asp-for="@Model.Groups[i].Permissions[j].Name" />
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</abp-column>
|
||||
</abp-row>
|
||||
|
||||
</abp-modal-body>
|
||||
|
||||
<abp-modal-footer buttons="@(AbpModalButtons.Cancel|AbpModalButtons.Save)"></abp-modal-footer>
|
||||
|
||||
</abp-modal>
|
||||
|
||||
</form>
|
@ -0,0 +1,139 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Volo.Abp.AspNetCore.Mvc.UI.RazorPages;
|
||||
using Volo.Abp.PermissionManagement.Web.Utils;
|
||||
|
||||
namespace Volo.Abp.PermissionManagement.Web.Pages.AbpPermissionManagement
|
||||
{
|
||||
public class PermissionManagementModal : AbpPageModel
|
||||
{
|
||||
private readonly IPermissionAppServiceGateway _permissionAppServiceGateway;
|
||||
|
||||
[Required]
|
||||
[HiddenInput]
|
||||
[BindProperty(SupportsGet = true)]
|
||||
public string ProviderName { get; set; }
|
||||
|
||||
[Required]
|
||||
[HiddenInput]
|
||||
[BindProperty(SupportsGet = true)]
|
||||
public string ProviderKey { get; set; }
|
||||
|
||||
[BindProperty]
|
||||
public List<PermissionGroupViewModel> Groups { get; set; }
|
||||
|
||||
public string EntityDisplayName { get; set; }
|
||||
|
||||
public PermissionManagementModal(IPermissionAppServiceGateway permissionAppServiceGateway)
|
||||
{
|
||||
_permissionAppServiceGateway = permissionAppServiceGateway;
|
||||
}
|
||||
|
||||
public async Task OnGetAsync()
|
||||
{
|
||||
ValidateModel();
|
||||
|
||||
var result = await _permissionAppServiceGateway.GetAsync(ProviderName, ProviderKey);
|
||||
|
||||
EntityDisplayName = result.EntityDisplayName;
|
||||
|
||||
Groups = ObjectMapper
|
||||
.Map<List<PermissionGroupDto>, List<PermissionGroupViewModel>>(result.Groups)
|
||||
.OrderBy(g => g.DisplayName)
|
||||
.ToList();
|
||||
|
||||
foreach (var group in Groups)
|
||||
{
|
||||
new FlatTreeDepthFinder<PermissionGrantInfoViewModel>().SetDepths(group.Permissions);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostAsync()
|
||||
{
|
||||
ValidateModel();
|
||||
|
||||
var updatePermissionDtos = Groups
|
||||
.SelectMany(g => g.Permissions)
|
||||
.Select(p => new UpdatePermissionDto
|
||||
{
|
||||
Name = p.Name,
|
||||
IsGranted = p.IsGranted
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
await _permissionAppServiceGateway.UpdateAsync(
|
||||
ProviderName,
|
||||
ProviderKey,
|
||||
new UpdatePermissionsDto
|
||||
{
|
||||
Permissions = updatePermissionDtos
|
||||
}
|
||||
);
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
public class PermissionGroupViewModel
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public string DisplayName { get; set; }
|
||||
|
||||
public List<PermissionGrantInfoViewModel> Permissions { get; set; }
|
||||
|
||||
public string GetNormalizedGroupName()
|
||||
{
|
||||
return Name.Replace(".", "_");
|
||||
}
|
||||
}
|
||||
|
||||
public class PermissionGrantInfoViewModel : IFlatTreeItem
|
||||
{
|
||||
[Required]
|
||||
[HiddenInput]
|
||||
public string Name { get; set; }
|
||||
|
||||
public string DisplayName { get; set; }
|
||||
|
||||
public int Depth { get; set; }
|
||||
|
||||
public string ParentName { get; set; }
|
||||
|
||||
public bool IsGranted { get; set; }
|
||||
|
||||
public List<ProviderInfoViewModel> Providers { get; set; }
|
||||
|
||||
public bool IsDisabled(string currentProviderName)
|
||||
{
|
||||
return IsGranted && Providers.All(p => p.ProviderName != currentProviderName);
|
||||
}
|
||||
|
||||
public string GetShownName(string currentProviderName)
|
||||
{
|
||||
if (!IsDisabled(currentProviderName))
|
||||
{
|
||||
return DisplayName;
|
||||
}
|
||||
|
||||
return string.Format(
|
||||
"{0} <span class=\"text-muted\">({1})</span>",
|
||||
DisplayName,
|
||||
Providers
|
||||
.Where(p => p.ProviderName != currentProviderName)
|
||||
.Select(p => p.ProviderName)
|
||||
.JoinAsString(", ")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public class ProviderInfoViewModel
|
||||
{
|
||||
public string ProviderName { get; set; }
|
||||
|
||||
public string ProviderKey { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||
@addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI.Bootstrap
|
@ -0,0 +1,27 @@
|
||||
{
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:55926/",
|
||||
"sslPort": 0
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"Volo.Abp.PermissionManagement.Web": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"applicationUrl": "http://localhost:55927/"
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<Import Project="..\..\common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<AssemblyName>Volo.Abp.PermissionManagement.Web</AssemblyName>
|
||||
<PackageId>Volo.Abp.PermissionManagement.Web</PackageId>
|
||||
<IsPackable>true</IsPackable>
|
||||
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
|
||||
<OutputType>Library</OutputType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="wwwroot\**\*.*" />
|
||||
<EmbeddedResource Include="Pages\**\*.cshtml" />
|
||||
<EmbeddedResource Include="Localization\Resources\**\*.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Volo.Abp.PermissionManagement.Application.Contracts\Volo.Abp.PermissionManagement.Application.Contracts.csproj" />
|
||||
|
||||
<ProjectReference Include="..\..\..\abp\src\Volo.Abp.AspNetCore.Mvc.UI.Bootstrap\Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.csproj" />
|
||||
<ProjectReference Include="..\..\..\abp\src\Volo.Abp.AutoMapper\Volo.Abp.AutoMapper.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
Reference in new issue