first commit
This commit is contained in:
@ -0,0 +1,25 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="..\..\common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>KonSoft.TenantManagement</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\KonSoft.TenantManagement.Domain.Shared\KonSoft.TenantManagement.Domain.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Volo.Abp.ObjectExtending" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.Account.Application.Contracts" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.Identity.Application.Contracts" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.PermissionManagement.Application.Contracts" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.TenantManagement.Application.Contracts" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.FeatureManagement.Application.Contracts" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.SettingManagement.Application.Contracts" Version="8.3.4" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -0,0 +1,20 @@
|
||||
using KonSoft.TenantManagement.Localization;
|
||||
using Volo.Abp.Authorization.Permissions;
|
||||
using Volo.Abp.Localization;
|
||||
|
||||
namespace KonSoft.TenantManagement.Permissions;
|
||||
|
||||
public class TenantManagementPermissionDefinitionProvider : PermissionDefinitionProvider
|
||||
{
|
||||
public override void Define(IPermissionDefinitionContext context)
|
||||
{
|
||||
var myGroup = context.AddGroup(TenantManagementPermissions.GroupName);
|
||||
//Define your own permissions here. Example:
|
||||
//myGroup.AddPermission(TenantManagementPermissions.MyPermission1, L("Permission:MyPermission1"));
|
||||
}
|
||||
|
||||
private static LocalizableString L(string name)
|
||||
{
|
||||
return LocalizableString.Create<TenantManagementResource>(name);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
namespace KonSoft.TenantManagement.Permissions;
|
||||
|
||||
public static class TenantManagementPermissions
|
||||
{
|
||||
public const string GroupName = "TenantManagement";
|
||||
|
||||
//Add your own permission names. Example:
|
||||
//public const string MyPermission1 = GroupName + ".MyPermission1";
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
using Volo.Abp.Account;
|
||||
using Volo.Abp.FeatureManagement;
|
||||
using Volo.Abp.Identity;
|
||||
using Volo.Abp.Modularity;
|
||||
using Volo.Abp.ObjectExtending;
|
||||
using Volo.Abp.PermissionManagement;
|
||||
using Volo.Abp.SettingManagement;
|
||||
using Volo.Abp.TenantManagement;
|
||||
|
||||
namespace KonSoft.TenantManagement;
|
||||
|
||||
[DependsOn(
|
||||
typeof(TenantManagementDomainSharedModule),
|
||||
typeof(AbpAccountApplicationContractsModule),
|
||||
typeof(AbpFeatureManagementApplicationContractsModule),
|
||||
typeof(AbpIdentityApplicationContractsModule),
|
||||
typeof(AbpPermissionManagementApplicationContractsModule),
|
||||
typeof(AbpSettingManagementApplicationContractsModule),
|
||||
typeof(AbpTenantManagementApplicationContractsModule),
|
||||
typeof(AbpObjectExtendingModule)
|
||||
)]
|
||||
public class TenantManagementApplicationContractsModule : AbpModule
|
||||
{
|
||||
public override void PreConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
TenantManagementDtoExtensions.Configure();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
using Volo.Abp.Identity;
|
||||
using Volo.Abp.ObjectExtending;
|
||||
using Volo.Abp.Threading;
|
||||
|
||||
namespace KonSoft.TenantManagement;
|
||||
|
||||
public static class TenantManagementDtoExtensions
|
||||
{
|
||||
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();
|
||||
|
||||
public static void Configure()
|
||||
{
|
||||
OneTimeRunner.Run(() =>
|
||||
{
|
||||
/* You can add extension properties to DTOs
|
||||
* defined in the depended modules.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* ObjectExtensionManager.Instance
|
||||
* .AddOrUpdateProperty<IdentityRoleDto, string>("Title");
|
||||
*
|
||||
* See the documentation for more:
|
||||
* https://docs.abp.io/en/abp/latest/Object-Extensions
|
||||
*/
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="..\..\common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>KonSoft.TenantManagement</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\KonSoft.TenantManagement.Domain\KonSoft.TenantManagement.Domain.csproj" />
|
||||
<ProjectReference Include="..\KonSoft.TenantManagement.Application.Contracts\KonSoft.TenantManagement.Application.Contracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Volo.Abp.Account.Application" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.Identity.Application" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.PermissionManagement.Application" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.TenantManagement.Application" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.FeatureManagement.Application" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.SettingManagement.Application" Version="8.3.4" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -0,0 +1,2 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
[assembly:InternalsVisibleToAttribute("KonSoft.TenantManagement.Application.Tests")]
|
||||
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using KonSoft.TenantManagement.Localization;
|
||||
using Volo.Abp.Application.Services;
|
||||
|
||||
namespace KonSoft.TenantManagement;
|
||||
|
||||
/* Inherit your application services from this class.
|
||||
*/
|
||||
public abstract class TenantManagementAppService : ApplicationService
|
||||
{
|
||||
protected TenantManagementAppService()
|
||||
{
|
||||
LocalizationResource = typeof(TenantManagementResource);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
using AutoMapper;
|
||||
|
||||
namespace KonSoft.TenantManagement;
|
||||
|
||||
public class TenantManagementApplicationAutoMapperProfile : Profile
|
||||
{
|
||||
public TenantManagementApplicationAutoMapperProfile()
|
||||
{
|
||||
/* You can configure your AutoMapper mapping configuration here.
|
||||
* Alternatively, you can split your mapping configurations
|
||||
* into multiple profile classes for a better organization. */
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
using Volo.Abp.Account;
|
||||
using Volo.Abp.AutoMapper;
|
||||
using Volo.Abp.FeatureManagement;
|
||||
using Volo.Abp.Identity;
|
||||
using Volo.Abp.Modularity;
|
||||
using Volo.Abp.PermissionManagement;
|
||||
using Volo.Abp.SettingManagement;
|
||||
using Volo.Abp.TenantManagement;
|
||||
|
||||
namespace KonSoft.TenantManagement;
|
||||
|
||||
[DependsOn(
|
||||
typeof(TenantManagementDomainModule),
|
||||
typeof(AbpAccountApplicationModule),
|
||||
typeof(TenantManagementApplicationContractsModule),
|
||||
typeof(AbpIdentityApplicationModule),
|
||||
typeof(AbpPermissionManagementApplicationModule),
|
||||
typeof(AbpTenantManagementApplicationModule),
|
||||
typeof(AbpFeatureManagementApplicationModule),
|
||||
typeof(AbpSettingManagementApplicationModule)
|
||||
)]
|
||||
public class TenantManagementApplicationModule : AbpModule
|
||||
{
|
||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
Configure<AbpAutoMapperOptions>(options =>
|
||||
{
|
||||
options.AddMaps<TenantManagementApplicationModule>();
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="..\..\common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>KonSoft.TenantManagement</RootNamespace>
|
||||
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Volo.Abp.Identity.Domain.Shared" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.BackgroundJobs.Domain.Shared" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.AuditLogging.Domain.Shared" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.TenantManagement.Domain.Shared" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.FeatureManagement.Domain.Shared" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.PermissionManagement.Domain.Shared" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.SettingManagement.Domain.Shared" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.OpenIddict.Domain.Shared" Version="8.3.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Localization\TenantManagement\*.json" />
|
||||
<Content Remove="Localization\TenantManagement\*.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="8.0.4" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -0,0 +1,9 @@
|
||||
{
|
||||
"culture": "ar",
|
||||
"texts": {
|
||||
"AppName": "TenantManagement",
|
||||
"Menu:Home": "الصفحة الرئيسية",
|
||||
"Welcome": "مرحباً",
|
||||
"LongWelcomeMessage": "مرحبا بكم في التطبيق. هذا مشروع بدء تشغيل يعتمد على إطار عمل ABP. لمزيد من المعلومات ، يرجى زيارة abp.io."
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
{
|
||||
"culture": "cs",
|
||||
"texts": {
|
||||
"AppName": "TenantManagement",
|
||||
"Menu:Home": "Úvod",
|
||||
"Welcome": "Vítejte",
|
||||
"LongWelcomeMessage": "Vítejte v aplikaci. Toto je startovací projekt založený na ABP frameworku. Pro více informací, navštivte abp.io."
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
{
|
||||
"culture": "de",
|
||||
"texts": {
|
||||
"AppName": "TenantManagement",
|
||||
"Menu:Home": "Home",
|
||||
"Welcome": "Willkommen",
|
||||
"LongWelcomeMessage": "Willkommen bei der Anwendung. Dies ist ein Startup-Projekt, das auf dem ABP-Framework basiert. Weitere Informationen finden Sie unter abp.io."
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
{
|
||||
"culture": "en-GB",
|
||||
"texts": {
|
||||
"AppName": "TenantManagement",
|
||||
"Menu:Home": "Home",
|
||||
"Welcome": "Welcome",
|
||||
"LongWelcomeMessage": "Welcome to the application. This is a startup project based on the ABP framework. For more information, visit abp.io."
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
{
|
||||
"culture": "en",
|
||||
"texts": {
|
||||
"AppName": "TenantManagement",
|
||||
"Menu:Home": "Home",
|
||||
"Welcome": "Welcome",
|
||||
"LongWelcomeMessage": "Welcome to the application. This is a startup project based on the ABP framework. For more information, visit abp.io."
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
{
|
||||
"culture": "es",
|
||||
"texts": {
|
||||
"AppName": "TenantManagement",
|
||||
"Menu:Home": "Inicio",
|
||||
"Welcome": "Bienvenido",
|
||||
"LongWelcomeMessage": "Bienvenido a la aplicación, este es un proyecto base basado en el framework ABP. Para más información, visita abp.io."
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
{
|
||||
"culture": "fi",
|
||||
"texts": {
|
||||
"AppName": "TenantManagement",
|
||||
"Menu:Home": "Koti",
|
||||
"Welcome": "Tervetuloa",
|
||||
"LongWelcomeMessage": "Tervetuloa sovellukseen. Tämä on ABP-kehykseen perustuva käynnistysprojekti. Lisätietoja on osoitteessa abp.io."
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
{
|
||||
"culture": "fr",
|
||||
"texts": {
|
||||
"AppName": "TenantManagement",
|
||||
"Menu:Home": "Accueil",
|
||||
"Welcome": "Bienvenue",
|
||||
"LongWelcomeMessage": "Bienvenue dans l'application. Il s'agit d'un projet de démarrage basé sur le framework ABP. Pour plus d'informations, visitez abp.io."
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
{
|
||||
"culture": "hi",
|
||||
"texts": {
|
||||
"AppName": "TenantManagement",
|
||||
"Menu:Home": "घर",
|
||||
"Welcome": "स्वागत हे",
|
||||
"LongWelcomeMessage": "आवेदन करने के लिए आपका स्वागत है। यह एबीपी ढांचे पर आधारित एक स्टार्टअप परियोजना है। अधिक जानकारी के लिए, abp.io पर जाएं।"
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
{
|
||||
"culture": "hr",
|
||||
"texts": {
|
||||
"AppName": "TenantManagement",
|
||||
"Menu:Home": "Početna",
|
||||
"Welcome": "Dobrodošli",
|
||||
"LongWelcomeMessage": "Dobrodošli u aplikaciju. Ovo je startup projekt temeljen na ABP framework-u. Za više informacija posjetite abp.io."
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
{
|
||||
"culture": "hu",
|
||||
"texts": {
|
||||
"AppName": "TenantManagement",
|
||||
"Menu:Home": "Kezdőlap",
|
||||
"Welcome": "Üdvözlöm",
|
||||
"LongWelcomeMessage": "Üdvözöljük az alkalmazásban. Ez egy ABP keretrendszeren alapuló startup projekt. További információkért látogasson el az abp.io oldalra."
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
{
|
||||
"culture": "is",
|
||||
"texts": {
|
||||
"AppName": "TenantManagement",
|
||||
"Menu:Home": "Heim",
|
||||
"Welcome": "Velkomin",
|
||||
"LongWelcomeMessage": "Verið velkomin í forritið. Þetta er startup verkefni sem byggir á ABP. Nánari upplýsingar er að finna á abp.io."
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
{
|
||||
"culture": "it",
|
||||
"texts": {
|
||||
"AppName": "TenantManagement",
|
||||
"Menu:Home": "Home",
|
||||
"Welcome": "Benvenuto",
|
||||
"LongWelcomeMessage": "Benvenuto nell'applicazione. Questo è un progetto di avvio basato sul framework ABP. Per ulteriori informazioni, visita abp.io."
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
{
|
||||
"culture": "nl",
|
||||
"texts": {
|
||||
"AppName": "TenantManagement",
|
||||
"Menu:Home": "Home",
|
||||
"Welcome": "Welkom",
|
||||
"LongWelcomeMessage": "Welkom bij de applicatie. Dit is een startup-project gebaseerd op het ABP-framework. Bezoek abp.io voor meer informatie."
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
{
|
||||
"culture": "pl-PL",
|
||||
"texts": {
|
||||
"AppName": "TenantManagement",
|
||||
"Menu:Home": "Home",
|
||||
"Welcome": "Witaj",
|
||||
"LongWelcomeMessage": "Witaj w aplikacji. To jest inicjalny projekt bazujący na ABP framework. Po więcej informacji odwiedź stronę abp.io."
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
{
|
||||
"culture": "pt-BR",
|
||||
"texts": {
|
||||
"AppName": "TenantManagement",
|
||||
"Menu:Home": "Principal",
|
||||
"Welcome": "Seja bem-vindo!",
|
||||
"LongWelcomeMessage": "Bem-vindo a esta aplicação. Este é um projeto inicial baseado no ABP framework. Para mais informações, visite abp.io."
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
{
|
||||
"culture": "ro-RO",
|
||||
"texts": {
|
||||
"AppName": "TenantManagement",
|
||||
"Menu:Home": "Acasă",
|
||||
"Welcome": "Bun venit",
|
||||
"LongWelcomeMessage": "Bun venit la aplicaţie. Acesta este un proiect de pornire bazat pe framework-ul ABP. Pentru mai multe informaţii, vizitaţi, visit abp.io."
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
{
|
||||
"culture": "ru",
|
||||
"texts": {
|
||||
"AppName": "TenantManagement",
|
||||
"Menu:Home": "Главная",
|
||||
"Welcome": "Добро пожаловать",
|
||||
"LongWelcomeMessage": "Добро пожаловать в приложение. Этот запущенный проект основан на фреймворке ABP. Для получения дополнительной информации посетите сайт abp.io."
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
{
|
||||
"culture": "sk",
|
||||
"texts": {
|
||||
"AppName": "TenantManagement",
|
||||
"Menu:Home": "Domov",
|
||||
"Welcome": "Vitajte",
|
||||
"LongWelcomeMessage": "Vitajte v aplikácii. Toto je štartovací projekt založený na ABP frameworku. Viac informácií nájdete na stránke abp.io."
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
{
|
||||
"culture": "sl",
|
||||
"texts": {
|
||||
"AppName": "TenantManagement",
|
||||
"Menu:Home": "Domov",
|
||||
"Welcome": "Dobrodošli",
|
||||
"LongWelcomeMessage": "Dobrodošli v aplikaciji. To je začetni projekt na osnovi okolja ABP. Za več informacij obiščite abp.io."
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
{
|
||||
"culture": "sv",
|
||||
"texts": {
|
||||
"AppName": "MittProjektNamn",
|
||||
"Menu:Home": "Hem",
|
||||
"Welcome": "Välkommen",
|
||||
"LongWelcomeMessage": "Välkommen till applikationen. Detta är ett startup-projekt baserat på ABP-ramverket. För mer information, besök abp.io."
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
{
|
||||
"culture": "tr",
|
||||
"texts": {
|
||||
"AppName": "TenantManagement",
|
||||
"Menu:Home": "Ana sayfa",
|
||||
"Welcome": "Hoşgeldiniz",
|
||||
"LongWelcomeMessage": "Uygulamaya hoşgeldiniz. Bu, ABP framework'ü üzerine bina edilmiş bir başlangıç projesidir. Daha fazla bilgi için abp.io adresini ziyaret edebilirsiniz."
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
{
|
||||
"culture": "vi",
|
||||
"texts": {
|
||||
"AppName": "TenantManagement",
|
||||
"Menu:Home": "Trang chủ",
|
||||
"Welcome": "Chào mừng bạn",
|
||||
"LongWelcomeMessage": "Chào mừng bạn đến ứng dụng. Đây là một dự án khởi nghiệp dựa trên khung ABP. Để biết thêm thông tin, hãy truy cập abp.io."
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
{
|
||||
"culture": "zh-Hans",
|
||||
"texts": {
|
||||
"AppName": "TenantManagement",
|
||||
"Menu:Home": "首页",
|
||||
"Welcome": "欢迎",
|
||||
"LongWelcomeMessage": "欢迎使用本应用程序。这是一个基于 ABP 框架的启动项目。更多信息,请访问 abp.io。"
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
{
|
||||
"culture": "zh-Hant",
|
||||
"texts": {
|
||||
"AppName": "TenantManagement",
|
||||
"Menu:Home": "首頁",
|
||||
"Welcome": "歡迎",
|
||||
"LongWelcomeMessage": "歡迎來到此應用程式. 這是一個基於ABP框架的起始專案. 有關更多訊息, 請瀏覽 abp.io."
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
using Volo.Abp.Localization;
|
||||
|
||||
namespace KonSoft.TenantManagement.Localization;
|
||||
|
||||
[LocalizationResourceName("TenantManagement")]
|
||||
public class TenantManagementResource
|
||||
{
|
||||
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
namespace KonSoft.TenantManagement.MultiTenancy;
|
||||
|
||||
public static class MultiTenancyConsts
|
||||
{
|
||||
/* Enable/disable multi-tenancy easily in a single point.
|
||||
* If you will never need to multi-tenancy, you can remove
|
||||
* related modules and code parts, including this file.
|
||||
*/
|
||||
public const bool IsEnabled = true;
|
||||
}
|
||||
@ -0,0 +1,6 @@
|
||||
namespace KonSoft.TenantManagement;
|
||||
|
||||
public static class TenantManagementDomainErrorCodes
|
||||
{
|
||||
/* You can add your business exception error codes here, as constants */
|
||||
}
|
||||
@ -0,0 +1,58 @@
|
||||
using KonSoft.TenantManagement.Localization;
|
||||
using Volo.Abp.AuditLogging;
|
||||
using Volo.Abp.BackgroundJobs;
|
||||
using Volo.Abp.FeatureManagement;
|
||||
using Volo.Abp.Identity;
|
||||
using Volo.Abp.Localization;
|
||||
using Volo.Abp.Localization.ExceptionHandling;
|
||||
using Volo.Abp.Modularity;
|
||||
using Volo.Abp.OpenIddict;
|
||||
using Volo.Abp.PermissionManagement;
|
||||
using Volo.Abp.SettingManagement;
|
||||
using Volo.Abp.TenantManagement;
|
||||
using Volo.Abp.Validation.Localization;
|
||||
using Volo.Abp.VirtualFileSystem;
|
||||
|
||||
namespace KonSoft.TenantManagement;
|
||||
|
||||
[DependsOn(
|
||||
typeof(AbpAuditLoggingDomainSharedModule),
|
||||
typeof(AbpBackgroundJobsDomainSharedModule),
|
||||
typeof(AbpFeatureManagementDomainSharedModule),
|
||||
typeof(AbpIdentityDomainSharedModule),
|
||||
typeof(AbpOpenIddictDomainSharedModule),
|
||||
typeof(AbpPermissionManagementDomainSharedModule),
|
||||
typeof(AbpSettingManagementDomainSharedModule),
|
||||
typeof(AbpTenantManagementDomainSharedModule)
|
||||
)]
|
||||
public class TenantManagementDomainSharedModule : AbpModule
|
||||
{
|
||||
public override void PreConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
TenantManagementGlobalFeatureConfigurator.Configure();
|
||||
TenantManagementModuleExtensionConfigurator.Configure();
|
||||
}
|
||||
|
||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
Configure<AbpVirtualFileSystemOptions>(options =>
|
||||
{
|
||||
options.FileSets.AddEmbedded<TenantManagementDomainSharedModule>();
|
||||
});
|
||||
|
||||
Configure<AbpLocalizationOptions>(options =>
|
||||
{
|
||||
options.Resources
|
||||
.Add<TenantManagementResource>("en")
|
||||
.AddBaseTypes(typeof(AbpValidationResource))
|
||||
.AddVirtualJson("/Localization/TenantManagement");
|
||||
|
||||
options.DefaultResourceType = typeof(TenantManagementResource);
|
||||
});
|
||||
|
||||
Configure<AbpExceptionLocalizationOptions>(options =>
|
||||
{
|
||||
options.MapCodeNamespace("TenantManagement", typeof(TenantManagementResource));
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
using Volo.Abp.Threading;
|
||||
|
||||
namespace KonSoft.TenantManagement;
|
||||
|
||||
public static class TenantManagementGlobalFeatureConfigurator
|
||||
{
|
||||
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();
|
||||
|
||||
public static void Configure()
|
||||
{
|
||||
OneTimeRunner.Run(() =>
|
||||
{
|
||||
/* You can configure (enable/disable) global features of the used modules here.
|
||||
*
|
||||
* YOU CAN SAFELY DELETE THIS CLASS AND REMOVE ITS USAGES IF YOU DON'T NEED TO IT!
|
||||
*
|
||||
* Please refer to the documentation to lear more about the Global Features System:
|
||||
* https://docs.abp.io/en/abp/latest/Global-Features
|
||||
*/
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,73 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Volo.Abp.Identity;
|
||||
using Volo.Abp.ObjectExtending;
|
||||
using Volo.Abp.Threading;
|
||||
|
||||
namespace KonSoft.TenantManagement;
|
||||
|
||||
public static class TenantManagementModuleExtensionConfigurator
|
||||
{
|
||||
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();
|
||||
|
||||
public static void Configure()
|
||||
{
|
||||
OneTimeRunner.Run(() =>
|
||||
{
|
||||
ConfigureExistingProperties();
|
||||
ConfigureExtraProperties();
|
||||
});
|
||||
}
|
||||
|
||||
private static void ConfigureExistingProperties()
|
||||
{
|
||||
/* You can change max lengths for properties of the
|
||||
* entities defined in the modules used by your application.
|
||||
*
|
||||
* Example: Change user and role name max lengths
|
||||
|
||||
AbpUserConsts.MaxNameLength = 99;
|
||||
IdentityRoleConsts.MaxNameLength = 99;
|
||||
|
||||
* Notice: It is not suggested to change property lengths
|
||||
* unless you really need it. Go with the standard values wherever possible.
|
||||
*
|
||||
* If you are using EF Core, you will need to run the add-migration command after your changes.
|
||||
*/
|
||||
}
|
||||
|
||||
private static void ConfigureExtraProperties()
|
||||
{
|
||||
/* You can configure extra properties for the
|
||||
* entities defined in the modules used by your application.
|
||||
*
|
||||
* This class can be used to define these extra properties
|
||||
* with a high level, easy to use API.
|
||||
*
|
||||
* Example: Add a new property to the user entity of the identity module
|
||||
|
||||
ObjectExtensionManager.Instance.Modules()
|
||||
.ConfigureIdentity(identity =>
|
||||
{
|
||||
identity.ConfigureUser(user =>
|
||||
{
|
||||
user.AddOrUpdateProperty<string>( //property type: string
|
||||
"SocialSecurityNumber", //property name
|
||||
property =>
|
||||
{
|
||||
//validation rules
|
||||
property.Attributes.Add(new RequiredAttribute());
|
||||
property.Attributes.Add(new StringLengthAttribute(64) {MinimumLength = 4});
|
||||
|
||||
property.Configuration[IdentityModuleExtensionConsts.ConfigurationNames.AllowUserToEdit] = true;
|
||||
|
||||
//...other configurations for this property
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
* See the documentation for more:
|
||||
* https://docs.abp.io/en/abp/latest/Module-Entity-Extensions
|
||||
*/
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KonSoft.TenantManagement.Data;
|
||||
|
||||
public interface ITenantManagementDbSchemaMigrator
|
||||
{
|
||||
Task MigrateAsync();
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
|
||||
namespace KonSoft.TenantManagement.Data;
|
||||
|
||||
/* This is used if database provider does't define
|
||||
* ITenantManagementDbSchemaMigrator implementation.
|
||||
*/
|
||||
public class NullTenantManagementDbSchemaMigrator : ITenantManagementDbSchemaMigrator, ITransientDependency
|
||||
{
|
||||
public Task MigrateAsync()
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,218 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Volo.Abp.Data;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
using Volo.Abp.Identity;
|
||||
using Volo.Abp.MultiTenancy;
|
||||
using Volo.Abp.TenantManagement;
|
||||
|
||||
namespace KonSoft.TenantManagement.Data;
|
||||
|
||||
public class TenantManagementDbMigrationService : ITransientDependency
|
||||
{
|
||||
public ILogger<TenantManagementDbMigrationService> Logger { get; set; }
|
||||
|
||||
private readonly IDataSeeder _dataSeeder;
|
||||
private readonly IEnumerable<ITenantManagementDbSchemaMigrator> _dbSchemaMigrators;
|
||||
private readonly ITenantRepository _tenantRepository;
|
||||
private readonly ICurrentTenant _currentTenant;
|
||||
|
||||
public TenantManagementDbMigrationService(
|
||||
IDataSeeder dataSeeder,
|
||||
IEnumerable<ITenantManagementDbSchemaMigrator> dbSchemaMigrators,
|
||||
ITenantRepository tenantRepository,
|
||||
ICurrentTenant currentTenant)
|
||||
{
|
||||
_dataSeeder = dataSeeder;
|
||||
_dbSchemaMigrators = dbSchemaMigrators;
|
||||
_tenantRepository = tenantRepository;
|
||||
_currentTenant = currentTenant;
|
||||
|
||||
Logger = NullLogger<TenantManagementDbMigrationService>.Instance;
|
||||
}
|
||||
|
||||
public async Task MigrateAsync()
|
||||
{
|
||||
var initialMigrationAdded = AddInitialMigrationIfNotExist();
|
||||
|
||||
if (initialMigrationAdded)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.LogInformation("Started database migrations...");
|
||||
|
||||
await MigrateDatabaseSchemaAsync();
|
||||
await SeedDataAsync();
|
||||
|
||||
Logger.LogInformation($"Successfully completed host database migrations.");
|
||||
|
||||
var tenants = await _tenantRepository.GetListAsync(includeDetails: true);
|
||||
|
||||
var migratedDatabaseSchemas = new HashSet<string>();
|
||||
foreach (var tenant in tenants)
|
||||
{
|
||||
using (_currentTenant.Change(tenant.Id))
|
||||
{
|
||||
if (tenant.ConnectionStrings.Any())
|
||||
{
|
||||
var tenantConnectionStrings = tenant.ConnectionStrings
|
||||
.Select(x => x.Value)
|
||||
.ToList();
|
||||
|
||||
if (!migratedDatabaseSchemas.IsSupersetOf(tenantConnectionStrings))
|
||||
{
|
||||
await MigrateDatabaseSchemaAsync(tenant);
|
||||
|
||||
migratedDatabaseSchemas.AddIfNotContains(tenantConnectionStrings);
|
||||
}
|
||||
}
|
||||
|
||||
await SeedDataAsync(tenant);
|
||||
}
|
||||
|
||||
Logger.LogInformation($"Successfully completed {tenant.Name} tenant database migrations.");
|
||||
}
|
||||
|
||||
Logger.LogInformation("Successfully completed all database migrations.");
|
||||
Logger.LogInformation("You can safely end this process...");
|
||||
}
|
||||
|
||||
private async Task MigrateDatabaseSchemaAsync(Tenant? tenant = null)
|
||||
{
|
||||
Logger.LogInformation(
|
||||
$"Migrating schema for {(tenant == null ? "host" : tenant.Name + " tenant")} database...");
|
||||
|
||||
foreach (var migrator in _dbSchemaMigrators)
|
||||
{
|
||||
await migrator.MigrateAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SeedDataAsync(Tenant? tenant = null)
|
||||
{
|
||||
Logger.LogInformation($"Executing {(tenant == null ? "host" : tenant.Name + " tenant")} database seed...");
|
||||
|
||||
await _dataSeeder.SeedAsync(new DataSeedContext(tenant?.Id)
|
||||
.WithProperty(IdentityDataSeedContributor.AdminEmailPropertyName, IdentityDataSeedContributor.AdminEmailDefaultValue)
|
||||
.WithProperty(IdentityDataSeedContributor.AdminPasswordPropertyName, IdentityDataSeedContributor.AdminPasswordDefaultValue)
|
||||
);
|
||||
}
|
||||
|
||||
private bool AddInitialMigrationIfNotExist()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!DbMigrationsProjectExists())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (!MigrationsFolderExists())
|
||||
{
|
||||
AddInitialMigration();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogWarning("Couldn't determinate if any migrations exist : " + e.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private bool DbMigrationsProjectExists()
|
||||
{
|
||||
var dbMigrationsProjectFolder = GetEntityFrameworkCoreProjectFolderPath();
|
||||
|
||||
return dbMigrationsProjectFolder != null;
|
||||
}
|
||||
|
||||
private bool MigrationsFolderExists()
|
||||
{
|
||||
var dbMigrationsProjectFolder = GetEntityFrameworkCoreProjectFolderPath();
|
||||
return dbMigrationsProjectFolder != null && Directory.Exists(Path.Combine(dbMigrationsProjectFolder, "Migrations"));
|
||||
}
|
||||
|
||||
private void AddInitialMigration()
|
||||
{
|
||||
Logger.LogInformation("Creating initial migration...");
|
||||
|
||||
string argumentPrefix;
|
||||
string fileName;
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
argumentPrefix = "-c";
|
||||
fileName = "/bin/bash";
|
||||
}
|
||||
else
|
||||
{
|
||||
argumentPrefix = "/C";
|
||||
fileName = "cmd.exe";
|
||||
}
|
||||
|
||||
var procStartInfo = new ProcessStartInfo(fileName,
|
||||
$"{argumentPrefix} \"abp create-migration-and-run-migrator \"{GetEntityFrameworkCoreProjectFolderPath()}\"\""
|
||||
);
|
||||
|
||||
try
|
||||
{
|
||||
Process.Start(procStartInfo);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw new Exception("Couldn't run ABP CLI...");
|
||||
}
|
||||
}
|
||||
|
||||
private string? GetEntityFrameworkCoreProjectFolderPath()
|
||||
{
|
||||
var slnDirectoryPath = GetSolutionDirectoryPath();
|
||||
|
||||
if (slnDirectoryPath == null)
|
||||
{
|
||||
throw new Exception("Solution folder not found!");
|
||||
}
|
||||
|
||||
var srcDirectoryPath = Path.Combine(slnDirectoryPath, "src");
|
||||
|
||||
return Directory.GetDirectories(srcDirectoryPath)
|
||||
.FirstOrDefault(d => d.EndsWith(".EntityFrameworkCore"));
|
||||
}
|
||||
|
||||
private string? GetSolutionDirectoryPath()
|
||||
{
|
||||
var currentDirectory = new DirectoryInfo(Directory.GetCurrentDirectory());
|
||||
|
||||
while (currentDirectory != null && Directory.GetParent(currentDirectory.FullName) != null)
|
||||
{
|
||||
currentDirectory = Directory.GetParent(currentDirectory.FullName);
|
||||
|
||||
if (currentDirectory != null && Directory.GetFiles(currentDirectory.FullName).FirstOrDefault(f => f.EndsWith(".sln")) != null)
|
||||
{
|
||||
return currentDirectory.FullName;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="..\..\common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>KonSoft.TenantManagement</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\KonSoft.TenantManagement.Domain.Shared\KonSoft.TenantManagement.Domain.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Volo.Abp.Emailing" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.Identity.Domain" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.PermissionManagement.Domain.Identity" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.BackgroundJobs.Domain" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.AuditLogging.Domain" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.TenantManagement.Domain" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.FeatureManagement.Domain" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.SettingManagement.Domain" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.OpenIddict.Domain" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.PermissionManagement.Domain.OpenIddict" Version="8.3.4" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -0,0 +1,327 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using OpenIddict.Abstractions;
|
||||
using Volo.Abp;
|
||||
using Volo.Abp.Authorization.Permissions;
|
||||
using Volo.Abp.Data;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
using Volo.Abp.OpenIddict.Applications;
|
||||
using Volo.Abp.OpenIddict.Scopes;
|
||||
using Volo.Abp.PermissionManagement;
|
||||
using Volo.Abp.Uow;
|
||||
|
||||
namespace KonSoft.TenantManagement.OpenIddict;
|
||||
|
||||
/* Creates initial data that is needed to property run the application
|
||||
* and make client-to-server communication possible.
|
||||
*/
|
||||
public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDependency
|
||||
{
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly IOpenIddictApplicationRepository _openIddictApplicationRepository;
|
||||
private readonly IAbpApplicationManager _applicationManager;
|
||||
private readonly IOpenIddictScopeRepository _openIddictScopeRepository;
|
||||
private readonly IOpenIddictScopeManager _scopeManager;
|
||||
private readonly IPermissionDataSeeder _permissionDataSeeder;
|
||||
private readonly IStringLocalizer<OpenIddictResponse> L;
|
||||
|
||||
public OpenIddictDataSeedContributor(
|
||||
IConfiguration configuration,
|
||||
IOpenIddictApplicationRepository openIddictApplicationRepository,
|
||||
IAbpApplicationManager applicationManager,
|
||||
IOpenIddictScopeRepository openIddictScopeRepository,
|
||||
IOpenIddictScopeManager scopeManager,
|
||||
IPermissionDataSeeder permissionDataSeeder,
|
||||
IStringLocalizer<OpenIddictResponse> l )
|
||||
{
|
||||
_configuration = configuration;
|
||||
_openIddictApplicationRepository = openIddictApplicationRepository;
|
||||
_applicationManager = applicationManager;
|
||||
_openIddictScopeRepository = openIddictScopeRepository;
|
||||
_scopeManager = scopeManager;
|
||||
_permissionDataSeeder = permissionDataSeeder;
|
||||
L = l;
|
||||
}
|
||||
|
||||
[UnitOfWork]
|
||||
public virtual async Task SeedAsync(DataSeedContext context)
|
||||
{
|
||||
await CreateScopesAsync();
|
||||
await CreateApplicationsAsync();
|
||||
}
|
||||
|
||||
private async Task CreateScopesAsync()
|
||||
{
|
||||
if (await _openIddictScopeRepository.FindByNameAsync("TenantManagement") == null)
|
||||
{
|
||||
await _scopeManager.CreateAsync(new OpenIddictScopeDescriptor {
|
||||
Name = "TenantManagement", DisplayName = "TenantManagement API", Resources = { "TenantManagement" }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private async Task CreateApplicationsAsync()
|
||||
{
|
||||
var commonScopes = new List<string> {
|
||||
OpenIddictConstants.Permissions.Scopes.Address,
|
||||
OpenIddictConstants.Permissions.Scopes.Email,
|
||||
OpenIddictConstants.Permissions.Scopes.Phone,
|
||||
OpenIddictConstants.Permissions.Scopes.Profile,
|
||||
OpenIddictConstants.Permissions.Scopes.Roles,
|
||||
"TenantManagement"
|
||||
};
|
||||
|
||||
var configurationSection = _configuration.GetSection("OpenIddict:Applications");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Swagger Client
|
||||
var swaggerClientId = configurationSection["TenantManagement_Swagger:ClientId"];
|
||||
if (!swaggerClientId.IsNullOrWhiteSpace())
|
||||
{
|
||||
var swaggerRootUrl = configurationSection["TenantManagement_Swagger:RootUrl"]?.TrimEnd('/');
|
||||
|
||||
await CreateApplicationAsync(
|
||||
name: swaggerClientId!,
|
||||
type: OpenIddictConstants.ClientTypes.Public,
|
||||
consentType: OpenIddictConstants.ConsentTypes.Implicit,
|
||||
displayName: "Swagger Application",
|
||||
secret: null,
|
||||
grantTypes: new List<string> { OpenIddictConstants.GrantTypes.AuthorizationCode, },
|
||||
scopes: commonScopes,
|
||||
redirectUri: $"{swaggerRootUrl}/swagger/oauth2-redirect.html",
|
||||
clientUri: swaggerRootUrl
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task CreateApplicationAsync(
|
||||
[NotNull] string name,
|
||||
[NotNull] string type,
|
||||
[NotNull] string consentType,
|
||||
string displayName,
|
||||
string? secret,
|
||||
List<string> grantTypes,
|
||||
List<string> scopes,
|
||||
string? clientUri = null,
|
||||
string? redirectUri = null,
|
||||
string? postLogoutRedirectUri = null,
|
||||
List<string>? permissions = null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(secret) && string.Equals(type, OpenIddictConstants.ClientTypes.Public,
|
||||
StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
throw new BusinessException(L["NoClientSecretCanBeSetForPublicApplications"]);
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(secret) && string.Equals(type, OpenIddictConstants.ClientTypes.Confidential,
|
||||
StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
throw new BusinessException(L["TheClientSecretIsRequiredForConfidentialApplications"]);
|
||||
}
|
||||
|
||||
var client = await _openIddictApplicationRepository.FindByClientIdAsync(name);
|
||||
|
||||
var application = new AbpApplicationDescriptor {
|
||||
ClientId = name,
|
||||
ClientType = type,
|
||||
ClientSecret = secret,
|
||||
ConsentType = consentType,
|
||||
DisplayName = displayName,
|
||||
ClientUri = clientUri,
|
||||
};
|
||||
|
||||
Check.NotNullOrEmpty(grantTypes, nameof(grantTypes));
|
||||
Check.NotNullOrEmpty(scopes, nameof(scopes));
|
||||
|
||||
if (new[] { OpenIddictConstants.GrantTypes.AuthorizationCode, OpenIddictConstants.GrantTypes.Implicit }.All(
|
||||
grantTypes.Contains))
|
||||
{
|
||||
application.Permissions.Add(OpenIddictConstants.Permissions.ResponseTypes.CodeIdToken);
|
||||
|
||||
if (string.Equals(type, OpenIddictConstants.ClientTypes.Public, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
application.Permissions.Add(OpenIddictConstants.Permissions.ResponseTypes.CodeIdTokenToken);
|
||||
application.Permissions.Add(OpenIddictConstants.Permissions.ResponseTypes.CodeToken);
|
||||
}
|
||||
}
|
||||
|
||||
if (!redirectUri.IsNullOrWhiteSpace() || !postLogoutRedirectUri.IsNullOrWhiteSpace())
|
||||
{
|
||||
application.Permissions.Add(OpenIddictConstants.Permissions.Endpoints.Logout);
|
||||
}
|
||||
|
||||
var buildInGrantTypes = new[] {
|
||||
OpenIddictConstants.GrantTypes.Implicit, OpenIddictConstants.GrantTypes.Password,
|
||||
OpenIddictConstants.GrantTypes.AuthorizationCode, OpenIddictConstants.GrantTypes.ClientCredentials,
|
||||
OpenIddictConstants.GrantTypes.DeviceCode, OpenIddictConstants.GrantTypes.RefreshToken
|
||||
};
|
||||
|
||||
foreach (var grantType in grantTypes)
|
||||
{
|
||||
if (grantType == OpenIddictConstants.GrantTypes.AuthorizationCode)
|
||||
{
|
||||
application.Permissions.Add(OpenIddictConstants.Permissions.GrantTypes.AuthorizationCode);
|
||||
application.Permissions.Add(OpenIddictConstants.Permissions.ResponseTypes.Code);
|
||||
}
|
||||
|
||||
if (grantType == OpenIddictConstants.GrantTypes.AuthorizationCode ||
|
||||
grantType == OpenIddictConstants.GrantTypes.Implicit)
|
||||
{
|
||||
application.Permissions.Add(OpenIddictConstants.Permissions.Endpoints.Authorization);
|
||||
}
|
||||
|
||||
if (grantType == OpenIddictConstants.GrantTypes.AuthorizationCode ||
|
||||
grantType == OpenIddictConstants.GrantTypes.ClientCredentials ||
|
||||
grantType == OpenIddictConstants.GrantTypes.Password ||
|
||||
grantType == OpenIddictConstants.GrantTypes.RefreshToken ||
|
||||
grantType == OpenIddictConstants.GrantTypes.DeviceCode)
|
||||
{
|
||||
application.Permissions.Add(OpenIddictConstants.Permissions.Endpoints.Token);
|
||||
application.Permissions.Add(OpenIddictConstants.Permissions.Endpoints.Revocation);
|
||||
application.Permissions.Add(OpenIddictConstants.Permissions.Endpoints.Introspection);
|
||||
}
|
||||
|
||||
if (grantType == OpenIddictConstants.GrantTypes.ClientCredentials)
|
||||
{
|
||||
application.Permissions.Add(OpenIddictConstants.Permissions.GrantTypes.ClientCredentials);
|
||||
}
|
||||
|
||||
if (grantType == OpenIddictConstants.GrantTypes.Implicit)
|
||||
{
|
||||
application.Permissions.Add(OpenIddictConstants.Permissions.GrantTypes.Implicit);
|
||||
}
|
||||
|
||||
if (grantType == OpenIddictConstants.GrantTypes.Password)
|
||||
{
|
||||
application.Permissions.Add(OpenIddictConstants.Permissions.GrantTypes.Password);
|
||||
}
|
||||
|
||||
if (grantType == OpenIddictConstants.GrantTypes.RefreshToken)
|
||||
{
|
||||
application.Permissions.Add(OpenIddictConstants.Permissions.GrantTypes.RefreshToken);
|
||||
}
|
||||
|
||||
if (grantType == OpenIddictConstants.GrantTypes.DeviceCode)
|
||||
{
|
||||
application.Permissions.Add(OpenIddictConstants.Permissions.GrantTypes.DeviceCode);
|
||||
application.Permissions.Add(OpenIddictConstants.Permissions.Endpoints.Device);
|
||||
}
|
||||
|
||||
if (grantType == OpenIddictConstants.GrantTypes.Implicit)
|
||||
{
|
||||
application.Permissions.Add(OpenIddictConstants.Permissions.ResponseTypes.IdToken);
|
||||
if (string.Equals(type, OpenIddictConstants.ClientTypes.Public, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
application.Permissions.Add(OpenIddictConstants.Permissions.ResponseTypes.IdTokenToken);
|
||||
application.Permissions.Add(OpenIddictConstants.Permissions.ResponseTypes.Token);
|
||||
}
|
||||
}
|
||||
|
||||
if (!buildInGrantTypes.Contains(grantType))
|
||||
{
|
||||
application.Permissions.Add(OpenIddictConstants.Permissions.Prefixes.GrantType + grantType);
|
||||
}
|
||||
}
|
||||
|
||||
var buildInScopes = new[] {
|
||||
OpenIddictConstants.Permissions.Scopes.Address, OpenIddictConstants.Permissions.Scopes.Email,
|
||||
OpenIddictConstants.Permissions.Scopes.Phone, OpenIddictConstants.Permissions.Scopes.Profile,
|
||||
OpenIddictConstants.Permissions.Scopes.Roles
|
||||
};
|
||||
|
||||
foreach (var scope in scopes)
|
||||
{
|
||||
if (buildInScopes.Contains(scope))
|
||||
{
|
||||
application.Permissions.Add(scope);
|
||||
}
|
||||
else
|
||||
{
|
||||
application.Permissions.Add(OpenIddictConstants.Permissions.Prefixes.Scope + scope);
|
||||
}
|
||||
}
|
||||
|
||||
if (redirectUri != null)
|
||||
{
|
||||
if (!redirectUri.IsNullOrEmpty())
|
||||
{
|
||||
if (!Uri.TryCreate(redirectUri, UriKind.Absolute, out var uri) || !uri.IsWellFormedOriginalString())
|
||||
{
|
||||
throw new BusinessException(L["InvalidRedirectUri", redirectUri]);
|
||||
}
|
||||
|
||||
if (application.RedirectUris.All(x => x != uri))
|
||||
{
|
||||
application.RedirectUris.Add(uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (postLogoutRedirectUri != null)
|
||||
{
|
||||
if (!postLogoutRedirectUri.IsNullOrEmpty())
|
||||
{
|
||||
if (!Uri.TryCreate(postLogoutRedirectUri, UriKind.Absolute, out var uri) ||
|
||||
!uri.IsWellFormedOriginalString())
|
||||
{
|
||||
throw new BusinessException(L["InvalidPostLogoutRedirectUri", postLogoutRedirectUri]);
|
||||
}
|
||||
|
||||
if (application.PostLogoutRedirectUris.All(x => x != uri))
|
||||
{
|
||||
application.PostLogoutRedirectUris.Add(uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (permissions != null)
|
||||
{
|
||||
await _permissionDataSeeder.SeedAsync(
|
||||
ClientPermissionValueProvider.ProviderName,
|
||||
name,
|
||||
permissions,
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
if (client == null)
|
||||
{
|
||||
await _applicationManager.CreateAsync(application);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!HasSameRedirectUris(client, application))
|
||||
{
|
||||
client.RedirectUris = JsonSerializer.Serialize(application.RedirectUris.Select(q => q.ToString().TrimEnd('/')));
|
||||
client.PostLogoutRedirectUris = JsonSerializer.Serialize(application.PostLogoutRedirectUris.Select(q => q.ToString().TrimEnd('/')));
|
||||
|
||||
await _applicationManager.UpdateAsync(client.ToModel());
|
||||
}
|
||||
|
||||
if (!HasSameScopes(client, application))
|
||||
{
|
||||
client.Permissions = JsonSerializer.Serialize(application.Permissions.Select(q => q.ToString()));
|
||||
await _applicationManager.UpdateAsync(client.ToModel());
|
||||
}
|
||||
}
|
||||
|
||||
private bool HasSameRedirectUris(OpenIddictApplication existingClient, AbpApplicationDescriptor application)
|
||||
{
|
||||
return existingClient.RedirectUris == JsonSerializer.Serialize(application.RedirectUris.Select(q => q.ToString().TrimEnd('/')));
|
||||
}
|
||||
|
||||
private bool HasSameScopes(OpenIddictApplication existingClient, AbpApplicationDescriptor application)
|
||||
{
|
||||
return existingClient.Permissions == JsonSerializer.Serialize(application.Permissions.Select(q => q.ToString().TrimEnd('/')));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
[assembly:InternalsVisibleToAttribute("KonSoft.TenantManagement.Domain.Tests")]
|
||||
[assembly:InternalsVisibleToAttribute("KonSoft.TenantManagement.TestBase")]
|
||||
@ -0,0 +1,12 @@
|
||||
using Volo.Abp.Settings;
|
||||
|
||||
namespace KonSoft.TenantManagement.Settings;
|
||||
|
||||
public class TenantManagementSettingDefinitionProvider : SettingDefinitionProvider
|
||||
{
|
||||
public override void Define(ISettingDefinitionContext context)
|
||||
{
|
||||
//Define your own settings here. Example:
|
||||
//context.Add(new SettingDefinition(TenantManagementSettings.MySetting1));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
namespace KonSoft.TenantManagement.Settings;
|
||||
|
||||
public static class TenantManagementSettings
|
||||
{
|
||||
private const string Prefix = "TenantManagement";
|
||||
|
||||
//Add your own setting names here. Example:
|
||||
//public const string MySetting1 = Prefix + ".MySetting1";
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
namespace KonSoft.TenantManagement;
|
||||
|
||||
public static class TenantManagementConsts
|
||||
{
|
||||
public const string DbTablePrefix = "App";
|
||||
|
||||
public const string DbSchema = null;
|
||||
}
|
||||
@ -0,0 +1,68 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using KonSoft.TenantManagement.MultiTenancy;
|
||||
using Volo.Abp.AuditLogging;
|
||||
using Volo.Abp.BackgroundJobs;
|
||||
using Volo.Abp.Emailing;
|
||||
using Volo.Abp.FeatureManagement;
|
||||
using Volo.Abp.Identity;
|
||||
using Volo.Abp.Localization;
|
||||
using Volo.Abp.Modularity;
|
||||
using Volo.Abp.MultiTenancy;
|
||||
using Volo.Abp.OpenIddict;
|
||||
using Volo.Abp.PermissionManagement.Identity;
|
||||
using Volo.Abp.PermissionManagement.OpenIddict;
|
||||
using Volo.Abp.SettingManagement;
|
||||
using Volo.Abp.TenantManagement;
|
||||
|
||||
namespace KonSoft.TenantManagement;
|
||||
|
||||
[DependsOn(
|
||||
typeof(TenantManagementDomainSharedModule),
|
||||
typeof(AbpAuditLoggingDomainModule),
|
||||
typeof(AbpBackgroundJobsDomainModule),
|
||||
typeof(AbpFeatureManagementDomainModule),
|
||||
typeof(AbpIdentityDomainModule),
|
||||
typeof(AbpOpenIddictDomainModule),
|
||||
typeof(AbpPermissionManagementDomainOpenIddictModule),
|
||||
typeof(AbpPermissionManagementDomainIdentityModule),
|
||||
typeof(AbpSettingManagementDomainModule),
|
||||
typeof(AbpTenantManagementDomainModule),
|
||||
typeof(AbpEmailingModule)
|
||||
)]
|
||||
public class TenantManagementDomainModule : AbpModule
|
||||
{
|
||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
Configure<AbpLocalizationOptions>(options =>
|
||||
{
|
||||
options.Languages.Add(new LanguageInfo("ar", "ar", "العربية"));
|
||||
options.Languages.Add(new LanguageInfo("cs", "cs", "Čeština"));
|
||||
options.Languages.Add(new LanguageInfo("en", "en", "English"));
|
||||
options.Languages.Add(new LanguageInfo("en-GB", "en-GB", "English (UK)"));
|
||||
options.Languages.Add(new LanguageInfo("hu", "hu", "Magyar"));
|
||||
options.Languages.Add(new LanguageInfo("hr", "hr", "Croatian"));
|
||||
options.Languages.Add(new LanguageInfo("fi", "fi", "Finnish"));
|
||||
options.Languages.Add(new LanguageInfo("fr", "fr", "Français"));
|
||||
options.Languages.Add(new LanguageInfo("hi", "hi", "Hindi"));
|
||||
options.Languages.Add(new LanguageInfo("it", "it", "Italiano"));
|
||||
options.Languages.Add(new LanguageInfo("pt-BR", "pt-BR", "Português"));
|
||||
options.Languages.Add(new LanguageInfo("ru", "ru", "Русский"));
|
||||
options.Languages.Add(new LanguageInfo("sk", "sk", "Slovak"));
|
||||
options.Languages.Add(new LanguageInfo("tr", "tr", "Türkçe"));
|
||||
options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文"));
|
||||
options.Languages.Add(new LanguageInfo("zh-Hant", "zh-Hant", "繁體中文"));
|
||||
options.Languages.Add(new LanguageInfo("de-DE", "de-DE", "Deutsch"));
|
||||
options.Languages.Add(new LanguageInfo("es", "es", "Español"));
|
||||
});
|
||||
|
||||
Configure<AbpMultiTenancyOptions>(options =>
|
||||
{
|
||||
options.IsEnabled = MultiTenancyConsts.IsEnabled;
|
||||
});
|
||||
|
||||
#if DEBUG
|
||||
context.Services.Replace(ServiceDescriptor.Singleton<IEmailSender, NullEmailSender>());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using KonSoft.TenantManagement.Data;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
|
||||
namespace KonSoft.TenantManagement.EntityFrameworkCore;
|
||||
|
||||
public class EntityFrameworkCoreTenantManagementDbSchemaMigrator
|
||||
: ITenantManagementDbSchemaMigrator, ITransientDependency
|
||||
{
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
|
||||
public EntityFrameworkCoreTenantManagementDbSchemaMigrator(
|
||||
IServiceProvider serviceProvider)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
public async Task MigrateAsync()
|
||||
{
|
||||
/* We intentionally resolve the TenantManagementDbContext
|
||||
* from IServiceProvider (instead of directly injecting it)
|
||||
* to properly get the connection string of the current tenant in the
|
||||
* current scope.
|
||||
*/
|
||||
|
||||
await _serviceProvider
|
||||
.GetRequiredService<TenantManagementDbContext>()
|
||||
.Database
|
||||
.MigrateAsync();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,86 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Volo.Abp.AuditLogging.EntityFrameworkCore;
|
||||
using Volo.Abp.BackgroundJobs.EntityFrameworkCore;
|
||||
using Volo.Abp.Data;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
using Volo.Abp.EntityFrameworkCore;
|
||||
using Volo.Abp.FeatureManagement.EntityFrameworkCore;
|
||||
using Volo.Abp.Identity;
|
||||
using Volo.Abp.Identity.EntityFrameworkCore;
|
||||
using Volo.Abp.OpenIddict.EntityFrameworkCore;
|
||||
using Volo.Abp.PermissionManagement.EntityFrameworkCore;
|
||||
using Volo.Abp.SettingManagement.EntityFrameworkCore;
|
||||
using Volo.Abp.TenantManagement;
|
||||
using Volo.Abp.TenantManagement.EntityFrameworkCore;
|
||||
|
||||
namespace KonSoft.TenantManagement.EntityFrameworkCore;
|
||||
|
||||
[ReplaceDbContext(typeof(IIdentityDbContext))]
|
||||
[ReplaceDbContext(typeof(ITenantManagementDbContext))]
|
||||
[ConnectionStringName("Default")]
|
||||
public class TenantManagementDbContext :
|
||||
AbpDbContext<TenantManagementDbContext>,
|
||||
IIdentityDbContext,
|
||||
ITenantManagementDbContext
|
||||
{
|
||||
/* Add DbSet properties for your Aggregate Roots / Entities here. */
|
||||
|
||||
#region Entities from the modules
|
||||
|
||||
/* Notice: We only implemented IIdentityDbContext and ITenantManagementDbContext
|
||||
* and replaced them for this DbContext. This allows you to perform JOIN
|
||||
* queries for the entities of these modules over the repositories easily. You
|
||||
* typically don't need that for other modules. But, if you need, you can
|
||||
* implement the DbContext interface of the needed module and use ReplaceDbContext
|
||||
* attribute just like IIdentityDbContext and ITenantManagementDbContext.
|
||||
*
|
||||
* More info: Replacing a DbContext of a module ensures that the related module
|
||||
* uses this DbContext on runtime. Otherwise, it will use its own DbContext class.
|
||||
*/
|
||||
|
||||
//Identity
|
||||
public DbSet<IdentityUser> Users { get; set; }
|
||||
public DbSet<IdentityRole> Roles { get; set; }
|
||||
public DbSet<IdentityClaimType> ClaimTypes { get; set; }
|
||||
public DbSet<OrganizationUnit> OrganizationUnits { get; set; }
|
||||
public DbSet<IdentitySecurityLog> SecurityLogs { get; set; }
|
||||
public DbSet<IdentityLinkUser> LinkUsers { get; set; }
|
||||
public DbSet<IdentityUserDelegation> UserDelegations { get; set; }
|
||||
public DbSet<IdentitySession> Sessions { get; set; }
|
||||
// Tenant Management
|
||||
public DbSet<Tenant> Tenants { get; set; }
|
||||
public DbSet<TenantConnectionString> TenantConnectionStrings { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
public TenantManagementDbContext(DbContextOptions<TenantManagementDbContext> options)
|
||||
: base(options)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
base.OnModelCreating(builder);
|
||||
|
||||
/* Include modules to your migration db context */
|
||||
|
||||
builder.ConfigurePermissionManagement();
|
||||
builder.ConfigureSettingManagement();
|
||||
builder.ConfigureBackgroundJobs();
|
||||
builder.ConfigureAuditLogging();
|
||||
builder.ConfigureIdentity();
|
||||
builder.ConfigureOpenIddict();
|
||||
builder.ConfigureFeatureManagement();
|
||||
builder.ConfigureTenantManagement();
|
||||
|
||||
/* Configure your own tables/entities inside here */
|
||||
|
||||
//builder.Entity<YourEntity>(b =>
|
||||
//{
|
||||
// b.ToTable(TenantManagementConsts.DbTablePrefix + "YourEntities", TenantManagementConsts.DbSchema);
|
||||
// b.ConfigureByConvention(); //auto configure for the base class props
|
||||
// //...
|
||||
//});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Design;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace KonSoft.TenantManagement.EntityFrameworkCore;
|
||||
|
||||
/* This class is needed for EF Core console commands
|
||||
* (like Add-Migration and Update-Database commands) */
|
||||
public class TenantManagementDbContextFactory : IDesignTimeDbContextFactory<TenantManagementDbContext>
|
||||
{
|
||||
public TenantManagementDbContext CreateDbContext(string[] args)
|
||||
{
|
||||
// https://www.npgsql.org/efcore/release-notes/6.0.html#opting-out-of-the-new-timestamp-mapping-logic
|
||||
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
||||
|
||||
TenantManagementEfCoreEntityExtensionMappings.Configure();
|
||||
|
||||
var configuration = BuildConfiguration();
|
||||
|
||||
var builder = new DbContextOptionsBuilder<TenantManagementDbContext>()
|
||||
.UseNpgsql(configuration.GetConnectionString("Default"));
|
||||
|
||||
return new TenantManagementDbContext(builder.Options);
|
||||
}
|
||||
|
||||
private static IConfigurationRoot BuildConfiguration()
|
||||
{
|
||||
var builder = new ConfigurationBuilder()
|
||||
.SetBasePath(Path.Combine(Directory.GetCurrentDirectory(), "../KonSoft.TenantManagement.DbMigrator/"))
|
||||
.AddJsonFile("appsettings.json", optional: false);
|
||||
|
||||
return builder.Build();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Volo.Abp.Identity;
|
||||
using Volo.Abp.ObjectExtending;
|
||||
using Volo.Abp.Threading;
|
||||
|
||||
namespace KonSoft.TenantManagement.EntityFrameworkCore;
|
||||
|
||||
public static class TenantManagementEfCoreEntityExtensionMappings
|
||||
{
|
||||
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();
|
||||
|
||||
public static void Configure()
|
||||
{
|
||||
TenantManagementGlobalFeatureConfigurator.Configure();
|
||||
TenantManagementModuleExtensionConfigurator.Configure();
|
||||
|
||||
OneTimeRunner.Run(() =>
|
||||
{
|
||||
/* You can configure extra properties for the
|
||||
* entities defined in the modules used by your application.
|
||||
*
|
||||
* This class can be used to map these extra properties to table fields in the database.
|
||||
*
|
||||
* USE THIS CLASS ONLY TO CONFIGURE EF CORE RELATED MAPPING.
|
||||
* USE TenantManagementModuleExtensionConfigurator CLASS (in the Domain.Shared project)
|
||||
* FOR A HIGH LEVEL API TO DEFINE EXTRA PROPERTIES TO ENTITIES OF THE USED MODULES
|
||||
*
|
||||
* Example: Map a property to a table field:
|
||||
|
||||
ObjectExtensionManager.Instance
|
||||
.MapEfCoreProperty<IdentityUser, string>(
|
||||
"MyProperty",
|
||||
(entityBuilder, propertyBuilder) =>
|
||||
{
|
||||
propertyBuilder.HasMaxLength(128);
|
||||
}
|
||||
);
|
||||
|
||||
* See the documentation for more:
|
||||
* https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Extending-Entities
|
||||
*/
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Volo.Abp.Uow;
|
||||
using Volo.Abp.AuditLogging.EntityFrameworkCore;
|
||||
using Volo.Abp.BackgroundJobs.EntityFrameworkCore;
|
||||
using Volo.Abp.EntityFrameworkCore;
|
||||
using Volo.Abp.EntityFrameworkCore.PostgreSql;
|
||||
using Volo.Abp.FeatureManagement.EntityFrameworkCore;
|
||||
using Volo.Abp.Identity.EntityFrameworkCore;
|
||||
using Volo.Abp.Modularity;
|
||||
using Volo.Abp.OpenIddict.EntityFrameworkCore;
|
||||
using Volo.Abp.PermissionManagement.EntityFrameworkCore;
|
||||
using Volo.Abp.SettingManagement.EntityFrameworkCore;
|
||||
using Volo.Abp.TenantManagement.EntityFrameworkCore;
|
||||
|
||||
namespace KonSoft.TenantManagement.EntityFrameworkCore;
|
||||
|
||||
[DependsOn(
|
||||
typeof(TenantManagementDomainModule),
|
||||
typeof(AbpIdentityEntityFrameworkCoreModule),
|
||||
typeof(AbpOpenIddictEntityFrameworkCoreModule),
|
||||
typeof(AbpPermissionManagementEntityFrameworkCoreModule),
|
||||
typeof(AbpSettingManagementEntityFrameworkCoreModule),
|
||||
typeof(AbpEntityFrameworkCorePostgreSqlModule),
|
||||
typeof(AbpBackgroundJobsEntityFrameworkCoreModule),
|
||||
typeof(AbpAuditLoggingEntityFrameworkCoreModule),
|
||||
typeof(AbpTenantManagementEntityFrameworkCoreModule),
|
||||
typeof(AbpFeatureManagementEntityFrameworkCoreModule)
|
||||
)]
|
||||
public class TenantManagementEntityFrameworkCoreModule : AbpModule
|
||||
{
|
||||
public override void PreConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
// https://www.npgsql.org/efcore/release-notes/6.0.html#opting-out-of-the-new-timestamp-mapping-logic
|
||||
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
||||
|
||||
TenantManagementEfCoreEntityExtensionMappings.Configure();
|
||||
}
|
||||
|
||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
context.Services.AddAbpDbContext<TenantManagementDbContext>(options =>
|
||||
{
|
||||
/* Remove "includeAllEntities: true" to create
|
||||
* default repositories only for aggregate roots */
|
||||
options.AddDefaultRepositories(includeAllEntities: true);
|
||||
});
|
||||
|
||||
Configure<AbpDbContextOptions>(options =>
|
||||
{
|
||||
/* The main point to change your DBMS.
|
||||
* See also TenantManagementMigrationsDbContextFactory for EF Core tooling. */
|
||||
options.UseNpgsql();
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="..\..\common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>KonSoft.TenantManagement</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\KonSoft.TenantManagement.Domain\KonSoft.TenantManagement.Domain.csproj" />
|
||||
<PackageReference Include="Volo.Abp.EntityFrameworkCore.PostgreSql" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.PermissionManagement.EntityFrameworkCore" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.SettingManagement.EntityFrameworkCore" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.Identity.EntityFrameworkCore" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.BackgroundJobs.EntityFrameworkCore" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.AuditLogging.EntityFrameworkCore" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.TenantManagement.EntityFrameworkCore" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.FeatureManagement.EntityFrameworkCore" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.OpenIddict.EntityFrameworkCore" Version="8.3.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,2 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
[assembly:InternalsVisibleToAttribute("KonSoft.TenantManagement.EntityFrameworkCore.Tests")]
|
||||
@ -0,0 +1,29 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="..\..\common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>KonSoft.TenantManagement</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\KonSoft.TenantManagement.Application.Contracts\KonSoft.TenantManagement.Application.Contracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Volo.Abp.Account.HttpApi.Client" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.Identity.HttpApi.Client" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.PermissionManagement.HttpApi.Client" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.TenantManagement.HttpApi.Client" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.FeatureManagement.HttpApi.Client" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.SettingManagement.HttpApi.Client" Version="8.3.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="**\*generate-proxy.json" />
|
||||
<Content Remove="**\*generate-proxy.json" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -0,0 +1,38 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Volo.Abp.Account;
|
||||
using Volo.Abp.FeatureManagement;
|
||||
using Volo.Abp.Identity;
|
||||
using Volo.Abp.Modularity;
|
||||
using Volo.Abp.PermissionManagement;
|
||||
using Volo.Abp.TenantManagement;
|
||||
using Volo.Abp.SettingManagement;
|
||||
using Volo.Abp.VirtualFileSystem;
|
||||
|
||||
namespace KonSoft.TenantManagement;
|
||||
|
||||
[DependsOn(
|
||||
typeof(TenantManagementApplicationContractsModule),
|
||||
typeof(AbpAccountHttpApiClientModule),
|
||||
typeof(AbpIdentityHttpApiClientModule),
|
||||
typeof(AbpPermissionManagementHttpApiClientModule),
|
||||
typeof(AbpTenantManagementHttpApiClientModule),
|
||||
typeof(AbpFeatureManagementHttpApiClientModule),
|
||||
typeof(AbpSettingManagementHttpApiClientModule)
|
||||
)]
|
||||
public class TenantManagementHttpApiClientModule : AbpModule
|
||||
{
|
||||
public const string RemoteServiceName = "Default";
|
||||
|
||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
context.Services.AddHttpClientProxies(
|
||||
typeof(TenantManagementApplicationContractsModule).Assembly,
|
||||
RemoteServiceName
|
||||
);
|
||||
|
||||
Configure<AbpVirtualFileSystemOptions>(options =>
|
||||
{
|
||||
options.FileSets.AddEmbedded<TenantManagementHttpApiClientModule>();
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
using KonSoft.TenantManagement.Localization;
|
||||
using Volo.Abp.AspNetCore.Mvc;
|
||||
|
||||
namespace KonSoft.TenantManagement.Controllers;
|
||||
|
||||
/* Inherit your controllers from this class.
|
||||
*/
|
||||
public abstract class TenantManagementController : AbpControllerBase
|
||||
{
|
||||
protected TenantManagementController()
|
||||
{
|
||||
LocalizationResource = typeof(TenantManagementResource);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="..\..\common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>KonSoft.TenantManagement</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\KonSoft.TenantManagement.Application.Contracts\KonSoft.TenantManagement.Application.Contracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Volo.Abp.Account.HttpApi" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.Identity.HttpApi" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.PermissionManagement.HttpApi" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.TenantManagement.HttpApi" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.FeatureManagement.HttpApi" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.SettingManagement.HttpApi" Version="8.3.4" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -0,0 +1,10 @@
|
||||
using System;
|
||||
|
||||
namespace KonSoft.TenantManagement.Models.Test;
|
||||
|
||||
public class TestModel
|
||||
{
|
||||
public string? Name { get; set; }
|
||||
|
||||
public DateTime BirthDate { get; set; }
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
using Localization.Resources.AbpUi;
|
||||
using KonSoft.TenantManagement.Localization;
|
||||
using Volo.Abp.Account;
|
||||
using Volo.Abp.FeatureManagement;
|
||||
using Volo.Abp.Identity;
|
||||
using Volo.Abp.Localization;
|
||||
using Volo.Abp.Modularity;
|
||||
using Volo.Abp.PermissionManagement.HttpApi;
|
||||
using Volo.Abp.SettingManagement;
|
||||
using Volo.Abp.TenantManagement;
|
||||
|
||||
namespace KonSoft.TenantManagement;
|
||||
|
||||
[DependsOn(
|
||||
typeof(TenantManagementApplicationContractsModule),
|
||||
typeof(AbpAccountHttpApiModule),
|
||||
typeof(AbpIdentityHttpApiModule),
|
||||
typeof(AbpPermissionManagementHttpApiModule),
|
||||
typeof(AbpTenantManagementHttpApiModule),
|
||||
typeof(AbpFeatureManagementHttpApiModule),
|
||||
typeof(AbpSettingManagementHttpApiModule)
|
||||
)]
|
||||
public class TenantManagementHttpApiModule : AbpModule
|
||||
{
|
||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
ConfigureLocalization();
|
||||
}
|
||||
|
||||
private void ConfigureLocalization()
|
||||
{
|
||||
Configure<AbpLocalizationOptions>(options =>
|
||||
{
|
||||
options.Resources
|
||||
.Get<TenantManagementResource>()
|
||||
.AddBaseTypes(
|
||||
typeof(AbpUiResource)
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="..\..\common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>KonSoft.TenantManagement</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\KonSoft.TenantManagement.Application\KonSoft.TenantManagement.Application.csproj" />
|
||||
<ProjectReference Include="..\KonSoft.TenantManagement.Domain.Tests\KonSoft.TenantManagement.Domain.Tests.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -0,0 +1,34 @@
|
||||
using Shouldly;
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp.Identity;
|
||||
using Volo.Abp.Modularity;
|
||||
using Xunit;
|
||||
|
||||
namespace KonSoft.TenantManagement.Samples;
|
||||
|
||||
/* This is just an example test class.
|
||||
* Normally, you don't test code of the modules you are using
|
||||
* (like IIdentityUserAppService here).
|
||||
* Only test your own application services.
|
||||
*/
|
||||
public abstract class SampleAppServiceTests<TStartupModule> : TenantManagementApplicationTestBase<TStartupModule>
|
||||
where TStartupModule : IAbpModule
|
||||
{
|
||||
private readonly IIdentityUserAppService _userAppService;
|
||||
|
||||
protected SampleAppServiceTests()
|
||||
{
|
||||
_userAppService = GetRequiredService<IIdentityUserAppService>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Initial_Data_Should_Contain_Admin_User()
|
||||
{
|
||||
//Act
|
||||
var result = await _userAppService.GetListAsync(new GetIdentityUsersInput());
|
||||
|
||||
//Assert
|
||||
result.TotalCount.ShouldBeGreaterThan(0);
|
||||
result.Items.ShouldContain(u => u.UserName == "admin");
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
using Volo.Abp.Modularity;
|
||||
|
||||
namespace KonSoft.TenantManagement;
|
||||
|
||||
public abstract class TenantManagementApplicationTestBase<TStartupModule> : TenantManagementTestBase<TStartupModule>
|
||||
where TStartupModule : IAbpModule
|
||||
{
|
||||
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
using Volo.Abp.Modularity;
|
||||
|
||||
namespace KonSoft.TenantManagement;
|
||||
|
||||
[DependsOn(
|
||||
typeof(TenantManagementApplicationModule),
|
||||
typeof(TenantManagementDomainTestModule)
|
||||
)]
|
||||
public class TenantManagementApplicationTestModule : AbpModule
|
||||
{
|
||||
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="..\..\common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>KonSoft.TenantManagement</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\KonSoft.TenantManagement.Domain\KonSoft.TenantManagement.Domain.csproj" />
|
||||
<ProjectReference Include="..\KonSoft.TenantManagement.TestBase\KonSoft.TenantManagement.TestBase.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -0,0 +1,46 @@
|
||||
using System.Threading.Tasks;
|
||||
using Shouldly;
|
||||
using Volo.Abp.Identity;
|
||||
using Volo.Abp.Modularity;
|
||||
using Xunit;
|
||||
|
||||
namespace KonSoft.TenantManagement.Samples;
|
||||
|
||||
/* This is just an example test class.
|
||||
* Normally, you don't test code of the modules you are using
|
||||
* (like IdentityUserManager here).
|
||||
* Only test your own domain services.
|
||||
*/
|
||||
public abstract class SampleDomainTests<TStartupModule> : TenantManagementDomainTestBase<TStartupModule>
|
||||
where TStartupModule : IAbpModule
|
||||
{
|
||||
private readonly IIdentityUserRepository _identityUserRepository;
|
||||
private readonly IdentityUserManager _identityUserManager;
|
||||
|
||||
protected SampleDomainTests()
|
||||
{
|
||||
_identityUserRepository = GetRequiredService<IIdentityUserRepository>();
|
||||
_identityUserManager = GetRequiredService<IdentityUserManager>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Should_Set_Email_Of_A_User()
|
||||
{
|
||||
IdentityUser adminUser;
|
||||
|
||||
/* Need to manually start Unit Of Work because
|
||||
* FirstOrDefaultAsync should be executed while db connection / context is available.
|
||||
*/
|
||||
await WithUnitOfWorkAsync(async () =>
|
||||
{
|
||||
adminUser = await _identityUserRepository
|
||||
.FindByNormalizedUserNameAsync("ADMIN");
|
||||
|
||||
await _identityUserManager.SetEmailAsync(adminUser, "newemail@abp.io");
|
||||
await _identityUserRepository.UpdateAsync(adminUser);
|
||||
});
|
||||
|
||||
adminUser = await _identityUserRepository.FindByNormalizedUserNameAsync("ADMIN");
|
||||
adminUser.Email.ShouldBe("newemail@abp.io");
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
using Volo.Abp.Modularity;
|
||||
|
||||
namespace KonSoft.TenantManagement;
|
||||
|
||||
/* Inherit from this class for your domain layer tests. */
|
||||
public abstract class TenantManagementDomainTestBase<TStartupModule> : TenantManagementTestBase<TStartupModule>
|
||||
where TStartupModule : IAbpModule
|
||||
{
|
||||
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
using Volo.Abp.Modularity;
|
||||
|
||||
namespace KonSoft.TenantManagement;
|
||||
|
||||
[DependsOn(
|
||||
typeof(TenantManagementDomainModule),
|
||||
typeof(TenantManagementTestBaseModule)
|
||||
)]
|
||||
public class TenantManagementDomainTestModule : AbpModule
|
||||
{
|
||||
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
using KonSoft.TenantManagement.Samples;
|
||||
using Xunit;
|
||||
|
||||
namespace KonSoft.TenantManagement.EntityFrameworkCore.Applications;
|
||||
|
||||
[Collection(TenantManagementTestConsts.CollectionDefinitionName)]
|
||||
public class EfCoreSampleAppServiceTests : SampleAppServiceTests<TenantManagementEntityFrameworkCoreTestModule>
|
||||
{
|
||||
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
using KonSoft.TenantManagement.Samples;
|
||||
using Xunit;
|
||||
|
||||
namespace KonSoft.TenantManagement.EntityFrameworkCore.Domains;
|
||||
|
||||
[Collection(TenantManagementTestConsts.CollectionDefinitionName)]
|
||||
public class EfCoreSampleDomainTests : SampleDomainTests<TenantManagementEntityFrameworkCoreTestModule>
|
||||
{
|
||||
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Shouldly;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp.Domain.Repositories;
|
||||
using Volo.Abp.Identity;
|
||||
using Xunit;
|
||||
|
||||
namespace KonSoft.TenantManagement.EntityFrameworkCore.Samples;
|
||||
|
||||
/* This is just an example test class.
|
||||
* Normally, you don't test ABP framework code
|
||||
* (like default AppUser repository IRepository<AppUser, Guid> here).
|
||||
* Only test your custom repository methods.
|
||||
*/
|
||||
[Collection(TenantManagementTestConsts.CollectionDefinitionName)]
|
||||
public class SampleRepositoryTests : TenantManagementEntityFrameworkCoreTestBase
|
||||
{
|
||||
private readonly IRepository<IdentityUser, Guid> _appUserRepository;
|
||||
|
||||
public SampleRepositoryTests()
|
||||
{
|
||||
_appUserRepository = GetRequiredService<IRepository<IdentityUser, Guid>>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Should_Query_AppUser()
|
||||
{
|
||||
/* Need to manually start Unit Of Work because
|
||||
* FirstOrDefaultAsync should be executed while db connection / context is available.
|
||||
*/
|
||||
await WithUnitOfWorkAsync(async () =>
|
||||
{
|
||||
//Act
|
||||
var adminUser = await (await _appUserRepository.GetQueryableAsync())
|
||||
.Where(u => u.UserName == "admin")
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
//Assert
|
||||
adminUser.ShouldNotBeNull();
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
using Xunit;
|
||||
|
||||
namespace KonSoft.TenantManagement.EntityFrameworkCore;
|
||||
|
||||
[CollectionDefinition(TenantManagementTestConsts.CollectionDefinitionName)]
|
||||
public class TenantManagementEntityFrameworkCoreCollection : ICollectionFixture<TenantManagementEntityFrameworkCoreFixture>
|
||||
{
|
||||
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
using KonSoft.TenantManagement.EntityFrameworkCore;
|
||||
using Xunit;
|
||||
|
||||
namespace KonSoft.TenantManagement.EntityFrameworkCore;
|
||||
|
||||
public class TenantManagementEntityFrameworkCoreCollectionFixtureBase : ICollectionFixture<TenantManagementEntityFrameworkCoreFixture>
|
||||
{
|
||||
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace KonSoft.TenantManagement.EntityFrameworkCore;
|
||||
|
||||
public class TenantManagementEntityFrameworkCoreFixture : IDisposable
|
||||
{
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
using Volo.Abp;
|
||||
|
||||
namespace KonSoft.TenantManagement.EntityFrameworkCore;
|
||||
|
||||
public abstract class TenantManagementEntityFrameworkCoreTestBase : TenantManagementTestBase<TenantManagementEntityFrameworkCoreTestModule>
|
||||
{
|
||||
|
||||
}
|
||||
@ -0,0 +1,82 @@
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Volo.Abp;
|
||||
using Volo.Abp.EntityFrameworkCore;
|
||||
using Volo.Abp.EntityFrameworkCore.Sqlite;
|
||||
using Volo.Abp.FeatureManagement;
|
||||
using Volo.Abp.Modularity;
|
||||
using Volo.Abp.PermissionManagement;
|
||||
using Volo.Abp.SettingManagement;
|
||||
using Volo.Abp.Uow;
|
||||
|
||||
namespace KonSoft.TenantManagement.EntityFrameworkCore;
|
||||
|
||||
[DependsOn(
|
||||
typeof(TenantManagementApplicationTestModule),
|
||||
typeof(TenantManagementEntityFrameworkCoreModule),
|
||||
typeof(AbpEntityFrameworkCoreSqliteModule)
|
||||
)]
|
||||
public class TenantManagementEntityFrameworkCoreTestModule : AbpModule
|
||||
{
|
||||
private SqliteConnection? _sqliteConnection;
|
||||
|
||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
Configure<FeatureManagementOptions>(options =>
|
||||
{
|
||||
options.SaveStaticFeaturesToDatabase = false;
|
||||
options.IsDynamicFeatureStoreEnabled = false;
|
||||
});
|
||||
Configure<PermissionManagementOptions>(options =>
|
||||
{
|
||||
options.SaveStaticPermissionsToDatabase = false;
|
||||
options.IsDynamicPermissionStoreEnabled = false;
|
||||
});
|
||||
Configure<SettingManagementOptions>(options =>
|
||||
{
|
||||
options.SaveStaticSettingsToDatabase = false;
|
||||
options.IsDynamicSettingStoreEnabled = false;
|
||||
});
|
||||
context.Services.AddAlwaysDisableUnitOfWorkTransaction();
|
||||
|
||||
ConfigureInMemorySqlite(context.Services);
|
||||
}
|
||||
|
||||
private void ConfigureInMemorySqlite(IServiceCollection services)
|
||||
{
|
||||
_sqliteConnection = CreateDatabaseAndGetConnection();
|
||||
|
||||
services.Configure<AbpDbContextOptions>(options =>
|
||||
{
|
||||
options.Configure(context =>
|
||||
{
|
||||
context.DbContextOptions.UseSqlite(_sqliteConnection);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public override void OnApplicationShutdown(ApplicationShutdownContext context)
|
||||
{
|
||||
_sqliteConnection?.Dispose();
|
||||
}
|
||||
|
||||
private static SqliteConnection CreateDatabaseAndGetConnection()
|
||||
{
|
||||
var connection = new AbpUnitTestSqliteConnection("Data Source=:memory:");
|
||||
connection.Open();
|
||||
|
||||
var options = new DbContextOptionsBuilder<TenantManagementDbContext>()
|
||||
.UseSqlite(connection)
|
||||
.Options;
|
||||
|
||||
using (var context = new TenantManagementDbContext(options))
|
||||
{
|
||||
context.GetService<IRelationalDatabaseCreator>().CreateTables();
|
||||
}
|
||||
|
||||
return connection;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="..\..\common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>KonSoft.TenantManagement</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\KonSoft.TenantManagement.EntityFrameworkCore\KonSoft.TenantManagement.EntityFrameworkCore.csproj" />
|
||||
<ProjectReference Include="..\KonSoft.TenantManagement.Application.Tests\KonSoft.TenantManagement.Application.Tests.csproj" />
|
||||
<PackageReference Include="Volo.Abp.EntityFrameworkCore.Sqlite" Version="8.3.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp.Account;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
|
||||
namespace KonSoft.TenantManagement.HttpApi.Client.ConsoleTestApp;
|
||||
|
||||
public class ClientDemoService : ITransientDependency
|
||||
{
|
||||
private readonly IProfileAppService _profileAppService;
|
||||
|
||||
public ClientDemoService(IProfileAppService profileAppService)
|
||||
{
|
||||
_profileAppService = profileAppService;
|
||||
}
|
||||
|
||||
public async Task RunAsync()
|
||||
{
|
||||
var output = await _profileAppService.GetAsync();
|
||||
Console.WriteLine($"UserName : {output.UserName}");
|
||||
Console.WriteLine($"Email : {output.Email}");
|
||||
Console.WriteLine($"Name : {output.Name}");
|
||||
Console.WriteLine($"Surname : {output.Surname}");
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Volo.Abp;
|
||||
|
||||
namespace KonSoft.TenantManagement.HttpApi.Client.ConsoleTestApp;
|
||||
|
||||
public class ConsoleTestAppHostedService : IHostedService
|
||||
{
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
public ConsoleTestAppHostedService(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
public async Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
using (var application = await AbpApplicationFactory.CreateAsync<TenantManagementConsoleApiClientModule>(options =>
|
||||
{
|
||||
options.Services.ReplaceConfiguration(_configuration);
|
||||
options.UseAutofac();
|
||||
}))
|
||||
{
|
||||
await application.InitializeAsync();
|
||||
|
||||
var demo = application.ServiceProvider.GetRequiredService<ClientDemoService>();
|
||||
await demo.RunAsync();
|
||||
|
||||
await application.ShutdownAsync();
|
||||
}
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="appsettings.json" />
|
||||
<Content Include="appsettings.json">
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<None Remove="appsettings.secrets.json" />
|
||||
<Content Include="appsettings.secrets.json">
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Volo.Abp.Http.Client.IdentityModel" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.Autofac" Version="8.3.4" />
|
||||
<ProjectReference Include="..\..\src\KonSoft.TenantManagement.HttpApi.Client\KonSoft.TenantManagement.HttpApi.Client.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -0,0 +1,22 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace KonSoft.TenantManagement.HttpApi.Client.ConsoleTestApp;
|
||||
|
||||
class Program
|
||||
{
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
await CreateHostBuilder(args).RunConsoleAsync();
|
||||
}
|
||||
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
Host.CreateDefaultBuilder(args)
|
||||
.AddAppSettingsSecretsJson()
|
||||
.ConfigureServices((hostContext, services) =>
|
||||
{
|
||||
services.AddHostedService<ConsoleTestAppHostedService>();
|
||||
});
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Polly;
|
||||
using Volo.Abp.Autofac;
|
||||
using Volo.Abp.Http.Client;
|
||||
using Volo.Abp.Http.Client.IdentityModel;
|
||||
using Volo.Abp.Modularity;
|
||||
|
||||
namespace KonSoft.TenantManagement.HttpApi.Client.ConsoleTestApp;
|
||||
|
||||
[DependsOn(
|
||||
typeof(AbpAutofacModule),
|
||||
typeof(TenantManagementHttpApiClientModule),
|
||||
typeof(AbpHttpClientIdentityModelModule)
|
||||
)]
|
||||
public class TenantManagementConsoleApiClientModule : AbpModule
|
||||
{
|
||||
public override void PreConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
PreConfigure<AbpHttpClientBuilderOptions>(options =>
|
||||
{
|
||||
options.ProxyClientBuildActions.Add((remoteServiceName, clientBuilder) =>
|
||||
{
|
||||
clientBuilder.AddTransientHttpErrorPolicy(
|
||||
policyBuilder => policyBuilder.WaitAndRetryAsync(3, i => TimeSpan.FromSeconds(Math.Pow(2, i)))
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
{
|
||||
"RemoteServices": {
|
||||
"Default": {
|
||||
"BaseUrl": "https://localhost:44316"
|
||||
}
|
||||
},
|
||||
"IdentityClients": {
|
||||
"Default": {
|
||||
"GrantType": "password",
|
||||
"ClientId": "TenantManagement_App",
|
||||
"UserName": "admin",
|
||||
"UserPassword": "1q2w3E*",
|
||||
"Authority": "https://localhost:44316",
|
||||
"Scope": "TenantManagement"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,2 @@
|
||||
{
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="..\..\common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>KonSoft.TenantManagement</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Volo.Abp.TestBase" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.Autofac" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.Authorization" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.BackgroundJobs.Abstractions" Version="8.3.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||
<PackageReference Include="NSubstitute" Version="5.1.0" />
|
||||
<PackageReference Include="NSubstitute.Analyzers.CSharp" Version="1.0.16">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Shouldly" Version="4.2.1" />
|
||||
<PackageReference Include="xunit" Version="2.6.1" />
|
||||
<PackageReference Include="xunit.extensibility.execution" Version="2.6.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -0,0 +1,25 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Claims;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
using Volo.Abp.Security.Claims;
|
||||
|
||||
namespace KonSoft.TenantManagement.Security;
|
||||
|
||||
[Dependency(ReplaceServices = true)]
|
||||
public class FakeCurrentPrincipalAccessor : ThreadCurrentPrincipalAccessor
|
||||
{
|
||||
protected override ClaimsPrincipal GetClaimsPrincipal()
|
||||
{
|
||||
return GetPrincipal();
|
||||
}
|
||||
|
||||
private ClaimsPrincipal GetPrincipal()
|
||||
{
|
||||
return new ClaimsPrincipal(new ClaimsIdentity(new List<Claim>
|
||||
{
|
||||
new Claim(AbpClaimTypes.UserId, "2e701e62-0953-4dd3-910b-dc6cc93ccb0d"),
|
||||
new Claim(AbpClaimTypes.UserName, "admin"),
|
||||
new Claim(AbpClaimTypes.Email, "admin@abp.io")
|
||||
}));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Volo.Abp;
|
||||
using Volo.Abp.Modularity;
|
||||
using Volo.Abp.Uow;
|
||||
using Volo.Abp.Testing;
|
||||
|
||||
namespace KonSoft.TenantManagement;
|
||||
|
||||
/* All test classes are derived from this class, directly or indirectly.
|
||||
*/
|
||||
public abstract class TenantManagementTestBase<TStartupModule> : AbpIntegratedTest<TStartupModule>
|
||||
where TStartupModule : IAbpModule
|
||||
{
|
||||
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)
|
||||
{
|
||||
options.UseAutofac();
|
||||
}
|
||||
|
||||
protected virtual Task WithUnitOfWorkAsync(Func<Task> func)
|
||||
{
|
||||
return WithUnitOfWorkAsync(new AbpUnitOfWorkOptions(), func);
|
||||
}
|
||||
|
||||
protected virtual async Task WithUnitOfWorkAsync(AbpUnitOfWorkOptions options, Func<Task> action)
|
||||
{
|
||||
using (var scope = ServiceProvider.CreateScope())
|
||||
{
|
||||
var uowManager = scope.ServiceProvider.GetRequiredService<IUnitOfWorkManager>();
|
||||
|
||||
using (var uow = uowManager.Begin(options))
|
||||
{
|
||||
await action();
|
||||
|
||||
await uow.CompleteAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual Task<TResult> WithUnitOfWorkAsync<TResult>(Func<Task<TResult>> func)
|
||||
{
|
||||
return WithUnitOfWorkAsync(new AbpUnitOfWorkOptions(), func);
|
||||
}
|
||||
|
||||
protected virtual async Task<TResult> WithUnitOfWorkAsync<TResult>(AbpUnitOfWorkOptions options, Func<Task<TResult>> func)
|
||||
{
|
||||
using (var scope = ServiceProvider.CreateScope())
|
||||
{
|
||||
var uowManager = scope.ServiceProvider.GetRequiredService<IUnitOfWorkManager>();
|
||||
|
||||
using (var uow = uowManager.Begin(options))
|
||||
{
|
||||
var result = await func();
|
||||
await uow.CompleteAsync();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,47 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Volo.Abp;
|
||||
using Volo.Abp.Authorization;
|
||||
using Volo.Abp.Autofac;
|
||||
using Volo.Abp.BackgroundJobs;
|
||||
using Volo.Abp.Data;
|
||||
using Volo.Abp.Modularity;
|
||||
using Volo.Abp.Threading;
|
||||
|
||||
namespace KonSoft.TenantManagement;
|
||||
|
||||
[DependsOn(
|
||||
typeof(AbpAutofacModule),
|
||||
typeof(AbpTestBaseModule),
|
||||
typeof(AbpAuthorizationModule),
|
||||
typeof(AbpBackgroundJobsAbstractionsModule)
|
||||
)]
|
||||
public class TenantManagementTestBaseModule : AbpModule
|
||||
{
|
||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
Configure<AbpBackgroundJobOptions>(options =>
|
||||
{
|
||||
options.IsJobExecutionEnabled = false;
|
||||
});
|
||||
|
||||
context.Services.AddAlwaysAllowAuthorization();
|
||||
}
|
||||
|
||||
public override void OnApplicationInitialization(ApplicationInitializationContext context)
|
||||
{
|
||||
SeedTestData(context);
|
||||
}
|
||||
|
||||
private static void SeedTestData(ApplicationInitializationContext context)
|
||||
{
|
||||
AsyncHelper.RunSync(async () =>
|
||||
{
|
||||
using (var scope = context.ServiceProvider.CreateScope())
|
||||
{
|
||||
await scope.ServiceProvider
|
||||
.GetRequiredService<IDataSeeder>()
|
||||
.SeedAsync();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,6 @@
|
||||
namespace KonSoft.TenantManagement;
|
||||
|
||||
public static class TenantManagementTestConsts
|
||||
{
|
||||
public const string CollectionDefinitionName = "TenantManagement collection";
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp.Data;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
|
||||
namespace KonSoft.TenantManagement;
|
||||
|
||||
public class TenantManagementTestDataSeedContributor : IDataSeedContributor, ITransientDependency
|
||||
{
|
||||
public Task SeedAsync(DataSeedContext context)
|
||||
{
|
||||
/* Seed additional test data... */
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user