Compare commits
5 Commits
main
...
feature/im
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f05d1a4b7e | ||
|
|
c2067700bc | ||
|
|
d12d26bc82 | ||
|
|
ae7ee3a93e | ||
|
|
4c8c115ff5 |
355
.gitignore
vendored
Normal file
355
.gitignore
vendored
Normal file
@@ -0,0 +1,355 @@
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
##
|
||||
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||
|
||||
# User-specific files
|
||||
*.rsuser
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Mono auto generated files
|
||||
mono_crash.*
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
[Ww][Ii][Nn]32/
|
||||
[Aa][Rr][Mm]/
|
||||
[Aa][Rr][Mm]64/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Oo]ut/
|
||||
[Ll]og/
|
||||
[Ll]ogs/
|
||||
|
||||
# Visual Studio 2015/2017 cache/options directory
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
#wwwroot/
|
||||
|
||||
# Visual Studio 2017 auto generated files
|
||||
Generated\ Files/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
# NUnit
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
nunit-*.xml
|
||||
|
||||
# Build Results of an ATL Project
|
||||
[Dd]ebugPS/
|
||||
[Rr]eleasePS/
|
||||
dlldata.c
|
||||
|
||||
# Benchmark Results
|
||||
BenchmarkDotNet.Artifacts/
|
||||
|
||||
# .NET Core
|
||||
project.lock.json
|
||||
project.fragment.lock.json
|
||||
artifacts/
|
||||
|
||||
# ASP.NET Scaffolding
|
||||
ScaffoldingReadMe.txt
|
||||
|
||||
# StyleCop
|
||||
StyleCopReport.xml
|
||||
|
||||
# Files built by Visual Studio
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_h.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.iobj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.ipdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*_wpftmp.csproj
|
||||
*.log
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.svclog
|
||||
*.scc
|
||||
|
||||
# Chutzpah Test files
|
||||
_Chutzpah*
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opendb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
*.sap
|
||||
|
||||
# Visual Studio Trace Files
|
||||
*.e2e
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
$tf/
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
*.DotSettings.user
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# AxoCover is a Code Coverage Tool
|
||||
.axoCover/*
|
||||
!.axoCover/settings.json
|
||||
|
||||
# Coverlet is a free, cross platform Code Coverage Tool
|
||||
coverage*.json
|
||||
coverage*.xml
|
||||
coverage*.info
|
||||
|
||||
# Visual Studio code coverage results
|
||||
*.coverage
|
||||
*.coveragexml
|
||||
|
||||
# NCrunch
|
||||
_NCrunch_*
|
||||
.*crunch*.local.xml
|
||||
nCrunchTemp_*
|
||||
|
||||
# MightyMoose
|
||||
*.mm.*
|
||||
AutoTest.Net/
|
||||
|
||||
# Web workbench (sass)
|
||||
.sass-cache/
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.[Pp]ublish.xml
|
||||
*.azurePubxml
|
||||
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||
# but database connection strings (with potential passwords) will be unencrypted
|
||||
*.pubxml
|
||||
*.publishproj
|
||||
|
||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||
# in these scripts will be unencrypted
|
||||
PublishScripts/
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
# NuGet Symbol Packages
|
||||
*.snupkg
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/[Pp]ackages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
!**/[Pp]ackages/build/
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
#!**/[Pp]ackages/repositories.config
|
||||
# NuGet v3's project.json files produces more ignorable files
|
||||
*.nuget.props
|
||||
*.nuget.targets
|
||||
|
||||
# Microsoft Azure Build Output
|
||||
csx/
|
||||
*.build.csdef
|
||||
|
||||
# Microsoft Azure Emulator
|
||||
ecf/
|
||||
rcf/
|
||||
|
||||
# Windows Store app package directories and files
|
||||
AppPackages/
|
||||
BundleArtifacts/
|
||||
Package.StoreAssociation.xml
|
||||
_pkginfo.txt
|
||||
*.appx
|
||||
*.appxbundle
|
||||
*.appxupload
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
*.[Cc]ache
|
||||
# but keep track of directories ending in .cache
|
||||
!?*.[Cc]ache/
|
||||
|
||||
# Others
|
||||
ClientBin/
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.jfm
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
orleans.codegen.cs
|
||||
|
||||
# Including strong name files can present a security risk
|
||||
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||
#*.snk
|
||||
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||
#bower_components/
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
ServiceFabricBackup/
|
||||
*.rptproj.bak
|
||||
|
||||
# SQL Server files
|
||||
*.mdf
|
||||
*.ldf
|
||||
*.ndf
|
||||
|
||||
# Business Intelligence projects
|
||||
*.rdl.data
|
||||
*.bim.layout
|
||||
*.bim_*.settings
|
||||
*.rptproj.rsuser
|
||||
*- [Bb]ackup.rdl
|
||||
*- [Bb]ackup ([0-9]).rdl
|
||||
*- [Bb]ackup ([0-9][0-9]).rdl
|
||||
|
||||
# Microsoft Fakes
|
||||
FakesAssemblies/
|
||||
|
||||
# GhostDoc plugin setting file
|
||||
*.GhostDoc.xml
|
||||
|
||||
# Node.js Tools for Visual Studio
|
||||
.ntvs_analysis.dat
|
||||
node_modules/
|
||||
|
||||
# Visual Studio 6 build log
|
||||
*.plg
|
||||
|
||||
# Visual Studio 6 workspace options file
|
||||
*.opt
|
||||
|
||||
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||
*.vbw
|
||||
|
||||
# Visual Studio LightSwitch build output
|
||||
**/*.HTMLClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/ModelManifest.xml
|
||||
**/*.Server/GeneratedArtifacts
|
||||
**/*.Server/ModelManifest.xml
|
||||
_Pvt_Extensions
|
||||
|
||||
# Paket dependency manager
|
||||
.paket/paket.exe
|
||||
paket-files/
|
||||
|
||||
# FAKE - F# Make
|
||||
.fake/
|
||||
|
||||
# CodeRush personal settings
|
||||
.cr/personal
|
||||
|
||||
# Python Tools for Visual Studio (PTVS)
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
# Cake - Uncomment if you are using it
|
||||
# tools/**
|
||||
# !tools/packages.config
|
||||
|
||||
# Tabs Studio
|
||||
*.tss
|
||||
|
||||
# Telerik's JustMock configuration file
|
||||
*.jmconfig
|
||||
|
||||
# BizTalk build output
|
||||
*.btp.cs
|
||||
*.btm.cs
|
||||
*.odx.cs
|
||||
*.xsd.cs
|
||||
|
||||
# OpenCover UI analysis results
|
||||
OpenCover/
|
||||
|
||||
# Azure Stream Analytics local run output
|
||||
ASALocalRun/
|
||||
|
||||
# MSBuild Binary and Structured Log
|
||||
*.binlog
|
||||
|
||||
# NVidia Nsight GPU debugger configuration file
|
||||
*.nvuser
|
||||
|
||||
# MFractors (Xamarin productivity tool) working folder
|
||||
.mfractor/
|
||||
|
||||
# Local History for Visual Studio
|
||||
.localhistory/
|
||||
|
||||
/Core.Cerberos.DAL.API/CerberosDALSettings.development.json
|
||||
/Core.Cerberos.DAL.API/cerberosprivkey.pem
|
||||
/Core.Cerberos.DAL.API/cerberospubkey.pem
|
||||
@@ -1,6 +1,6 @@
|
||||
// ***********************************************************************
|
||||
// <copyright file="ModuleController.cs">
|
||||
// Heath
|
||||
// AgileWebs
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// ***********************************************************************
|
||||
// <copyright file="PermissionController.cs">
|
||||
// Heath
|
||||
// AgileWebs
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// ***********************************************************************
|
||||
// <copyright file="RoleController.cs">
|
||||
// Heath
|
||||
// AgileWebs
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
using Asp.Versioning;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// ***********************************************************************
|
||||
// <copyright file="UserController.cs">
|
||||
// Heath
|
||||
// AgileWebs
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
using Asp.Versioning;
|
||||
@@ -438,58 +438,5 @@ namespace LSA.Core.Kerberos.API.Controllers
|
||||
return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Consent Form PDF.
|
||||
/// </summary>
|
||||
/// <returns>The <see cref="BlobDownloadUriAdapter"/> found pdf.</returns>
|
||||
/// <response code="200">The pdf found.</response>
|
||||
/// <response code="404">The pdf not found error.</response>
|
||||
/// <response code="500">The service internal error.</response>
|
||||
[HttpGet]
|
||||
[Route("GetConsentFormPDF")]
|
||||
[ProducesResponseType(typeof(BlobDownloadUriAdapter), StatusCodes.Status200OK)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.HeathScheme)]
|
||||
[Permission("UserManagement.Read")]
|
||||
public async Task<IActionResult> GetConsentFormPDFService()
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await service.GetConsentFormPDFService();
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Error in GetConsentFormPDFService");
|
||||
return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Accept user consent form.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="UserAdapter"/> representing
|
||||
/// the asynchronous execution of the service.</returns>
|
||||
/// <response code="200">The User found.</response>
|
||||
/// <response code="404">The User not found.</response>
|
||||
/// <response code="500">The service internal error.</response>
|
||||
[HttpPatch("AcceptUserConsentForm")]
|
||||
[ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)]
|
||||
[Authorize(AuthenticationSchemes = $"{Schemes.HeathScheme}, {Schemes.AzureScheme}")]
|
||||
public async Task<IActionResult> AcceptUserConsentFormAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await service.AcceptUserConsentFormService().ConfigureAwait(false);
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Error in AcceptUserConsentFormService");
|
||||
return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Blueprint.Logging" Version="0.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Core.Blueprint.Logging.Configuration;
|
||||
using Core.Cerberos.Adapters.Extensions;
|
||||
using Core.Cerberos.Adapters.Helpers;
|
||||
using Core.Cerberos.Provider;
|
||||
@@ -21,6 +22,8 @@ builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
|
||||
builder.Services.AddLogs(builder);
|
||||
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("AllowAll", policyBuilder =>
|
||||
@@ -79,6 +82,7 @@ var app = builder.Build();
|
||||
|
||||
app.UseSwaggerUI(builder.Configuration, authSettings);
|
||||
app.ConfigureSwagger(builder.Configuration);
|
||||
app.UseLogging(builder.Configuration);
|
||||
app.UseHttpsRedirection();
|
||||
app.UseAuthorization();
|
||||
app.MapControllers();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// ***********************************************************************
|
||||
// <copyright file="ModuleRequest.cs">
|
||||
// Heath
|
||||
// AgileWebs
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// ***********************************************************************
|
||||
// <copyright file="PermissionRequest.cs">
|
||||
// Heath
|
||||
// AgileWebs
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// ***********************************************************************
|
||||
// <copyright file="RoleRequest.cs">
|
||||
// Heath
|
||||
// AgileWebs
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// ***********************************************************************
|
||||
// <copyright file="UserAddDto.cs">
|
||||
// Heath
|
||||
// AgileWebs
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Core.Cerberos.Adapters" Version="0.3.0-alpha0042" />
|
||||
<PackageReference Include="Cerberos.Building.Blocks" Version="0.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Core.Cerberos.Adapters" Version="0.3.0-alpha0042" />
|
||||
<PackageReference Include="Microsoft.Azure.StackExchangeRedis" Version="3.1.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// ***********************************************************************
|
||||
// <copyright file="IModuleService.cs">
|
||||
// Heath
|
||||
// AgileWebs
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
using Core.Cerberos.Adapters;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// ***********************************************************************
|
||||
// <copyright file="IPermissionService.cs">
|
||||
// Heath
|
||||
// AgileWebs
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
using Core.Cerberos.Adapters;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// ***********************************************************************
|
||||
// <copyright file="IRoleService.cs">
|
||||
// Heath
|
||||
// AgileWebs
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
using Core.Cerberos.Adapters;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// ***********************************************************************
|
||||
// <copyright file="IUserService.cs">
|
||||
// Heath
|
||||
// AgileWebs
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
using Core.Blueprint.Storage.Adapters;
|
||||
@@ -125,19 +125,5 @@ namespace Core.Cerberos.Provider.Contracts
|
||||
/// <param name="email">The user's email.</param>
|
||||
/// <returns>A <see cref="{Task{TokenAdapter}}"/> representing the asynchronous execution of the service.</returns>
|
||||
Task<TokenAdapter?> GetTokenAdapter(string email);
|
||||
|
||||
/// <summary>
|
||||
/// Get Consent Form PDF.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="{Task{BlobDownloadUriAdapter}}"/> representing
|
||||
/// the asynchronous execution of the service.</returns>
|
||||
Task<BlobDownloadUriAdapter> GetConsentFormPDFService();
|
||||
|
||||
/// <summary>
|
||||
/// Accept user consent form.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="{Task{UserAdapter}}"/> representing
|
||||
/// the asynchronous execution of the service.</returns>
|
||||
Task<UserAdapter?> AcceptUserConsentFormService();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Core.Blueprint.Storage" Version="0.3.0-alpha0049" />
|
||||
<PackageReference Include="Core.Cerberos.Adapters" Version="0.3.0-alpha0042" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
|
||||
<PackageReference Include="MongoDB.Driver" Version="3.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// ***********************************************************************
|
||||
// <copyright file="Helper.cs">
|
||||
// Heath
|
||||
// AgileWebs
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// ***********************************************************************
|
||||
// <copyright file="ModuleService.cs">
|
||||
// Heath
|
||||
// AgileWebs
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
using Core.Cerberos.Adapters;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// ***********************************************************************
|
||||
// <copyright file="PermissionService.cs">
|
||||
// Heath
|
||||
// AgileWebs
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
using Core.Cerberos.Adapters;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// ***********************************************************************
|
||||
// <copyright file="RoleService.cs">
|
||||
// Heath
|
||||
// AgileWebs
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
using Core.Cerberos.Adapters;
|
||||
|
||||
627
Core.Cerberos.Provider/Providers/Onboarding/UserService.cs
Normal file
627
Core.Cerberos.Provider/Providers/Onboarding/UserService.cs
Normal file
@@ -0,0 +1,627 @@
|
||||
// ***********************************************************************
|
||||
// <copyright file="UserService.cs">
|
||||
// AgileWebs
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
|
||||
using Core.Cerberos.Adapters;
|
||||
using Core.Cerberos.Adapters.Common.Constants;
|
||||
using Core.Cerberos.Adapters.Common.Enums;
|
||||
using Core.Cerberos.Domain.Contexts.Onboarding.Mappers;
|
||||
using Core.Cerberos.Domain.Contexts.Onboarding.Request;
|
||||
using Core.Cerberos.Infraestructure.Caching.Configs;
|
||||
using Core.Cerberos.Infraestructure.Caching.Contracts;
|
||||
using Core.Cerberos.Provider.Contracts;
|
||||
using LSA.Core.Dapper.Service.Caching;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.Serialization;
|
||||
using MongoDB.Driver;
|
||||
using System.Text.RegularExpressions;
|
||||
using Core.Blueprint.Storage.Contracts;
|
||||
using Core.Blueprint.Storage.Adapters;
|
||||
|
||||
namespace Core.Cerberos.Provider.Providers.Onboarding
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles all services and business rules related to <see cref="UserAdapter"/>.
|
||||
/// </summary>
|
||||
public class UserService(ILogger<UserService> logger, IHttpContextAccessor httpContextAccessor, ICacheService cacheService,
|
||||
IOptions<CacheSettings> cacheSettings, IMongoDatabase database, IBlobStorageProvider blobStorageProvider) : IUserService
|
||||
{
|
||||
private readonly CacheSettings _cacheSettings = cacheSettings.Value;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new User.
|
||||
/// </summary>
|
||||
/// <param name="newUser">The User to be created.</param>
|
||||
/// <returns>A <see cref="{Task{UserAdapter}}"/> representing
|
||||
/// the asynchronous execution of the service.</returns>
|
||||
public async Task<UserAdapter> CreateUserService(UserRequest newUser)
|
||||
{
|
||||
try
|
||||
{
|
||||
var entity = newUser.ToAdapter(httpContextAccessor);
|
||||
await database.GetCollection<UserAdapter>(CollectionNames.User).InsertOneAsync(entity);
|
||||
entity.Id = (entity as dynamic ?? "").Id.ToString();
|
||||
|
||||
return entity;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"CreateUserService: Error in getting data - {ex.Message}");
|
||||
throw new Exception(ex.Message, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an User by identifier.
|
||||
/// </summary>
|
||||
/// <param name="id">The User identifier.</param>
|
||||
/// <returns>A <see cref="{Task{UserAdapter}}"/> representing
|
||||
/// the asynchronous execution of the service.</returns>
|
||||
public async Task<UserAdapter> GetUserByIdService(string id)
|
||||
{
|
||||
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserByIdService", id);
|
||||
var cachedData = await cacheService.GetAsync<UserAdapter>(cacheKey);
|
||||
|
||||
if (cachedData is not null) return cachedData;
|
||||
|
||||
try
|
||||
{
|
||||
var filter = Builders<UserAdapter>.Filter.And(
|
||||
Builders<UserAdapter>.Filter.Eq("_id", ObjectId.Parse(id)),
|
||||
Builders<UserAdapter>.Filter.Eq("status", StatusEnum.Active.ToString())
|
||||
);
|
||||
|
||||
var user = await database.GetCollection<UserAdapter>(CollectionNames.User)
|
||||
.Find(filter)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
var cacheDuration = CacheHelper.GetCacheDuration(_cacheSettings);
|
||||
|
||||
await cacheService.SetAsync(cacheKey, user, cacheDuration);
|
||||
|
||||
return user;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"GetUserByIdService: Error in getting data - {ex.Message}");
|
||||
throw new Exception(ex.Message, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the users.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="{Task{IEnumerable{UserAdapter}}}"/> representing
|
||||
/// the asynchronous execution of the service.</returns>
|
||||
public async Task<IEnumerable<UserAdapter>> GetAllUsersService()
|
||||
{
|
||||
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllUsersService");
|
||||
var cachedData = await cacheService.GetAsync<IEnumerable<UserAdapter>>(cacheKey) ?? [];
|
||||
|
||||
if (cachedData.Any()) return cachedData;
|
||||
|
||||
try
|
||||
{
|
||||
var filter = Builders<UserAdapter>.Filter.Eq("status", StatusEnum.Active.ToString());
|
||||
|
||||
var users = await database.GetCollection<UserAdapter>(CollectionNames.User)
|
||||
.Find(filter)
|
||||
.ToListAsync();
|
||||
|
||||
var cacheDuration = CacheHelper.GetCacheDuration(_cacheSettings);
|
||||
await cacheService.SetAsync(cacheKey, users, cacheDuration);
|
||||
|
||||
return users;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"GetAllUsersService: Error in getting data - {ex.Message}");
|
||||
throw new Exception(ex.Message, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an User by email.
|
||||
/// </summary>
|
||||
/// <param name="email">The User email.</param>
|
||||
/// <returns>A <see cref="{Task{UserAdapter}}"/> representing
|
||||
/// the asynchronous execution of the service.</returns>
|
||||
public async Task<UserAdapter> GetUserByEmailService(string? email)
|
||||
{
|
||||
try
|
||||
{
|
||||
var filter = Builders<UserAdapter>.Filter.And(
|
||||
Builders<UserAdapter>.Filter.Regex("email", new BsonRegularExpression($"^{Regex.Escape(email ?? "")}$", "i")),
|
||||
Builders<UserAdapter>.Filter.Eq("status", StatusEnum.Active.ToString())
|
||||
);
|
||||
|
||||
var user = await database.GetCollection<UserAdapter>(CollectionNames.User)
|
||||
.Find(filter)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
return user;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"GetUserByEmailService: Error in getting data - {ex.Message}");
|
||||
throw new Exception(ex.Message, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates if a users exists by email..
|
||||
/// </summary>
|
||||
/// <param name="email">The User email.</param>
|
||||
/// <returns>A <see cref="{Task{UserAdapter}}"/> representing
|
||||
/// the asynchronous execution of the service.</returns>
|
||||
public async Task<UserAdapter> ValidateUserExistenceService(string? email)
|
||||
{
|
||||
try
|
||||
{
|
||||
var filter = Builders<UserAdapter>.Filter.And(
|
||||
Builders<UserAdapter>.Filter.Regex("email", new BsonRegularExpression($"^{Regex.Escape(email ?? "")}$", "i")),
|
||||
Builders<UserAdapter>.Filter.Eq("status", StatusEnum.Active.ToString())
|
||||
);
|
||||
|
||||
var user = await database.GetCollection<UserAdapter>(CollectionNames.User)
|
||||
.Find(filter)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
return user;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"ValidateUserExistenceService: Error in getting data - {ex.Message}");
|
||||
throw new Exception(ex.Message, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes an User by id.
|
||||
/// </summary>
|
||||
/// <param name="id">The User identifier.</param>
|
||||
/// <returns>A <see cref="{Task{UserAdapter}}"/> representing
|
||||
/// the asynchronous execution of the service.</returns>
|
||||
public async Task<UserAdapter> DeleteUserService(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var filter = Builders<UserAdapter>.Filter
|
||||
.Eq("_id", ObjectId.Parse(id));
|
||||
|
||||
var update = Builders<UserAdapter>.Update
|
||||
.Set(v => v.Status, StatusEnum.Inactive);
|
||||
|
||||
await database.GetCollection<UserAdapter>(CollectionNames.User).UpdateOneAsync(filter, update);
|
||||
|
||||
var deletedUser = await database.GetCollection<UserAdapter>(CollectionNames.User).Find(filter).FirstAsync();
|
||||
|
||||
return deletedUser;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"DeleteUserService: Error in getting data - {ex.Message}");
|
||||
throw new Exception(ex.Message, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the status of the user.
|
||||
/// </summary>
|
||||
/// <param name="id">The user identifier.</param>
|
||||
/// <param name="newStatus">The new status of the user.</param>
|
||||
/// <returns>A <see cref="{Task{UserAdapter}}"/> representing
|
||||
/// the asynchronous execution of the service.</returns>
|
||||
public async Task<UserAdapter> ChangeUserStatusService(string id, StatusEnum newStatus)
|
||||
{
|
||||
try
|
||||
{
|
||||
var filter = Builders<UserAdapter>.Filter
|
||||
.Eq("_id", ObjectId.Parse(id));
|
||||
|
||||
var update = Builders<UserAdapter>.Update
|
||||
.Set(v => v.Status, newStatus)
|
||||
.Set(v => v.UpdatedBy, Helper.GetEmail(httpContextAccessor))
|
||||
.Set(v => v.UpdatedAt, DateTime.UtcNow);
|
||||
|
||||
await database.GetCollection<UserAdapter>(CollectionNames.User).UpdateOneAsync(filter, update);
|
||||
|
||||
var updatedUser = await database.GetCollection<UserAdapter>(CollectionNames.User)
|
||||
.Find(filter)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
return updatedUser;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"ChangeUserStatusService: Error in getting data - {ex.Message}");
|
||||
throw new Exception(ex.Message, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates a User by id.
|
||||
/// </summary>
|
||||
/// <param name="entity">The User to be updated.</param>
|
||||
/// <param name="id">The User identifier.</param>
|
||||
/// <returns>A <see cref="{Task{UserAdapter}}"/> representing
|
||||
/// the asynchronous execution of the service.</returns>
|
||||
public async Task<UserAdapter> UpdateUserService(UserAdapter entity, string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var filter = Builders<UserAdapter>.Filter
|
||||
.Eq("_id", ObjectId.Parse(id));
|
||||
|
||||
var update = Builders<UserAdapter>.Update
|
||||
.Set(v => v.Email, entity.Email)
|
||||
.Set(v => v.Name, entity.Name)
|
||||
.Set(v => v.MiddleName, entity.MiddleName)
|
||||
.Set(v => v.LastName, entity.LastName)
|
||||
.Set(v => v.DisplayName, $"{entity.Name} {entity.MiddleName} {entity.LastName}")
|
||||
.Set(v => v.RoleId, entity.RoleId)
|
||||
.Set(v => v.Companies, entity.Companies)
|
||||
.Set(v => v.Projects, entity.Projects)
|
||||
.Set(v => v.Status, entity.Status)
|
||||
.Set(v => v.UpdatedBy, Helper.GetEmail(httpContextAccessor))
|
||||
.Set(v => v.UpdatedAt, DateTime.UtcNow);
|
||||
|
||||
await database.GetCollection<UserAdapter>(CollectionNames.User).UpdateOneAsync(filter, update);
|
||||
|
||||
var updatedUser = await GetUserByIdService(id);
|
||||
|
||||
return updatedUser;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"UpdateUserService: Error in getting data - {ex.Message}");
|
||||
throw new Exception(ex.Message, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Logs in the user.
|
||||
/// </summary>
|
||||
/// <param name="id">The User identifier.</param>
|
||||
/// <returns>A <see cref="{Task{UserAdapter}}"/> representing
|
||||
/// the asynchronous execution of the service.</returns>
|
||||
public async Task<UserAdapter?> LogInUserService(string email)
|
||||
{
|
||||
try
|
||||
{
|
||||
var filter = Builders<UserAdapter>.Filter
|
||||
.Regex("email", new BsonRegularExpression($"^{Regex.Escape(email ?? "")}$", "i"));
|
||||
|
||||
var update = Builders<UserAdapter>.Update
|
||||
.Set(v => v.LastLogIn, DateTime.UtcNow);
|
||||
|
||||
await database.GetCollection<UserAdapter>(CollectionNames.User).UpdateOneAsync(filter, update);
|
||||
|
||||
var user = await database.GetCollection<UserAdapter>(CollectionNames.User)
|
||||
.Find(filter)
|
||||
.FirstAsync();
|
||||
|
||||
return user;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"LogInUserService: Error in getting data - {ex.Message}");
|
||||
throw new Exception(ex.Message, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Logs out the user's session.
|
||||
/// </summary>
|
||||
/// <param name="email">The User email.</param>
|
||||
/// <returns>A <see cref="{Task{UserAdapter}}"/> representing
|
||||
/// the asynchronous execution of the service.</returns>
|
||||
public async Task<UserAdapter> LogOutUserSessionService(string email)
|
||||
{
|
||||
try
|
||||
{
|
||||
var filter = Builders<UserAdapter>.Filter
|
||||
.Regex("email", new BsonRegularExpression($"^{Regex.Escape(email ?? "")}$", "i"));
|
||||
|
||||
|
||||
var update = Builders<UserAdapter>.Update
|
||||
.Set(v => v.LastLogOut, DateTime.UtcNow);
|
||||
|
||||
await database.GetCollection<UserAdapter>(CollectionNames.User).UpdateOneAsync(filter, update);
|
||||
|
||||
var user = await database.GetCollection<UserAdapter>(CollectionNames.User)
|
||||
.Find(filter)
|
||||
.FirstAsync();
|
||||
|
||||
return user;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"LogOutUserSessionService: Error in getting data - {ex.Message}");
|
||||
throw new Exception(ex.Message, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a company to the user's list of companies.
|
||||
/// </summary>
|
||||
/// <param name="userId">The identifier of the user to whom the company will be added.</param>
|
||||
/// <param name="companyId">The identifier of the company to add.</param>
|
||||
/// <returns>A <see cref="Task{UserAdapter}"/> representing the asynchronous operation, with the updated user object.</returns>
|
||||
public async Task<UserAdapter> AddCompanyToUserService(string userId, string companyId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var filter = Builders<UserAdapter>.Filter.Eq("_id", ObjectId.Parse(userId));
|
||||
var update = Builders<UserAdapter>.Update.AddToSet(v => v.Companies, companyId);
|
||||
|
||||
await database.GetCollection<UserAdapter>(CollectionNames.User).UpdateOneAsync(filter, update);
|
||||
|
||||
var updatedUser = await database.GetCollection<UserAdapter>(CollectionNames.User)
|
||||
.Find(filter)
|
||||
.FirstOrDefaultAsync();
|
||||
return updatedUser;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"AddCompanyToUserService: Error in getting data - {ex.Message}");
|
||||
throw new Exception(ex.Message, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a company from the user's list of companies.
|
||||
/// </summary>
|
||||
/// <param name="userId">The identifier of the user from whom the company will be removed.</param>
|
||||
/// <param name="companyId">The identifier of the company to remove.</param>
|
||||
/// <returns>A <see cref="Task{UserAdapter}"/> representing the asynchronous operation, with the updated user object.</returns>
|
||||
public async Task<UserAdapter> RemoveCompanyFromUserService(string userId, string companyId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var filter = Builders<UserAdapter>.Filter.Eq("_id", ObjectId.Parse(userId));
|
||||
var update = Builders<UserAdapter>.Update.Pull(v => v.Companies, companyId);
|
||||
|
||||
await database.GetCollection<UserAdapter>(CollectionNames.User).UpdateOneAsync(filter, update);
|
||||
|
||||
var updatedUser = await database.GetCollection<UserAdapter>(CollectionNames.User)
|
||||
.Find(filter)
|
||||
.FirstOrDefaultAsync();
|
||||
return updatedUser;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"RemoveCompanyFromUserService: Error in getting data - {ex.Message}");
|
||||
throw new Exception(ex.Message, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a project to the user's list of projects.
|
||||
/// </summary>
|
||||
/// <param name="userId">The identifier of the user to whom the project will be added.</param>
|
||||
/// <param name="projectId">The identifier of the project to add.</param>
|
||||
/// <returns>A <see cref="Task{UserAdapter}"/> representing the asynchronous operation, with the updated user object.</returns>
|
||||
public async Task<UserAdapter> AddProjectToUserService(string userId, string projectId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var filter = Builders<UserAdapter>.Filter.Eq("_id", ObjectId.Parse(userId));
|
||||
var update = Builders<UserAdapter>.Update.AddToSet(v => v.Projects, projectId);
|
||||
|
||||
await database.GetCollection<UserAdapter>(CollectionNames.User).UpdateOneAsync(filter, update);
|
||||
|
||||
var updatedUser = await database.GetCollection<UserAdapter>(CollectionNames.User)
|
||||
.Find(filter)
|
||||
.FirstOrDefaultAsync();
|
||||
return updatedUser;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"AddProjectToUserService: Error in getting data - {ex.Message}");
|
||||
throw new Exception(ex.Message, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a project from the user's list of projects.
|
||||
/// </summary>
|
||||
/// <param name="userId">The identifier of the user from whom the project will be removed.</param>
|
||||
/// <param name="projectId">The identifier of the project to remove.</param>
|
||||
/// <returns>A <see cref="Task{UserAdapter}"/> representing the asynchronous operation, with the updated user object.</returns>
|
||||
public async Task<UserAdapter> RemoveProjectFromUserService(string userId, string projectId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var filter = Builders<UserAdapter>.Filter.Eq("_id", ObjectId.Parse(userId));
|
||||
var update = Builders<UserAdapter>.Update.Pull(v => v.Projects, projectId);
|
||||
|
||||
await database.GetCollection<UserAdapter>(CollectionNames.User).UpdateOneAsync(filter, update);
|
||||
|
||||
var updatedUser = await database.GetCollection<UserAdapter>(CollectionNames.User)
|
||||
.Find(filter)
|
||||
.FirstOrDefaultAsync();
|
||||
return updatedUser;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"RemoveProjectFromUserService: Error in getting data - {ex.Message}");
|
||||
throw new Exception(ex.Message, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the token adapter for a user.
|
||||
/// </summary>
|
||||
/// <param name="email">The user's email.</param>
|
||||
/// <returns>A <see cref="{Task{TokenAdapter}}"/> representing the asynchronous execution of the service.</returns>
|
||||
public async Task<TokenAdapter?> GetTokenAdapter(string email)
|
||||
{
|
||||
try
|
||||
{
|
||||
var pipeline = new[]
|
||||
{
|
||||
new BsonDocument("$match", new BsonDocument
|
||||
{
|
||||
{ "email", new BsonDocument
|
||||
{
|
||||
{ "$regex", $"^{Regex.Escape(email)}$" },
|
||||
{ "$options", "i" }
|
||||
}
|
||||
},
|
||||
{ "status", StatusEnum.Active.ToString() }
|
||||
}),
|
||||
|
||||
new BsonDocument("$lookup", new BsonDocument
|
||||
{
|
||||
{ "from", "Roles" },
|
||||
{ "localField", "roleId" },
|
||||
{ "foreignField", "_id" },
|
||||
{ "as", "role" }
|
||||
}),
|
||||
|
||||
new BsonDocument("$unwind", "$role"),
|
||||
new BsonDocument("$match", new BsonDocument("role.status", StatusEnum.Active.ToString())),
|
||||
|
||||
new BsonDocument("$addFields", new BsonDocument
|
||||
{
|
||||
{ "role.permissions", new BsonDocument("$map", new BsonDocument
|
||||
{
|
||||
{ "input", "$role.permissions" },
|
||||
{ "as", "perm" },
|
||||
{ "in", new BsonDocument("$toObjectId", "$$perm") }
|
||||
})
|
||||
},
|
||||
{ "role.modules", new BsonDocument("$map", new BsonDocument
|
||||
{
|
||||
{ "input", "$role.modules" },
|
||||
{ "as", "mod" },
|
||||
{ "in", new BsonDocument("$toObjectId", "$$mod") }
|
||||
})
|
||||
}
|
||||
}),
|
||||
|
||||
new BsonDocument("$lookup", new BsonDocument
|
||||
{
|
||||
{ "from", "Permissions" },
|
||||
{ "localField", "role.permissions" },
|
||||
{ "foreignField", "_id" },
|
||||
{ "as", "permissions" }
|
||||
}),
|
||||
new BsonDocument("$lookup", new BsonDocument
|
||||
{
|
||||
{ "from", "Modules" },
|
||||
{ "localField", "role.modules" },
|
||||
{ "foreignField", "_id" },
|
||||
{ "as", "modules" }
|
||||
}),
|
||||
new BsonDocument("$project", new BsonDocument
|
||||
{
|
||||
{ "_id", 1 },
|
||||
{ "guid", 1 },
|
||||
{ "email", 1 },
|
||||
{ "name", 1 },
|
||||
{ "middleName", 1 },
|
||||
{ "lastName", 1 },
|
||||
{ "displayName", 1 },
|
||||
{ "roleId", 1 },
|
||||
{ "companies", 1 },
|
||||
{ "projects", 1 },
|
||||
{ "lastLogIn", 1 },
|
||||
{ "lastLogOut", 1 },
|
||||
{ "createdBy", 1 },
|
||||
{ "updatedBy", 1 },
|
||||
{ "status", 1 },
|
||||
{ "createdAt", 1 },
|
||||
{ "updatedAt", 1 },
|
||||
{ "role._id", 1 },
|
||||
{ "role.name", 1 },
|
||||
{ "role.description", 1 },
|
||||
{ "role.applications", 1 },
|
||||
{ "role.permissions", 1 },
|
||||
{ "role.modules", 1 },
|
||||
{ "role.status", 1 },
|
||||
{ "role.createdAt", 1 },
|
||||
{ "role.updatedAt", 1 },
|
||||
{ "role.createdBy", 1 },
|
||||
{ "role.updatedBy", 1 },
|
||||
{ "permissions", 1 },
|
||||
{ "modules", 1 }
|
||||
})
|
||||
};
|
||||
|
||||
|
||||
var result = await database.GetCollection<BsonDocument>(CollectionNames.User)
|
||||
.Aggregate<BsonDocument>(pipeline)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (result is null) return null;
|
||||
|
||||
var tokenAdapter = new TokenAdapter
|
||||
{
|
||||
User = new UserAdapter
|
||||
{
|
||||
Id = result["_id"]?.ToString() ?? "",
|
||||
Guid = result["guid"].AsString,
|
||||
Email = result["email"].AsString,
|
||||
Name = result["name"].AsString,
|
||||
MiddleName = result["middleName"].AsString,
|
||||
LastName = result["lastName"].AsString,
|
||||
DisplayName = result["displayName"].AsString,
|
||||
RoleId = result["roleId"]?.ToString() ?? "",
|
||||
Companies = result["companies"].AsBsonArray
|
||||
.Select(c => c.AsString)
|
||||
.ToArray(),
|
||||
Projects = result["projects"].AsBsonArray
|
||||
.Select(c => c.AsString)
|
||||
.ToArray(),
|
||||
LastLogIn = result["lastLogIn"].ToUniversalTime(),
|
||||
LastLogOut = result["lastLogOut"].ToUniversalTime(),
|
||||
CreatedAt = result["createdAt"].ToUniversalTime(),
|
||||
CreatedBy = result["createdBy"].AsString,
|
||||
UpdatedAt = result["updatedAt"].ToUniversalTime(),
|
||||
UpdatedBy = result["updatedBy"].AsString,
|
||||
Status = (StatusEnum)Enum.Parse(typeof(StatusEnum), result["status"].AsString),
|
||||
},
|
||||
Role = new RoleAdapter
|
||||
{
|
||||
Id = result["role"]["_id"]?.ToString() ?? "",
|
||||
Name = result["role"]["name"].AsString,
|
||||
Description = result["role"]["description"].AsString,
|
||||
Applications = result["role"]["applications"].AsBsonArray
|
||||
.Select(c => (ApplicationsEnum)c.AsInt32)
|
||||
.ToArray(),
|
||||
Modules = result["role"]["modules"].AsBsonArray
|
||||
.Select(c => c.ToString() ?? "")
|
||||
.ToArray(),
|
||||
Permissions = result["role"]["permissions"].AsBsonArray
|
||||
.Select(c => c.ToString() ?? "")
|
||||
.ToArray(),
|
||||
Status = (StatusEnum)Enum.Parse(typeof(StatusEnum), result["role"]["status"].AsString),
|
||||
CreatedAt = result["role"]["createdAt"].ToUniversalTime(),
|
||||
UpdatedAt = result["role"]["updatedAt"].ToUniversalTime(),
|
||||
CreatedBy = result["role"]["createdBy"].AsString,
|
||||
UpdatedBy = result["role"]["updatedBy"].AsString
|
||||
},
|
||||
Permissions = result["permissions"].AsBsonArray
|
||||
.Select(permission => BsonSerializer.Deserialize<PermissionAdapter>(permission.AsBsonDocument))
|
||||
.Where(permission => permission.Status == StatusEnum.Active)
|
||||
.ToList()
|
||||
};
|
||||
|
||||
return tokenAdapter;
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"GetTokenAdapter: Error in getting data - {ex.Message}");
|
||||
throw new Exception(ex.Message, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user