mirror of https://github.com/abpframework/abp.git
795 changed files with 62149 additions and 11234 deletions
@ -0,0 +1,3 @@ |
|||
# abp.auth JavaScript API |
|||
|
|||
TODO |
|||
@ -0,0 +1,24 @@ |
|||
# JavaScript API |
|||
|
|||
ABP provides some JavaScript APIs for ASP.NET Core MVC / Razor Pages applications. They can be used to perform some common application requirements in the client side. |
|||
|
|||
## APIs |
|||
|
|||
* abp.ajax |
|||
* [abp.auth](Auth.md) |
|||
* abp.currentUser |
|||
* abp.dom |
|||
* abp.event |
|||
* abp.features |
|||
* abp.localization |
|||
* abp.log |
|||
* abp.ModalManager |
|||
* abp.notify |
|||
* abp.security |
|||
* abp.setting |
|||
* abp.ui |
|||
* abp.utils |
|||
* abp.ResourceLoader |
|||
* abp.WidgetManager |
|||
* Other APIs |
|||
|
|||
@ -1,3 +1,369 @@ |
|||
## Authorization |
|||
# Authorization |
|||
|
|||
TODO |
|||
Authorization is used to check if a user is allowed to perform some specific operations in the application. |
|||
|
|||
ABP extends [ASP.NET Core Authorization](https://docs.microsoft.com/en-us/aspnet/core/security/authorization/introduction) by adding **permissions** as auto [policies](https://docs.microsoft.com/en-us/aspnet/core/security/authorization/policies) and allowing authorization system to be usable in the **[application services](Application-Services.md)** too. |
|||
|
|||
So, all the ASP.NET Core authorization features and the documentation are valid in an ABP based application. This document focuses on the features that added on top of ASP.NET Core authorization features. |
|||
|
|||
## Authorize Attribute |
|||
|
|||
ASP.NET Core defines the [**Authorize**](https://docs.microsoft.com/en-us/aspnet/core/security/authorization/simple) attribute that can be used for an action, a controller or a page. ABP allows you to use the same attribute for an [application service](Application-Services.md) too. |
|||
|
|||
Example: |
|||
|
|||
````csharp |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using Volo.Abp.Application.Services; |
|||
|
|||
namespace Acme.BookStore |
|||
{ |
|||
[Authorize] |
|||
public class AuthorAppService : ApplicationService, IAuthorAppService |
|||
{ |
|||
public Task<List<AuthorDto>> GetListAsync() |
|||
{ |
|||
... |
|||
} |
|||
|
|||
[AllowAnonymous] |
|||
public Task<AuthorDto> GetAsync(Guid id) |
|||
{ |
|||
... |
|||
} |
|||
|
|||
[Authorize("BookStore_Author_Create")] |
|||
public Task CreateAsync(CreateAuthorDto input) |
|||
{ |
|||
... |
|||
} |
|||
} |
|||
} |
|||
|
|||
```` |
|||
|
|||
* `Authorize` attribute forces the user to login into the application in order to use the `AuthorAppService` methods. So, `GetListAsync` method is only available to the authenticated users. |
|||
* `AllowAnonymous` suppresses the authentication. So, `GetAsync` method is available to everyone including unauthorized users. |
|||
* `[Authorize("BookStore_Author_Create")]` defines a policy (see [policy based authorization](https://docs.microsoft.com/en-us/aspnet/core/security/authorization/policies)) that is checked to authorize the current user. |
|||
|
|||
"BookStore_Author_Create" is an arbitrary policy name. If you declare an attribute like that, ASP.NET Core authorization system expects a policy to be defined before. |
|||
|
|||
You can, of course, implement your policies as stated in the ASP.NET Core documentation. But for simple true/false conditions like a policy was granted to a user or not, ABP defines the permission system which will be explained in the next section. |
|||
|
|||
## Permission System |
|||
|
|||
A permission is a simple policy that is granted or prohibited for a particular user, role or client. |
|||
|
|||
### Defining Permissions |
|||
|
|||
To define permissions, create a class inheriting from the `PermissionDefinitionProvider` as shown below: |
|||
|
|||
````csharp |
|||
using Volo.Abp.Authorization.Permissions; |
|||
|
|||
namespace Acme.BookStore.Permissions |
|||
{ |
|||
public class BookStorePermissionDefinitionProvider : PermissionDefinitionProvider |
|||
{ |
|||
public override void Define(IPermissionDefinitionContext context) |
|||
{ |
|||
var myGroup = context.AddGroup("BookStore"); |
|||
|
|||
myGroup.AddPermission("BookStore_Author_Create"); |
|||
} |
|||
} |
|||
} |
|||
```` |
|||
|
|||
> ABP automatically discovers this class. No additional configuration required! |
|||
|
|||
In the `Define` method, you first need to add a **permission group** or get an existing group then add **permissions** to this group. |
|||
|
|||
When you define a permission, it becomes usable in the ASP.NET Core authorization system as a **policy** name. It also becomes visible in the UI. See permissions dialog for a role: |
|||
|
|||
 |
|||
|
|||
* The "BookStore" group is shown as a new tab on the left side. |
|||
* "BookStore_Author_Create" on the right side is the permission name. You can grant or prohibit it for the role. |
|||
|
|||
When you save the dialog, it is saved to the database and used in the authorization system. |
|||
|
|||
> The screen above is available when you have installed the identity module, which is basically used for user and role management. Startup templates come with the identity module pre-installed. |
|||
|
|||
#### Localizing the Permission Name |
|||
|
|||
"BookStore_Author_Create" is not a good permission name for the UI. Fortunately, `AddPermission` and `AddGroup` methods can take `LocalizableString` as second parameters: |
|||
|
|||
````csharp |
|||
var myGroup = context.AddGroup( |
|||
"BookStore", |
|||
LocalizableString.Create<BookStoreResource>("BookStore") |
|||
); |
|||
|
|||
myGroup.AddPermission( |
|||
"BookStore_Author_Create", |
|||
LocalizableString.Create<BookStoreResource>("Permission:BookStore_Author_Create") |
|||
); |
|||
```` |
|||
|
|||
Then you can define texts for "BookStore" and "Permission:BookStore_Author_Create" keys in the localization file: |
|||
|
|||
````json |
|||
"BookStore": "Book Store", |
|||
"Permission:BookStore_Author_Create": "Creating a new author" |
|||
```` |
|||
|
|||
> For more information, see the [localization document](Localization.md) on the localization system. |
|||
|
|||
The localized UI will be as seen below: |
|||
|
|||
 |
|||
|
|||
#### Multi-Tenancy |
|||
|
|||
ABP supports [multi-tenancy](Multi-Tenancy.md) as a first class citizen. You can define multi-tenancy side option while defining a new permission. It gets one of the three values defined below: |
|||
|
|||
* **Host**: The permission is available only for the host side. |
|||
* **Tenant**: The permission is available only for the tenant side. |
|||
* **Both** (default): The permission is available both for tenant and host sides. |
|||
|
|||
> If your application is not multi-tenant, you can ignore this option. |
|||
|
|||
To set the multi-tenancy side option, pass to the third parameter of the `AddPermission` method: |
|||
|
|||
````csharp |
|||
myGroup.AddPermission( |
|||
"BookStore_Author_Create", |
|||
LocalizableString.Create<BookStoreResource>("Permission:BookStore_Author_Create"), |
|||
multiTenancySide: MultiTenancySides.Tenant //set multi-tenancy side! |
|||
); |
|||
```` |
|||
|
|||
#### Child Permissions |
|||
|
|||
A permission may have child permissions. It is especially useful when you want to create a hierarchical permission tree where a permission may have additional sub permissions which are available only if the parent permission has been granted. |
|||
|
|||
Example definition: |
|||
|
|||
````csharp |
|||
var authorManagement = myGroup.AddPermission("Author_Management"); |
|||
authorManagement.AddChild("Author_Management_Create_Books"); |
|||
authorManagement.AddChild("Author_Management_Edit_Books"); |
|||
authorManagement.AddChild("Author_Management_Delete_Books"); |
|||
```` |
|||
|
|||
The result on the UI is shown below (you probably want to localize permissions for your application): |
|||
|
|||
 |
|||
|
|||
For the example code, it is assumed that a role/user with "Author_Management" permission granted may have additional permissions. Then a typical application service that checks permissions can be defined as shown below: |
|||
|
|||
````csharp |
|||
[Authorize("Author_Management")] |
|||
public class AuthorAppService : ApplicationService, IAuthorAppService |
|||
{ |
|||
public Task<List<AuthorDto>> GetListAsync() |
|||
{ |
|||
... |
|||
} |
|||
|
|||
public Task<AuthorDto> GetAsync(Guid id) |
|||
{ |
|||
... |
|||
} |
|||
|
|||
[Authorize("Author_Management_Create_Books")] |
|||
public Task CreateAsync(CreateAuthorDto input) |
|||
{ |
|||
... |
|||
} |
|||
|
|||
[Authorize("Author_Management_Edit_Books")] |
|||
public Task UpdateAsync(CreateAuthorDto input) |
|||
{ |
|||
... |
|||
} |
|||
|
|||
[Authorize("Author_Management_Delete_Books")] |
|||
public Task DeleteAsync(CreateAuthorDto input) |
|||
{ |
|||
... |
|||
} |
|||
} |
|||
```` |
|||
|
|||
* `GetListAsync` and `GetAsync` will be available to users if they have `Author_Management` permission is granted. |
|||
* Other methods require additional permissions. |
|||
|
|||
### Overriding a Permission by a Custom Policy |
|||
|
|||
If you define and register a policy to the ASP.NET Core authorization system with the same name of a permission, your policy will override the existing permission. This is a powerful way to extend the authorization for a pre-built module that you are using in your application. |
|||
|
|||
See [policy based authorization](https://docs.microsoft.com/en-us/aspnet/core/security/authorization/policies) document to learn how to define a custom policy. |
|||
|
|||
## IAuthorizationService |
|||
|
|||
ASP.NET Core provides the `IAuthorizationService` that can be used to check for authorization. Once you inject, you can use it in your code to conditionally control the authorization. |
|||
|
|||
Example: |
|||
|
|||
````csharp |
|||
public async Task CreateAsync(CreateAuthorDto input) |
|||
{ |
|||
var result = await AuthorizationService |
|||
.AuthorizeAsync("Author_Management_Create_Books"); |
|||
if (result.Succeeded == false) |
|||
{ |
|||
//throw exception |
|||
throw new AbpAuthorizationException("..."); |
|||
} |
|||
|
|||
//continue to the normal flow... |
|||
} |
|||
```` |
|||
|
|||
> `AuthorizationService` is available as a property when you derive from ABP's `ApplicationService` base class. Since it is widely used in application services, `ApplicationService` pre-injects it for you. Otherwise, you can directly [inject](Dependency-Injection.md) it into your class. |
|||
|
|||
Since this is a typical code block, ABP provides extension methods to simplify it. |
|||
|
|||
Example: |
|||
|
|||
````csharp |
|||
public async Task CreateAsync(CreateAuthorDto input) |
|||
{ |
|||
await AuthorizationService.CheckAsync("Author_Management_Create_Books"); |
|||
|
|||
//continue to the normal flow... |
|||
} |
|||
```` |
|||
|
|||
`CheckAsync` extension method throws `AbpAuthorizationException` if the current user/client is not granted for the given permission. There is also `IsGrantedAsync` extension method that returns `true` or `false`. |
|||
|
|||
`IAuthorizationService` has some overloads for the `AuthorizeAsync` method. These are explained in the [ASP.NET Core authorization documentation](https://docs.microsoft.com/en-us/aspnet/core/security/authorization/introduction). |
|||
|
|||
> Tip: Prefer to use the `Authorize` attribute wherever possible, since it is declarative & simple. Use `IAuthorizationService` if you need to conditionally check a permission and run a business code based on the permission check. |
|||
|
|||
### Check a Permission in JavaScript |
|||
|
|||
You may need to check a policy/permission on the client side. For ASP.NET Core MVC / Razor Pages applications, you can use the `abp.auth` API. Example: |
|||
|
|||
````js |
|||
abp.auth.isGranted('MyPermissionName'); |
|||
```` |
|||
|
|||
See [abp.auth](AspNetCore/JavaScript-API/Auth.md) API documentation for details. |
|||
|
|||
## Permission Management |
|||
|
|||
Permission management is normally done by an admin user using the permission management modal: |
|||
|
|||
 |
|||
|
|||
If you need to manage permissions by code, inject the `IPermissionManager` and use as shown below: |
|||
|
|||
````csharp |
|||
public class MyService : ITransientDependency |
|||
{ |
|||
private readonly IPermissionManager _permissionManager; |
|||
|
|||
public MyService(IPermissionManager permissionManager) |
|||
{ |
|||
_permissionManager = permissionManager; |
|||
} |
|||
|
|||
public async Task GrantPermissionForUserAsync(Guid userId, string permissionName) |
|||
{ |
|||
await _permissionManager.SetForUserAsync(userId, permissionName, true); |
|||
} |
|||
|
|||
public async Task ProhibitPermissionForUserAsync(Guid userId, string permissionName) |
|||
{ |
|||
await _permissionManager.SetForUserAsync(userId, permissionName, false); |
|||
} |
|||
} |
|||
```` |
|||
|
|||
`SetForUserAsync` sets the value (true/false) for a permission of a user. There are more extension methods like `SetForRoleAsync` and `SetForClientAsync`. |
|||
|
|||
`IPermissionManager` is defined by the permission management module. See the [permission management module documentation](Modules/Permission-Management.md) for more information. |
|||
|
|||
## Advanced Topics |
|||
|
|||
### Permission Value Providers |
|||
|
|||
Permission checking system is extensible. Any class derived from `PermissionValueProvider` (or implements `IPermissionValueProvider`) can contribute to the permission check. There are three pre-defined value providers: |
|||
|
|||
* `UserPermissionValueProvider` checks if the current user is granted for the given permission. It gets user id from the current claims. User claim name is defined with the `AbpClaimTypes.UserId` static property. |
|||
* `RolePermissionValueProvider` checks if any of the roles of the current user is granted for the given permission. It gets role names from the current claims. Role claims name is defined with the `AbpClaimTypes.Role` static property. |
|||
* `ClientPermissionValueProvider` checks if the current client is granted for the given permission. This is especially useful on a machine to machine interaction where there is no current user. It gets the client id from the current claims. Client claim name is defined with the `AbpClaimTypes.ClientId` static property. |
|||
|
|||
You can extend the permission checking system by defining your own permission value provider. |
|||
|
|||
Example: |
|||
|
|||
````csharp |
|||
public class SystemAdminPermissionValueProvider : PermissionValueProvider |
|||
{ |
|||
public SystemAdminPermissionValueProvider(IPermissionStore permissionStore) |
|||
: base(permissionStore) |
|||
{ |
|||
} |
|||
|
|||
public override string Name => "SystemAdmin"; |
|||
|
|||
public override async Task<PermissionGrantResult> |
|||
CheckAsync(PermissionValueCheckContext context) |
|||
{ |
|||
if (context.Principal?.FindFirst("User_Type")?.Value == "SystemAdmin") |
|||
{ |
|||
return PermissionGrantResult.Granted; |
|||
} |
|||
|
|||
return PermissionGrantResult.Undefined; |
|||
} |
|||
} |
|||
```` |
|||
|
|||
This provider allows for all permissions to a user with a `User_Type` claim that has `SystemAdmin` value. It is common to use current claims and `IPermissionStore` in a permission value provider. |
|||
|
|||
A permission value provider should return one of the following values from the `CheckAsync` method: |
|||
|
|||
* `PermissionGrantResult.Granted` is returned to grant the user for the permission. If any of the providers return `Granted`, the result will be `Granted`, if no other provider returns `Prohibited`. |
|||
* `PermissionGrantResult.Prohibited` is returned to prohibit the user for the permission. If any of the providers return `Prohibited`, the result will always be `Prohibited`. Doesn't matter what other providers return. |
|||
* `PermissionGrantResult.Undefined` is returned if this value provider could not decide about the permission value. Return this to let other providers check the permission. |
|||
|
|||
Once a provider is defined, it should be added to the `PermissionOptions` as shown below: |
|||
|
|||
````csharp |
|||
Configure<PermissionOptions>(options => |
|||
{ |
|||
options.ValueProviders.Add<SystemAdminPermissionValueProvider>(); |
|||
}); |
|||
```` |
|||
|
|||
### Permission Store |
|||
|
|||
`IPermissionStore` is the only interface that needs to be implemented to read the value of permissions from a persistence source, generally a database system. Permission management module implements it. See the [permission management module documentation](Modules/Permission-Management.md) for more information |
|||
|
|||
### AlwaysAllowAuthorizationService |
|||
|
|||
`AlwaysAllowAuthorizationService` is a class that is used to bypass the authorization service. It is generally used in integration tests where you may want to disable the authorization system. |
|||
|
|||
Use `IServiceCollection.AddAlwaysAllowAuthorization()` extension method to register the `AlwaysAllowAuthorizationService` to the [dependency injection](Dependency-Injection.md) system: |
|||
|
|||
````csharp |
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
context.Services.AddAlwaysAllowAuthorization(); |
|||
} |
|||
```` |
|||
|
|||
This is already done for the startup template integration tests. |
|||
|
|||
## See Also |
|||
|
|||
* [Permission Management Module](Modules/Permission-Management.md) |
|||
* [ASP.NET Core MVC / Razor Pages JavaScript Auth API](AspNetCore/JavaScript-API/Auth.md) |
|||
|
|||
@ -0,0 +1,21 @@ |
|||
# ABP v0.21 Has Been Released based on the ASP.NET Core 3.0 |
|||
|
|||
Just one hour after Microsoft released it, ABP v0.21 [has been released](https://twitter.com/abpframework/status/1176185493119258624) based on the ASP.NET Core 3.0. |
|||
|
|||
v0.21 has no new feature. It just upgrades to the stable ASP.NET Core 3.0. Check [v0.20 release notes](https://github.com/abpframework/abp/releases/tag/0.20.0) for new features, enhancements and bug fixes. |
|||
|
|||
## About v1.0 |
|||
|
|||
ABP framework is getting closer to v1.0. We intent to release it in the middle of this October. In this time, we will test and document more. |
|||
|
|||
## .NET Conf 2019 |
|||
|
|||
Microsoft has lunched ASP.NET Core 3.0 in the .NET Conf 2019, a 3-days virtual conference. ABP's lead developer [Halil ibrahim Kalkan](https://twitter.com/hibrahimkalkan) has also talked in the conference to introduce the ABP framework. It was great to be a part of this important event. |
|||
|
|||
## Techorama Netherlands 2019 |
|||
|
|||
[Techorama NL](https://techorama.nl/) is one of the biggest conferences in Europe. This year, Volosoft is a sponsor of the conference and will have a booth to talk to software developers about the ABP framework and software development. Our booth wall will look like shown below: |
|||
|
|||
 |
|||
|
|||
If you are in the conference, come to out booth to talk about the ABP framework. We will also have nice swags for you :) |
|||
|
After Width: | Height: | Size: 226 KiB |
@ -0,0 +1,3 @@ |
|||
# Permission Management Module |
|||
|
|||
TODO |
|||
|
After Width: | Height: | Size: 61 KiB |
|
After Width: | Height: | Size: 40 KiB |
|
After Width: | Height: | Size: 42 KiB |
@ -0,0 +1,21 @@ |
|||
# 基于ASP.NET Core 3.0的ABP v0.21已发布 |
|||
|
|||
在微软发布仅仅一个小时后, 基于ASP.NET Core 3.0的ABP v0.21也紧跟着[发布了.](https://twitter.com/abpframework/status/1176185493119258624) |
|||
|
|||
v0.21没有新功能.它只是升级到稳定的ASP.NET Core 3.0. 查看[v0.20发行说明](https://github.com/abpframework/abp/releases/tag/0.20.0)以获取新功能,增强功能和错误修复. |
|||
|
|||
## 关于v1.0 |
|||
|
|||
ABP框架越来越接近v1.0.我们打算在今年10月中旬发布1.0. 现在,我们将完善测试和文档. |
|||
|
|||
## .NET Conf 2019 |
|||
|
|||
微软已经在为期3天的虚拟会议.NET Conf 2019发布了ASP.NET Core 3.0. ABP的首席开发人员[Halil ibrahim Kalkan](https://twitter.com/hibrahimkalkan)在会议上也发表了讲话,介绍了ABP框架.能够参加这一重要活动真是太棒了. |
|||
|
|||
## Techorama荷兰2019 |
|||
|
|||
[Techorama NL](https://techorama.nl/)是欧洲最大的会议之一.今年,Volosoft是会议的赞助商,并将有一个展位与软件开发人员讨论ABP框架和软件开发.我们的展位墙如下图所示: |
|||
|
|||
 |
|||
|
|||
如果您也参加会议,请到展位讨论ABP框架.我们还为您准备了一些私货:) |
|||
|
After Width: | Height: | Size: 226 KiB |
@ -1,20 +1,21 @@ |
|||
@using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Themes.Basic.Components.Brand |
|||
@using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Themes.Basic.Components.Menu |
|||
@using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Themes.Basic.Components.Toolbar |
|||
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top" id="main-navbar"> |
|||
@(await Component.InvokeAsync<MainNavbarBrandViewComponent>()) |
|||
<button class="navbar-toggler" type="button" data-toggle="collapse" |
|||
data-target="#main-navbar-collapse" aria-controls="main-navbar-collapse" |
|||
aria-expanded="false" aria-label="Toggle navigation"> |
|||
<span class="navbar-toggler-icon"></span> |
|||
</button> |
|||
<div class="collapse navbar-collapse" id="main-navbar-collapse"> |
|||
<ul class="navbar-nav mr-auto"> |
|||
@(await Component.InvokeAsync<MainNavbarMenuViewComponent>()) |
|||
</ul> |
|||
|
|||
<span id="main-navbar-tools"> |
|||
@(await Component.InvokeAsync<MainNavbarToolbarViewComponent>()) |
|||
</span> |
|||
<nav class="navbar navbar-expand-md navbar-dark bg-dark shadow-sm flex-column flex-md-row mb-4" id="main-navbar" style="min-height: 4rem;"> |
|||
<div class="container"> |
|||
@(await Component.InvokeAsync<MainNavbarBrandViewComponent>()) |
|||
<button class="navbar-toggler" type="button" data-toggle="collapse" |
|||
data-target="#main-navbar-collapse" aria-controls="main-navbar-collapse" |
|||
aria-expanded="false" aria-label="Toggle navigation"> |
|||
<span class="navbar-toggler-icon"></span> |
|||
</button> |
|||
<div class="collapse navbar-collapse" id="main-navbar-collapse"> |
|||
<ul class="navbar-nav mx-auto"> |
|||
@(await Component.InvokeAsync<MainNavbarMenuViewComponent>()) |
|||
</ul> |
|||
<ul class="navbar-nav"> |
|||
@(await Component.InvokeAsync<MainNavbarToolbarViewComponent>()) |
|||
</ul> |
|||
</div> |
|||
</div> |
|||
</nav> |
|||
</nav> |
|||
@ -1,36 +1,59 @@ |
|||
body { |
|||
padding-top: 5rem; |
|||
} |
|||
|
|||
body.abp-empty-layout { |
|||
padding-top: 0; |
|||
} |
|||
|
|||
|
|||
#main-navbar-tools a.dropdown-toggle { |
|||
text-decoration: none; |
|||
color: #fff; |
|||
} |
|||
|
|||
/* Main Menu */ |
|||
|
|||
|
|||
.navbar .dropdown-submenu { |
|||
position: relative; |
|||
} |
|||
|
|||
.navbar .dropdown-submenu a { |
|||
padding: 0.25rem 1.4rem; |
|||
.navbar .dropdown-menu { |
|||
margin: 0; |
|||
padding: 0; |
|||
} |
|||
.navbar .dropdown-menu a { |
|||
font-size: .9em; |
|||
padding: 10px 15px; |
|||
display: block; |
|||
min-width: 210px; |
|||
text-align: left; |
|||
border-radius: 0.25rem; |
|||
min-height: 44px; |
|||
} |
|||
.navbar .dropdown-submenu a::after { |
|||
transform: rotate(-90deg); |
|||
position: absolute; |
|||
right: 16px; |
|||
top: 18px; |
|||
} |
|||
.navbar .dropdown-submenu .dropdown-menu { |
|||
top: 0; |
|||
left: 100%; |
|||
} |
|||
|
|||
.card-header .btn { |
|||
padding: 2px 6px; |
|||
} |
|||
.card-header h5 { |
|||
margin: 0; |
|||
} |
|||
.container > .card { |
|||
box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075) !important; |
|||
} |
|||
|
|||
.navbar .dropdown-submenu a::after { |
|||
transform: rotate(-90deg); |
|||
position: absolute; |
|||
right: 16px; |
|||
top: 18px; |
|||
} |
|||
@media screen and (min-width: 768px) { |
|||
.navbar .dropdown:hover > .dropdown-menu { |
|||
display: block; |
|||
} |
|||
|
|||
.navbar .dropdown-submenu .dropdown-menu { |
|||
top: 0; |
|||
left: 100%; |
|||
margin-left: .1rem; |
|||
margin-right: .1rem; |
|||
.navbar .dropdown-submenu:hover > .dropdown-menu { |
|||
display: block; |
|||
} |
|||
} |
|||
.input-validation-error { |
|||
border-color: #dc3545; |
|||
} |
|||
.field-validation-error { |
|||
font-size: 0.8em; |
|||
} |
|||
|
|||
@ -0,0 +1,20 @@ |
|||
using System.Linq; |
|||
using System.Reflection; |
|||
using Microsoft.AspNetCore.Mvc.ApplicationParts; |
|||
|
|||
namespace Microsoft.Extensions.DependencyInjection |
|||
{ |
|||
public static class AbpMvcBuilderExtensions |
|||
{ |
|||
public static void AddApplicationPartIfNotExists(this IMvcBuilder mvcBuilder, Assembly assembly) |
|||
{ |
|||
if (mvcBuilder.PartManager.ApplicationParts.Any( |
|||
p => p is AssemblyPart assemblyPart && assemblyPart.Assembly == assembly)) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
mvcBuilder.PartManager.ApplicationParts.Add(new AssemblyPart(assembly)); |
|||
} |
|||
} |
|||
} |
|||
@ -1,15 +1,55 @@ |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using System; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.ObjectMapping; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc |
|||
{ |
|||
public abstract class AbpViewComponent : ViewComponent |
|||
{ |
|||
public IObjectMapper ObjectMapper { get; set; } |
|||
public IServiceProvider ServiceProvider { get; set; } |
|||
protected readonly object ServiceProviderLock = new object(); |
|||
|
|||
protected AbpViewComponent() |
|||
protected TService LazyGetRequiredService<TService>(ref TService reference) |
|||
=> LazyGetRequiredService(typeof(TService), ref reference); |
|||
|
|||
protected TRef LazyGetRequiredService<TRef>(Type serviceType, ref TRef reference) |
|||
{ |
|||
|
|||
if (reference == null) |
|||
{ |
|||
lock (ServiceProviderLock) |
|||
{ |
|||
if (reference == null) |
|||
{ |
|||
reference = (TRef)ServiceProvider.GetRequiredService(serviceType); |
|||
} |
|||
} |
|||
} |
|||
|
|||
return reference; |
|||
} |
|||
|
|||
protected Type ObjectMapperContext { get; set; } |
|||
public IObjectMapper ObjectMapper |
|||
{ |
|||
get |
|||
{ |
|||
if (_objectMapper != null) |
|||
{ |
|||
return _objectMapper; |
|||
} |
|||
|
|||
if (ObjectMapperContext == null) |
|||
{ |
|||
return LazyGetRequiredService(ref _objectMapper); |
|||
} |
|||
|
|||
return LazyGetRequiredService( |
|||
typeof(IObjectMapper<>).MakeGenericType(ObjectMapperContext), |
|||
ref _objectMapper |
|||
); |
|||
} |
|||
} |
|||
private IObjectMapper _objectMapper; |
|||
} |
|||
} |
|||
|
|||
@ -1,63 +0,0 @@ |
|||
using System; |
|||
|
|||
namespace Microsoft.AspNetCore.InProcess |
|||
{ |
|||
/// <summary>
|
|||
/// https://github.com/aspnet/AspNetCore.Docs/blob/master/aspnetcore/host-and-deploy/aspnet-core-module/samples_snapshot/2.x/CurrentDirectoryHelpers.cs
|
|||
/// TODO: Remove CurrentDirectoryHelpers.cs when upgrade to ASP.NET Core 3.0.
|
|||
/// </summary>
|
|||
public class CurrentDirectoryHelpers |
|||
{ |
|||
internal const string AspNetCoreModuleDll = "aspnetcorev2_inprocess.dll"; |
|||
|
|||
[System.Runtime.InteropServices.DllImport("kernel32.dll")] |
|||
private static extern IntPtr GetModuleHandle(string lpModuleName); |
|||
|
|||
[System.Runtime.InteropServices.DllImport(AspNetCoreModuleDll)] |
|||
private static extern int http_get_application_properties(ref IISConfigurationData iiConfigData); |
|||
|
|||
[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)] |
|||
private struct IISConfigurationData |
|||
{ |
|||
public IntPtr pNativeApplication; |
|||
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.BStr)] |
|||
public string pwzFullApplicationPath; |
|||
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.BStr)] |
|||
public string pwzVirtualApplicationPath; |
|||
public bool fWindowsAuthEnabled; |
|||
public bool fBasicAuthEnabled; |
|||
public bool fAnonymousAuthEnable; |
|||
} |
|||
|
|||
public static void SetCurrentDirectory() |
|||
{ |
|||
try |
|||
{ |
|||
// Check if physical path was provided by ANCM
|
|||
var sitePhysicalPath = Environment.GetEnvironmentVariable("ASPNETCORE_IIS_PHYSICAL_PATH"); |
|||
if (string.IsNullOrEmpty(sitePhysicalPath)) |
|||
{ |
|||
// Skip if not running ANCM InProcess
|
|||
if (GetModuleHandle(AspNetCoreModuleDll) == IntPtr.Zero) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
IISConfigurationData configurationData = default(IISConfigurationData); |
|||
if (http_get_application_properties(ref configurationData) != 0) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
sitePhysicalPath = configurationData.pwzFullApplicationPath; |
|||
} |
|||
|
|||
Environment.CurrentDirectory = sitePhysicalPath; |
|||
} |
|||
catch |
|||
{ |
|||
// ignore
|
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
using Microsoft.Extensions.DependencyInjection.Extensions; |
|||
using Volo.Abp.AutoMapper; |
|||
using Volo.Abp.ObjectMapping; |
|||
|
|||
namespace Microsoft.Extensions.DependencyInjection |
|||
{ |
|||
public static class AbpAutoMapperServiceCollectionExtensions |
|||
{ |
|||
public static IServiceCollection AddAutoMapperObjectMapper(this IServiceCollection services) |
|||
{ |
|||
return services.Replace( |
|||
ServiceDescriptor.Transient<IAutoObjectMappingProvider, AutoMapperAutoObjectMappingProvider>() |
|||
); |
|||
} |
|||
|
|||
public static IServiceCollection AddAutoMapperObjectMapper<TContext>(this IServiceCollection services) |
|||
{ |
|||
return services.Replace( |
|||
ServiceDescriptor.Transient<IAutoObjectMappingProvider<TContext>, AutoMapperAutoObjectMappingProvider<TContext>>() |
|||
); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
using Volo.Abp.ObjectMapping; |
|||
|
|||
namespace Volo.Abp.AutoMapper |
|||
{ |
|||
public class AutoMapperAutoObjectMappingProvider<TContext> : AutoMapperAutoObjectMappingProvider, IAutoObjectMappingProvider<TContext> |
|||
{ |
|||
public AutoMapperAutoObjectMappingProvider(IMapperAccessor mapperAccessor) |
|||
: base(mapperAccessor) |
|||
{ |
|||
} |
|||
} |
|||
|
|||
public class AutoMapperAutoObjectMappingProvider : IAutoObjectMappingProvider |
|||
{ |
|||
public IMapperAccessor MapperAccessor { get; } |
|||
|
|||
public AutoMapperAutoObjectMappingProvider(IMapperAccessor mapperAccessor) |
|||
{ |
|||
MapperAccessor = mapperAccessor; |
|||
} |
|||
|
|||
public virtual TDestination Map<TSource, TDestination>(object source) |
|||
{ |
|||
return MapperAccessor.Mapper.Map<TDestination>(source); |
|||
} |
|||
|
|||
public virtual TDestination Map<TSource, TDestination>(TSource source, TDestination destination) |
|||
{ |
|||
return MapperAccessor.Mapper.Map(source, destination); |
|||
} |
|||
} |
|||
} |
|||
@ -1,29 +0,0 @@ |
|||
using System; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.ObjectMapping; |
|||
|
|||
namespace Volo.Abp.AutoMapper |
|||
{ |
|||
[Dependency(ServiceLifetime.Transient, ReplaceServices = true)] |
|||
public class AutoMapperObjectMapper : DefaultObjectMapper |
|||
{ |
|||
protected IMapperAccessor MapperAccessor { get; } |
|||
|
|||
public AutoMapperObjectMapper(IMapperAccessor mapperAccessor, IServiceProvider serviceProvider) |
|||
: base(serviceProvider) |
|||
{ |
|||
MapperAccessor = mapperAccessor; |
|||
} |
|||
|
|||
protected override TDestination AutoMap<TSource, TDestination>(object source) |
|||
{ |
|||
return MapperAccessor.Mapper.Map<TDestination>(source); |
|||
} |
|||
|
|||
protected override TDestination AutoMap<TSource, TDestination>(TSource source, TDestination destination) |
|||
{ |
|||
return MapperAccessor.Mapper.Map(source, destination); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
using AutoMapper; |
|||
using Volo.Abp.AutoMapper; |
|||
|
|||
namespace Volo.Abp.ObjectMapping |
|||
{ |
|||
public static class AbpAutoMapperObjectMapperExtensions |
|||
{ |
|||
public static IMapper GetMapper(this IObjectMapper objectMapper) |
|||
{ |
|||
return objectMapper.AutoObjectMappingProvider.GetMapper(); |
|||
} |
|||
|
|||
public static IMapper GetMapper(this IAutoObjectMappingProvider autoObjectMappingProvider) |
|||
{ |
|||
if (autoObjectMappingProvider is AutoMapperAutoObjectMappingProvider autoMapperAutoObjectMappingProvider) |
|||
{ |
|||
return autoMapperAutoObjectMappingProvider.MapperAccessor.Mapper; |
|||
} |
|||
|
|||
throw new AbpException($"Given object is not an instance of {typeof(AutoMapperAutoObjectMappingProvider).AssemblyQualifiedName}. The type of the given object it {autoObjectMappingProvider.GetType().AssemblyQualifiedName}"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,212 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Text.RegularExpressions; |
|||
using System.Xml; |
|||
using Volo.Abp.Cli.ProjectBuilding.Files; |
|||
|
|||
namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps |
|||
{ |
|||
public class ProjectReferenceReplaceStep : ProjectBuildPipelineStep |
|||
{ |
|||
public override void Execute(ProjectBuildContext context) |
|||
{ |
|||
if (context.BuildArgs.ExtraProperties.ContainsKey("local-framework-ref")) |
|||
{ |
|||
var localAbpRepoPath = context.BuildArgs.AbpGitHubLocalRepositoryPath; |
|||
|
|||
if (string.IsNullOrWhiteSpace(localAbpRepoPath)) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
new ProjectReferenceReplacer.LocalProjectPathReferenceReplacer( |
|||
context.Files, |
|||
"MyCompanyName.MyProjectName", |
|||
localAbpRepoPath |
|||
).Run(); |
|||
} |
|||
else |
|||
{ |
|||
var nugetPackageVersion = context.TemplateFile.Version; |
|||
|
|||
if (IsBranchName(nugetPackageVersion)) |
|||
{ |
|||
nugetPackageVersion = context.TemplateFile.LatestVersion; |
|||
} |
|||
|
|||
new ProjectReferenceReplacer.NugetReferenceReplacer( |
|||
context.Files, |
|||
"MyCompanyName.MyProjectName", |
|||
nugetPackageVersion |
|||
).Run(); |
|||
} |
|||
} |
|||
|
|||
private bool IsBranchName(string versionOrBranchName) |
|||
{ |
|||
Check.NotNullOrWhiteSpace(versionOrBranchName, nameof(versionOrBranchName)); |
|||
|
|||
if (char.IsDigit(versionOrBranchName[0])) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
if (versionOrBranchName[0].IsIn('v', 'V') && |
|||
versionOrBranchName.Length > 1 && |
|||
char.IsDigit(versionOrBranchName[1])) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
private abstract class ProjectReferenceReplacer |
|||
{ |
|||
private readonly List<FileEntry> _entries; |
|||
private readonly string _companyAndProjectNamePlaceHolder; |
|||
|
|||
protected ProjectReferenceReplacer( |
|||
List<FileEntry> entries, |
|||
string companyAndProjectNamePlaceHolder) |
|||
{ |
|||
_entries = entries; |
|||
_companyAndProjectNamePlaceHolder = companyAndProjectNamePlaceHolder; |
|||
} |
|||
|
|||
public void Run() |
|||
{ |
|||
foreach (var fileEntry in _entries) |
|||
{ |
|||
if (fileEntry.Name.EndsWith(".csproj")) |
|||
{ |
|||
fileEntry.SetContent(ProcessFileContent(fileEntry.Content)); |
|||
} |
|||
} |
|||
} |
|||
|
|||
private string ProcessFileContent(string content) |
|||
{ |
|||
Check.NotNull(content, nameof(content)); |
|||
|
|||
var doc = new XmlDocument() { PreserveWhitespace = true }; |
|||
|
|||
doc.Load(GenerateStreamFromString(content)); |
|||
|
|||
return ProcessReferenceNodes(doc, content); |
|||
} |
|||
|
|||
private string ProcessReferenceNodes(XmlDocument doc, string content) |
|||
{ |
|||
Check.NotNull(content, nameof(content)); |
|||
|
|||
var nodes = doc.SelectNodes("/Project/ItemGroup/ProjectReference[@Include]"); |
|||
|
|||
foreach (XmlNode oldNode in nodes) |
|||
{ |
|||
var oldNodeIncludeValue = oldNode.Attributes["Include"].Value; |
|||
|
|||
// ReSharper disable once PossibleNullReferenceException : Can not be null because nodes are selected with include attribute filter in previous method
|
|||
if (oldNodeIncludeValue.Contains($"{_companyAndProjectNamePlaceHolder}")) |
|||
{ |
|||
continue; |
|||
} |
|||
|
|||
XmlNode newNode = null; |
|||
|
|||
newNode = GetNewReferenceNode(doc, oldNodeIncludeValue); |
|||
|
|||
oldNode.ParentNode.ReplaceChild(newNode, oldNode); |
|||
} |
|||
|
|||
return doc.OuterXml; |
|||
} |
|||
|
|||
protected abstract XmlElement GetNewReferenceNode(XmlDocument doc, string oldNodeIncludeValue); |
|||
|
|||
private static Stream GenerateStreamFromString(string s) |
|||
{ |
|||
var stream = new MemoryStream(); |
|||
var writer = new StreamWriter(stream); |
|||
writer.Write(s); |
|||
writer.Flush(); |
|||
stream.Position = 0; |
|||
return stream; |
|||
} |
|||
|
|||
|
|||
public class NugetReferenceReplacer : ProjectReferenceReplacer |
|||
{ |
|||
private readonly string _nugetPackageVersion; |
|||
|
|||
public NugetReferenceReplacer(List<FileEntry> entries, string companyAndProjectNamePlaceHolder, string nugetPackageVersion) |
|||
: base(entries, companyAndProjectNamePlaceHolder) |
|||
{ |
|||
_nugetPackageVersion = nugetPackageVersion; |
|||
} |
|||
|
|||
protected override XmlElement GetNewReferenceNode(XmlDocument doc, string oldNodeIncludeValue) |
|||
{ |
|||
var newNode = doc.CreateElement("PackageReference"); |
|||
|
|||
var includeAttr = doc.CreateAttribute("Include"); |
|||
includeAttr.Value = ConvertToNugetReference(oldNodeIncludeValue); |
|||
newNode.Attributes.Append(includeAttr); |
|||
|
|||
var versionAttr = doc.CreateAttribute("Version"); |
|||
versionAttr.Value = _nugetPackageVersion; |
|||
newNode.Attributes.Append(versionAttr); |
|||
return newNode; |
|||
} |
|||
|
|||
private string ConvertToNugetReference(string oldValue) |
|||
{ |
|||
var newValue = Regex.Match(oldValue, @"\\((?!.+?\\).+?)\.csproj", RegexOptions.CultureInvariant | RegexOptions.Compiled); |
|||
if (newValue.Success && newValue.Groups.Count == 2) |
|||
{ |
|||
return newValue.Groups[1].Value; |
|||
} |
|||
|
|||
return oldValue; |
|||
} |
|||
} |
|||
|
|||
|
|||
public class LocalProjectPathReferenceReplacer : ProjectReferenceReplacer |
|||
{ |
|||
private readonly string _gitHubLocalRepositoryPath; |
|||
|
|||
public LocalProjectPathReferenceReplacer(List<FileEntry> entries, string companyAndProjectNamePlaceHolder, string gitHubLocalRepositoryPath) |
|||
: base(entries, companyAndProjectNamePlaceHolder) |
|||
{ |
|||
_gitHubLocalRepositoryPath = gitHubLocalRepositoryPath; |
|||
} |
|||
|
|||
protected override XmlElement GetNewReferenceNode(XmlDocument doc, string oldNodeIncludeValue) |
|||
{ |
|||
var newNode = doc.CreateElement("ProjectReference"); |
|||
|
|||
var includeAttr = doc.CreateAttribute("Include"); |
|||
includeAttr.Value = SetGithubPath(oldNodeIncludeValue); |
|||
newNode.Attributes.Append(includeAttr); |
|||
|
|||
return newNode; |
|||
} |
|||
|
|||
private string SetGithubPath(string includeValue) |
|||
{ |
|||
while (includeValue.StartsWith("..\\")) |
|||
{ |
|||
includeValue = includeValue.TrimStart('.'); |
|||
includeValue = includeValue.TrimStart('\\'); |
|||
} |
|||
|
|||
includeValue = _gitHubLocalRepositoryPath.EnsureEndsWith('\\') + includeValue; |
|||
|
|||
return includeValue; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<Import Project="..\..\..\common.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netstandard2.0</TargetFramework> |
|||
<AssemblyName>Volo.Abp.Ddd.Application.Contracts</AssemblyName> |
|||
<PackageId>Volo.Abp.Ddd.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.Auditing\Volo.Abp.Auditing.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,12 @@ |
|||
using Volo.Abp.Auditing; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.Application |
|||
{ |
|||
[DependsOn( |
|||
typeof(AbpAuditingModule) |
|||
)] |
|||
public class AbpDddApplicationContractsModule : AbpModule |
|||
{ |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
using System; |
|||
|
|||
namespace Volo.Abp.EventBus.Distributed |
|||
{ |
|||
public class EtoMappingDictionaryItem |
|||
{ |
|||
public Type EtoType { get; } |
|||
|
|||
public Type ObjectMappingContextType { get; } |
|||
|
|||
public EtoMappingDictionaryItem(Type etoType, Type objectMappingContextType = null) |
|||
{ |
|||
EtoType = etoType; |
|||
ObjectMappingContextType = objectMappingContextType; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
namespace Volo.Abp.ObjectMapping |
|||
{ |
|||
public interface IAutoObjectMappingProvider |
|||
{ |
|||
TDestination Map<TSource, TDestination>(object source); |
|||
|
|||
TDestination Map<TSource, TDestination>(TSource source, TDestination destination); |
|||
} |
|||
|
|||
public interface IAutoObjectMappingProvider<TContext> : IAutoObjectMappingProvider |
|||
{ |
|||
|
|||
} |
|||
} |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue