mirror of https://github.com/abpframework/abp.git
126 changed files with 8906 additions and 6183 deletions
|
After Width: | Height: | Size: 51 KiB |
@ -0,0 +1,24 @@ |
|||
# ASP.NET Core MVC / Razor Pages UI: JavaScript Auth API |
|||
|
|||
Auth API allows you to check permissions (policies) for the current user in the client side. In this way, you can conditionally show/hide UI parts or perform your client side logic based on the current permissions. |
|||
|
|||
> This document only explains the JavaScript API. See the [authorization document](../../../Authorization.md) to understand the ABP authorization & permission system. |
|||
|
|||
## Basic Usage |
|||
|
|||
`abp.auth.isGranted(...)` function is used to check if a permission/policy has granted or not: |
|||
|
|||
````js |
|||
if (abp.auth.isGranted('DeleteUsers')) { |
|||
//TODO: Delete the user |
|||
} else { |
|||
alert("You don't have permission to delete a user!"); |
|||
} |
|||
```` |
|||
|
|||
## Other Fields & Functions |
|||
|
|||
* ` abp.auth.isAnyGranted(...)`: Gets one or more permission/policy names and returns `true` if at least one of them has granted. |
|||
* `abp.auth.areAllGranted(...)`: Gets one or more permission/policy names and returns `true` if all of them of them have granted. |
|||
* `abp.auth.policies`: This is an object where its keys are the permission/policy names. You can find all permission/policy names here. |
|||
* `abp.auth.grantedPolicies`: This is an object where its keys are the permission/policy names. You can find the granted permission/policy names here. |
|||
@ -0,0 +1,56 @@ |
|||
# ASP.NET Core MVC / Razor Pages UI: JavaScript UI Block/Busy API |
|||
|
|||
UI Block API disables (blocks) the page or a part of the page. |
|||
|
|||
## Basic Usage |
|||
|
|||
**Example: Block (disable) the complete page** |
|||
|
|||
````js |
|||
abp.ui.block(); |
|||
```` |
|||
|
|||
**Example: Block (disable) an HTML element** |
|||
|
|||
````js |
|||
abp.ui.block('#MyContainer'); |
|||
```` |
|||
|
|||
**Example: Enables the previously blocked element or page:** |
|||
|
|||
````js |
|||
abp.ui.unblock(); |
|||
```` |
|||
|
|||
## Options |
|||
|
|||
`abp.ui.block()` method can get an options object which may contain the following fields: |
|||
|
|||
* `elm`: An optional selector to find the element to be blocked (e.g. `#MyContainerId`). If not provided, the entire page is blocked. The selector can also be directly passed to the `block()` method as shown above. |
|||
* `busy`: Set to `true` to show a progress indicator on the blocked area. |
|||
* `promise`: A promise object with `always` or `finally` callbacks. This can be helpful if you want to automatically unblock the blocked area when a deferred operation completes. |
|||
|
|||
**Example: Block an element with busy indicator** |
|||
|
|||
````js |
|||
abp.ui.block({ |
|||
elm: '#MySection', |
|||
busy: true |
|||
}); |
|||
```` |
|||
|
|||
The resulting UI will look like below: |
|||
|
|||
 |
