mirror of https://github.com/abpframework/abp.git
committed by
GitHub
10 changed files with 449 additions and 315 deletions
@ -1,35 +1,35 @@ |
|||||
using Microsoft.AspNetCore.Mvc; |
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.Extensions.Options; |
using Microsoft.Extensions.Options; |
||||
using Volo.Abp.Auditing; |
using Volo.Abp.Auditing; |
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Mvc.Auditing |
namespace Volo.Abp.AspNetCore.Mvc.Auditing |
||||
{ |
{ |
||||
[Route("api/audit-test")] |
[Route("api/audit-test")] |
||||
[Audited] |
[Audited] |
||||
public class AuditTestController : AbpController |
public class AuditTestController : AbpController |
||||
{ |
{ |
||||
private readonly AbpAuditingOptions _options; |
private readonly AbpAuditingOptions _options; |
||||
|
|
||||
public AuditTestController(IOptions<AbpAuditingOptions> options) |
public AuditTestController(IOptions<AbpAuditingOptions> options) |
||||
{ |
{ |
||||
_options = options.Value; |
_options = options.Value; |
||||
} |
} |
||||
|
|
||||
[Route("audit-success")] |
[Route("audit-success")] |
||||
public IActionResult AuditSuccessForGetRequests() |
public IActionResult AuditSuccessForGetRequests() |
||||
{ |
{ |
||||
return Ok(); |
return Ok(); |
||||
} |
} |
||||
|
|
||||
[Route("audit-fail")] |
[Route("audit-fail")] |
||||
public IActionResult AuditFailForGetRequests() |
public IActionResult AuditFailForGetRequests() |
||||
{ |
{ |
||||
throw new UserFriendlyException("Exception occurred!"); |
throw new UserFriendlyException("Exception occurred!"); |
||||
} |
} |
||||
[Route("audit-fail-object")] |
[Route("audit-fail-object")] |
||||
public object AuditFailForGetRequestsReturningObject() |
public object AuditFailForGetRequestsReturningObject() |
||||
{ |
{ |
||||
throw new UserFriendlyException("Exception occurred!"); |
throw new UserFriendlyException("Exception occurred!"); |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -1,65 +1,65 @@ |
|||||
using System; |
using System; |
||||
using Microsoft.Extensions.DependencyInjection; |
using Microsoft.Extensions.DependencyInjection; |
||||
using Microsoft.Extensions.DependencyInjection.Extensions; |
using Microsoft.Extensions.DependencyInjection.Extensions; |
||||
using Microsoft.Extensions.Hosting; |
using Microsoft.Extensions.Hosting; |
||||
using Microsoft.Extensions.Options; |
using Microsoft.Extensions.Options; |
||||
using NSubstitute; |
using NSubstitute; |
||||
using System.Threading.Tasks; |
using System.Threading.Tasks; |
||||
using Volo.Abp.Auditing; |
using Volo.Abp.Auditing; |
||||
using Xunit; |
using Xunit; |
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Mvc.Auditing |
namespace Volo.Abp.AspNetCore.Mvc.Auditing |
||||
{ |
{ |
||||
public class AuditTestController_Tests : AspNetCoreMvcTestBase |
public class AuditTestController_Tests : AspNetCoreMvcTestBase |
||||
{ |
{ |
||||
private readonly AbpAuditingOptions _options; |
private readonly AbpAuditingOptions _options; |
||||
private IAuditingStore _auditingStore; |
private IAuditingStore _auditingStore; |
||||
|
|
||||
public AuditTestController_Tests() |
public AuditTestController_Tests() |
||||
{ |
{ |
||||
_options = ServiceProvider.GetRequiredService<IOptions<AbpAuditingOptions>>().Value; |
_options = ServiceProvider.GetRequiredService<IOptions<AbpAuditingOptions>>().Value; |
||||
_auditingStore = ServiceProvider.GetRequiredService<IAuditingStore>(); |
_auditingStore = ServiceProvider.GetRequiredService<IAuditingStore>(); |
||||
} |
} |
||||
|
|
||||
protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services) |
protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services) |
||||
{ |
{ |
||||
_auditingStore = Substitute.For<IAuditingStore>(); |
_auditingStore = Substitute.For<IAuditingStore>(); |
||||
services.Replace(ServiceDescriptor.Singleton(_auditingStore)); |
services.Replace(ServiceDescriptor.Singleton(_auditingStore)); |
||||
base.ConfigureServices(context, services); |
base.ConfigureServices(context, services); |
||||
} |
} |
||||
|
|
||||
[Fact] |
[Fact] |
||||
public async Task Should_Trigger_Middleware_And_AuditLog_Success_For_GetRequests() |
public async Task Should_Trigger_Middleware_And_AuditLog_Success_For_GetRequests() |
||||
{ |
{ |
||||
_options.IsEnabledForGetRequests = true; |
_options.IsEnabledForGetRequests = true; |
||||
_options.AlwaysLogOnException = false; |
_options.AlwaysLogOnException = false; |
||||
await GetResponseAsync("api/audit-test/audit-success"); |
await GetResponseAsync("api/audit-test/audit-success"); |
||||
await _auditingStore.Received().SaveAsync(Arg.Any<AuditLogInfo>()); |
await _auditingStore.Received().SaveAsync(Arg.Any<AuditLogInfo>()); |
||||
} |
} |
||||
|
|
||||
[Fact] |
[Fact] |
||||
public async Task Should_Trigger_Middleware_And_AuditLog_Exception_Always() |
public async Task Should_Trigger_Middleware_And_AuditLog_Exception_Always() |
||||
{ |
{ |
||||
_options.IsEnabled = true; |
_options.IsEnabled = true; |
||||
_options.AlwaysLogOnException = true; |
_options.AlwaysLogOnException = true; |
||||
|
|
||||
try |
try |
||||
{ |
{ |
||||
await GetResponseAsync("api/audit-test/audit-fail", System.Net.HttpStatusCode.Forbidden); |
await GetResponseAsync("api/audit-test/audit-fail", System.Net.HttpStatusCode.Forbidden); |
||||
} |
} |
||||
catch { } |
catch { } |
||||
|
|
||||
await _auditingStore.Received().SaveAsync(Arg.Any<AuditLogInfo>()); |
await _auditingStore.Received().SaveAsync(Arg.Any<AuditLogInfo>()); |
||||
} |
} |
||||
[Fact] |
[Fact] |
||||
public async Task Should_Trigger_Middleware_And_AuditLog_Exception_When_Returns_Object() |
public async Task Should_Trigger_Middleware_And_AuditLog_Exception_When_Returns_Object() |
||||
{ |
{ |
||||
_options.IsEnabled = true; |
_options.IsEnabled = true; |
||||
_options.AlwaysLogOnException = true; |
_options.AlwaysLogOnException = true; |
||||
|
|
||||
await GetResponseAsync("api/audit-test/audit-fail-object", System.Net.HttpStatusCode.Forbidden); |
await GetResponseAsync("api/audit-test/audit-fail-object", System.Net.HttpStatusCode.Forbidden); |
||||
|
|
||||
await _auditingStore.Received().SaveAsync(Arg.Any<AuditLogInfo>()); |
await _auditingStore.Received().SaveAsync(Arg.Any<AuditLogInfo>()); |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,53 @@ |
|||||
|
@using Volo.Docs.Pages.Documents.Shared.DocumentNotFoundComponent |
||||
|
@model DocumentNotFoundPageModel |
||||
|
@{ |
||||
|
} |
||||
|
<div class="row position-relative vh-100" style="background: #e8e8e8;"> |
||||
|
<div class="center"> |
||||
|
<span class="notfound-404">404</span> |
||||
|
<h1> |
||||
|
<strong>"@Model.DocumentName"</strong> not found in <strong>@Model.ProjectName</strong> documents, with <strong>@Model.Version</strong> version and <strong>@Model.LanguageCode</strong> language. |
||||
|
</h1> |
||||
|
<br /> |
||||
|
<a href="@(Model.DocumentsUrlPrefix + Model.LanguageCode + "/" +Model.ProjectName + "/" + Model.Version)" class="btn btn-primary px-4"> |
||||
|
Go Back |
||||
|
</a> |
||||
|
</div> |
||||
|
</div> |
||||
|
|
||||
|
|
||||
|
<style> |
||||
|
h1 { |
||||
|
font-size: 1.75em; |
||||
|
line-height: 1.75; |
||||
|
color: #777; |
||||
|
font-weight: normal; |
||||
|
} |
||||
|
|
||||
|
h1 strong { |
||||
|
color: #222; |
||||
|
} |
||||
|
|
||||
|
.center { |
||||
|
position: absolute; |
||||
|
left: 50%; |
||||
|
top: 50%; |
||||
|
-webkit-transform: translate(-50%, -50%); |
||||
|
-ms-transform: translate(-50%, -50%); |
||||
|
transform: translate(-50%, -50%); |
||||
|
text-align: center; |
||||
|
} |
||||
|
|
||||
|
.notfound-404 { |
||||
|
font-size: 300px; |
||||
|
font-weight: 700; |
||||
|
line-height: 1.25; |
||||
|
margin: 0px; |
||||
|
color: #fff; |
||||
|
text-transform: uppercase; |
||||
|
display: block; |
||||
|
margin-bottom: -150px; |
||||
|
z-index: -1; |
||||
|
position: relative; |
||||
|
} |
||||
|
</style> |
||||
@ -0,0 +1,15 @@ |
|||||
|
namespace Volo.Docs.Pages.Documents.Shared.DocumentNotFoundComponent |
||||
|
{ |
||||
|
public class DocumentNotFoundPageModel |
||||
|
{ |
||||
|
public string ProjectName { get; set; } |
||||
|
|
||||
|
public string LanguageCode { get; set; } |
||||
|
|
||||
|
public string Version { get; set; } |
||||
|
|
||||
|
public string DocumentName { get; set; } |
||||
|
|
||||
|
public string DocumentsUrlPrefix { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,26 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using Microsoft.Extensions.Options; |
||||
|
using Volo.Abp.AspNetCore.Mvc; |
||||
|
|
||||
|
namespace Volo.Docs.Pages.Documents.Shared.DocumentNotFoundComponent |
||||
|
{ |
||||
|
public class DocumentNotFoundViewComponent : AbpViewComponent |
||||
|
{ |
||||
|
private readonly DocsUiOptions _options; |
||||
|
|
||||
|
public DocumentNotFoundViewComponent(IOptions<DocsUiOptions> options) |
||||
|
{ |
||||
|
_options = options.Value; |
||||
|
} |
||||
|
public IViewComponentResult Invoke(DocumentNotFoundPageModel model, string defaultErrorMessageKey) |
||||
|
{ |
||||
|
model.DocumentsUrlPrefix = _options.RoutePrefix; |
||||
|
|
||||
|
return View("~/Pages/Documents/Shared/DocumentNotFoundComponent/Default.cshtml", model); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue