feat(api): добавлено поле lastLogon в таблицы Users, Hosts
This commit is contained in:
@@ -13,6 +13,8 @@
|
|||||||
public string? WorkGroup { get; set; }
|
public string? WorkGroup { get; set; }
|
||||||
|
|
||||||
public string? ResponseArea { get; set; }
|
public string? ResponseArea { get; set; }
|
||||||
|
|
||||||
|
public DateTimeOffset? LastLogon { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
public string Description { get; set; } = string.Empty;
|
public string Description { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public DateTimeOffset? LastLogon { get; set; }
|
||||||
|
|
||||||
public List<RoleResponse>? Roles { get; set; }
|
public List<RoleResponse>? Roles { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,16 +44,28 @@ namespace PARR.API.Services.Implementations
|
|||||||
|
|
||||||
var user = await userService.GetByIpWithRolesAsync(ipAddress);
|
var user = await userService.GetByIpWithRolesAsync(ipAddress);
|
||||||
if (user != null)
|
if (user != null)
|
||||||
|
{
|
||||||
user.Roles.ToList().ForEach(t =>
|
user.Roles.ToList().ForEach(t =>
|
||||||
{
|
{
|
||||||
if (t.Role != null)
|
if (t.Role != null)
|
||||||
roles.Add(new UserRoleInCache { Name = t.Role.Name, Description = t.Role.Description });
|
roles.Add(new UserRoleInCache { Name = t.Role.Name, Description = t.Role.Description });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// сохраняем время входа
|
||||||
|
user.LastLogon = DateTimeOffset.UtcNow;
|
||||||
|
await userService.CommitAsync();
|
||||||
|
}
|
||||||
|
|
||||||
var host = await hostService.GetByIpAsync(ipAddress);
|
var host = await hostService.GetByIpAsync(ipAddress);
|
||||||
if (host != null)
|
if (host != null)
|
||||||
|
{
|
||||||
roles.Add(new UserRoleInCache { Name = ParrRoles.Agent.Role, Description = ParrRoles.Agent.Description });
|
roles.Add(new UserRoleInCache { Name = ParrRoles.Agent.Role, Description = ParrRoles.Agent.Description });
|
||||||
|
|
||||||
|
// сохраняем время входа
|
||||||
|
host.LastLogon = DateTimeOffset.UtcNow;
|
||||||
|
await hostService.CommitAsync();
|
||||||
|
}
|
||||||
|
|
||||||
if (user == null && host == null)
|
if (user == null && host == null)
|
||||||
{
|
{
|
||||||
// если это не пользователь и не хост, добавляем в кэш на блокировку
|
// если это не пользователь и не хост, добавляем в кэш на блокировку
|
||||||
|
|||||||
2869
PARR.DAL/Migrations/20231206005200_TblUsersAddLastLogon.Designer.cs
generated
Normal file
2869
PARR.DAL/Migrations/20231206005200_TblUsersAddLastLogon.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
29
PARR.DAL/Migrations/20231206005200_TblUsersAddLastLogon.cs
Normal file
29
PARR.DAL/Migrations/20231206005200_TblUsersAddLastLogon.cs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace PARR.DAL.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class TblUsersAddLastLogon : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<DateTimeOffset>(
|
||||||
|
name: "LastLogon",
|
||||||
|
table: "Users",
|
||||||
|
type: "timestamp with time zone",
|
||||||
|
nullable: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "LastLogon",
|
||||||
|
table: "Users");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
2872
PARR.DAL/Migrations/20231206010010_TblHostsAddLastLogon.Designer.cs
generated
Normal file
2872
PARR.DAL/Migrations/20231206010010_TblHostsAddLastLogon.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
29
PARR.DAL/Migrations/20231206010010_TblHostsAddLastLogon.cs
Normal file
29
PARR.DAL/Migrations/20231206010010_TblHostsAddLastLogon.cs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace PARR.DAL.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class TblHostsAddLastLogon : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<DateTimeOffset>(
|
||||||
|
name: "LastLogon",
|
||||||
|
table: "Hosts",
|
||||||
|
type: "timestamp with time zone",
|
||||||
|
nullable: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "LastLogon",
|
||||||
|
table: "Hosts");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1624,6 +1624,9 @@ namespace PARR.DAL.Migrations
|
|||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("text");
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset?>("LastLogon")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
b.Property<int>("ResponseAreaCode")
|
b.Property<int>("ResponseAreaCode")
|
||||||
.HasColumnType("integer");
|
.HasColumnType("integer");
|
||||||
|
|
||||||
@@ -2355,6 +2358,9 @@ namespace PARR.DAL.Migrations
|
|||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("text");
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset?>("LastLogon")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
b.Property<string>("Name")
|
b.Property<string>("Name")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("text");
|
.HasColumnType("text");
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ namespace PARR.DAL.Models
|
|||||||
|
|
||||||
public int ResponseAreaCode { get; set; }
|
public int ResponseAreaCode { get; set; }
|
||||||
|
|
||||||
|
public DateTimeOffset? LastLogon { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public ICollection<ApplicationInHost> ApplicationsInHosts { get; set; } = new HashSet<ApplicationInHost>();
|
public ICollection<ApplicationInHost> ApplicationsInHosts { get; set; } = new HashSet<ApplicationInHost>();
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ namespace PARR.DAL.Models
|
|||||||
|
|
||||||
public string? Description { get; set; }
|
public string? Description { get; set; }
|
||||||
|
|
||||||
|
public DateTimeOffset? LastLogon { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public ICollection<UsersInRole> Roles { get; set; } = new HashSet<UsersInRole>();
|
public ICollection<UsersInRole> Roles { get; set; } = new HashSet<UsersInRole>();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user