mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
WIP change to ids
This commit is contained in:
@@ -51,6 +51,8 @@
|
||||
<Compile Include="Common\Interfaces\ISettingsProxy.cs" />
|
||||
<Compile Include="Common\Mappings\IMapFrom.cs" />
|
||||
<Compile Include="Common\Mappings\MappingProfile.cs" />
|
||||
<Compile Include="Entry\Queries\GetEntry\GetEntryQuery.cs" />
|
||||
<Compile Include="Group\Queries\GetGroup\GetGroupQuery.cs" />
|
||||
<Compile Include="Parameters\Commands\SetCipher\SetCipherCommand.cs" />
|
||||
<Compile Include="Parameters\Commands\SetCompression\SetCompressionCommand.cs" />
|
||||
<Compile Include="Parameters\Commands\SetHasRecycleBin\SetHasRecycleBinCommand.cs" />
|
||||
@@ -79,8 +81,6 @@
|
||||
<Compile Include="Group\Commands\AddGroup\AddGroupCommand.cs" />
|
||||
<Compile Include="Group\Commands\CreateEntry\CreateEntryCommand.cs" />
|
||||
<Compile Include="Group\Commands\CreateGroup\CreateGroupCommand.cs" />
|
||||
<Compile Include="Group\Commands\DeleteEntry\DeleteEntryCommand.cs" />
|
||||
<Compile Include="Group\Commands\DeleteGroup\DeleteGroupCommand.cs" />
|
||||
<Compile Include="Group\Commands\InsertEntry\InsertEntryCommand.cs" />
|
||||
<Compile Include="Group\Commands\RemoveEntry\RemoveEntryCommand.cs" />
|
||||
<Compile Include="Group\Commands\RemoveGroup\RemoveGroupCommand.cs" />
|
||||
@@ -94,9 +94,7 @@
|
||||
<Content Include="Services\DatabaseService.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Entry\Queries\GetEntry\" />
|
||||
<Folder Include="Group\Commands\UpdateGroup\" />
|
||||
<Folder Include="Group\Queries\GetGroup\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ModernKeePass.Domain\Domain.csproj">
|
||||
|
@@ -9,17 +9,16 @@ namespace ModernKeePass.Application.Common.Interfaces
|
||||
{
|
||||
bool IsOpen { get; }
|
||||
string Name { get; }
|
||||
GroupEntity RootGroup { get; }
|
||||
|
||||
GroupEntity RecycleBin { get; set; }
|
||||
string RootGroupId { get; }
|
||||
string RecycleBinId { get; set; }
|
||||
string CipherId { get; set; }
|
||||
string KeyDerivationId { get; set; }
|
||||
string Compression { get; set; }
|
||||
bool IsRecycleBinEnabled { get; set; }
|
||||
|
||||
Task<GroupEntity> Open(FileInfo fileInfo, Credentials credentials);
|
||||
Task<GroupEntity> ReOpen();
|
||||
Task<GroupEntity> Create(FileInfo fileInfo, Credentials credentials, DatabaseVersion version = DatabaseVersion.V2);
|
||||
Task Open(FileInfo fileInfo, Credentials credentials);
|
||||
Task ReOpen();
|
||||
Task Create(FileInfo fileInfo, Credentials credentials, DatabaseVersion version = DatabaseVersion.V2);
|
||||
Task SaveDatabase();
|
||||
Task SaveDatabase(string filePath);
|
||||
void SetRecycleBin(string id);
|
||||
@@ -31,14 +30,13 @@ namespace ModernKeePass.Application.Common.Interfaces
|
||||
Task AddGroup(string parentGroupId, string groupId);
|
||||
void UpdateEntry(string entryId, string fieldName, object fieldValue);
|
||||
void UpdateGroup(string groupId);
|
||||
Task RemoveEntry(string parentGroupId, string entryId);
|
||||
Task RemoveGroup(string parentGroupId, string groupId);
|
||||
Task RemoveEntry(string parentGroupId, string entryId, bool isToBeDeleted);
|
||||
Task RemoveGroup(string parentGroupId, string groupId, bool isToBeDeleted);
|
||||
EntryEntity CreateEntry(string parentGroupId);
|
||||
GroupEntity CreateGroup(string parentGroupId, string nameId, bool isRecycleBin = false);
|
||||
Task DeleteEntry(string entryId);
|
||||
Task DeleteGroup(string groupId);
|
||||
|
||||
void SortEntries(string groupId);
|
||||
void SortSubGroups(string groupId);
|
||||
EntryEntity GetEntry(string id);
|
||||
GroupEntity GetGroup(string id);
|
||||
}
|
||||
}
|
@@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using ModernKeePass.Application.Group.Models;
|
||||
using ModernKeePass.Domain.Enums;
|
||||
|
||||
namespace ModernKeePass.Application.Common.Interfaces
|
||||
@@ -9,7 +8,7 @@ namespace ModernKeePass.Application.Common.Interfaces
|
||||
string Id { get; set; }
|
||||
string Title { get; set; }
|
||||
Icon Icon { get; set; }
|
||||
List<GroupVm> Breadcrumb { get; }
|
||||
GroupVm ParentGroup { get; set; }
|
||||
List<IEntityVm> Breadcrumb { get; }
|
||||
string ParentGroupId { get; set; }
|
||||
}
|
||||
}
|
@@ -1,35 +1,31 @@
|
||||
using MediatR;
|
||||
using System.Threading.Tasks;
|
||||
using AutoMapper;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Group.Models;
|
||||
using ModernKeePass.Domain.Dtos;
|
||||
using ModernKeePass.Domain.Exceptions;
|
||||
|
||||
namespace ModernKeePass.Application.Database.Commands.CreateDatabase
|
||||
{
|
||||
public class CreateDatabaseCommand : IRequest<GroupVm>
|
||||
public class CreateDatabaseCommand : IRequest
|
||||
{
|
||||
public string FilePath { get; set; }
|
||||
public string Password { get; set; }
|
||||
public string KeyFilePath { get; set; }
|
||||
|
||||
public class CreateDatabaseCommandHandler : IAsyncRequestHandler<CreateDatabaseCommand, GroupVm>
|
||||
public class CreateDatabaseCommandHandler : IAsyncRequestHandler<CreateDatabaseCommand>
|
||||
{
|
||||
private readonly IDatabaseProxy _database;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public CreateDatabaseCommandHandler(IDatabaseProxy database, IMapper mapper)
|
||||
public CreateDatabaseCommandHandler(IDatabaseProxy database)
|
||||
{
|
||||
_database = database;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public async Task<GroupVm> Handle(CreateDatabaseCommand message)
|
||||
public async Task Handle(CreateDatabaseCommand message)
|
||||
{
|
||||
if (_database.IsOpen) throw new DatabaseOpenException();
|
||||
|
||||
var rootGroup = await _database.Create(
|
||||
await _database.Create(
|
||||
new FileInfo
|
||||
{
|
||||
Path = message.FilePath
|
||||
@@ -39,7 +35,6 @@ namespace ModernKeePass.Application.Database.Commands.CreateDatabase
|
||||
KeyFilePath = message.KeyFilePath,
|
||||
Password = message.Password
|
||||
});
|
||||
return GroupVm.BuildHierarchy(null, rootGroup, _mapper);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -6,8 +6,8 @@ namespace ModernKeePass.Application.Database.Models
|
||||
{
|
||||
public bool IsOpen { get; set; }
|
||||
public string Name { get; set; }
|
||||
public GroupVm RootGroup { get; set; }
|
||||
public GroupVm RecycleBin { get; set; }
|
||||
public string RootGroupId { get; set; }
|
||||
public string RecycleBinId { get; set; }
|
||||
public bool IsRecycleBinEnabled { get; set; }
|
||||
public string Compression { get; set; }
|
||||
public string CipherId { get; set; }
|
||||
|
@@ -28,9 +28,9 @@ namespace ModernKeePass.Application.Database.Queries.GetDatabase
|
||||
if (database.IsOpen)
|
||||
{
|
||||
database.Name = _databaseProxy.Name;
|
||||
database.RootGroup = GroupVm.BuildHierarchy(null, _databaseProxy.RootGroup, _mapper);
|
||||
database.RootGroupId = _databaseProxy.RootGroupId;
|
||||
database.IsRecycleBinEnabled = _databaseProxy.IsRecycleBinEnabled;
|
||||
database.RecycleBin = _mapper.Map<GroupVm>(_databaseProxy.RecycleBin);
|
||||
database.RecycleBinId = _databaseProxy.RecycleBinId;
|
||||
database.Compression = _databaseProxy.Compression;
|
||||
database.CipherId = _databaseProxy.CipherId;
|
||||
database.KeyDerivationId = _databaseProxy.CipherId;
|
||||
|
@@ -1,38 +1,31 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using AutoMapper;
|
||||
using System.Threading.Tasks;
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Entry.Models;
|
||||
using ModernKeePass.Application.Group.Models;
|
||||
using ModernKeePass.Domain.Dtos;
|
||||
using ModernKeePass.Domain.Entities;
|
||||
using ModernKeePass.Domain.Exceptions;
|
||||
|
||||
namespace ModernKeePass.Application.Database.Queries.OpenDatabase
|
||||
{
|
||||
public class OpenDatabaseQuery: IRequest<GroupVm>
|
||||
public class OpenDatabaseQuery: IRequest
|
||||
{
|
||||
public string FilePath { get; set; }
|
||||
public string Password { get; set; }
|
||||
public string KeyFilePath { get; set; }
|
||||
|
||||
public class OpenDatabaseQueryHandler : IAsyncRequestHandler<OpenDatabaseQuery, GroupVm>
|
||||
public class OpenDatabaseQueryHandler : IAsyncRequestHandler<OpenDatabaseQuery>
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IDatabaseProxy _database;
|
||||
|
||||
public OpenDatabaseQueryHandler(IMapper mapper, IDatabaseProxy database)
|
||||
public OpenDatabaseQueryHandler(IDatabaseProxy database)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_database = database;
|
||||
}
|
||||
|
||||
public async Task<GroupVm> Handle(OpenDatabaseQuery request)
|
||||
public async Task Handle(OpenDatabaseQuery request)
|
||||
{
|
||||
if (_database.IsOpen) throw new DatabaseOpenException();
|
||||
|
||||
var rootGroup = await _database.Open(
|
||||
await _database.Open(
|
||||
new FileInfo
|
||||
{
|
||||
Path = request.FilePath
|
||||
@@ -42,7 +35,6 @@ namespace ModernKeePass.Application.Database.Queries.OpenDatabase
|
||||
KeyFilePath = request.KeyFilePath,
|
||||
Password = request.Password
|
||||
});
|
||||
return GroupVm.BuildHierarchy(null, rootGroup, _mapper);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,31 +1,26 @@
|
||||
using System.Threading.Tasks;
|
||||
using AutoMapper;
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Group.Models;
|
||||
using ModernKeePass.Domain.Exceptions;
|
||||
|
||||
namespace ModernKeePass.Application.Database.Queries.ReOpenDatabase
|
||||
{
|
||||
public class ReOpenDatabaseQuery: IRequest<GroupVm>
|
||||
public class ReOpenDatabaseQuery: IRequest
|
||||
{
|
||||
public class ReOpenDatabaseQueryHandler : IAsyncRequestHandler<ReOpenDatabaseQuery, GroupVm>
|
||||
public class ReOpenDatabaseQueryHandler : IAsyncRequestHandler<ReOpenDatabaseQuery>
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IDatabaseProxy _database;
|
||||
|
||||
public ReOpenDatabaseQueryHandler(IMapper mapper, IDatabaseProxy database)
|
||||
public ReOpenDatabaseQueryHandler(IDatabaseProxy database)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_database = database;
|
||||
}
|
||||
|
||||
public async Task<GroupVm> Handle(ReOpenDatabaseQuery request)
|
||||
public async Task Handle(ReOpenDatabaseQuery request)
|
||||
{
|
||||
if (!_database.IsOpen) throw new DatabaseClosedException();
|
||||
|
||||
var rootGroup = await _database.ReOpen();
|
||||
return GroupVm.BuildHierarchy(null, rootGroup, _mapper);
|
||||
await _database.ReOpen();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -4,7 +4,6 @@ using System.Drawing;
|
||||
using AutoMapper;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Common.Mappings;
|
||||
using ModernKeePass.Application.Group.Models;
|
||||
using ModernKeePass.Domain.Entities;
|
||||
using ModernKeePass.Domain.Enums;
|
||||
|
||||
@@ -12,8 +11,8 @@ namespace ModernKeePass.Application.Entry.Models
|
||||
{
|
||||
public class EntryVm: IEntityVm, IMapFrom<EntryEntity>
|
||||
{
|
||||
public GroupVm ParentGroup { get; set; }
|
||||
public List<GroupVm> Breadcrumb { get; } = new List<GroupVm>();
|
||||
public string ParentGroupId { get; set; }
|
||||
public List<IEntityVm> Breadcrumb { get; } = new List<IEntityVm>();
|
||||
public string Id { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Username { get; set; }
|
||||
@@ -37,7 +36,7 @@ namespace ModernKeePass.Application.Entry.Models
|
||||
public void Mapping(Profile profile)
|
||||
{
|
||||
profile.CreateMap<EntryEntity, EntryVm>()
|
||||
.ForMember(d => d.ParentGroup, opts => opts.Ignore())
|
||||
.ForMember(d => d.ParentGroupId, opts => opts.MapFrom(s => s.ParentId))
|
||||
.ForMember(d => d.Id, opts => opts.MapFrom(s => s.Id))
|
||||
.ForMember(d => d.Title, opts => opts.MapFrom(s => s.Name))
|
||||
.ForMember(d => d.Username, opts => opts.MapFrom(s => s.UserName))
|
||||
|
@@ -0,0 +1,31 @@
|
||||
using AutoMapper;
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Entry.Models;
|
||||
using ModernKeePass.Domain.Exceptions;
|
||||
|
||||
namespace ModernKeePass.Application.Entry.Queries.GetEntry
|
||||
{
|
||||
public class GetEntryQuery: IRequest<EntryVm>
|
||||
{
|
||||
public string Id { get; set; }
|
||||
|
||||
public class GetEntryQueryHandler: IRequestHandler<GetEntryQuery, EntryVm>
|
||||
{
|
||||
private readonly IDatabaseProxy _database;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public GetEntryQueryHandler(IDatabaseProxy database, IMapper mapper)
|
||||
{
|
||||
_database = database;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public EntryVm Handle(GetEntryQuery message)
|
||||
{
|
||||
if (!_database.IsOpen) throw new DatabaseClosedException();
|
||||
return _mapper.Map<EntryVm>(_database.GetEntry(message.Id));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -8,7 +8,7 @@ namespace ModernKeePass.Application.Group.Commands.CreateGroup
|
||||
{
|
||||
public class CreateGroupCommand : IRequest<GroupVm>
|
||||
{
|
||||
public GroupVm ParentGroup { get; set; }
|
||||
public string ParentGroupId { get; set; }
|
||||
public string Name { get; set; }
|
||||
public bool IsRecycleBin { get; set; }
|
||||
|
||||
@@ -27,10 +27,8 @@ namespace ModernKeePass.Application.Group.Commands.CreateGroup
|
||||
{
|
||||
if (!_database.IsOpen) throw new DatabaseClosedException();
|
||||
|
||||
var group = _database.CreateGroup(message.ParentGroup.Id, message.Name, message.IsRecycleBin);
|
||||
var group = _database.CreateGroup(message.ParentGroupId, message.Name, message.IsRecycleBin);
|
||||
var groupVm = _mapper.Map<GroupVm>(group);
|
||||
groupVm.ParentGroup = message.ParentGroup;
|
||||
message.ParentGroup.SubGroups.Add(groupVm);
|
||||
return groupVm;
|
||||
}
|
||||
}
|
||||
|
@@ -1,31 +0,0 @@
|
||||
using System.Threading.Tasks;
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Entry.Models;
|
||||
using ModernKeePass.Domain.Exceptions;
|
||||
|
||||
namespace ModernKeePass.Application.Group.Commands.DeleteEntry
|
||||
{
|
||||
public class DeleteEntryCommand : IRequest
|
||||
{
|
||||
public EntryVm Entry { get; set; }
|
||||
|
||||
public class DeleteEntryCommandHandler : IAsyncRequestHandler<DeleteEntryCommand>
|
||||
{
|
||||
private readonly IDatabaseProxy _database;
|
||||
|
||||
public DeleteEntryCommandHandler(IDatabaseProxy database)
|
||||
{
|
||||
_database = database;
|
||||
}
|
||||
|
||||
public async Task Handle(DeleteEntryCommand message)
|
||||
{
|
||||
if (!_database.IsOpen) throw new DatabaseClosedException();
|
||||
|
||||
await _database.DeleteEntry(message.Entry.Id);
|
||||
message.Entry = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,31 +0,0 @@
|
||||
using System.Threading.Tasks;
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Group.Models;
|
||||
using ModernKeePass.Domain.Exceptions;
|
||||
|
||||
namespace ModernKeePass.Application.Group.Commands.DeleteGroup
|
||||
{
|
||||
public class DeleteGroupCommand : IRequest
|
||||
{
|
||||
public GroupVm Group { get; set; }
|
||||
|
||||
public class DeleteGroupCommandHandler : IAsyncRequestHandler<DeleteGroupCommand>
|
||||
{
|
||||
private readonly IDatabaseProxy _database;
|
||||
|
||||
public DeleteGroupCommandHandler(IDatabaseProxy database)
|
||||
{
|
||||
_database = database;
|
||||
}
|
||||
|
||||
public async Task Handle(DeleteGroupCommand message)
|
||||
{
|
||||
if (!_database.IsOpen) throw new DatabaseClosedException();
|
||||
|
||||
await _database.DeleteGroup(message.Group.Id);
|
||||
message.Group = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -11,6 +11,7 @@ namespace ModernKeePass.Application.Group.Commands.RemoveEntry
|
||||
{
|
||||
public GroupVm ParentGroup { get; set; }
|
||||
public EntryVm Entry { get; set; }
|
||||
public bool IsDelete { get; set; }
|
||||
|
||||
public class RemoveEntryCommandHandler : IAsyncRequestHandler<RemoveEntryCommand>
|
||||
{
|
||||
@@ -25,7 +26,7 @@ namespace ModernKeePass.Application.Group.Commands.RemoveEntry
|
||||
{
|
||||
if (!_database.IsOpen) throw new DatabaseClosedException();
|
||||
|
||||
await _database.RemoveEntry(message.ParentGroup.Id, message.Entry.Id);
|
||||
await _database.RemoveEntry(message.ParentGroup.Id, message.Entry.Id, message.IsDelete);
|
||||
message.ParentGroup.Entries.Remove(message.Entry);
|
||||
}
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@ namespace ModernKeePass.Application.Group.Commands.RemoveGroup
|
||||
{
|
||||
public GroupVm ParentGroup { get; set; }
|
||||
public GroupVm Group { get; set; }
|
||||
public bool IsDelete { get; set; }
|
||||
|
||||
public class RemoveGroupCommandHandler : IAsyncRequestHandler<RemoveGroupCommand>
|
||||
{
|
||||
@@ -24,7 +25,7 @@ namespace ModernKeePass.Application.Group.Commands.RemoveGroup
|
||||
{
|
||||
if (!_database.IsOpen) throw new DatabaseClosedException();
|
||||
|
||||
await _database.RemoveGroup(message.ParentGroup.Id, message.Group.Id);
|
||||
await _database.RemoveGroup(message.ParentGroup.Id, message.Group.Id, message.IsDelete);
|
||||
message.ParentGroup.SubGroups.Remove(message.Group);
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using AutoMapper;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Common.Mappings;
|
||||
@@ -13,11 +11,11 @@ namespace ModernKeePass.Application.Group.Models
|
||||
{
|
||||
public class GroupVm: IEntityVm, ISelectableModel, IMapFrom<GroupEntity>
|
||||
{
|
||||
public GroupVm ParentGroup { get; set; }
|
||||
public string ParentGroupId { get; set; }
|
||||
public string Id { get; set; }
|
||||
public string Title { get; set; }
|
||||
public Icon Icon { get; set; }
|
||||
public List<GroupVm> Breadcrumb { get; } = new List<GroupVm>();
|
||||
public List<IEntityVm> Breadcrumb { get; } = new List<IEntityVm>();
|
||||
public List<GroupVm> SubGroups { get; set; }
|
||||
public List<EntryVm> Entries { get; set; }
|
||||
public bool IsSelected { get; set; }
|
||||
@@ -30,34 +28,13 @@ namespace ModernKeePass.Application.Group.Models
|
||||
public void Mapping(Profile profile)
|
||||
{
|
||||
profile.CreateMap<GroupEntity, GroupVm>()
|
||||
.ForMember(d => d.ParentGroup, opts => opts.Ignore())
|
||||
.ForMember(d => d.ParentGroupId, opts => opts.MapFrom(s => s.ParentId))
|
||||
.ForMember(d => d.Id, opts => opts.MapFrom(s => s.Id))
|
||||
.ForMember(d => d.Title, opts => opts.MapFrom(s => s.Name))
|
||||
.ForMember(d => d.Icon, opts => opts.MapFrom(s => s.Icon))
|
||||
.ForMember(d => d.Entries, opts => opts.Ignore())
|
||||
.ForMember(d => d.SubGroups, opts => opts.Ignore());
|
||||
}
|
||||
|
||||
internal static GroupVm BuildHierarchy(GroupVm parentGroup, GroupEntity groupEntity, IMapper mapper)
|
||||
{
|
||||
var groupVm = mapper.Map<GroupVm>(groupEntity);
|
||||
groupVm.ParentGroup = parentGroup;
|
||||
if (parentGroup != null)
|
||||
{
|
||||
groupVm.Breadcrumb.AddRange(parentGroup.Breadcrumb);
|
||||
groupVm.Breadcrumb.Add(parentGroup);
|
||||
}
|
||||
groupVm.Entries = groupEntity.Entries.Select(e =>
|
||||
{
|
||||
var entry = mapper.Map<EntryVm>(e);
|
||||
entry.ParentGroup = groupVm;
|
||||
entry.Breadcrumb.AddRange(groupVm.Breadcrumb);
|
||||
entry.Breadcrumb.Add(groupVm);
|
||||
return entry;
|
||||
}).OrderBy(e => e.Title).ToList();
|
||||
groupVm.SubGroups = groupEntity.SubGroups.Select(g => BuildHierarchy(groupVm, g, mapper)).ToList();
|
||||
|
||||
return groupVm;
|
||||
.ForMember(d => d.Entries, opts => opts.MapFrom(s => s.Entries))
|
||||
.ForMember(d => d.SubGroups, opts => opts.MapFrom(s => s.SubGroups))
|
||||
.MaxDepth(1);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
using AutoMapper;
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Group.Models;
|
||||
using ModernKeePass.Domain.Exceptions;
|
||||
|
||||
namespace ModernKeePass.Application.Group.Queries.GetGroup
|
||||
{
|
||||
public class GetGroupQuery : IRequest<GroupVm>
|
||||
{
|
||||
public string Id { get; set; }
|
||||
|
||||
public class GetGroupQueryHandler : IRequestHandler<GetGroupQuery, GroupVm>
|
||||
{
|
||||
private readonly IDatabaseProxy _database;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public GetGroupQueryHandler(IDatabaseProxy database, IMapper mapper)
|
||||
{
|
||||
_database = database;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public GroupVm Handle(GetGroupQuery message)
|
||||
{
|
||||
if (!_database.IsOpen) throw new DatabaseClosedException();
|
||||
return _mapper.Map<GroupVm>(_database.GetGroup(message.Id));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -6,7 +6,6 @@ namespace ModernKeePass.Domain.Entities
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public GroupEntity ParentGroup { get; set; }
|
||||
public string ParentId { get; set; }
|
||||
public DateTimeOffset LastModificationDate { get; set; }
|
||||
}
|
||||
|
@@ -19,7 +19,6 @@ namespace ModernKeePass.Infrastructure.KeePass
|
||||
{
|
||||
Uri url;
|
||||
CreateMap<PwEntry, EntryEntity>()
|
||||
.ForMember(dest => dest.ParentGroup, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.ParentId, opt => opt.MapFrom(src => src.ParentGroup.Uuid.ToHexString()))
|
||||
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Uuid.ToHexString()))
|
||||
.ForMember(dest => dest.Name, opt => opt.MapFrom(src => GetEntryValue(src, PwDefs.TitleField)))
|
||||
@@ -27,7 +26,8 @@ namespace ModernKeePass.Infrastructure.KeePass
|
||||
.ForMember(dest => dest.Password, opt => opt.MapFrom(src => GetEntryValue(src, PwDefs.PasswordField)))
|
||||
.ForMember(dest => dest.Url, opt =>
|
||||
{
|
||||
opt.PreCondition(src => Uri.TryCreate(GetEntryValue(src, PwDefs.UrlField), UriKind.Absolute, out url));
|
||||
opt.PreCondition(src =>
|
||||
Uri.TryCreate(GetEntryValue(src, PwDefs.UrlField), UriKind.Absolute, out url));
|
||||
opt.MapFrom(src => new Uri(GetEntryValue(src, PwDefs.UrlField)));
|
||||
})
|
||||
.ForMember(dest => dest.Notes, opt => opt.MapFrom(src => GetEntryValue(src, PwDefs.NotesField)))
|
||||
@@ -37,8 +37,11 @@ namespace ModernKeePass.Infrastructure.KeePass
|
||||
.ForMember(dest => dest.HasExpirationDate, opt => opt.MapFrom(src => src.Expires))
|
||||
.ForMember(dest => dest.Icon, opt => opt.MapFrom(src => IconMapper.MapPwIconToIcon(src.IconId)))
|
||||
.ForMember(dest => dest.AdditionalFields, opt => opt.MapFrom(src =>
|
||||
src.Strings.Where(s => !PwDefs.GetStandardFields().Contains(s.Key)).ToDictionary(s => s.Key, s => GetEntryValue(src, s.Key))))
|
||||
.ForMember(dest => dest.LastModificationDate, opt => opt.MapFrom(src => new DateTimeOffset(src.LastModificationTime)));
|
||||
src.Strings.Where(s => !PwDefs.GetStandardFields().Contains(s.Key))
|
||||
.ToDictionary(s => s.Key, s => GetEntryValue(src, s.Key))))
|
||||
.ForMember(dest => dest.LastModificationDate,
|
||||
opt => opt.MapFrom(src => new DateTimeOffset(src.LastModificationTime)))
|
||||
.MaxDepth(1);
|
||||
}
|
||||
|
||||
private void FromModelToDto()
|
||||
|
@@ -15,14 +15,14 @@ namespace ModernKeePass.Infrastructure.KeePass
|
||||
private void FromDtoToModel()
|
||||
{
|
||||
CreateMap<PwGroup, GroupEntity>()
|
||||
.ForMember(dest => dest.ParentGroup, opt => opt.Ignore())
|
||||
.ForMember(d => d.ParentId, opts => opts.MapFrom(s => s.ParentGroup.Uuid.ToHexString()))
|
||||
.ForMember(d => d.Id, opts => opts.MapFrom(s => s.Uuid.ToHexString()))
|
||||
.ForMember(d => d.Name, opts => opts.MapFrom(s => s.Name))
|
||||
.ForMember(d => d.Icon, opts => opts.MapFrom(s => IconMapper.MapPwIconToIcon(s.IconId)))
|
||||
.ForMember(d => d.LastModificationDate, opts => opts.MapFrom(s => s.LastModificationTime))
|
||||
.ForMember(d => d.Entries, opts => opts.Ignore())
|
||||
.ForMember(d => d.SubGroups, opts => opts.Ignore());
|
||||
.ForMember(d => d.Entries, opts => opts.MapFrom(s => s.Entries))
|
||||
.ForMember(d => d.SubGroups, opts => opts.MapFrom(s => s.Groups))
|
||||
.MaxDepth(1);
|
||||
}
|
||||
|
||||
private void FromModelToDto()
|
||||
|
@@ -30,7 +30,7 @@ namespace ModernKeePass.Infrastructure.KeePass
|
||||
// Main information
|
||||
public bool IsOpen => (_pwDatabase?.IsOpen).GetValueOrDefault();
|
||||
public string Name => _pwDatabase?.Name;
|
||||
public GroupEntity RootGroup { get; private set; }
|
||||
public string RootGroupId => _pwDatabase?.RootGroup.Uuid.ToHexString();
|
||||
|
||||
// Settings
|
||||
public bool IsRecycleBinEnabled
|
||||
@@ -39,19 +39,18 @@ namespace ModernKeePass.Infrastructure.KeePass
|
||||
set { _pwDatabase.RecycleBinEnabled = value; }
|
||||
}
|
||||
|
||||
public GroupEntity RecycleBin
|
||||
public string RecycleBinId
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_pwDatabase.RecycleBinEnabled)
|
||||
{
|
||||
var pwGroup = _pwDatabase.RootGroup.FindGroup(_pwDatabase.RecycleBinUuid, true);
|
||||
return _mapper.Map<GroupEntity>(pwGroup);
|
||||
return _pwDatabase.RecycleBinUuid.ToHexString();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
set { _pwDatabase.RecycleBinUuid = BuildIdFromString(value.Id); }
|
||||
set { _pwDatabase.RecycleBinUuid = BuildIdFromString(value); }
|
||||
}
|
||||
|
||||
public string CipherId
|
||||
@@ -83,7 +82,7 @@ namespace ModernKeePass.Infrastructure.KeePass
|
||||
_dateTime = dateTime;
|
||||
}
|
||||
|
||||
public async Task<GroupEntity> Open(FileInfo fileInfo, Credentials credentials)
|
||||
public async Task Open(FileInfo fileInfo, Credentials credentials)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -94,9 +93,6 @@ namespace ModernKeePass.Infrastructure.KeePass
|
||||
|
||||
_credentials = credentials;
|
||||
_fileAccessToken = fileInfo.Path;
|
||||
|
||||
RootGroup = BuildHierarchy(null, _pwDatabase.RootGroup);
|
||||
return RootGroup;
|
||||
}
|
||||
catch (InvalidCompositeKeyException ex)
|
||||
{
|
||||
@@ -104,12 +100,12 @@ namespace ModernKeePass.Infrastructure.KeePass
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<GroupEntity> ReOpen()
|
||||
public async Task ReOpen()
|
||||
{
|
||||
return await Open(new FileInfo {Path = _fileAccessToken}, _credentials);
|
||||
await Open(new FileInfo {Path = _fileAccessToken}, _credentials);
|
||||
}
|
||||
|
||||
public async Task<GroupEntity> Create(FileInfo fileInfo, Credentials credentials, DatabaseVersion version = DatabaseVersion.V2)
|
||||
public async Task Create(FileInfo fileInfo, Credentials credentials, DatabaseVersion version = DatabaseVersion.V2)
|
||||
{
|
||||
var compositeKey = await CreateCompositeKey(credentials);
|
||||
var ioConnection = await BuildConnectionInfo(fileInfo);
|
||||
@@ -124,9 +120,6 @@ namespace ModernKeePass.Infrastructure.KeePass
|
||||
}
|
||||
|
||||
_fileAccessToken = fileInfo.Path;
|
||||
|
||||
RootGroup = BuildHierarchy(null, _pwDatabase.RootGroup);
|
||||
return RootGroup;
|
||||
}
|
||||
|
||||
public async Task SaveDatabase()
|
||||
@@ -201,23 +194,33 @@ namespace ModernKeePass.Infrastructure.KeePass
|
||||
parentPwGroup.Groups.Add(pwGroup);
|
||||
});
|
||||
}
|
||||
public async Task RemoveEntry(string parentGroupId, string entryId)
|
||||
public async Task RemoveEntry(string parentGroupId, string entryId, bool isToBeDeleted)
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
var parentPwGroup = _pwDatabase.RootGroup.FindGroup(BuildIdFromString(parentGroupId), true);
|
||||
var pwEntry = parentPwGroup.FindEntry(BuildIdFromString(entryId), false);
|
||||
parentPwGroup.Entries.Remove(pwEntry);
|
||||
|
||||
if (isToBeDeleted && (!_pwDatabase.RecycleBinEnabled || parentPwGroup.Uuid.Equals(_pwDatabase.RecycleBinUuid)))
|
||||
{
|
||||
_pwDatabase.DeletedObjects.Add(new PwDeletedObject(pwEntry.Uuid, _dateTime.Now));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public async Task RemoveGroup(string parentGroupId, string groupId)
|
||||
public async Task RemoveGroup(string parentGroupId, string groupId, bool isToBeDeleted)
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
var parentPwGroup = _pwDatabase.RootGroup.FindGroup(BuildIdFromString(parentGroupId), true);
|
||||
var pwGroup = parentPwGroup.FindGroup(BuildIdFromString(groupId), false);
|
||||
parentPwGroup.Groups.Remove(pwGroup);
|
||||
|
||||
if (isToBeDeleted && (!_pwDatabase.RecycleBinEnabled || parentPwGroup.Uuid.Equals(_pwDatabase.RecycleBinUuid)))
|
||||
{
|
||||
_pwDatabase.DeletedObjects.Add(new PwDeletedObject(pwGroup.Uuid, _dateTime.Now));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -272,36 +275,6 @@ namespace ModernKeePass.Infrastructure.KeePass
|
||||
return _mapper.Map<GroupEntity>(pwGroup);
|
||||
}
|
||||
|
||||
public async Task DeleteEntry(string entryId)
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
var pwEntry = _pwDatabase.RootGroup.FindEntry(BuildIdFromString(entryId), true);
|
||||
var id = pwEntry.Uuid;
|
||||
pwEntry.ParentGroup.Entries.Remove(pwEntry);
|
||||
|
||||
if (!_pwDatabase.RecycleBinEnabled || pwEntry.ParentGroup.Uuid.Equals(_pwDatabase.RecycleBinUuid))
|
||||
{
|
||||
_pwDatabase.DeletedObjects.Add(new PwDeletedObject(id, DateTime.UtcNow));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public async Task DeleteGroup(string groupId)
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
var pwGroup = _pwDatabase.RootGroup.FindGroup(BuildIdFromString(groupId), true);
|
||||
var id = pwGroup.Uuid;
|
||||
pwGroup.ParentGroup.Groups.Remove(pwGroup);
|
||||
|
||||
if (!_pwDatabase.RecycleBinEnabled || pwGroup.ParentGroup.Uuid.Equals(_pwDatabase.RecycleBinUuid))
|
||||
{
|
||||
_pwDatabase.DeletedObjects.Add(new PwDeletedObject(id, DateTime.UtcNow));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void SortEntries(string groupId)
|
||||
{
|
||||
var pwGroup = _pwDatabase.RootGroup.FindGroup(BuildIdFromString(groupId), true);
|
||||
@@ -315,6 +288,18 @@ namespace ModernKeePass.Infrastructure.KeePass
|
||||
pwGroup.SortSubGroups(false);
|
||||
}
|
||||
|
||||
public EntryEntity GetEntry(string id)
|
||||
{
|
||||
var pwEntry = _pwDatabase.RootGroup.FindEntry(BuildIdFromString(id), true);
|
||||
return _mapper.Map<EntryEntity>(pwEntry);
|
||||
}
|
||||
|
||||
public GroupEntity GetGroup(string id)
|
||||
{
|
||||
var pwGroup = _pwDatabase.RootGroup.FindGroup(BuildIdFromString(id), true);
|
||||
return _mapper.Map<GroupEntity>(pwGroup);
|
||||
}
|
||||
|
||||
public async Task UpdateCredentials(Credentials credentials)
|
||||
{
|
||||
_pwDatabase.MasterKey = await CreateCompositeKey(credentials);
|
||||
@@ -337,28 +322,6 @@ namespace ModernKeePass.Infrastructure.KeePass
|
||||
var fileContents = await _fileService.OpenBinaryFile(fileInfo.Path);
|
||||
return IOConnectionInfo.FromByteArray(fileContents);
|
||||
}
|
||||
private GroupEntity BuildHierarchy(GroupEntity parentGroup, PwGroup pwGroup)
|
||||
{
|
||||
var group = _mapper.Map<GroupEntity>(pwGroup);
|
||||
group.ParentGroup = parentGroup;
|
||||
group.Entries = pwGroup.Entries.Select(e =>
|
||||
{
|
||||
var entry = _mapper.Map<EntryEntity>(e);
|
||||
entry.ParentGroup = group;
|
||||
return entry;
|
||||
}).ToList();
|
||||
group.SubGroups = pwGroup.Groups.Select(g => BuildHierarchy(group, g)).ToList();
|
||||
|
||||
/*var group = new GroupEntity
|
||||
{
|
||||
Id = pwGroup.Uuid.ToHexString(),
|
||||
Name = pwGroup.Name,
|
||||
Icon = IconMapper.MapPwIconToIcon(pwGroup.IconId),
|
||||
Entries = pwGroup.Entries.Select(e => _mapper.Map<EntryEntity>(e)).ToList(),
|
||||
SubGroups = pwGroup.Groups.Select(BuildHierarchy).ToList()
|
||||
};*/
|
||||
return group;
|
||||
}
|
||||
|
||||
private PwUuid BuildIdFromString(string id)
|
||||
{
|
||||
|
@@ -28,10 +28,6 @@ namespace ModernKeePass.Interfaces
|
||||
/// <param name="destination">The destination to move the entity to</param>
|
||||
Task Move(GroupVm destination);
|
||||
/// <summary>
|
||||
/// Delete from Model
|
||||
/// </summary>
|
||||
Task CommitDelete();
|
||||
/// <summary>
|
||||
/// Delete from ViewModel
|
||||
/// </summary>
|
||||
Task MarkForDelete(string recycleBinTitle);
|
||||
|
@@ -11,7 +11,6 @@ using ModernKeePass.Application.Database.Queries.GetDatabase;
|
||||
using ModernKeePass.Application.Entry.Commands.SetFieldValue;
|
||||
using ModernKeePass.Application.Group.Commands.AddEntry;
|
||||
using ModernKeePass.Application.Group.Commands.CreateGroup;
|
||||
using ModernKeePass.Application.Group.Commands.DeleteEntry;
|
||||
using ModernKeePass.Application.Group.Commands.RemoveEntry;
|
||||
using ModernKeePass.Application.Security.Commands.GeneratePassword;
|
||||
using ModernKeePass.Application.Security.Queries.EstimatePasswordComplexity;
|
||||
@@ -266,18 +265,9 @@ namespace ModernKeePass.ViewModels
|
||||
public async Task Move(Application.Group.Models.GroupVm destination)
|
||||
{
|
||||
await _mediator.Send(new AddEntryCommand { ParentGroup = destination, Entry = _entry });
|
||||
await _mediator.Send(new RemoveEntryCommand { ParentGroup = _entry.ParentGroup, Entry = _entry });
|
||||
if (destination == null)
|
||||
{
|
||||
await _mediator.Send(new DeleteEntryCommand { Entry = _entry });
|
||||
}
|
||||
await _mediator.Send(new RemoveEntryCommand { ParentGroup = _entry.ParentGroup, Entry = _entry, IsDelete = true });
|
||||
}
|
||||
|
||||
public async Task CommitDelete()
|
||||
{
|
||||
await _mediator.Send(new DeleteEntryCommand {Entry = _entry});
|
||||
}
|
||||
|
||||
|
||||
public Application.Entry.Models.EntryVm GetEntry()
|
||||
{
|
||||
return _entry;
|
||||
|
@@ -13,7 +13,6 @@ using ModernKeePass.Application.Group.Commands.AddEntry;
|
||||
using ModernKeePass.Application.Group.Commands.AddGroup;
|
||||
using ModernKeePass.Application.Group.Commands.CreateEntry;
|
||||
using ModernKeePass.Application.Group.Commands.CreateGroup;
|
||||
using ModernKeePass.Application.Group.Commands.DeleteGroup;
|
||||
using ModernKeePass.Application.Group.Commands.InsertEntry;
|
||||
using ModernKeePass.Application.Group.Commands.RemoveEntry;
|
||||
using ModernKeePass.Application.Group.Commands.RemoveGroup;
|
||||
@@ -182,16 +181,7 @@ namespace ModernKeePass.ViewModels
|
||||
public async Task Move(Application.Group.Models.GroupVm destination)
|
||||
{
|
||||
await _mediator.Send(new AddGroupCommand {ParentGroup = destination, Group = _group});
|
||||
await _mediator.Send(new RemoveGroupCommand {ParentGroup = _group.ParentGroup, Group = _group});
|
||||
if (destination == null)
|
||||
{
|
||||
await _mediator.Send(new DeleteGroupCommand { Group = _group });
|
||||
}
|
||||
}
|
||||
|
||||
public async Task CommitDelete()
|
||||
{
|
||||
await _mediator.Send(new DeleteGroupCommand { Group = _group });
|
||||
await _mediator.Send(new RemoveGroupCommand {ParentGroup = _group.ParentGroup, Group = _group, IsDelete = true });
|
||||
}
|
||||
|
||||
private async Task SortEntriesAsync()
|
||||
|
Reference in New Issue
Block a user