Skip to content

Commit

Permalink
fix Bug 70202
Browse files Browse the repository at this point in the history
  • Loading branch information
MaksimChegulov committed Sep 13, 2024
1 parent 43e45db commit 879307d
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 127 deletions.
17 changes: 7 additions & 10 deletions web/ASC.Web.Api/Api/SecurityController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public class SecurityController(PermissionContext permissionContext,
AuditActionMapper auditActionMapper,
CoreBaseSettings coreBaseSettings,
ApiContext apiContext,
CspSettingsHelper cspSettingsHelper,
IMapper mapper)
CspSettingsHelper cspSettingsHelper,
ApiDateTimeHelper apiDateTimeHelper)
: ControllerBase
{
/// <summary>
Expand All @@ -66,8 +66,7 @@ public async Task<IEnumerable<LoginEventDto>> GetLastLoginEventsAsync()

DemandBaseAuditPermission();

var events = await loginEventsRepository.GetByFilterAsync(startIndex: 0, limit: 20);
return mapper.Map<IEnumerable<LoginEventDto>>(events);
return (await loginEventsRepository.GetByFilterAsync(startIndex: 0, limit: 20)).Select(x => new LoginEventDto(x, apiDateTimeHelper));
}

/// <summary>
Expand All @@ -88,8 +87,7 @@ public async Task<IEnumerable<AuditEventDto>> GetLastAuditEventsAsync()

DemandBaseAuditPermission();

var events = await auditEventsRepository.GetByFilterAsync(startIndex: 0, limit: 20);
return mapper.Map<IEnumerable<AuditEventDto>>(events);
return (await auditEventsRepository.GetByFilterAsync(startIndex: 0, limit: 20)).Select(x => new AuditEventDto(x, auditActionMapper, apiDateTimeHelper));
}

/// <summary>
Expand Down Expand Up @@ -128,8 +126,7 @@ public async Task<IEnumerable<LoginEventDto>> GetLoginEventsByFilterAsync(Guid u

await DemandAuditPermissionAsync();

var events = await loginEventsRepository.GetByFilterAsync(userId, action, from, to, startIndex, limit);
return mapper.Map<IEnumerable<LoginEventDto>>(events);
return (await loginEventsRepository.GetByFilterAsync(userId, action, from, to, startIndex, limit)).Select(x => new LoginEventDto(x, apiDateTimeHelper));
}

/// <summary>
Expand Down Expand Up @@ -178,8 +175,8 @@ public async Task<IEnumerable<AuditEventDto>> GetAuditEventsByFilterAsync(Guid u

await DemandAuditPermissionAsync();

var events = await auditEventsRepository.GetByFilterAsync(userId, productType, moduleType, actionType, action, entryType, target, from, to, startIndex, limit);
return mapper.Map<IEnumerable<AuditEventDto>>(events);
return (await auditEventsRepository.GetByFilterAsync(userId, productType, moduleType, actionType, action, entryType, target, from, to, startIndex, limit))
.Select(x => new AuditEventDto(x, auditActionMapper, apiDateTimeHelper));
}

/// <summary>
Expand Down
57 changes: 42 additions & 15 deletions web/ASC.Web.Api/ApiModels/ResponseDto/AuditEventDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace ASC.Web.Api.ApiModel.ResponseDto;

/// <summary>
/// </summary>
public class AuditEventDto : IMapFrom<AuditEvent>
public class AuditEventDto
{
/// <summary>ID</summary>
/// <type>System.Int32, System</type>
Expand Down Expand Up @@ -101,20 +101,47 @@ public class AuditEventDto : IMapFrom<AuditEvent>
/// <summary>Context</summary>
/// <type>System.String, System</type>
public string Context { get; set; }

public void Mapping(Profile profile)
public AuditEventDto(AuditEvent auditEvent, AuditActionMapper auditActionMapper, ApiDateTimeHelper apiDateTimeHelper)
{
profile.CreateMap<AuditEvent, AuditEventDto>()
.ForMember(x => x.User, opt =>
opt.MapFrom(x => x.UserName))
.ForMember(x => x.Action, opt =>
opt.MapFrom(x => x.ActionText))
.ForMember(x => x.ActionId, opt =>
opt.MapFrom(x => (MessageAction)x.Action))
.ForMember(x => x.Date, opt =>
opt.ConvertUsing<ApiDateTimeMappingConverter, DateTime>())
.ForMember(x => x.Target, opt =>
opt.MapFrom(x => x.Target != null ? x.Target.GetItems() : null))
.AfterMap<AuditEventMapperAction>();
Id = auditEvent.Id;
Date = apiDateTimeHelper.Get(auditEvent.Date);
User = auditEvent.UserName;
UserId = auditEvent.UserId;
Action = auditEvent.ActionText;
ActionId = (MessageAction)auditEvent.Action;
IP = auditEvent.IP;
Country = auditEvent.Country;
City = auditEvent.City;
Browser = auditEvent.Browser;
Platform = auditEvent.Platform;
Page = auditEvent.Page;

var maps = auditActionMapper.GetMessageMaps(auditEvent.Action);

ActionType = maps.ActionType;
Product = maps.ProductType;
Module = maps.ModuleType;

var list = new List<EntryType>(2);

if (maps.EntryType1 != EntryType.None)
{
list.Add(maps.EntryType1);
}

if (maps.EntryType2 != EntryType.None)
{
list.Add(maps.EntryType2);
}

Entries = list;

if (auditEvent.Target != null)
{
Target = auditEvent.Target.GetItems();
}

Context = auditEvent.Context;
}
}
28 changes: 16 additions & 12 deletions web/ASC.Web.Api/ApiModels/ResponseDto/LoginEventDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace ASC.Web.Api.ApiModel.ResponseDto;

/// <summary>
/// </summary>
public class LoginEventDto : IMapFrom<LoginEvent>
public class LoginEventDto
{
/// <summary>ID</summary>
/// <type>System.Int32, System</type>
Expand Down Expand Up @@ -81,17 +81,21 @@ public class LoginEventDto : IMapFrom<LoginEvent>
/// <summary>Page</summary>
/// <type>System.String, System</type>
public string Page { get; set; }

public void Mapping(Profile profile)
public LoginEventDto(LoginEvent loginEvent, ApiDateTimeHelper apiDateTimeHelper)
{
profile.CreateMap<LoginEvent, LoginEventDto>()
.ForMember(x => x.User, opt =>
opt.MapFrom(x => x.UserName))
.ForMember(x => x.Action, opt =>
opt.MapFrom(x => x.ActionText))
.ForMember(x => x.ActionId, opt =>
opt.MapFrom(x => (MessageAction)x.Action))
.ForMember(x => x.Date, opt =>
opt.ConvertUsing<ApiDateTimeMappingConverter, DateTime>());
Id = loginEvent.Id;
Date = apiDateTimeHelper.Get(loginEvent.Date);
User = loginEvent.UserName;
UserId = loginEvent.UserId;
Login = loginEvent.Login;
Action = loginEvent.ActionText;
ActionId = (MessageAction)loginEvent.Action;
IP = loginEvent.IP;
Country = loginEvent.Country;
City = loginEvent.City;
Browser = loginEvent.Browser;
Platform = loginEvent.Platform;
Page = loginEvent.Page;
}
}
36 changes: 0 additions & 36 deletions web/ASC.Web.Api/Mapping/ApiDateTimeMappingConverter.cs

This file was deleted.

54 changes: 0 additions & 54 deletions web/ASC.Web.Api/Mapping/AuditEventMapperAction.cs

This file was deleted.

0 comments on commit 879307d

Please sign in to comment.