|||
|
|||
## setBusy |
|||
|
|||
`abp.ui.setBusy(...)` and `abp.ui.clearBusy()` are shortcut functions if you want to use the block with `busy` option. |
|||
|
|||
**Example: Block with busy** |
|||
|
|||
````js |
|||
abp.ui.setBusy('#MySection'); |
|||
```` |
|||
|
|||
Then you can use `abp.ui.clearBusy();` to re-enable the busy area/page. |
|||
@ -0,0 +1,49 @@ |
|||
# ASP.NET Core MVC / Razor Pages UI: JavaScript CurrentUser API |
|||
|
|||
`abp.currentUser` is an object that contains information about the current user of the application. |
|||
|
|||
> This document only explains the JavaScript API. See the [CurrentUser document](../../../CurrentUser.md) to get information about the current user in the server side. |
|||
|
|||
## Authenticated User |
|||
|
|||
If the user was authenticated, this object will be something like below: |
|||
|
|||
````js |
|||
{ |
|||
isAuthenticated: true, |
|||
id: "34f1f4a7-13cc-4b91-84d1-b91c87afa95f", |
|||
tenantId: null, |
|||
userName: "john", |
|||
name: "John", |
|||
surName: "Nash", |
|||
email: "john.nash@abp.io", |
|||
emailVerified: true, |
|||
phoneNumber: null, |
|||
phoneNumberVerified: false, |
|||
roles: ["moderator","supporter"] |
|||
} |
|||
```` |
|||
|
|||
So, `abp.currentUser.userName` returns `john` in this case. |
|||
|
|||
## Anonymous User |
|||
|
|||
If the user was not authenticated, this object will be something like below: |
|||
|
|||
````js |
|||
{ |
|||
isAuthenticated: false, |
|||
id: null, |
|||
tenantId: null, |
|||
userName: null, |
|||
name: null, |
|||
surName: null, |
|||
email: null, |
|||
emailVerified: false, |
|||
phoneNumber: null, |
|||
phoneNumberVerified: false, |
|||
roles: [] |
|||
} |
|||
```` |
|||
|
|||
You can check `abp.currentUser.isAuthenticated` to understand if the use was authenticated or not. |
|||
@ -0,0 +1,117 @@ |
|||
# ASP.NET Core MVC / Razor Pages UI: JavaScript DOM API |
|||
|
|||
`abp.dom` (Document Object Model) provides events that you can subscribe to get notified when elements dynamically added to and removed from the page (DOM). |
|||
|
|||
It is especially helpful if you want to initialize the new loaded elements. This is generally needed when you dynamically add elements to DOM (for example, get some HTML elements via AJAX) after page initialization. |
|||
|
|||
> ABP uses the [MutationObserver](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver) to observe the changes made on the DOM. |
|||
|
|||
## Node Events |
|||
|
|||
### onNodeAdded |
|||
|
|||
This event is triggered when an element is added to the DOM. Example: |
|||
|
|||
````js |
|||
abp.dom.onNodeAdded(function(args){ |
|||
console.log(args.$el); |
|||
}); |
|||
```` |
|||
|
|||
`args` object has the following fields; |
|||
|
|||
* `$el`: The JQuery selection to get the new element inserted to the DOM. |
|||
|
|||
### onNodeRemoved |
|||
|
|||
This event is triggered when an element is removed from the DOM. Example: |
|||
|
|||
````js |
|||
abp.dom.onNodeRemoved(function(args){ |
|||
console.log(args.$el); |
|||
}); |
|||
```` |
|||
|
|||
`args` object has the following fields; |
|||
|
|||
* `$el`: The JQuery selection to get the element removed from the DOM. |
|||
|
|||
## Pre-Build Initializers |
|||
|
|||
ABP Framework is using the DOM events to initialize some kind of HTML elements when they are added to the DOM after than the page was already initialized. |
|||
|
|||
> Note that the same initializers also work if these elements were already included in the initial DOM. So, whether they are initially or lazy loaded, they work as expected. |
|||
|
|||
### Form Initializer |
|||
|
|||
The Form initializer (defined as `abp.dom.initializers.initializeForms`) initializes the lazy loaded forms; |
|||
|
|||
* Automatically enabled the `unobtrusive` validation on the form. |
|||
* Can automatically show a confirmation message when you submit the form. To enable this feature, just add `data-confirm` attribute with a message (like `data-confirm="Are you sure?"`) to the `form` element. |
|||
* If the `form` element has `data-ajaxForm="true"` attribute, then automatically calls the `.abpAjaxForm()` on the `form` element, to make the form posted via AJAX. |
|||
|
|||
See the [Forms & Validation](../Forms-Validation.md) document for more. |
|||
|
|||
### Script Initializer |
|||
|
|||
Script initializer (`abp.dom.initializers.initializeScript`) can execute a JavaScript code for a DOM element. |
|||
|
|||
**Example: Lazy load a component and execute some code when the element has loaded** |
|||
|
|||
Assume that you've a container to load the element inside: |
|||
|
|||
````html |
|||
<div id="LazyComponent"></div> |
|||
```` |
|||
|
|||
And this is the component that will be loaded via AJAX from the server and inserted into the container: |
|||
|
|||
````html |
|||
<div data-script-class="MyCustomClass"> |
|||
<p>Sample message</p> |
|||
</div> |
|||
```` |
|||
|
|||
`data-script-class="MyCustomClass"` indicates the JavaScript class that will be used to perform some logic on this element: |
|||
|
|||
`MyCustomClass` is a global object defined as shown below: |
|||
|
|||
````js |
|||
MyCustomClass = function(){ |
|||
|
|||
function initDom($el){ |
|||
$el.css('color', 'red'); |
|||
} |
|||
|
|||
return { |
|||
initDom: initDom |
|||
} |
|||
}; |
|||
```` |
|||
|
|||
`initDom` is the function that is called by the ABP Framework. The `$el` argument is the loaded HTML element as a JQuery selection. |
|||
|
|||
Finally, you can load the component inside the container after an AJAX call: |
|||
|
|||
````js |
|||
$(function () { |
|||
setTimeout(function(){ |
|||
$.get('/get-my-element').then(function(response){ |
|||
$('#LazyComponent').html(response); |
|||
}); |
|||
}, 2000); |
|||
}); |
|||
```` |
|||
|
|||
Script Initialization system is especially helpful if you don't know how and when the component will be loaded into the DOM. This can be possible if you've developed a reusable UI component in a library and you want the application developer shouldn't care how to initialize the component in different use cases. |
|||
|
|||
> Script initialization doesn't work if the component was loaded in the initial DOM. In this case, you are responsible to initialize it. |
|||
|
|||
### Other Initializers |
|||
|
|||
The following Bootstrap components and libraries are automatically initialized when they are added to the DOM: |
|||
|
|||
* Tooltip |
|||
* Popover |
|||
* Timeage |
|||
|
|||
@ -0,0 +1,15 @@ |
|||
# ASP.NET Core MVC / Razor Pages UI: JavaScript Features API |
|||
|
|||
`abp.features` API allows you to check features or get the values of the features on the client side. You can read the current value of a feature in the client side only if it is allowed by the feature definition (on the server side). |
|||
|
|||
> This document only explains the JavaScript API. See the [Features](../../../Features.md) document to understand the ABP Features system. |
|||
|
|||
## Basic Usage |
|||
|
|||
`abp.features.values` can be used to access to the all feature values. |
|||
|
|||
````js |
|||
var excelExportFeatureValue = abp.features.values["ExportingToExcel"]; |
|||
```` |
|||
|
|||
Then you can check the value of the feature to perform your logic. |
|||
@ -1,3 +1,50 @@ |
|||
# ASP.NET Core MVC / Razor Pages UI: JavaScript Logging API |
|||
|
|||
TODO |
|||
`abp.log` API is used to write simple logs in the client side. |
|||
|
|||
> The logs are written to console, using the `console.log`, by default. |
|||
|
|||
> This document is for simple client side logging. See the [Logging](../../../Logging.md) document for server side logging system. |
|||
|
|||
## Basic Usage |
|||
|
|||
Use one of the `abp.log.xxx(...)` methods based on the severity of your log message. |
|||
|
|||
````js |
|||
abp.log.debug("Some debug log here..."); //Logging a simple debug message |
|||
abp.log.info({ name: "john", age: 42 }); //Logging an object as an information log |
|||
abp.log.warn("A warning message"); //Logging a warning message |
|||
abp.log.error('An error happens...'); //Error message |
|||
abp.log.fatal('Network connection has gone away!'); //Fatal error |
|||
```` |
|||
|
|||
## Log Levels |
|||
|
|||
There are 5 levels for a log message: |
|||
|
|||
* DEBUG = 1 |
|||
* INFO = 2 |
|||
* WARN = 3 |
|||
* ERROR = 4 |
|||
* FATAL = 5 |
|||
|
|||
These are defined in the `abp.log.levels` object (like `abp.log.levels.WARN`). |
|||
|
|||
### Changing the Current Log Level |
|||
|
|||
You can control the log level as shown below: |
|||
|
|||
````js |
|||
abp.log.level = abp.log.levels.WARN; |
|||
```` |
|||
|
|||
Default log level is `DEBUG`. |
|||
|
|||
### Logging with Specifying the Level |
|||
|
|||
Instead of calling `abp.log.info(...)` function, you can use the `abp.log.log` by specifying the log level as a parameter: |
|||
|
|||
````js |
|||
abp.log.log("log message...", abp.log.levels.INFO); |
|||
```` |
|||
|
|||
|
|||
@ -0,0 +1,40 @@ |
|||
# ASP.NET Core MVC / Razor Pages UI: JavaScript Resource Loader API |
|||
|
|||
`abp.ResourceLoader` is a service that can load a JavaScript or CSS file on demand. It guarantees to load the file only once even if you request multiple times. |
|||
|
|||
## Loading Script Files |
|||
|
|||
`abp.ResourceLoader.loadScript(...)` function **loads** a JavaScript file from the server and **executes** it. |
|||
|
|||
**Example: Load a JavaScript file** |
|||
|
|||
````js |
|||
abp.ResourceLoader.loadScript('/Pages/my-script.js'); |
|||
```` |
|||
|
|||
### Parameters |
|||
|
|||
`loadScript` function can get three parameters; |
|||
|
|||
* `url` (required, `string`): The URL of the script file to be loaded. |
|||
* `loadCallback` (optional, `function`): A callback function that is called once the script is loaded & executed. In this callback you can safely use the code in the script file. This callback is called even if the file was loaded before. |
|||
* `failCallback` (optional, `function`): A callback function that is called if loading the script fails. |
|||
|
|||
**Example: Provide the `loadCallback` argument** |
|||
|
|||
````js |
|||
abp.ResourceLoader.loadScript('/Pages/my-script.js', function() { |
|||
console.log('successfully loaded :)'); |
|||
}); |
|||
```` |
|||
|
|||
## Loading Style Files |
|||
|
|||
`abp.ResourceLoader.loadStyle(...)` function adds a `link` element to the `head` of the document for the given URL, so the CSS file is automatically loaded by the browser. |
|||
|
|||
**Example: Load a CSS file** |
|||
|
|||
````js |
|||
abp.ResourceLoader.loadStyle('/Pages/my-styles.css'); |
|||
```` |
|||
|
|||
|
After Width: | Height: | Size: 135 KiB |
@ -1,9 +1,13 @@ |
|||
namespace Volo.Abp.Settings |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.Abp.Settings |
|||
{ |
|||
public interface ISettingDefinitionContext |
|||
{ |
|||
SettingDefinition GetOrNull(string name); |
|||
|
|||
IReadOnlyList<SettingDefinition> GetAll(); |
|||
|
|||
void Add(params SettingDefinition[] definitions); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,9 @@ |
|||
namespace Volo.Abp.IdentityServer.ApiResources |
|||
{ |
|||
public class ApiResourcePropertyConsts |
|||
{ |
|||
public static int KeyMaxLength { get; set; } = 250; |
|||
|
|||
public static int ValueMaxLength { get; set; } = 2000; |
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
namespace Volo.Abp.IdentityServer.ApiResources |
|||
{ |
|||
public class ApiResourceScopeConsts |
|||
{ |
|||
public static int ScopeMaxLength { get; set; } = 200; |
|||
} |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
namespace Volo.Abp.IdentityServer.ApiResources |
|||
{ |
|||
public class ApiResourceSecretConsts |
|||
{ |
|||
/// <summary>
|
|||
/// Default value: 250
|
|||
/// </summary>
|
|||
public static int TypeMaxLength { get; set; } = 250; |
|||
|
|||
/// <summary>
|
|||
/// Default value: 4000
|
|||
/// </summary>
|
|||
public static int ValueMaxLength { get; set; } = 4000; |
|||
|
|||
/// <summary>
|
|||
/// Default value: 1000
|
|||
/// </summary>
|
|||
public static int DescriptionMaxLength { get; set; } = 1000; |
|||
} |
|||
} |
|||
@ -1,9 +0,0 @@ |
|||
namespace Volo.Abp.IdentityServer.ApiResources |
|||
{ |
|||
public class ApiScopeConsts |
|||
{ |
|||
public const int NameMaxLength = 200; |
|||
public const int DisplayNameMaxLength = 200; |
|||
public const int DescriptionMaxLength = 1000; |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
namespace Volo.Abp.IdentityServer.ApiScopes |
|||
{ |
|||
public class ApiScopeConsts |
|||
{ |
|||
public static int NameMaxLength { get; set; } = 200; |
|||
|
|||
public static int DisplayNameMaxLength { get; set; } = 200; |
|||
|
|||
public static int DescriptionMaxLength { get; set; } = 1000; |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
namespace Volo.Abp.IdentityServer.ApiScopes |
|||
{ |
|||
public class ApiScopePropertyConsts |
|||
{ |
|||
public static int KeyMaxLength { get; set; } = 250; |
|||
|
|||
public static int ValueMaxLength { get; set; } = 2000; |
|||
} |
|||
} |
|||
@ -1,22 +1,20 @@ |
|||
namespace Volo.Abp.IdentityServer |
|||
namespace Volo.Abp.IdentityServer.Clients |
|||
{ |
|||
public class SecretConsts |
|||
public class ClientSecretConsts |
|||
{ |
|||
/// <summary>
|
|||
/// Default value: 250
|
|||
/// </summary>
|
|||
public static int TypeMaxLength { get; set; } = 250; |
|||
|
|||
|
|||
/// <summary>
|
|||
/// Default value: 4000
|
|||
/// </summary>
|
|||
public static int ValueMaxLength { get; set; } = 4000; |
|||
|
|||
public static int ValueMaxLengthValue { get; set; } = ValueMaxLength; |
|||
|
|||
|
|||
/// <summary>
|
|||
/// Default value: 2000
|
|||
/// </summary>
|
|||
public static int DescriptionMaxLength { get; set; } = 2000; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
namespace Volo.Abp.IdentityServer.Devices |
|||
{ |
|||
public class DeviceFlowCodesConsts |
|||
{ |
|||
public static int DeviceCodeMaxLength { get; set; } = 200; |
|||
|
|||
public static int UserCodeMaxLength { get; set; } = 200; |
|||
|
|||
public static int SubjectIdMaxLength { get; set; } = 200; |
|||
|
|||
public static int SessionIdMaxLength { get; set; } = 100; |
|||
|
|||
public static int DescriptionMaxLength { get; set; } = 200; |
|||
|
|||
public static int ClientIdMaxLength { get; set; } = 200; |
|||
|
|||
public static int DataMaxLength { get; set; } = 50000; |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
namespace Volo.Abp.IdentityServer.IdentityResources |
|||
{ |
|||
public class IdentityResourcePropertyConsts |
|||
{ |
|||
public static int KeyMaxLength { get; set; } = 250; |
|||
|
|||
public static int ValueMaxLength { get; set; } = 2000; |
|||
} |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using AutoMapper; |
|||
|
|||
namespace Volo.Abp.IdentityServer |
|||
{ |
|||
public class AllowedSigningAlgorithmsConverter : |
|||
IValueConverter<ICollection<string>, string>, |
|||
IValueConverter<string, ICollection<string>> |
|||
{ |
|||
public static AllowedSigningAlgorithmsConverter Converter = new AllowedSigningAlgorithmsConverter(); |
|||
|
|||
public string Convert(ICollection<string> sourceMember, ResolutionContext context) |
|||
{ |
|||
if (sourceMember == null || !sourceMember.Any()) |
|||
{ |
|||
return null; |
|||
} |
|||
return sourceMember.Aggregate((x, y) => $"{x},{y}"); |
|||
} |
|||
|
|||
public ICollection<string> Convert(string sourceMember, ResolutionContext context) |
|||
{ |
|||
var list = new HashSet<string>(); |
|||
if (!String.IsNullOrWhiteSpace(sourceMember)) |
|||
{ |
|||
sourceMember = sourceMember.Trim(); |
|||
foreach (var item in sourceMember.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Distinct()) |
|||
{ |
|||
list.Add(item); |
|||
} |
|||
} |
|||
return list; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
using System; |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace Volo.Abp.IdentityServer.ApiResources |
|||
{ |
|||
public class ApiResourceProperty : Entity |
|||
{ |
|||
public virtual Guid ApiResourceId { get; protected set; } |
|||
|
|||
public virtual string Key { get; set; } |
|||
|
|||
public virtual string Value { get; set; } |
|||
|
|||
protected ApiResourceProperty() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public virtual bool Equals(Guid aiResourceId, [NotNull] string key, string value) |
|||
{ |
|||
return ApiResourceId == aiResourceId && Key == key && Value == value; |
|||
} |
|||
|
|||
protected internal ApiResourceProperty(Guid aiResourceId, [NotNull] string key, [NotNull] string value) |
|||
{ |
|||
Check.NotNull(key, nameof(key)); |
|||
|
|||
ApiResourceId = aiResourceId; |
|||
Key = key; |
|||
Value = value; |
|||
} |
|||
|
|||
public override object[] GetKeys() |
|||
{ |
|||
return new object[] { ApiResourceId, Key }; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
using System; |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace Volo.Abp.IdentityServer.ApiResources |
|||
{ |
|||
public class ApiResourceScope : Entity |
|||
{ |
|||
public virtual Guid ApiResourceId { get; protected set; } |
|||
|
|||
public virtual string Scope { get; set; } |
|||
|
|||
protected ApiResourceScope() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public virtual bool Equals(Guid apiResourceId, [NotNull] string scope) |
|||
{ |
|||
return ApiResourceId == apiResourceId && Scope == scope; |
|||
} |
|||
|
|||
protected internal ApiResourceScope( |
|||
Guid apiResourceId, |
|||
[NotNull] string scope) |
|||
{ |
|||
Check.NotNull(scope, nameof(scope)); |
|||
|
|||
ApiResourceId = apiResourceId; |
|||
Scope = scope; |
|||
} |
|||
|
|||
public override object[] GetKeys() |
|||
{ |
|||
return new object[] { ApiResourceId, Scope }; |
|||
} |
|||
} |
|||
} |
|||
@ -1,37 +0,0 @@ |
|||
using System; |
|||
using JetBrains.Annotations; |
|||
|
|||
namespace Volo.Abp.IdentityServer.ApiResources |
|||
{ |
|||
public class ApiScopeClaim : UserClaim |
|||
{ |
|||
public Guid ApiResourceId { get; protected set; } |
|||
|
|||
[NotNull] |
|||
public string Name { get; protected set; } |
|||
|
|||
protected ApiScopeClaim() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public virtual bool Equals(Guid apiResourceId, [NotNull] string name, [NotNull] string type) |
|||
{ |
|||
return ApiResourceId == apiResourceId && Name == name && Type == type; |
|||
} |
|||
|
|||
protected internal ApiScopeClaim(Guid apiResourceId, [NotNull] string name, [NotNull] string type) |
|||
: base(type) |
|||
{ |
|||
Check.NotNull(name, nameof(name)); |
|||
|
|||
ApiResourceId = apiResourceId; |
|||
Name = name; |
|||
} |
|||
|
|||
public override object[] GetKeys() |
|||
{ |
|||
return new object[] { ApiResourceId, Name, Type }; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
using System; |
|||
using JetBrains.Annotations; |
|||
|
|||
namespace Volo.Abp.IdentityServer.ApiScopes |
|||
{ |
|||
public class ApiScopeClaim : UserClaim |
|||
{ |
|||
public Guid ApiScopeId { get; protected set; } |
|||
|
|||
protected ApiScopeClaim() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public virtual bool Equals(Guid apiScopeId, [NotNull] string type) |
|||
{ |
|||
return ApiScopeId == apiScopeId && Type == type; |
|||
} |
|||
|
|||
protected internal ApiScopeClaim(Guid apiScopeId, [NotNull] string type) |
|||
: base(type) |
|||
{ |
|||
ApiScopeId = apiScopeId; |
|||
} |
|||
|
|||
public override object[] GetKeys() |
|||
{ |
|||
return new object[] { ApiScopeId, Type }; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
using System; |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace Volo.Abp.IdentityServer.ApiScopes |
|||
{ |
|||
public class ApiScopeProperty : Entity |
|||
{ |
|||
public virtual Guid ApiScopeId { get; set; } |
|||
|
|||
public virtual string Key { get; set; } |
|||
|
|||
public virtual string Value { get; set; } |
|||
|
|||
protected ApiScopeProperty() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public virtual bool Equals(Guid apiScopeId, [NotNull] string key, string value) |
|||
{ |
|||
return ApiScopeId == apiScopeId && Key == key && Value == value; |
|||
} |
|||
|
|||
protected internal ApiScopeProperty(Guid apiScopeId, [NotNull] string key, [NotNull] string value) |
|||
{ |
|||
Check.NotNull(key, nameof(key)); |
|||
|
|||
ApiScopeId = apiScopeId; |
|||
Key = key; |
|||
Value = value; |
|||
} |
|||
|
|||
public override object[] GetKeys() |
|||
{ |
|||
return new object[] { ApiScopeId, Key }; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace Volo.Abp.IdentityServer.ApiScopes |
|||
{ |
|||
public interface IApiScopeRepository : IBasicRepository<ApiScope, Guid> |
|||
{ |
|||
Task<ApiScope> GetByNameAsync( |
|||
string scopeName, |
|||
bool includeDetails = true, |
|||
CancellationToken cancellationToken = default |
|||
); |
|||
|
|||
Task<List<ApiScope>> GetListByNameAsync( |
|||
string[] scopeNames, |
|||
bool includeDetails = false, |
|||
CancellationToken cancellationToken = default |
|||
); |
|||
|
|||
Task<List<ApiScope>> GetListAsync( |
|||
string sorting, |
|||
int skipCount, |
|||
int maxResultCount, |
|||
string filter = null, |
|||
bool includeDetails = false, |
|||
CancellationToken cancellationToken = default |
|||
); |
|||
|
|||
Task<bool> CheckNameExistAsync( |
|||
string name, |
|||
Guid? expectedId = null, |
|||
CancellationToken cancellationToken = default |
|||
); |
|||
} |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
using System; |
|||
using System.Diagnostics.CodeAnalysis; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace Volo.Abp.IdentityServer.IdentityResources |
|||
{ |
|||
public class IdentityResourceProperty : Entity |
|||
{ |
|||
public virtual Guid IdentityResourceId { get; set; } |
|||
|
|||
public virtual string Key { get; set; } |
|||
|
|||
public virtual string Value { get; set; } |
|||
|
|||
protected IdentityResourceProperty() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public virtual bool Equals(Guid identityResourceId, [NotNull] string key, string value) |
|||
{ |
|||
return IdentityResourceId == identityResourceId && Key == key && Value == value; |
|||
} |
|||
|
|||
protected internal IdentityResourceProperty(Guid identityResourceId, [NotNull] string key, [NotNull] string value) |
|||
{ |
|||
Check.NotNull(key, nameof(key)); |
|||
|
|||
IdentityResourceId = identityResourceId; |
|||
Key = key; |
|||
Value = value; |
|||
} |
|||
|
|||
public override object[] GetKeys() |
|||
{ |
|||
return new object[] { IdentityResourceId, Key }; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,75 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Linq.Dynamic.Core; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
using Volo.Abp.IdentityServer.EntityFrameworkCore; |
|||
|
|||
namespace Volo.Abp.IdentityServer.ApiScopes |
|||
{ |
|||
public class ApiScopeRepository : EfCoreRepository<IIdentityServerDbContext, ApiScope, Guid>, IApiScopeRepository |
|||
{ |
|||
public ApiScopeRepository(IDbContextProvider<IIdentityServerDbContext> dbContextProvider) : base( |
|||
dbContextProvider) |
|||
{ |
|||
} |
|||
|
|||
public async Task<ApiScope> GetByNameAsync(string scopeName, bool includeDetails = true, CancellationToken cancellationToken = default) |
|||
{ |
|||
return await DbSet.FirstOrDefaultAsync(x => x.Name == scopeName, GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public async Task<List<ApiScope>> GetListByNameAsync(string[] scopeNames, bool includeDetails = false, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var query = from scope in DbSet.IncludeDetails(includeDetails) |
|||
where scopeNames.Contains(scope.Name) |
|||
select scope; |
|||
|
|||
return await query.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public async Task<List<ApiScope>> GetListAsync(string sorting, int skipCount, int maxResultCount, string filter = null, bool includeDetails = false, CancellationToken cancellationToken = default) |
|||
{ |
|||
return await DbSet |
|||
.IncludeDetails(includeDetails) |
|||
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter) || |
|||
x.Description.Contains(filter) || |
|||
x.DisplayName.Contains(filter)) |
|||
.OrderBy(sorting ?? "name desc") |
|||
.PageBy(skipCount, maxResultCount) |
|||
.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public async Task<bool> CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default) |
|||
{ |
|||
return await DbSet.AnyAsync(x => x.Id != expectedId && x.Name == name, GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public override async Task DeleteAsync(Guid id, bool autoSave = false, CancellationToken cancellationToken = new CancellationToken()) |
|||
{ |
|||
var scopeClaims = DbContext.Set<ApiScopeClaim>().Where(sc => sc.ApiScopeId == id); |
|||
foreach (var claim in scopeClaims) |
|||
{ |
|||
DbContext.Set<ApiScopeClaim>().Remove(claim); |
|||
} |
|||
|
|||
var scopeProperties = DbContext.Set<ApiScopeProperty>().Where(s => s.ApiScopeId == id); |
|||
foreach (var property in scopeProperties) |
|||
{ |
|||
DbContext.Set<ApiScopeProperty>().Remove(property); |
|||
} |
|||
|
|||
await base.DeleteAsync(id, autoSave, cancellationToken); |
|||
} |
|||
|
|||
public override IQueryable<ApiScope> WithDetails() |
|||
{ |
|||
return GetQueryable().IncludeDetails(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,57 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using MongoDB.Driver; |
|||
using MongoDB.Driver.Linq; |
|||
using Volo.Abp.Domain.Repositories.MongoDB; |
|||
using Volo.Abp.IdentityServer.ApiScopes; |
|||
using System.Linq.Dynamic.Core; |
|||
using Volo.Abp.MongoDB; |
|||
|
|||
namespace Volo.Abp.IdentityServer.MongoDB |
|||
{ |
|||
public class MongoApiScopeRepository : MongoDbRepository<IAbpIdentityServerMongoDbContext, ApiScope, Guid>, |
|||
IApiScopeRepository |
|||
{ |
|||
public MongoApiScopeRepository(IMongoDbContextProvider<IAbpIdentityServerMongoDbContext> dbContextProvider) : |
|||
base(dbContextProvider) |
|||
{ |
|||
} |
|||
|
|||
public async Task<ApiScope> GetByNameAsync(string scopeName, bool includeDetails = true, CancellationToken cancellationToken = default) |
|||
{ |
|||
return await GetMongoQueryable().FirstOrDefaultAsync(x => x.Name == scopeName, GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public async Task<List<ApiScope>> GetListByNameAsync(string[] scopeNames, bool includeDetails = false, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var query = from scope in GetMongoQueryable() |
|||
where scopeNames.Contains(scope.Name) |
|||
select scope; |
|||
|
|||
return await query.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public async Task<List<ApiScope>> GetListAsync(string sorting, int skipCount, int maxResultCount, string filter = null, bool includeDetails = false, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return await GetMongoQueryable() |
|||
.WhereIf(!filter.IsNullOrWhiteSpace(), |
|||
x => x.Name.Contains(filter) || |
|||
x.Description.Contains(filter) || |
|||
x.DisplayName.Contains(filter)) |
|||
.OrderBy(sorting ?? nameof(ApiScope.Name)) |
|||
.As<IMongoQueryable<ApiScope>>() |
|||
.PageBy<ApiScope, IMongoQueryable<ApiScope>>(skipCount, maxResultCount) |
|||
.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public async Task<bool> CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default) |
|||
{ |
|||
return await GetMongoQueryable().AnyAsync(x => x.Id != expectedId && x.Name == name, GetCancellationToken(cancellationToken)); |
|||
} |
|||
} |
|||
} |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue