1.2.7 - cache reset support
parent
4b1f168bef
commit
e08972292c
|
@ -1,7 +1,7 @@
|
|||
<Project>
|
||||
<Import Project="dependencies.props" />
|
||||
<PropertyGroup>
|
||||
<Version>1.2.5</Version>
|
||||
<Version>1.2.7</Version>
|
||||
<Authors>Tudor Stanciu</Authors>
|
||||
<Company>STA</Company>
|
||||
<PackageTags>NetworkResurrector</PackageTags>
|
||||
|
|
|
@ -188,6 +188,16 @@
|
|||
<Content>
|
||||
General improvements
|
||||
• Added environment variables support for frontend.
|
||||
• From now on, there is no hardcoded URL in the source code of the application.
|
||||
</Content>
|
||||
</Note>
|
||||
<Note>
|
||||
<Version>1.2.7</Version>
|
||||
<Date>2023-05-07 00:52</Date>
|
||||
<Content>
|
||||
Cache reset support
|
||||
• A new permission called "System administration" has been added.
|
||||
• The cache can now be reset from UI by a user who has "System administration" permission.
|
||||
</Content>
|
||||
</Note>
|
||||
</ReleaseNotes>
|
|
@ -0,0 +1,28 @@
|
|||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Netmash.Extensions.Caching.Services;
|
||||
using NetworkResurrector.Api.PublishedLanguage.Commands;
|
||||
using NetworkResurrector.Api.PublishedLanguage.Dto;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NetworkResurrector.Api.Application.CommandHandlers
|
||||
{
|
||||
internal class ResetCacheHandler : IRequestHandler<ResetCache, CommandResult>
|
||||
{
|
||||
private readonly ILogger<CancelMachineHandler> _logger;
|
||||
private readonly ICacheService _cache;
|
||||
|
||||
public ResetCacheHandler(ILogger<CancelMachineHandler> logger, ICacheService cache)
|
||||
{
|
||||
_logger=logger;
|
||||
_cache=cache;
|
||||
}
|
||||
|
||||
public async Task<CommandResult> Handle(ResetCache request, CancellationToken cancellationToken)
|
||||
{
|
||||
_cache.Reset();
|
||||
return await Task.FromResult(new CommandResult());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NetworkResurrector.Server.Wrapper.Services;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
@ -23,21 +24,23 @@ namespace NetworkResurrector.Api.Application.Queries
|
|||
public class QueryHandler : IRequestHandler<Query, Model>
|
||||
{
|
||||
private readonly IResurrectorService _resurrectorService;
|
||||
private readonly ILogger<GetSystemVersion> _logger;
|
||||
|
||||
public QueryHandler(IResurrectorService resurrectorService)
|
||||
public QueryHandler(IResurrectorService resurrectorService, ILogger<GetSystemVersion> logger)
|
||||
{
|
||||
_resurrectorService=resurrectorService;
|
||||
_logger=logger;
|
||||
}
|
||||
|
||||
public async Task<Model> Handle(Query request, CancellationToken cancellationToken)
|
||||
{
|
||||
var serverVersion = await _resurrectorService.GetServiceVersion();
|
||||
var apiVersion = GetApiVersion();
|
||||
var serverVersion = await GetServerVersion();
|
||||
|
||||
var result = new Model
|
||||
{
|
||||
Api = apiVersion,
|
||||
Server = new ServiceVersion(serverVersion.Version, serverVersion.LastReleaseDate)
|
||||
Server = serverVersion
|
||||
};
|
||||
|
||||
return result;
|
||||
|
@ -60,6 +63,20 @@ namespace NetworkResurrector.Api.Application.Queries
|
|||
var result = new ServiceVersion(version, lastReleaseDate);
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<ServiceVersion> GetServerVersion()
|
||||
{
|
||||
try
|
||||
{
|
||||
var serverVersion = await _resurrectorService.GetServiceVersion();
|
||||
return new ServiceVersion(serverVersion.Version, serverVersion.LastReleaseDate);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Server version could not be obtained.");
|
||||
}
|
||||
return new ServiceVersion("0.0.0", DateTime.MinValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,9 @@
|
|||
<None Update="Scripts\1.2.5\02.UserRoleAuthorization table.sql">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Scripts\1.2.6\01.Add system administration permission.sql">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
if not exists (select top 1 1 from Permission where PermissionCode = 'SYSTEM_ADMINISTRATION')
|
||||
begin
|
||||
insert into Permission(PermissionCode, PermissionName, PermissionDescription)
|
||||
values ('SYSTEM_ADMINISTRATION', 'System administration', 'The user with this permission can perform system administration operations such as resetting the cache.')
|
||||
end
|
|
@ -9,6 +9,7 @@
|
|||
VIEW_MACHINES = "VIEW_MACHINES",
|
||||
MANAGE_MACHINES = "MANAGE_MACHINES",
|
||||
OPERATE_MACHINES = "OPERATE_MACHINES",
|
||||
GUEST_ACCESS = "GUEST_ACCESS";
|
||||
GUEST_ACCESS = "GUEST_ACCESS",
|
||||
SYSTEM_ADMINISTRATION = "SYSTEM_ADMINISTRATION";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
using MediatR;
|
||||
using NetworkResurrector.Api.PublishedLanguage.Dto;
|
||||
|
||||
namespace NetworkResurrector.Api.PublishedLanguage.Commands
|
||||
{
|
||||
public record ResetCache : IRequest<CommandResult> { }
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
namespace NetworkResurrector.Api.PublishedLanguage.Dto
|
||||
{
|
||||
public record CommandResult();
|
||||
}
|
|
@ -4,6 +4,7 @@
|
|||
{
|
||||
public const string
|
||||
OperateMachines = "OPERATE_MACHINES",
|
||||
ViewMachines = "VIEW_MACHINES";
|
||||
ViewMachines = "VIEW_MACHINES",
|
||||
SystemAdministration = "SYSTEM_ADMINISTRATION";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,10 @@ namespace NetworkResurrector.Api.Authorization
|
|||
{
|
||||
policy.Requirements.Add(new ViewMachinesRequirement());
|
||||
});
|
||||
options.AddPolicy(Policies.SystemAdministration, policy =>
|
||||
{
|
||||
policy.Requirements.Add(new SystemAdministrationRequirement());
|
||||
});
|
||||
});
|
||||
|
||||
services.AddScoped<IAuthorizationHandler, PermissionsBasedAuthorizationHandler>();
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
using NetworkResurrector.Api.Domain.Constants;
|
||||
|
||||
namespace NetworkResurrector.Api.Authorization.Requirements
|
||||
{
|
||||
public class SystemAdministrationRequirement : IPermissionsBasedAuthorizationRequirement
|
||||
{
|
||||
public string[] AllRequired => new string[] { PermissionCodes.SYSTEM_ADMINISTRATION };
|
||||
public string[] OneOf => null;
|
||||
}
|
||||
}
|
|
@ -2,6 +2,8 @@
|
|||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NetworkResurrector.Api.Application.Queries;
|
||||
using NetworkResurrector.Api.Authorization.Constants;
|
||||
using NetworkResurrector.Api.PublishedLanguage.Commands;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
@ -39,5 +41,13 @@ namespace NetworkResurrector.Api.Controllers
|
|||
var result = await _mediator.Send(query);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpPost("reset-cache")]
|
||||
[Authorize(Policy = Policies.SystemAdministration)]
|
||||
public async Task<IActionResult> WakeMachine([FromBody] ResetCache resetCache)
|
||||
{
|
||||
var result = await _mediator.Send(resetCache);
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue