first commit
This commit is contained in:
@ -0,0 +1,8 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KonSoft.Report.Data;
|
||||
|
||||
public interface IReportDbSchemaMigrator
|
||||
{
|
||||
Task MigrateAsync();
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
|
||||
namespace KonSoft.Report.Data;
|
||||
|
||||
/* This is used if database provider does't define
|
||||
* IReportDbSchemaMigrator implementation.
|
||||
*/
|
||||
public class NullReportDbSchemaMigrator : IReportDbSchemaMigrator, 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.Report.Data;
|
||||
|
||||
public class ReportDbMigrationService : ITransientDependency
|
||||
{
|
||||
public ILogger<ReportDbMigrationService> Logger { get; set; }
|
||||
|
||||
private readonly IDataSeeder _dataSeeder;
|
||||
private readonly IEnumerable<IReportDbSchemaMigrator> _dbSchemaMigrators;
|
||||
private readonly ITenantRepository _tenantRepository;
|
||||
private readonly ICurrentTenant _currentTenant;
|
||||
|
||||
public ReportDbMigrationService(
|
||||
IDataSeeder dataSeeder,
|
||||
IEnumerable<IReportDbSchemaMigrator> dbSchemaMigrators,
|
||||
ITenantRepository tenantRepository,
|
||||
ICurrentTenant currentTenant)
|
||||
{
|
||||
_dataSeeder = dataSeeder;
|
||||
_dbSchemaMigrators = dbSchemaMigrators;
|
||||
_tenantRepository = tenantRepository;
|
||||
_currentTenant = currentTenant;
|
||||
|
||||
Logger = NullLogger<ReportDbMigrationService>.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.Report</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\KonSoft.Report.Domain.Shared\KonSoft.Report.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.Report.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("Report") == null)
|
||||
{
|
||||
await _scopeManager.CreateAsync(new OpenIddictScopeDescriptor {
|
||||
Name = "Report", DisplayName = "Report API", Resources = { "Report" }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
"Report"
|
||||
};
|
||||
|
||||
var configurationSection = _configuration.GetSection("OpenIddict:Applications");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Swagger Client
|
||||
var swaggerClientId = configurationSection["Report_Swagger:ClientId"];
|
||||
if (!swaggerClientId.IsNullOrWhiteSpace())
|
||||
{
|
||||
var swaggerRootUrl = configurationSection["Report_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.Report.Domain.Tests")]
|
||||
[assembly:InternalsVisibleToAttribute("KonSoft.Report.TestBase")]
|
||||
8
modules/report/src/KonSoft.Report.Domain/ReportConsts.cs
Normal file
8
modules/report/src/KonSoft.Report.Domain/ReportConsts.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace KonSoft.Report;
|
||||
|
||||
public static class ReportConsts
|
||||
{
|
||||
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.Report.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.Report;
|
||||
|
||||
[DependsOn(
|
||||
typeof(ReportDomainSharedModule),
|
||||
typeof(AbpAuditLoggingDomainModule),
|
||||
typeof(AbpBackgroundJobsDomainModule),
|
||||
typeof(AbpFeatureManagementDomainModule),
|
||||
typeof(AbpIdentityDomainModule),
|
||||
typeof(AbpOpenIddictDomainModule),
|
||||
typeof(AbpPermissionManagementDomainOpenIddictModule),
|
||||
typeof(AbpPermissionManagementDomainIdentityModule),
|
||||
typeof(AbpSettingManagementDomainModule),
|
||||
typeof(AbpTenantManagementDomainModule),
|
||||
typeof(AbpEmailingModule)
|
||||
)]
|
||||
public class ReportDomainModule : 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,12 @@
|
||||
using Volo.Abp.Settings;
|
||||
|
||||
namespace KonSoft.Report.Settings;
|
||||
|
||||
public class ReportSettingDefinitionProvider : SettingDefinitionProvider
|
||||
{
|
||||
public override void Define(ISettingDefinitionContext context)
|
||||
{
|
||||
//Define your own settings here. Example:
|
||||
//context.Add(new SettingDefinition(ReportSettings.MySetting1));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
namespace KonSoft.Report.Settings;
|
||||
|
||||
public static class ReportSettings
|
||||
{
|
||||
private const string Prefix = "Report";
|
||||
|
||||
//Add your own setting names here. Example:
|
||||
//public const string MySetting1 = Prefix + ".MySetting1";
|
||||
}
|
||||
Reference in New Issue
Block a user