This commit is contained in:
2023-07-29 16:25:16 +03:00
parent 90f0386bfe
commit 4312a5c084
34 changed files with 1998 additions and 61 deletions
@@ -10,6 +10,7 @@ using Models.Account;
using Services.Account;
using Services.Account.Domain;
using MyOffice.Web.Infrastructure.Attributes;
using Services.Identity;
[Authorize]
[ApiController]
@@ -19,16 +20,19 @@ public class SettingsAccountController : BaseApiController
private readonly ILogger<SettingsAccountController> _logger;
private readonly IMapper _mapper;
private readonly AccountService _accountService;
private readonly IContextProvider _contextProvider;
public SettingsAccountController(
ILogger<SettingsAccountController> logger,
IMapper mapper,
AccountService accountService
AccountService accountService,
IContextProvider contextProvider
)
{
_logger = logger;
_mapper = mapper;
_accountService = accountService;
_contextProvider = contextProvider;
}
[HttpGet("~/api/settings/account-categories")]
@@ -251,8 +255,6 @@ public class SettingsAccountController : BaseApiController
return ProblemBadRequest("Account not found.");
case AccessInviteStatus.access_exists:
return ProblemBadRequest("Access allowed.");
case AccessInviteStatus.invite_exists:
case AccessInviteStatus.success:
return exec.Result!;
@@ -279,6 +281,53 @@ public class SettingsAccountController : BaseApiController
default:
throw new NotSupportedException(exec.Status.ToString());
}
}
[HttpGet("~/api/settings/accounts/invites")]
public List<AccountAccessInviteViewModel> AccountInvites()
{
var invites = _accountService.InvitesGet(_contextProvider.User.Email);
return _mapper.Map<List<AccountAccessInviteViewModel>>(invites);
}
[HttpPost("~/api/settings/accounts/invites/{id}/accept")]
public object AccountInviteAccept([AsGuid]string id, AccountInviteAcceptRequest request)
{
var exec = _accountService.InviteAccept(UserId, id.AsGuid(), request.Name);
switch (exec.Status)
{
case InviteAcceptStatus.invite_not_found:
return ProblemBadRequest("Invite not found.");
case InviteAcceptStatus.account_not_found:
return ProblemBadRequest("Account not found.");
case InviteAcceptStatus.already_accepted:
case InviteAcceptStatus.success:
return _mapper.Map<AccountViewModel>(exec.Result!);
default:
throw new NotSupportedException(exec.Status.ToString());
}
}
[HttpPost("~/api/settings/accounts/invites/{id}/reject")]
public object AccountInviteReject([AsGuid] string id)
{
var exec = _accountService.InviteReject(id.AsGuid());
switch (exec.Status)
{
case GeneralExecStatus.not_found:
case GeneralExecStatus.failure:
return ProblemBadRequest("Invite not found.");
case GeneralExecStatus.success:
return _mapper.Map<AccountAccessInviteViewModel>(exec.Result!);
default:
throw new NotSupportedException(exec.Status.ToString());
}
}
}
@@ -0,0 +1,13 @@
namespace MyOffice.Web.Models.Account;
using Core.Attributes;
using Services.Account.Domain;
[LinkFrom(typeof(AccountAccessInviteDto))]
[LinkWith(typeof(AccountViewModelProfile))]
public class AccountAccessInviteViewModel
{
public string? Id { get; set; }
public string? Account { get; set; }
public bool? AllowWrite { get; set; }
}
@@ -1,29 +1,16 @@
namespace MyOffice.Web.Models.Account
namespace MyOffice.Web.Models.Account;
using MyOffice.Core.Attributes;
using MyOffice.Services.Account.Domain;
using System.ComponentModel.DataAnnotations;
[Link(typeof(AccountCategoryDto))]
public class AccountCategoryViewModel
{
using System.ComponentModel.DataAnnotations;
using Core.Extensions;
using Data.Models.Accounts;
public string? Id { get; set; }
public class AccountCategoryViewModel
{
public string? Id { get; set; }
[Required]
public string? Name { get; set; }
[Required]
public string? Name { get; set; }
public bool? AllowDelete { get; set; }
}
public static class AccountCategoryViewModelExtensions
{
public static AccountCategoryViewModel ToModel(this AccountCategory input)
{
return new AccountCategoryViewModel
{
Id = input.Id.ToShort(),
Name = input.Name,
AllowDelete = !input.Accounts?.Any(),
};
}
}
}
public bool? AllowDelete { get; set; }
}
@@ -0,0 +1,6 @@
namespace MyOffice.Web.Models.Account;
public class AccountInviteAcceptRequest
{
public string Name { get; set; } = null!;
}
@@ -3,11 +3,7 @@
using AutoMapper;
using MyOffice.Services.Identity;
using Services.Account.Domain;
using Services.Mapper;
using System.Security.Cryptography;
using Core.Extensions;
using User;
using static MyOffice.Web.Models.Account.AccountAccessViewModel;
public class CustomResolver : IValueResolver<AccountAccessDto, AccessRightsViewModel, bool>
{
@@ -61,11 +57,15 @@ public class AccountViewModelProfile : Profile
(src, dst) => src.OwnerId == src.UserId))
;
CreateMap<AccountAccessItemViewModel, AccountAccessDto>()
CreateMap<AccountAccessViewModel.AccountAccessItemViewModel, AccountAccessDto>()
.ForMember(x => x.IsAllowWrite, o => o.MapFrom(x => x.AllowWrite))
;
CreateMap<AccountCategoryDto, AccountCategoryViewModel>()
;
CreateMap<AccountAccessInviteDto, AccountAccessInviteViewModel>()
.ForMember(x => x.AllowWrite, o => o.MapFrom(x => x.IsAllowWrite))
;
}
}
+8
View File
@@ -64,6 +64,13 @@ using MyOffice.Services.Mapper;
//TODO: Response model from base type
//TODO: XXXResult -> XXXStatus
//TODO: SPA isAllowDelete -> allowDelete (remove is)
//TODO: Repository auto registration
//TODO: Services auto registration
//TODO: openid-configuration failed - lock login
//TODO: BUG some times after login redirect to dashboard but exists return url
//TODO: email confirmation
//TODO: email password reset
//TODO: automapper -> Extension ToModel() ToDbo() FromModel() FromDbo()
public class Program
{
@@ -262,6 +269,7 @@ public class Program
builder.Services.AddScoped<IAccountCategoryRepository, AccountCategoryRepository>();
builder.Services.AddScoped<IAccountRepository, AccountRepository>();
builder.Services.AddScoped<IAccountAccessRepository, AccountAccessRepository>();
builder.Services.AddScoped<IAccountAccessInviteRepository, AccountAccessInviteRepository>();
builder.Services.AddScoped<IAccountAccountCategoryRepository, AccountAccountCategoryRepository>();
builder.Services.AddScoped<IItemCategoryRepository, ItemCategoryRepository>();