From 16b0bbbc052883ce56007062f7c74e064a8361e1 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Mon, 9 Jul 2018 17:13:05 +0300 Subject: [PATCH] Added Audit logging module --- .../audit-logging/Volo.Abp.AuditLogging.sln | 74 +++++++++++++++++++ ...Volo.Abp.AuditLogging.Domain.Shared.csproj | 19 +++++ .../AbpAuditLoggingDomainSharedModule.cs | 13 ++++ .../Abp/AuditLogging/AuditLogActionConsts.cs | 13 ++++ .../Volo/Abp/AuditLogging/AuditLogConsts.cs | 10 +++ .../Volo.Abp.AuditLogging.Domain.csproj | 21 ++++++ .../Abp/AuditLogging/AbpAuditLoggingConsts.cs | 10 +++ .../AbpAuditLoggingDomainModule.cs | 18 +++++ .../Volo/Abp/AuditLogging/AuditLog.cs | 61 +++++++++++++++ .../Volo/Abp/AuditLogging/AuditLogAction.cs | 39 ++++++++++ .../Volo/Abp/AuditLogging/AuditingStore.cs | 21 ++++++ .../Volo/Abp/AuditLogging/EntityChange.cs | 39 ++++++++++ .../Abp/AuditLogging/IAuditLogRepository.cs | 9 +++ ...bp.AuditLogging.EntityFrameworkCore.csproj | 20 +++++ .../AbpAuditLoggingDbContext.cs | 33 +++++++++ ...bpAuditLoggingEntityFrameworkCoreModule.cs | 23 ++++++ ...LoggingtDbContextModelBuilderExtensions.cs | 61 +++++++++++++++ .../EfCoreAuditLogRepository.cs | 15 ++++ .../IAuditLoggingDbContext.cs | 16 ++++ .../Volo.Abp.AuditLogging.MongoDB.csproj | 20 +++++ .../MongoDB/AbpAuditLoggingBsonClassMap.cs | 21 ++++++ .../MongoDB/AbpAuditLoggingMongoDbModule.cs | 25 +++++++ ...ttingManagementMongoDbContextExtensions.cs | 26 +++++++ .../MongoDB/AuditLoggingMongoDbContext.cs | 24 ++++++ ...ngMongoModelBuilderConfigurationOptions.cs | 13 ++++ .../MongoDB/IAuditLoggingMongoDbContext.cs | 12 +++ .../MongoDB/MongoAuditLogRepository.cs | 15 ++++ ...itLogging.EntityFrameworkCore.Tests.csproj | 25 +++++++ ...ditLoggingEntityFrameworkCoreTestModule.cs | 40 ++++++++++ .../Volo.Abp.AuditLogging.TestBase.csproj | 29 ++++++++ .../AbpAuditLoggingTestBaseModule.cs | 33 +++++++++ .../Abp/AuditLogging/AuditLoggingTestBase.cs | 13 ++++ .../Volo/Abp/AuditLogging/AuditingTestData.cs | 16 ++++ .../AuditLogging/AuditingTestDataBuilder.cs | 23 ++++++ .../Volo.Abp.AuditLogging.Tests.csproj | 22 ++++++ .../AuditLogging/AbpAuditLoggingTestModule.cs | 15 ++++ .../Abp/AuditLogging/AuditLogsTestBase.cs | 33 +++++++++ .../AuditLogging/AuditStore_Basic_Tests.cs | 42 +++++++++++ 38 files changed, 962 insertions(+) create mode 100644 modules/audit-logging/Volo.Abp.AuditLogging.sln create mode 100644 modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo.Abp.AuditLogging.Domain.Shared.csproj create mode 100644 modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AbpAuditLoggingDomainSharedModule.cs create mode 100644 modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AuditLogActionConsts.cs create mode 100644 modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AuditLogConsts.cs create mode 100644 modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo.Abp.AuditLogging.Domain.csproj create mode 100644 modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AbpAuditLoggingConsts.cs create mode 100644 modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AbpAuditLoggingDomainModule.cs create mode 100644 modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLog.cs create mode 100644 modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLogAction.cs create mode 100644 modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditingStore.cs create mode 100644 modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/EntityChange.cs create mode 100644 modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogRepository.cs create mode 100644 modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo.Abp.AuditLogging.EntityFrameworkCore.csproj create mode 100644 modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingDbContext.cs create mode 100644 modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingEntityFrameworkCoreModule.cs create mode 100644 modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingtDbContextModelBuilderExtensions.cs create mode 100644 modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/EfCoreAuditLogRepository.cs create mode 100644 modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/IAuditLoggingDbContext.cs create mode 100644 modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo.Abp.AuditLogging.MongoDB.csproj create mode 100644 modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AbpAuditLoggingBsonClassMap.cs create mode 100644 modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AbpAuditLoggingMongoDbModule.cs create mode 100644 modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AbpSettingManagementMongoDbContextExtensions.cs create mode 100644 modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AuditLoggingMongoDbContext.cs create mode 100644 modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AuditLoggingMongoModelBuilderConfigurationOptions.cs create mode 100644 modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/IAuditLoggingMongoDbContext.cs create mode 100644 modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs create mode 100644 modules/audit-logging/test/Volo.Abp.AuditLogging.EntityFrameworkCore.Tests/Volo.Abp.AuditLogging.EntityFrameworkCore.Tests.csproj create mode 100644 modules/audit-logging/test/Volo.Abp.AuditLogging.EntityFrameworkCore.Tests/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingEntityFrameworkCoreTestModule.cs create mode 100644 modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo.Abp.AuditLogging.TestBase.csproj create mode 100644 modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AbpAuditLoggingTestBaseModule.cs create mode 100644 modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditLoggingTestBase.cs create mode 100644 modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditingTestData.cs create mode 100644 modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditingTestDataBuilder.cs create mode 100644 modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo.Abp.AuditLogging.Tests.csproj create mode 100644 modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/AbpAuditLoggingTestModule.cs create mode 100644 modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/AuditLogsTestBase.cs create mode 100644 modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/AuditStore_Basic_Tests.cs diff --git a/modules/audit-logging/Volo.Abp.AuditLogging.sln b/modules/audit-logging/Volo.Abp.AuditLogging.sln new file mode 100644 index 0000000000..08fd018a6d --- /dev/null +++ b/modules/audit-logging/Volo.Abp.AuditLogging.sln @@ -0,0 +1,74 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.27703.2035 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.AuditLogging.Domain.Shared", "src\Volo.Abp.AuditLogging.Domain.Shared\Volo.Abp.AuditLogging.Domain.Shared.csproj", "{6BFAB2F3-230A-45C2-8C94-4955CE3FF93E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AuditLogging.Domain", "src\Volo.Abp.AuditLogging.Domain\Volo.Abp.AuditLogging.Domain.csproj", "{1878DA13-BFA0-4EEA-A268-272DC1C34B43}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AuditLogging.EntityFrameworkCore", "src\Volo.Abp.AuditLogging.EntityFrameworkCore\Volo.Abp.AuditLogging.EntityFrameworkCore.csproj", "{E1B915D0-7F7B-4F92-B8D5-6C7DECE75E45}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AuditLogging.MongoDB", "src\Volo.Abp.AuditLogging.MongoDB\Volo.Abp.AuditLogging.MongoDB.csproj", "{FA5154D2-26B2-4DBC-8A12-536A7323F3CD}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{CFAB155F-5255-4D99-94E2-3361D8EA4B15}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{971E31E2-FC37-41D3-8B6E-96848105C446}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AuditLogging.Tests", "test\Volo.Abp.AuditLogging.Tests\Volo.Abp.AuditLogging.Tests.csproj", "{9946C645-1234-49D9-98C1-152311FBBAB5}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AuditLogging.TestBase", "test\Volo.Abp.AuditLogging.TestBase\Volo.Abp.AuditLogging.TestBase.csproj", "{6CDB588F-B5FD-4F2A-9599-49ACE2D7AF83}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AuditLogging.EntityFrameworkCore.Tests", "test\Volo.Abp.AuditLogging.EntityFrameworkCore.Tests\Volo.Abp.AuditLogging.EntityFrameworkCore.Tests.csproj", "{CBED3E11-0A33-4B56-A75C-A57D25C98C38}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6BFAB2F3-230A-45C2-8C94-4955CE3FF93E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6BFAB2F3-230A-45C2-8C94-4955CE3FF93E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6BFAB2F3-230A-45C2-8C94-4955CE3FF93E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6BFAB2F3-230A-45C2-8C94-4955CE3FF93E}.Release|Any CPU.Build.0 = Release|Any CPU + {1878DA13-BFA0-4EEA-A268-272DC1C34B43}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1878DA13-BFA0-4EEA-A268-272DC1C34B43}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1878DA13-BFA0-4EEA-A268-272DC1C34B43}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1878DA13-BFA0-4EEA-A268-272DC1C34B43}.Release|Any CPU.Build.0 = Release|Any CPU + {E1B915D0-7F7B-4F92-B8D5-6C7DECE75E45}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E1B915D0-7F7B-4F92-B8D5-6C7DECE75E45}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E1B915D0-7F7B-4F92-B8D5-6C7DECE75E45}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E1B915D0-7F7B-4F92-B8D5-6C7DECE75E45}.Release|Any CPU.Build.0 = Release|Any CPU + {FA5154D2-26B2-4DBC-8A12-536A7323F3CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FA5154D2-26B2-4DBC-8A12-536A7323F3CD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FA5154D2-26B2-4DBC-8A12-536A7323F3CD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FA5154D2-26B2-4DBC-8A12-536A7323F3CD}.Release|Any CPU.Build.0 = Release|Any CPU + {9946C645-1234-49D9-98C1-152311FBBAB5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9946C645-1234-49D9-98C1-152311FBBAB5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9946C645-1234-49D9-98C1-152311FBBAB5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9946C645-1234-49D9-98C1-152311FBBAB5}.Release|Any CPU.Build.0 = Release|Any CPU + {6CDB588F-B5FD-4F2A-9599-49ACE2D7AF83}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6CDB588F-B5FD-4F2A-9599-49ACE2D7AF83}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6CDB588F-B5FD-4F2A-9599-49ACE2D7AF83}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6CDB588F-B5FD-4F2A-9599-49ACE2D7AF83}.Release|Any CPU.Build.0 = Release|Any CPU + {CBED3E11-0A33-4B56-A75C-A57D25C98C38}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CBED3E11-0A33-4B56-A75C-A57D25C98C38}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CBED3E11-0A33-4B56-A75C-A57D25C98C38}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CBED3E11-0A33-4B56-A75C-A57D25C98C38}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {6BFAB2F3-230A-45C2-8C94-4955CE3FF93E} = {CFAB155F-5255-4D99-94E2-3361D8EA4B15} + {1878DA13-BFA0-4EEA-A268-272DC1C34B43} = {CFAB155F-5255-4D99-94E2-3361D8EA4B15} + {E1B915D0-7F7B-4F92-B8D5-6C7DECE75E45} = {CFAB155F-5255-4D99-94E2-3361D8EA4B15} + {FA5154D2-26B2-4DBC-8A12-536A7323F3CD} = {CFAB155F-5255-4D99-94E2-3361D8EA4B15} + {9946C645-1234-49D9-98C1-152311FBBAB5} = {971E31E2-FC37-41D3-8B6E-96848105C446} + {6CDB588F-B5FD-4F2A-9599-49ACE2D7AF83} = {971E31E2-FC37-41D3-8B6E-96848105C446} + {CBED3E11-0A33-4B56-A75C-A57D25C98C38} = {971E31E2-FC37-41D3-8B6E-96848105C446} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {9F36BAE5-A9CF-460C-8E7E-4580347F71F6} + EndGlobalSection +EndGlobal diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo.Abp.AuditLogging.Domain.Shared.csproj b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo.Abp.AuditLogging.Domain.Shared.csproj new file mode 100644 index 0000000000..274bae34d6 --- /dev/null +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo.Abp.AuditLogging.Domain.Shared.csproj @@ -0,0 +1,19 @@ + + + + netstandard2.0 + Volo.Abp.AuditLogging.Domain.Shared + Volo.Abp.AuditLogging.Domain.Shared + $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; + false + false + false + + + + + + + + + diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AbpAuditLoggingDomainSharedModule.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AbpAuditLoggingDomainSharedModule.cs new file mode 100644 index 0000000000..9cb51d5a3b --- /dev/null +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AbpAuditLoggingDomainSharedModule.cs @@ -0,0 +1,13 @@ +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Modularity; + +namespace Volo.Abp.AuditLogging +{ + public class AbpAuditLoggingDomainSharedModule : AbpModule + { + public override void ConfigureServices(ServiceConfigurationContext context) + { + context.Services.AddAssemblyOf(); + } + } +} diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AuditLogActionConsts.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AuditLogActionConsts.cs new file mode 100644 index 0000000000..9fc2140144 --- /dev/null +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AuditLogActionConsts.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Volo.Abp.AuditLogging +{ + public class AuditLogActionConsts + { + public static int MaxServiceNameLength = 256; + public static int MaxMethodNameLength = 256; + public static int MaxParametersLength = 1024; + } +} diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AuditLogConsts.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AuditLogConsts.cs new file mode 100644 index 0000000000..5ea616d8f9 --- /dev/null +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AuditLogConsts.cs @@ -0,0 +1,10 @@ +namespace Volo.Abp.AuditLogging +{ + public static class AuditLogConsts + { + public static int MaxClientIpAddressLength = 64; + public static int MaxClientNameLength = 128; + public static int MaxBrowserInfoLength = 512; + public static int MaxExceptionLength = 2000; + } +} diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo.Abp.AuditLogging.Domain.csproj b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo.Abp.AuditLogging.Domain.csproj new file mode 100644 index 0000000000..cbcd43a9a7 --- /dev/null +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo.Abp.AuditLogging.Domain.csproj @@ -0,0 +1,21 @@ + + + + netstandard2.0 + Volo.Abp.AuditLogging.Domain + Volo.Abp.AuditLogging.Domain + $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; + false + false + false + + + + + + + + + + + diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AbpAuditLoggingConsts.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AbpAuditLoggingConsts.cs new file mode 100644 index 0000000000..7687e15652 --- /dev/null +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AbpAuditLoggingConsts.cs @@ -0,0 +1,10 @@ + +namespace Volo.Abp.AuditLogging +{ + public static class AbpAuditLoggingConsts + { + public const string DefaultDbTablePrefix = "Abp"; + + public const string DefaultDbSchema = null; + } +} diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AbpAuditLoggingDomainModule.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AbpAuditLoggingDomainModule.cs new file mode 100644 index 0000000000..5fb0208e85 --- /dev/null +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AbpAuditLoggingDomainModule.cs @@ -0,0 +1,18 @@ +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Auditing; +using Volo.Abp.Domain; +using Volo.Abp.Modularity; + +namespace Volo.Abp.AuditLogging +{ + [DependsOn(typeof(AbpAuditingModule))] + [DependsOn(typeof(AbpDddDomainModule))] + [DependsOn(typeof(AbpAuditLoggingDomainSharedModule))] + public class AbpAuditLoggingDomainModule : AbpModule + { + public override void ConfigureServices(ServiceConfigurationContext context) + { + context.Services.AddAssemblyOf(); + } + } +} diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLog.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLog.cs new file mode 100644 index 0000000000..780e46050e --- /dev/null +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLog.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Volo.Abp.Auditing; +using Volo.Abp.Data; +using Volo.Abp.Domain.Entities; +using Volo.Abp.MultiTenancy; + +namespace Volo.Abp.AuditLogging +{ + public class AuditLog : Entity, IHasExtraProperties, IMultiTenant + { + public virtual Guid? TenantId { get; set; } + + public virtual Guid? UserId { get; set; } + + public virtual Guid? ImpersonatorUserId { get; set; } + + public virtual Guid? ImpersonatorTenantId { get; set; } + + public virtual DateTime ExecutionTime { get; set; } + + public virtual int ExecutionDuration { get; set; } + + public virtual string ClientIpAddress { get; set; } + + public virtual string ClientName { get; set; } + + public virtual string BrowserInfo { get; set; } + + public virtual List Exceptions { get; } + + public Dictionary ExtraProperties { get; } + + public ICollection EntityChanges { get; } + + public ICollection Actions { get; set; } + + protected AuditLog() + { + + } + + public AuditLog(AuditLogInfo auditInfo) + { + TenantId = auditInfo.TenantId; + UserId = auditInfo.UserId; + ExecutionTime = auditInfo.ExecutionTime; + ExecutionDuration = auditInfo.ExecutionDuration; + ClientIpAddress = auditInfo.ClientIpAddress; + ClientName = auditInfo.ClientName; + BrowserInfo = auditInfo.BrowserInfo; + ImpersonatorUserId = auditInfo.ImpersonatorUserId; + ImpersonatorTenantId = auditInfo.ImpersonatorTenantId; + ExtraProperties = auditInfo.ExtraProperties; + EntityChanges = auditInfo.EntityChanges.Select(e=> new EntityChange(e)).ToList(); + Actions = auditInfo.Actions.Select(e=> new AuditLogAction(e)).ToList(); + Exceptions = auditInfo.Exceptions.Select(e => e.ToString()).ToList(); + } + } +} diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLogAction.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLogAction.cs new file mode 100644 index 0000000000..2a7a5604bd --- /dev/null +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLogAction.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Volo.Abp.Auditing; +using Volo.Abp.Domain.Entities; +using Volo.Abp.MultiTenancy; + +namespace Volo.Abp.AuditLogging +{ + public class AuditLogAction : Entity + { + public virtual string ServiceName { get; set; } + + public virtual string MethodName { get; set; } + + public virtual string Parameters { get; set; } + + public virtual DateTime ExecutionTime { get; set; } + + public virtual int ExecutionDuration { get; set; } + + public virtual Dictionary ExtraProperties { get; } + + protected AuditLogAction() + { + ExtraProperties = new Dictionary(); + } + + public AuditLogAction(AuditLogActionInfo auditLogActionInfo) + { + ServiceName = auditLogActionInfo.ServiceName; + MethodName = auditLogActionInfo.MethodName; + Parameters = auditLogActionInfo.Parameters; + ExecutionTime = auditLogActionInfo.ExecutionTime; + ExecutionDuration = auditLogActionInfo.ExecutionDuration; + ExtraProperties = auditLogActionInfo.ExtraProperties; + } + } +} diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditingStore.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditingStore.cs new file mode 100644 index 0000000000..887ff4e97c --- /dev/null +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditingStore.cs @@ -0,0 +1,21 @@ +using System.Threading.Tasks; +using Volo.Abp.Auditing; +using Volo.Abp.DependencyInjection; + +namespace Volo.Abp.AuditLogging +{ + public class AuditingStore : IAuditingStore, ITransientDependency + { + private readonly IAuditLogRepository _auditLogRepository; + + public AuditingStore(IAuditLogRepository auditLogRepository) + { + _auditLogRepository = auditLogRepository; + } + + public async Task SaveAsync(AuditLogInfo auditInfo) + { + await _auditLogRepository.InsertAsync(new AuditLog(auditInfo)); + } + } +} diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/EntityChange.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/EntityChange.cs new file mode 100644 index 0000000000..b4b1d43ba4 --- /dev/null +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/EntityChange.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Volo.Abp.Auditing; +using Volo.Abp.Domain.Entities; +using Volo.Abp.MultiTenancy; + +namespace Volo.Abp.AuditLogging +{ + public class EntityChange : Entity, IMultiTenant + { + public virtual Guid? TenantId { get; set; } + + public virtual DateTime ChangeTime { get; set; } + + public virtual EntityChangeType ChangeType { get; set; } + + public virtual string EntityId { get; set; } + + public virtual string EntityTypeFullName { get; set; } + + public ICollection PropertyChanges { get; set; } + + protected EntityChange() + { + + } + + public EntityChange(EntityChangeInfo entityChangeInfo) + { + TenantId = entityChangeInfo.TenantId; + ChangeTime = entityChangeInfo.ChangeTime; + ChangeType = entityChangeInfo.ChangeType; + EntityId = entityChangeInfo.EntityId; + EntityTypeFullName = entityChangeInfo.EntityTypeFullName; + PropertyChanges = entityChangeInfo.PropertyChanges; + } + } +} diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogRepository.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogRepository.cs new file mode 100644 index 0000000000..c1d15c7226 --- /dev/null +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogRepository.cs @@ -0,0 +1,9 @@ +using System; +using Volo.Abp.Domain.Repositories; + +namespace Volo.Abp.AuditLogging +{ + public interface IAuditLogRepository : IBasicRepository + { + } +} diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo.Abp.AuditLogging.EntityFrameworkCore.csproj b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo.Abp.AuditLogging.EntityFrameworkCore.csproj new file mode 100644 index 0000000000..084f0f4bb8 --- /dev/null +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo.Abp.AuditLogging.EntityFrameworkCore.csproj @@ -0,0 +1,20 @@ + + + + netstandard2.0 + Volo.Abp.AuditLogging.EntityFrameworkCore + Volo.Abp.AuditLogging.EntityFrameworkCore + $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; + false + false + false + + + + + + + + + + diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingDbContext.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingDbContext.cs new file mode 100644 index 0000000000..ddcac0354a --- /dev/null +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingDbContext.cs @@ -0,0 +1,33 @@ +using Microsoft.EntityFrameworkCore; +using Volo.Abp.Data; +using Volo.Abp.EntityFrameworkCore; + +namespace Volo.Abp.AuditLogging.EntityFrameworkCore +{ + [ConnectionStringName("AbpAuditLogging")] + public class AbpAuditLoggingDbContext : AbpDbContext, IAuditLoggingDbContext + { + public static string TablePrefix { get; set; } = AbpAuditLoggingConsts.DefaultDbTablePrefix; + + public static string Schema { get; set; } = AbpAuditLoggingConsts.DefaultDbSchema; + + public DbSet AuditLogs { get; set; } + + public DbSet AuditLogAction { get; set; } + + public DbSet EntityChange { get; set; } + + public AbpAuditLoggingDbContext(DbContextOptions options) + : base(options) + { + + } + + protected override void OnModelCreating(ModelBuilder builder) + { + base.OnModelCreating(builder); + + builder.ConfigureAuditLogging(TablePrefix, Schema); + } + } +} diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingEntityFrameworkCoreModule.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingEntityFrameworkCoreModule.cs new file mode 100644 index 0000000000..f8a6efc41d --- /dev/null +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingEntityFrameworkCoreModule.cs @@ -0,0 +1,23 @@ +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.EntityFrameworkCore; +using Volo.Abp.Modularity; + +namespace Volo.Abp.AuditLogging.EntityFrameworkCore +{ + [DependsOn(typeof(AbpAuditLoggingDomainModule))] + [DependsOn(typeof(AbpEntityFrameworkCoreModule))] + public class AbpAuditLoggingEntityFrameworkCoreModule : AbpModule + { + public override void ConfigureServices(ServiceConfigurationContext context) + { + context.Services.AddAbpDbContext(options => + { + options.AddDefaultRepositories(); + + options.AddRepository(); + }); + + context.Services.AddAssemblyOf(); + } + } +} diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingtDbContextModelBuilderExtensions.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingtDbContextModelBuilderExtensions.cs new file mode 100644 index 0000000000..d0e28944a2 --- /dev/null +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingtDbContextModelBuilderExtensions.cs @@ -0,0 +1,61 @@ +using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore; +using Volo.Abp; +using Volo.Abp.EntityFrameworkCore.Modeling; + +namespace Volo.Abp.AuditLogging.EntityFrameworkCore +{ + public static class AbpAuditLoggingtDbContextModelBuilderExtensions + { + public static void ConfigureAuditLogging( + [NotNull] this ModelBuilder builder, + [CanBeNull] string tablePrefix = AbpAuditLoggingConsts.DefaultDbTablePrefix, + [CanBeNull] string schema = AbpAuditLoggingConsts.DefaultDbSchema) + { + Check.NotNull(builder, nameof(builder)); + + if (tablePrefix == null) + { + tablePrefix = ""; + } + + builder.Entity(b => + { + b.ToTable(tablePrefix + "AuditLogs", schema); + + b.Property(x => x.ClientIpAddress).HasMaxLength(AuditLogConsts.MaxClientIpAddressLength); + b.Property(x => x.ClientName).HasMaxLength(AuditLogConsts.MaxClientNameLength); + b.Property(x => x.BrowserInfo).HasMaxLength(AuditLogConsts.MaxBrowserInfoLength); + b.Property(x => x.Exceptions).HasMaxLength(AuditLogConsts.MaxExceptionLength); + + b.HasIndex(x => new { x.TenantId, x.UserId, x.ExecutionTime}); + + b.HasOne().WithMany().HasForeignKey(x => x.EntityChanges); + b.HasOne().WithMany().HasForeignKey(x => x.Actions); + }); + + builder.Entity(b => + { + b.ToTable(tablePrefix + "EntityChanges", schema); + + b.Property(x => x.EntityTypeFullName).IsRequired(); + b.Property(x => x.EntityId).IsRequired(); + + b.HasIndex(x => new { x.TenantId, x.EntityTypeFullName}); + }); + + builder.Entity(b => + { + b.ToTable(tablePrefix + "AuditLogActions", schema); + + b.Property(x => x.ServiceName).HasMaxLength(AuditLogActionConsts.MaxServiceNameLength); + b.Property(x => x.MethodName).HasMaxLength(AuditLogActionConsts.MaxMethodNameLength); + b.Property(x => x.Parameters).HasMaxLength(AuditLogActionConsts.MaxParametersLength); + + b.HasIndex(x => new { x.ServiceName, x.ExecutionTime}); + }); + + + } + } +} diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/EfCoreAuditLogRepository.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/EfCoreAuditLogRepository.cs new file mode 100644 index 0000000000..ead5cfec1b --- /dev/null +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/EfCoreAuditLogRepository.cs @@ -0,0 +1,15 @@ +using System; +using Volo.Abp.Domain.Repositories.EntityFrameworkCore; +using Volo.Abp.EntityFrameworkCore; + +namespace Volo.Abp.AuditLogging.EntityFrameworkCore +{ + public class EfCoreAuditLogRepository : EfCoreRepository, IAuditLogRepository + { + public EfCoreAuditLogRepository(IDbContextProvider dbContextProvider) + : base(dbContextProvider) + { + } + + } +} diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/IAuditLoggingDbContext.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/IAuditLoggingDbContext.cs new file mode 100644 index 0000000000..28c8fcdad3 --- /dev/null +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/IAuditLoggingDbContext.cs @@ -0,0 +1,16 @@ +using Microsoft.EntityFrameworkCore; +using Volo.Abp.Data; +using Volo.Abp.EntityFrameworkCore; + +namespace Volo.Abp.AuditLogging.EntityFrameworkCore +{ + [ConnectionStringName("AbpAuditLogging")] + public interface IAuditLoggingDbContext : IEfCoreDbContext + { + DbSet AuditLogs { get; set; } + + DbSet AuditLogAction { get; set; } + + DbSet EntityChange { get; set; } + } +} \ No newline at end of file diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo.Abp.AuditLogging.MongoDB.csproj b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo.Abp.AuditLogging.MongoDB.csproj new file mode 100644 index 0000000000..87c4f90379 --- /dev/null +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo.Abp.AuditLogging.MongoDB.csproj @@ -0,0 +1,20 @@ + + + + netstandard2.0 + Volo.Abp.AuditLogging.MongoDB + Volo.Abp.AuditLogging.MongoDB + $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; + false + false + false + + + + + + + + + + diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AbpAuditLoggingBsonClassMap.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AbpAuditLoggingBsonClassMap.cs new file mode 100644 index 0000000000..cb8fa2eb67 --- /dev/null +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AbpAuditLoggingBsonClassMap.cs @@ -0,0 +1,21 @@ +using MongoDB.Bson.Serialization; +using Volo.Abp.Threading; + +namespace Volo.Abp.AuditLogging.MongoDB +{ + public static class AbpAuditLoggingBsonClassMap + { + private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner(); + + public static void Configure() + { + OneTimeRunner.Run(() => + { + BsonClassMap.RegisterClassMap(map => + { + map.AutoMap(); + }); + }); + } + } +} diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AbpAuditLoggingMongoDbModule.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AbpAuditLoggingMongoDbModule.cs new file mode 100644 index 0000000000..7cb873028f --- /dev/null +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AbpAuditLoggingMongoDbModule.cs @@ -0,0 +1,25 @@ +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Modularity; +using Volo.Abp.MongoDB; + +namespace Volo.Abp.AuditLogging.MongoDB +{ + [DependsOn(typeof(AbpAuditLoggingDomainModule))] + [DependsOn(typeof(AbpMongoDbModule))] + public class AbpAuditLoggingMongoDbModule : AbpModule + { + public override void ConfigureServices(ServiceConfigurationContext context) + { + AbpAuditLoggingBsonClassMap.Configure(); + + context.Services.AddMongoDbContext(options => + { + options.AddDefaultRepositories(); + + options.AddRepository(); + }); + + context.Services.AddAssemblyOf(); + } + } +} diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AbpSettingManagementMongoDbContextExtensions.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AbpSettingManagementMongoDbContextExtensions.cs new file mode 100644 index 0000000000..62ddbd5d35 --- /dev/null +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AbpSettingManagementMongoDbContextExtensions.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Volo.Abp.MongoDB; + +namespace Volo.Abp.AuditLogging.MongoDB +{ + public static class AbpSettingManagementMongoDbContextExtensions + { + public static void ConfigureSettingManagement( + this IMongoModelBuilder builder, + Action optionsAction = null) + { + Check.NotNull(builder, nameof(builder)); + + var options = new AuditLoggingMongoModelBuilderConfigurationOptions(); + + optionsAction?.Invoke(options); + + builder.Entity(b => + { + b.CollectionName = options.CollectionPrefix + "Settings"; + }); + } + } +} diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AuditLoggingMongoDbContext.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AuditLoggingMongoDbContext.cs new file mode 100644 index 0000000000..0c30099899 --- /dev/null +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AuditLoggingMongoDbContext.cs @@ -0,0 +1,24 @@ +using MongoDB.Driver; +using Volo.Abp.Data; +using Volo.Abp.MongoDB; + +namespace Volo.Abp.AuditLogging.MongoDB +{ + [ConnectionStringName("AbpAuditLogging")] + public class AuditLoggingMongoDbContext : AbpMongoDbContext, IAuditLoggingMongoDbContext + { + public static string CollectionPrefix { get; set; } = AbpAuditLoggingConsts.DefaultDbTablePrefix; + + public IMongoCollection AuditLogs => Collection(); + + protected override void CreateModel(IMongoModelBuilder modelBuilder) + { + base.CreateModel(modelBuilder); + + modelBuilder.ConfigureSettingManagement(options => + { + options.CollectionPrefix = CollectionPrefix; + }); + } + } +} diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AuditLoggingMongoModelBuilderConfigurationOptions.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AuditLoggingMongoModelBuilderConfigurationOptions.cs new file mode 100644 index 0000000000..3f31028b5a --- /dev/null +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AuditLoggingMongoModelBuilderConfigurationOptions.cs @@ -0,0 +1,13 @@ +using JetBrains.Annotations; +using Volo.Abp.MongoDB; + +namespace Volo.Abp.AuditLogging.MongoDB +{ + public class AuditLoggingMongoModelBuilderConfigurationOptions : MongoModelBuilderConfigurationOptions + { + public AuditLoggingMongoModelBuilderConfigurationOptions([NotNull] string tablePrefix = AbpAuditLoggingConsts.DefaultDbTablePrefix) + : base(tablePrefix) + { + } + } +} diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/IAuditLoggingMongoDbContext.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/IAuditLoggingMongoDbContext.cs new file mode 100644 index 0000000000..f7f30a3083 --- /dev/null +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/IAuditLoggingMongoDbContext.cs @@ -0,0 +1,12 @@ +using MongoDB.Driver; +using Volo.Abp.Data; +using Volo.Abp.MongoDB; + +namespace Volo.Abp.AuditLogging.MongoDB +{ + [ConnectionStringName("AbpAuditLogging")] + public interface IAuditLoggingMongoDbContext : IAbpMongoDbContext + { + IMongoCollection AuditLogs { get; } + } +} diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs new file mode 100644 index 0000000000..61c83861eb --- /dev/null +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs @@ -0,0 +1,15 @@ +using System; +using Volo.Abp.Domain.Repositories.MongoDB; +using Volo.Abp.MongoDB; + +namespace Volo.Abp.AuditLogging.MongoDB +{ + public class MongoAuditLogRepository : MongoDbRepository, IAuditLogRepository + { + public MongoAuditLogRepository(IMongoDbContextProvider dbContextProvider) + : base(dbContextProvider) + { + + } + } +} diff --git a/modules/audit-logging/test/Volo.Abp.AuditLogging.EntityFrameworkCore.Tests/Volo.Abp.AuditLogging.EntityFrameworkCore.Tests.csproj b/modules/audit-logging/test/Volo.Abp.AuditLogging.EntityFrameworkCore.Tests/Volo.Abp.AuditLogging.EntityFrameworkCore.Tests.csproj new file mode 100644 index 0000000000..f161c9e4d8 --- /dev/null +++ b/modules/audit-logging/test/Volo.Abp.AuditLogging.EntityFrameworkCore.Tests/Volo.Abp.AuditLogging.EntityFrameworkCore.Tests.csproj @@ -0,0 +1,25 @@ + + + + netstandard2.0 + Volo.Abp.AuditLogging.EntityFrameworkCore.Tests + Volo.Abp.AuditLogging.EntityFrameworkCore.Tests + true + false + false + false + + + + + + + + + + + + + + + diff --git a/modules/audit-logging/test/Volo.Abp.AuditLogging.EntityFrameworkCore.Tests/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingEntityFrameworkCoreTestModule.cs b/modules/audit-logging/test/Volo.Abp.AuditLogging.EntityFrameworkCore.Tests/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingEntityFrameworkCoreTestModule.cs new file mode 100644 index 0000000000..55f837773d --- /dev/null +++ b/modules/audit-logging/test/Volo.Abp.AuditLogging.EntityFrameworkCore.Tests/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingEntityFrameworkCoreTestModule.cs @@ -0,0 +1,40 @@ +using Microsoft.Data.Sqlite; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.EntityFrameworkCore; +using Volo.Abp.Modularity; + +namespace Volo.Abp.AuditLogging.EntityFrameworkCore +{ + public class AbpAuditLoggingEntityFrameworkCoreTestModule : AbpModule + { + public override void ConfigureServices(ServiceConfigurationContext context) + { + var sqliteConnection = CreateDatabaseAndGetConnection(); + + context.Services.Configure(options => + { + options.Configure(abpDbContextConfigurationContext => + { + abpDbContextConfigurationContext.DbContextOptions.UseSqlite(sqliteConnection); + }); + }); + + context.Services.AddAssemblyOf(); + } + + private static SqliteConnection CreateDatabaseAndGetConnection() + { + var connection = new SqliteConnection("Data Source=:memory:"); + connection.Open(); + + new AbpAuditLoggingDbContext( + new DbContextOptionsBuilder().UseSqlite(connection).Options + ).GetService().CreateTables(); + + return connection; + } + } +} \ No newline at end of file diff --git a/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo.Abp.AuditLogging.TestBase.csproj b/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo.Abp.AuditLogging.TestBase.csproj new file mode 100644 index 0000000000..908d8ed2bf --- /dev/null +++ b/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo.Abp.AuditLogging.TestBase.csproj @@ -0,0 +1,29 @@ + + + + netstandard2.0 + Volo.Abp.AuditLogging.TestBase + Volo.Abp.AuditLogging.TestBase + true + false + false + false + + + + + + + + + + + + + + + + + + + diff --git a/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AbpAuditLoggingTestBaseModule.cs b/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AbpAuditLoggingTestBaseModule.cs new file mode 100644 index 0000000000..78800a7c86 --- /dev/null +++ b/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AbpAuditLoggingTestBaseModule.cs @@ -0,0 +1,33 @@ +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Autofac; +using Volo.Abp.Modularity; + +namespace Volo.Abp.AuditLogging +{ + [DependsOn( + typeof(AbpAutofacModule), + typeof(AbpTestBaseModule), + typeof(AbpAuditLoggingDomainModule))] + public class AbpAuditLoggingTestBaseModule : AbpModule + { + public override void ConfigureServices(ServiceConfigurationContext context) + { + context.Services.AddAssemblyOf(); + } + + public override void OnApplicationInitialization(ApplicationInitializationContext context) + { + SeedTestData(context); + } + + private static void SeedTestData(ApplicationInitializationContext context) + { + using (var scope = context.ServiceProvider.CreateScope()) + { + scope.ServiceProvider + .GetRequiredService () + .Build(); + } + } + } +} diff --git a/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditLoggingTestBase.cs b/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditLoggingTestBase.cs new file mode 100644 index 0000000000..6cbe6bd126 --- /dev/null +++ b/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditLoggingTestBase.cs @@ -0,0 +1,13 @@ +using Volo.Abp.Modularity; + +namespace Volo.Abp.AuditLogging +{ + public class AuditLoggingTestBase : AbpIntegratedTest + where TStartupModule : IAbpModule + { + protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) + { + options.UseAutofac(); + } + } +} diff --git a/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditingTestData.cs b/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditingTestData.cs new file mode 100644 index 0000000000..314ca30390 --- /dev/null +++ b/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditingTestData.cs @@ -0,0 +1,16 @@ +using System; +using Volo.Abp.DependencyInjection; + +namespace Volo.Abp.AuditLogging +{ + public class AuditingTestData : ISingletonDependency + { + public Guid UserId { get; } = Guid.NewGuid(); + + public Guid TenantId { get; } = Guid.NewGuid(); + + public Guid ImpersonatorUserId { get; } = Guid.NewGuid(); + + public Guid ImpersonatorTenantId { get; } = Guid.NewGuid(); + } +} diff --git a/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditingTestDataBuilder.cs b/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditingTestDataBuilder.cs new file mode 100644 index 0000000000..9b53c00850 --- /dev/null +++ b/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditingTestDataBuilder.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using Volo.Abp.DependencyInjection; + +namespace Volo.Abp.AuditLogging +{ + public class AuditingTestDataBuilder : ITransientDependency + { + private readonly IAuditLogRepository _auditLogRepository; + private readonly AuditingTestData _auditingTestData; + + public AuditingTestDataBuilder(IAuditLogRepository auditLogRepository, AuditingTestData auditingTestData ) + { + _auditLogRepository = auditLogRepository; + _auditingTestData = auditingTestData; + } + + public void Build() + { + + } + } +} \ No newline at end of file diff --git a/modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo.Abp.AuditLogging.Tests.csproj b/modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo.Abp.AuditLogging.Tests.csproj new file mode 100644 index 0000000000..a6f0862adf --- /dev/null +++ b/modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo.Abp.AuditLogging.Tests.csproj @@ -0,0 +1,22 @@ + + + + netstandard2.0 + Volo.Abp.AuditLogging.Tests + Volo.Abp.AuditLogging.Tests + true + false + false + false + + + + + + + + + + + + diff --git a/modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/AbpAuditLoggingTestModule.cs b/modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/AbpAuditLoggingTestModule.cs new file mode 100644 index 0000000000..d4d93faab5 --- /dev/null +++ b/modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/AbpAuditLoggingTestModule.cs @@ -0,0 +1,15 @@ +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.AuditLogging.EntityFrameworkCore; +using Volo.Abp.Modularity; + +namespace Volo.Abp.AuditLogging +{ + [DependsOn(typeof(AbpAuditLoggingEntityFrameworkCoreTestModule))] + public class AbpAuditLoggingTestModule : AbpModule + { + public override void ConfigureServices(ServiceConfigurationContext context) + { + context.Services.AddAssemblyOf(); + } + } +} diff --git a/modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/AuditLogsTestBase.cs b/modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/AuditLogsTestBase.cs new file mode 100644 index 0000000000..5757dafabe --- /dev/null +++ b/modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/AuditLogsTestBase.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Volo.Abp.AuditLogging.EntityFrameworkCore; + +namespace Volo.Abp.AuditLogging +{ + public class AuditLogsTestBase : AuditLoggingTestBase + { + protected virtual void UsingDbContext(Action action) + { + using (var dbContext = GetRequiredService()) + { + action.Invoke(dbContext); + } + } + + protected virtual T UsingDbContext(Func action) + { + using (var dbContext = GetRequiredService()) + { + return action.Invoke(dbContext); + } + } + + protected List GetSAuditLogsFromDbContext() + { + return UsingDbContext(context => + context.AuditLogs.ToList() + ); + } + } +} \ No newline at end of file diff --git a/modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/AuditStore_Basic_Tests.cs b/modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/AuditStore_Basic_Tests.cs new file mode 100644 index 0000000000..03682dc980 --- /dev/null +++ b/modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/AuditStore_Basic_Tests.cs @@ -0,0 +1,42 @@ +using System; +using System.Threading.Tasks; +using Volo.Abp.Auditing; +using Xunit; + +namespace Volo.Abp.AuditLogging +{ + public class AuditStore_Basic_Tests : AuditLogsTestBase + { + private readonly IAuditingStore _auditingStore; + + public AuditStore_Basic_Tests() + { + _auditingStore = GetRequiredService(); + } + + [Fact] + public async Task Should_Save_A_Audit_Log() + { + var auditLog = new AuditLogInfo() + { + TenantId = Guid.NewGuid(), + UserId = Guid.NewGuid(), + ImpersonatorUserId = Guid.NewGuid(), + ImpersonatorTenantId = Guid.NewGuid(), + ExecutionTime = DateTime.Today, + ExecutionDuration = 42, + ClientIpAddress = "153.1.7.61", + ClientName = "MyDesktop", + BrowserInfo = "Chrome", + //ServiceName = "SampleService2", + //MethodName = "SampleMethod2", + //Parameters = "SampleParameter", + //Exceptions = new Exceptions("something went wrong.") + }; + + await Assert.ThrowsAsync( + async () => await _auditingStore.SaveAsync(auditLog) + ); + } + } +}