7 Commits

Author SHA1 Message Date
Oscar Morales
a36fd0e480 Change the references and structure of the code to use Blueprint.Mongo package 2025-05-19 14:12:00 -06:00
Sergio Matias Urquin
24efe5612c reeplace cerberos by talos 2025-05-18 19:11:08 -06:00
Sergio Matias Urquin
f05d1a4b7e Change copyright 2025-05-17 18:16:15 -06:00
Sergio Matias Urquin
c2067700bc Use bluprint logging and fix user service error 2025-05-17 18:11:18 -06:00
Sergio Matias Urquin
d12d26bc82 add git ignore 2025-05-15 17:46:16 -06:00
Sergio Matias Urquin
ae7ee3a93e remove user consent services 2025-05-12 21:29:33 -06:00
Sergio Matias Urquin
4c8c115ff5 add CBB local reference 2025-05-12 21:27:54 -06:00
46 changed files with 1112 additions and 459 deletions

355
.gitignore vendored Normal file
View 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.Thalos.DAL.API/ThalosDALSettings.development.json
/Core.Thalos.DAL.API/thalosprivkey.pem
/Core.Thalos.DAL.API/thalospubkey.pem

View File

@@ -1,6 +0,0 @@
@Core.Cerberos.DAL.API_HostAddress = http://localhost:5211
GET {{Core.Cerberos.DAL.API_HostAddress}}/weatherforecast/
Accept: application/json
###

View File

@@ -1,25 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Providers\Onboarding\UserService - Copy.cs" />
</ItemGroup>
<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>
<ItemGroup>
<ProjectReference Include="..\Core.Cerberos.Domain\Core.Cerberos.Domain.csproj" />
<ProjectReference Include="..\Core.Cerberos.Infraestructure\Core.Cerberos.Infrastructure.csproj" />
</ItemGroup>
</Project>

View File

@@ -3,15 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.10.35027.167 VisualStudioVersion = 17.10.35027.167
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Cerberos.DAL.API", "Core.Cerberos.DAL.API\Core.Cerberos.DAL.API.csproj", "{F00B4683-03B3-487A-9608-4B30675AA278}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Thalos.DAL.API", "Core.Thalos.DAL.API\Core.Thalos.DAL.API.csproj", "{F00B4683-03B3-487A-9608-4B30675AA278}"
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Application", "Application", "{2E7D918E-AB9F-44BF-A334-FD675C9B626E}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Application", "Application", "{2E7D918E-AB9F-44BF-A334-FD675C9B626E}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Cerberos.Domain", "Core.Cerberos.Domain\Core.Cerberos.Domain.csproj", "{BE8E05D6-05B2-4317-B619-21853B7D21DB}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Thalos.Domain", "Core.Thalos.Domain\Core.Thalos.Domain.csproj", "{BE8E05D6-05B2-4317-B619-21853B7D21DB}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Cerberos.Infrastructure", "Core.Cerberos.Infraestructure\Core.Cerberos.Infrastructure.csproj", "{43BD5F47-132F-4E78-83F1-A1FEED01A502}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Thalos.Infrastructure", "Core.Thalos.Infraestructure\Core.Thalos.Infrastructure.csproj", "{43BD5F47-132F-4E78-83F1-A1FEED01A502}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Cerberos.Provider", "Core.Cerberos.Provider\Core.Cerberos.Provider.csproj", "{8CAE8380-475F-46B8-AF90-C495AAC58606}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Thalos.Provider", "Core.Thalos.Provider\Core.Thalos.Provider.csproj", "{8CAE8380-475F-46B8-AF90-C495AAC58606}"
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Presentation", "Presentation", "{36839283-6407-476A-BB33-F0EE90383E2B}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Presentation", "Presentation", "{36839283-6407-476A-BB33-F0EE90383E2B}"
EndProject EndProject

View File

@@ -1,16 +1,16 @@
// *********************************************************************** // ***********************************************************************
// <copyright file="ModuleController.cs"> // <copyright file="ModuleController.cs">
// Heath // AgileWebs
// </copyright> // </copyright>
// *********************************************************************** // ***********************************************************************
using Asp.Versioning; using Asp.Versioning;
using Core.Cerberos.Adapters; using Core.Thalos.Adapters;
using Core.Cerberos.Adapters.Attributes; using Core.Thalos.Adapters.Attributes;
using Core.Cerberos.Adapters.Common.Constants; using Core.Thalos.Adapters.Common.Constants;
using Core.Cerberos.Adapters.Common.Enums; using Core.Thalos.Adapters.Common.Enums;
using Core.Cerberos.Domain.Contexts.Onboarding.Request; using Core.Thalos.Domain.Contexts.Onboarding.Request;
using Core.Cerberos.Provider.Contracts; using Core.Thalos.Provider.Contracts;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@@ -37,7 +37,7 @@ namespace LSA.Core.Kerberos.API.Controllers
[Consumes(MimeTypes.ApplicationJson)] [Consumes(MimeTypes.ApplicationJson)]
[Produces(MimeTypes.ApplicationJson)] [Produces(MimeTypes.ApplicationJson)]
[ProducesResponseType(typeof(IEnumerable<ModuleAdapter>), StatusCodes.Status200OK)] [ProducesResponseType(typeof(IEnumerable<ModuleAdapter>), StatusCodes.Status200OK)]
[Authorize(AuthenticationSchemes = Schemes.HeathScheme)] [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
[Permission("ModuleManagement.Read, RoleManagement.Read")] [Permission("ModuleManagement.Read, RoleManagement.Read")]
public async Task<IActionResult> GetAllModulesAsync() public async Task<IActionResult> GetAllModulesAsync()
{ {
@@ -67,7 +67,7 @@ namespace LSA.Core.Kerberos.API.Controllers
[Consumes(MimeTypes.ApplicationJson)] [Consumes(MimeTypes.ApplicationJson)]
[Produces(MimeTypes.ApplicationJson)] [Produces(MimeTypes.ApplicationJson)]
[ProducesResponseType(typeof(IEnumerable<ModuleAdapter>), StatusCodes.Status200OK)] [ProducesResponseType(typeof(IEnumerable<ModuleAdapter>), StatusCodes.Status200OK)]
[Authorize(AuthenticationSchemes = Schemes.HeathScheme)] [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
[Permission("ModuleManagement.Read")] [Permission("ModuleManagement.Read")]
public async Task<IActionResult> GetAllModulesByList([FromBody] string[] modules) public async Task<IActionResult> GetAllModulesByList([FromBody] string[] modules)
{ {
@@ -108,7 +108,7 @@ namespace LSA.Core.Kerberos.API.Controllers
[Consumes(MimeTypes.ApplicationJson)] [Consumes(MimeTypes.ApplicationJson)]
[Produces(MimeTypes.ApplicationJson)] [Produces(MimeTypes.ApplicationJson)]
[ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)]
[Authorize(AuthenticationSchemes = Schemes.HeathScheme)] [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
[Permission("ModuleManagement.Read")] [Permission("ModuleManagement.Read")]
public async Task<IActionResult> GetModuleByIdAsync([FromRoute] string id) public async Task<IActionResult> GetModuleByIdAsync([FromRoute] string id)
{ {
@@ -137,7 +137,7 @@ namespace LSA.Core.Kerberos.API.Controllers
/// <response code="500">The service internal e|ror.</response> /// <response code="500">The service internal e|ror.</response>
[HttpPost] [HttpPost]
[ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status201Created)] [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status201Created)]
[Authorize(AuthenticationSchemes = Schemes.HeathScheme)] [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
[Permission("ModuleManagement.Write")] [Permission("ModuleManagement.Write")]
public async Task<IActionResult> CreateModuleAsync([FromBody] ModuleRequest newModule) public async Task<IActionResult> CreateModuleAsync([FromBody] ModuleRequest newModule)
{ {
@@ -168,7 +168,7 @@ namespace LSA.Core.Kerberos.API.Controllers
[Consumes(MimeTypes.ApplicationJson)] [Consumes(MimeTypes.ApplicationJson)]
[Produces(MimeTypes.ApplicationJson)] [Produces(MimeTypes.ApplicationJson)]
[ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)]
[Authorize(AuthenticationSchemes = Schemes.HeathScheme)] [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
[Permission("ModuleManagement.Write")] [Permission("ModuleManagement.Write")]
public async Task<IActionResult> UpdateModuleAsync(ModuleAdapter entity, string id) public async Task<IActionResult> UpdateModuleAsync(ModuleAdapter entity, string id)
{ {
@@ -200,7 +200,7 @@ namespace LSA.Core.Kerberos.API.Controllers
[Consumes(MimeTypes.ApplicationJson)] [Consumes(MimeTypes.ApplicationJson)]
[Produces(MimeTypes.ApplicationJson)] [Produces(MimeTypes.ApplicationJson)]
[ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)]
[Authorize(AuthenticationSchemes = Schemes.HeathScheme)] [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
[Permission("ModuleManagement.Write")] [Permission("ModuleManagement.Write")]
public async Task<IActionResult> ChangeModuleStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus) public async Task<IActionResult> ChangeModuleStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus)
{ {

View File

@@ -1,16 +1,16 @@
// *********************************************************************** // ***********************************************************************
// <copyright file="PermissionController.cs"> // <copyright file="PermissionController.cs">
// Heath // AgileWebs
// </copyright> // </copyright>
// *********************************************************************** // ***********************************************************************
using Asp.Versioning; using Asp.Versioning;
using Core.Cerberos.Adapters; using Core.Thalos.Adapters;
using Core.Cerberos.Adapters.Attributes; using Core.Thalos.Adapters.Attributes;
using Core.Cerberos.Adapters.Common.Constants; using Core.Thalos.Adapters.Common.Constants;
using Core.Cerberos.Adapters.Common.Enums; using Core.Thalos.Adapters.Common.Enums;
using Core.Cerberos.Domain.Contexts.Onboarding.Request; using Core.Thalos.Domain.Contexts.Onboarding.Request;
using Core.Cerberos.Provider.Contracts; using Core.Thalos.Provider.Contracts;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@@ -37,7 +37,7 @@ namespace LSA.Core.Kerberos.API.Controllers
[Consumes(MimeTypes.ApplicationJson)] [Consumes(MimeTypes.ApplicationJson)]
[Produces(MimeTypes.ApplicationJson)] [Produces(MimeTypes.ApplicationJson)]
[ProducesResponseType(typeof(IEnumerable<PermissionAdapter>), StatusCodes.Status200OK)] [ProducesResponseType(typeof(IEnumerable<PermissionAdapter>), StatusCodes.Status200OK)]
[Authorize(AuthenticationSchemes = Schemes.HeathScheme)] [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
[Permission("PermissionManagement.Read, RoleManagement.Read")] [Permission("PermissionManagement.Read, RoleManagement.Read")]
public async Task<IActionResult> GetAllPermissionsAsync() public async Task<IActionResult> GetAllPermissionsAsync()
{ {
@@ -67,7 +67,7 @@ namespace LSA.Core.Kerberos.API.Controllers
[Consumes(MimeTypes.ApplicationJson)] [Consumes(MimeTypes.ApplicationJson)]
[Produces(MimeTypes.ApplicationJson)] [Produces(MimeTypes.ApplicationJson)]
[ProducesResponseType(typeof(IEnumerable<PermissionAdapter>), StatusCodes.Status200OK)] [ProducesResponseType(typeof(IEnumerable<PermissionAdapter>), StatusCodes.Status200OK)]
[Authorize(AuthenticationSchemes = Schemes.HeathScheme)] [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
[Permission("PermissionManagement.Read")] [Permission("PermissionManagement.Read")]
public async Task<IActionResult> GetAllPermissionsByList([FromBody] string[] permissions) public async Task<IActionResult> GetAllPermissionsByList([FromBody] string[] permissions)
{ {
@@ -107,7 +107,7 @@ namespace LSA.Core.Kerberos.API.Controllers
[Consumes(MimeTypes.ApplicationJson)] [Consumes(MimeTypes.ApplicationJson)]
[Produces(MimeTypes.ApplicationJson)] [Produces(MimeTypes.ApplicationJson)]
[ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)] [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)]
[Authorize(AuthenticationSchemes = Schemes.HeathScheme)] [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
[Permission("PermissionManagement.Read")] [Permission("PermissionManagement.Read")]
public async Task<IActionResult> GetPermissionByIdAsync([FromRoute] string id) public async Task<IActionResult> GetPermissionByIdAsync([FromRoute] string id)
{ {
@@ -136,7 +136,7 @@ namespace LSA.Core.Kerberos.API.Controllers
/// <response code="500">The service internal e|ror.</response> /// <response code="500">The service internal e|ror.</response>
[HttpPost] [HttpPost]
[ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status201Created)] [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status201Created)]
[Authorize(AuthenticationSchemes = Schemes.HeathScheme)] [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
[Permission("PermissionManagement.Write")] [Permission("PermissionManagement.Write")]
public async Task<IActionResult> CreatePermissionAsync([FromBody] PermissionRequest newPermission) public async Task<IActionResult> CreatePermissionAsync([FromBody] PermissionRequest newPermission)
{ {
@@ -167,7 +167,7 @@ namespace LSA.Core.Kerberos.API.Controllers
[Consumes(MimeTypes.ApplicationJson)] [Consumes(MimeTypes.ApplicationJson)]
[Produces(MimeTypes.ApplicationJson)] [Produces(MimeTypes.ApplicationJson)]
[ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)] [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)]
[Authorize(AuthenticationSchemes = Schemes.HeathScheme)] [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
[Permission("PermissionManagement.Write")] [Permission("PermissionManagement.Write")]
public async Task<IActionResult> UpdatePermissionAsync(PermissionAdapter entity, string id) public async Task<IActionResult> UpdatePermissionAsync(PermissionAdapter entity, string id)
{ {
@@ -199,7 +199,7 @@ namespace LSA.Core.Kerberos.API.Controllers
[Consumes(MimeTypes.ApplicationJson)] [Consumes(MimeTypes.ApplicationJson)]
[Produces(MimeTypes.ApplicationJson)] [Produces(MimeTypes.ApplicationJson)]
[ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)] [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)]
[Authorize(AuthenticationSchemes = Schemes.HeathScheme)] [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
[Permission("PermissionManagement.Write")] [Permission("PermissionManagement.Write")]
public async Task<IActionResult> ChangePermissionStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus) public async Task<IActionResult> ChangePermissionStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus)
{ {

View File

@@ -1,15 +1,15 @@
// *********************************************************************** // ***********************************************************************
// <copyright file="RoleController.cs"> // <copyright file="RoleController.cs">
// Heath // AgileWebs
// </copyright> // </copyright>
// *********************************************************************** // ***********************************************************************
using Asp.Versioning; using Asp.Versioning;
using Core.Cerberos.Adapters; using Core.Thalos.Adapters;
using Core.Cerberos.Adapters.Attributes; using Core.Thalos.Adapters.Attributes;
using Core.Cerberos.Adapters.Common.Constants; using Core.Thalos.Adapters.Common.Constants;
using Core.Cerberos.Adapters.Common.Enums; using Core.Thalos.Adapters.Common.Enums;
using Core.Cerberos.Domain.Contexts.Onboarding.Request; using Core.Thalos.Domain.Contexts.Onboarding.Request;
using Core.Cerberos.Provider.Contracts; using Core.Thalos.Provider.Contracts;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@@ -34,7 +34,7 @@ namespace LSA.Core.Kerberos.API.Controllers
/// <response code="500">The service internal error.</response> /// <response code="500">The service internal error.</response>
[HttpGet] [HttpGet]
[ProducesResponseType(typeof(IEnumerable<RoleAdapter>), StatusCodes.Status200OK)] [ProducesResponseType(typeof(IEnumerable<RoleAdapter>), StatusCodes.Status200OK)]
[Authorize(AuthenticationSchemes = Schemes.HeathScheme)] [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
[Permission("RoleManagement.Read")] [Permission("RoleManagement.Read")]
public async Task<IActionResult> GetAllRolesAsync() public async Task<IActionResult> GetAllRolesAsync()
{ {
@@ -62,7 +62,7 @@ namespace LSA.Core.Kerberos.API.Controllers
[HttpGet] [HttpGet]
[Route(Routes.Id)] [Route(Routes.Id)]
[ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)]
[Authorize(AuthenticationSchemes = Schemes.HeathScheme)] [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
[Permission("RoleManagement.Read")] [Permission("RoleManagement.Read")]
public async Task<IActionResult> GetRoleByIdAsync([FromRoute] string id) public async Task<IActionResult> GetRoleByIdAsync([FromRoute] string id)
{ {
@@ -91,7 +91,7 @@ namespace LSA.Core.Kerberos.API.Controllers
/// <response code="500">The service internal error.</response> /// <response code="500">The service internal error.</response>
[HttpPost] [HttpPost]
[ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status201Created)] [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status201Created)]
[Authorize(AuthenticationSchemes = Schemes.HeathScheme)] [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
[Permission("RoleManagement.Write")] [Permission("RoleManagement.Write")]
public async Task<IActionResult> CreateRoleAsync([FromBody] RoleRequest newRole) public async Task<IActionResult> CreateRoleAsync([FromBody] RoleRequest newRole)
{ {
@@ -121,7 +121,7 @@ namespace LSA.Core.Kerberos.API.Controllers
[HttpPut] [HttpPut]
[Route(Routes.Id)] [Route(Routes.Id)]
[ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)]
[Authorize(AuthenticationSchemes = Schemes.HeathScheme)] [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
[Permission("RoleManagement.Write")] [Permission("RoleManagement.Write")]
public async Task<IActionResult> UpdateRoleAsync([FromBody] RoleAdapter entity, [FromRoute] string id) public async Task<IActionResult> UpdateRoleAsync([FromBody] RoleAdapter entity, [FromRoute] string id)
{ {
@@ -151,7 +151,7 @@ namespace LSA.Core.Kerberos.API.Controllers
[HttpPatch] [HttpPatch]
[Route(Routes.ChangeStatus)] [Route(Routes.ChangeStatus)]
[ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)]
[Authorize(AuthenticationSchemes = Schemes.HeathScheme)] [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
[Permission("RoleManagement.Write")] [Permission("RoleManagement.Write")]
public async Task<IActionResult> ChangeRoleStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus) public async Task<IActionResult> ChangeRoleStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus)
{ {
@@ -181,7 +181,7 @@ namespace LSA.Core.Kerberos.API.Controllers
/// <response code="500">The service internal error.</response> /// <response code="500">The service internal error.</response>
[HttpPost(Routes.AddApplication)] [HttpPost(Routes.AddApplication)]
[ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)]
[Authorize(AuthenticationSchemes = Schemes.HeathScheme)] [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
[Permission("RoleManagement.Write")] [Permission("RoleManagement.Write")]
public async Task<IActionResult> AddApplicationToRoleAsync([FromRoute] string roleId, public async Task<IActionResult> AddApplicationToRoleAsync([FromRoute] string roleId,
[FromRoute] ApplicationsEnum application) [FromRoute] ApplicationsEnum application)
@@ -211,7 +211,7 @@ namespace LSA.Core.Kerberos.API.Controllers
/// <response code="500">The service internal error.</response> /// <response code="500">The service internal error.</response>
[HttpDelete(Routes.RemoveApplication)] [HttpDelete(Routes.RemoveApplication)]
[ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)]
[Authorize(AuthenticationSchemes = Schemes.HeathScheme)] [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
[Permission("RoleManagement.Write")] [Permission("RoleManagement.Write")]
public async Task<IActionResult> RemoveApplicationFromRoleAsync([FromRoute] string roleId, public async Task<IActionResult> RemoveApplicationFromRoleAsync([FromRoute] string roleId,
[FromRoute] ApplicationsEnum application) [FromRoute] ApplicationsEnum application)

View File

@@ -1,19 +1,18 @@
// *********************************************************************** // ***********************************************************************
// <copyright file="UserController.cs"> // <copyright file="UserController.cs">
// Heath // AgileWebs
// </copyright> // </copyright>
// *********************************************************************** // ***********************************************************************
using Asp.Versioning; using Asp.Versioning;
using Core.Blueprint.Storage.Adapters; using Core.Blueprint.Mongo;
using Core.Cerberos.Adapters; using Core.Thalos.Adapters;
using Core.Cerberos.Adapters.Attributes; using Core.Thalos.Adapters.Attributes;
using Core.Cerberos.Adapters.Common.Constants; using Core.Thalos.Adapters.Common.Constants;
using Core.Cerberos.Adapters.Common.Enums; using Core.Thalos.Provider.Contracts;
using Core.Cerberos.Provider.Contracts;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Graph; using Microsoft.Graph;
using UserRequest = Core.Cerberos.Domain.Contexts.Onboarding.Request.UserRequest; using UserRequest = Core.Thalos.Domain.Contexts.Onboarding.Request.UserRequest;
namespace LSA.Core.Kerberos.API.Controllers namespace LSA.Core.Kerberos.API.Controllers
{ {
@@ -25,7 +24,7 @@ namespace LSA.Core.Kerberos.API.Controllers
[Produces(MimeTypes.ApplicationJson)] [Produces(MimeTypes.ApplicationJson)]
[Consumes(MimeTypes.ApplicationJson)] [Consumes(MimeTypes.ApplicationJson)]
[ApiController] [ApiController]
public class UserController(IUserService service, ILogger<UserController> logger) : ControllerBase public class UserController(IUserProvider service) : ControllerBase
{ {
/// <summary> /// <summary>
/// Gets all the users. /// Gets all the users.
@@ -36,22 +35,13 @@ namespace LSA.Core.Kerberos.API.Controllers
/// <response code="500">The service internal error.</response> /// <response code="500">The service internal error.</response>
[HttpGet] [HttpGet]
[ProducesResponseType(typeof(IEnumerable<UserAdapter>), StatusCodes.Status200OK)] [ProducesResponseType(typeof(IEnumerable<UserAdapter>), StatusCodes.Status200OK)]
[Authorize(AuthenticationSchemes = Schemes.HeathScheme)] [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
[Permission("UserManagement.Read")] [Permission("UserManagement.Read")]
public async Task<IActionResult> GetAllUsersService() public async Task<IActionResult> GetAllUsers(CancellationToken cancellationToken)
{ {
try var result = await service.GetAllUsers(cancellationToken).ConfigureAwait(false);
{
var result = await service.GetAllUsersService();
return Ok(result); return Ok(result);
} }
catch (Exception ex)
{
logger.LogError(ex, "Error in GetAllUsersService");
return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}");
}
}
/// <summary> /// <summary>
/// Gets the user by identifier. /// Gets the user by identifier.
@@ -64,24 +54,19 @@ namespace LSA.Core.Kerberos.API.Controllers
[HttpGet] [HttpGet]
[Route(Routes.Id)] [Route(Routes.Id)]
[ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)]
[Authorize(AuthenticationSchemes = Schemes.HeathScheme)] [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
[Permission("UserManagement.Read")] [Permission("UserManagement.Read")]
public async Task<IActionResult> GetUserByIdService([FromRoute] string id) public async Task<IActionResult> GetUserById([FromRoute] string _id, CancellationToken cancellationToken)
{ {
try var result = await service.GetUserById(_id, cancellationToken).ConfigureAwait(false);
{
var result = await service.GetUserByIdService(id);
if (result is null) return NotFound($"user with id: '{id}' not found"); if (result == null)
{
return NotFound("Entity not found");
}
return Ok(result); return Ok(result);
} }
catch (Exception ex)
{
logger.LogError(ex, "Error in GetUserByIdService");
return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}");
}
}
/// <summary> /// <summary>
/// Gets the user by email. /// Gets the user by email.
@@ -94,23 +79,18 @@ namespace LSA.Core.Kerberos.API.Controllers
[HttpGet] [HttpGet]
[Route(Routes.Email)] [Route(Routes.Email)]
[ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)]
[Authorize(AuthenticationSchemes = $"{Schemes.HeathScheme}, {Schemes.AzureScheme}")] [Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.AzureScheme}")]
public async Task<IActionResult> GetUserByEmail([FromRoute] string email) public async Task<IActionResult> GetUserByEmail([FromRoute] string email, CancellationToken cancellationToken)
{ {
try var result = await service.GetUserByEmail(email, cancellationToken).ConfigureAwait(false);
{
var result = await service.GetUserByEmailService(email);
if (result is null) return NotFound($"user with email: '{email}' not found"); if (result == null)
{
return NotFound("User not found");
}
return Ok(result); return Ok(result);
} }
catch (Exception ex)
{
logger.LogError(ex, "Error in GetUserByIdEmail");
return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}");
}
}
/// <summary> /// <summary>
/// Validates if a user exists on the database. /// Validates if a user exists on the database.
@@ -124,24 +104,16 @@ namespace LSA.Core.Kerberos.API.Controllers
[Route("{email}/ValidateExistence")] [Route("{email}/ValidateExistence")]
[ProducesResponseType(typeof(UserExistenceAdapter), StatusCodes.Status200OK)] [ProducesResponseType(typeof(UserExistenceAdapter), StatusCodes.Status200OK)]
[AllowAnonymous] [AllowAnonymous]
public async Task<IActionResult> ValidateUserExistence([FromRoute] string email) public async Task<IActionResult> ValidateUserExistence([FromRoute] string email, CancellationToken cancellationToken)
{ {
try var result = await service.ValidateUserExistence(email, cancellationToken).ConfigureAwait(false);
{
var result = await service.ValidateUserExistenceService(email);
var existence = new UserExistenceAdapter if (result == null)
{ {
Existence = (result is not null) ? true : false return NotFound("User not found");
}; }
return Ok(existence); return Ok(result);
}
catch (Exception ex)
{
logger.LogError(ex, "Error in ValidateUserExistance");
return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}");
}
} }
/// <summary> /// <summary>
@@ -155,26 +127,12 @@ namespace LSA.Core.Kerberos.API.Controllers
/// <response code="500">The service internal error.</response> /// <response code="500">The service internal error.</response>
[HttpPost(Routes.Register)] [HttpPost(Routes.Register)]
[ProducesResponseType(typeof(UserAdapter), StatusCodes.Status201Created)] [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status201Created)]
[Authorize(AuthenticationSchemes = Schemes.HeathScheme)] [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
[Permission("UserManagement.Write")] [Permission("UserManagement.Write")]
public async Task<IActionResult> CreateUserAsync([FromBody] UserRequest newUser, [FromRoute] bool sendInvitation) public async Task<IActionResult> CreateUserAsync([FromBody] UserRequest newUser, CancellationToken cancellationToken)
{ {
try var result = await service.CreateUser(newUser, cancellationToken).ConfigureAwait(false);
{ return Created("CreatedWithIdAsync", result);
var user = await service.GetUserByEmailService(newUser.Email).ConfigureAwait(false);
if (user is not null)
return UnprocessableEntity("There is a user with the same email registered in the database");
var result = await service.CreateUserService(newUser).ConfigureAwait(false);
return Created("CreatedWithIdService", result);
}
catch (Exception ex)
{
logger.LogError(ex, "Error in CreateUserAsync");
return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}");
}
} }
/// <summary> /// <summary>
@@ -190,22 +148,19 @@ namespace LSA.Core.Kerberos.API.Controllers
[HttpPut] [HttpPut]
[Route(Routes.Id)] [Route(Routes.Id)]
[ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)]
[Authorize(AuthenticationSchemes = Schemes.HeathScheme)] [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
[Permission("UserManagement.Write")] [Permission("UserManagement.Write")]
public async Task<IActionResult> UpdateUserAsync([FromBody] UserAdapter entity, [FromRoute] string id) public async Task<IActionResult> UpdateUserAsync([FromRoute] string _id, [FromBody] UserAdapter entity, CancellationToken cancellationToken)
{ {
try if (_id != entity._Id?.ToString())
{ {
var result = await service.UpdateUserService(entity, id); return BadRequest("User ID mismatch");
}
var result = await service.UpdateUser(entity, cancellationToken).ConfigureAwait(false);
return Ok(result); return Ok(result);
} }
catch (Exception ex)
{
logger.LogError(ex, "Error in UpdateUserAsync");
return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}");
}
}
/// <summary> /// <summary>
/// Logs in the user. /// Logs in the user.
@@ -218,24 +173,16 @@ namespace LSA.Core.Kerberos.API.Controllers
/// <response code="500">The service internal error.</response> /// <response code="500">The service internal error.</response>
[HttpPatch(Routes.LogIn)] [HttpPatch(Routes.LogIn)]
[ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)]
[Authorize(AuthenticationSchemes = $"{Schemes.HeathScheme}, {Schemes.AzureScheme}")] [Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.AzureScheme}")]
public async Task<IActionResult> LoginUserAsync([FromRoute] string email) public async Task<IActionResult> LoginUserAsync([FromRoute] string email, CancellationToken cancellationToken)
{ {
try var result = await service.LogInUser(email, cancellationToken).ConfigureAwait(false);
{
var result = await service.LogInUserService(email).ConfigureAwait(false);
if (result is null) if (result is null)
return new NotFoundObjectResult($"The user with email: '{email}' was not found"); return new NotFoundObjectResult($"The user with email: '{email}' was not found");
return Ok(result); return Ok(result);
} }
catch (Exception ex)
{
logger.LogError(ex, "Error in LogInUserService");
return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}");
}
}
/// <summary> /// <summary>
/// Logs out the user. /// Logs out the user.
@@ -247,20 +194,12 @@ namespace LSA.Core.Kerberos.API.Controllers
/// <response code="500">The service internal error.</response> /// <response code="500">The service internal error.</response>
[HttpPatch(Routes.LogOut)] [HttpPatch(Routes.LogOut)]
[ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)]
[Authorize(AuthenticationSchemes = $"{Schemes.HeathScheme}, {Schemes.AzureScheme}")] [Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.AzureScheme}")]
public async Task<IActionResult> LogOutUserSessionAsync([FromRoute] string email) public async Task<IActionResult> LogOutUserSessionAsync([FromRoute] string email, CancellationToken cancellationToken)
{ {
try var result = await service.LogOutUserSession(email, cancellationToken).ConfigureAwait(false);
{
var result = await service.LogOutUserSessionService(email).ConfigureAwait(false);
return Ok(result); return Ok(result);
}
catch (Exception ex)
{
logger.LogError(ex, "Error in LogOutUserSessionService");
return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}");
}
} }
@@ -277,22 +216,13 @@ namespace LSA.Core.Kerberos.API.Controllers
[HttpPatch] [HttpPatch]
[Route(Routes.ChangeStatus)] [Route(Routes.ChangeStatus)]
[ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)]
[Authorize(AuthenticationSchemes = Schemes.HeathScheme)] [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
[Permission("UserManagement.Write")] [Permission("UserManagement.Write")]
public async Task<IActionResult> ChangeUserStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus) public async Task<IActionResult> ChangeUserStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken)
{ {
try var result = await service.ChangeUserStatus(id, newStatus, cancellationToken).ConfigureAwait(false);
{
var result = await service.ChangeUserStatusService(id, newStatus);
return Ok(result); return Ok(result);
} }
catch (Exception ex)
{
logger.LogError(ex, "Error in ChangeUserStatus");
return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}");
}
}
/// <summary> /// <summary>
/// Adds a company to the user's list of companies. /// Adds a company to the user's list of companies.
@@ -306,22 +236,13 @@ namespace LSA.Core.Kerberos.API.Controllers
[HttpPost] [HttpPost]
[Route(Routes.AddCompany)] [Route(Routes.AddCompany)]
[ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)]
[Authorize(AuthenticationSchemes = Schemes.HeathScheme)] [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
[Permission("UserManagement.Write")] [Permission("UserManagement.Write")]
public async Task<IActionResult> AddCompanyToUserAsync([FromRoute] string userId, [FromRoute] string companyId) public async Task<IActionResult> AddCompanyToUserAsync([FromRoute] string userId, [FromRoute] string companyId, CancellationToken cancellationToken)
{ {
try var result = await service.AddCompanyToUser(userId, companyId, cancellationToken).ConfigureAwait(false);
{
var result = await service.AddCompanyToUserService(userId, companyId);
return Ok(result); return Ok(result);
} }
catch (Exception ex)
{
logger.LogError(ex, "Error in AddCompanyToUserAsync");
return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}");
}
}
/// <summary> /// <summary>
/// Removes a company from the user's list of companies. /// Removes a company from the user's list of companies.
@@ -335,22 +256,13 @@ namespace LSA.Core.Kerberos.API.Controllers
[HttpDelete] [HttpDelete]
[Route(Routes.RemoveCompany)] [Route(Routes.RemoveCompany)]
[ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)]
[Authorize(AuthenticationSchemes = Schemes.HeathScheme)] [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
[Permission("UserManagement.Write")] [Permission("UserManagement.Write")]
public async Task<IActionResult> RemoveCompanyFromUserAsync([FromRoute] string userId, [FromRoute] string companyId) public async Task<IActionResult> RemoveCompanyFromUserAsync([FromRoute] string userId, [FromRoute] string companyId, CancellationToken cancellationToken)
{ {
try var result = await service.RemoveCompanyFromUser(userId, companyId, cancellationToken).ConfigureAwait(false); ;
{
var result = await service.RemoveCompanyFromUserService(userId, companyId);
return Ok(result); return Ok(result);
} }
catch (Exception ex)
{
logger.LogError(ex, "Error in RemoveCompanyFromUserAsync");
return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}");
}
}
/// <summary> /// <summary>
/// Adds a project to the user's list of projects. /// Adds a project to the user's list of projects.
@@ -364,22 +276,13 @@ namespace LSA.Core.Kerberos.API.Controllers
[HttpPost] [HttpPost]
[Route(Routes.AddProject)] [Route(Routes.AddProject)]
[ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)]
[Authorize(AuthenticationSchemes = Schemes.HeathScheme)] [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
[Permission("UserManagement.Write")] [Permission("UserManagement.Write")]
public async Task<IActionResult> AddProjectToUserAsync([FromRoute] string userId, [FromRoute] string projectId) public async Task<IActionResult> AddProjectToUserAsync([FromRoute] string userId, [FromRoute] string projectId, CancellationToken cancellationToken)
{ {
try var result = await service.AddProjectToUser(userId, projectId, cancellationToken).ConfigureAwait(false);
{
var result = await service.AddProjectToUserService(userId, projectId);
return Ok(result); return Ok(result);
} }
catch (Exception ex)
{
logger.LogError(ex, "Error in AddProjectToUserAsync");
return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}");
}
}
/// <summary> /// <summary>
/// Removes a project from the user's list of projects. /// Removes a project from the user's list of projects.
@@ -393,22 +296,13 @@ namespace LSA.Core.Kerberos.API.Controllers
[HttpDelete] [HttpDelete]
[Route(Routes.RemoveProject)] [Route(Routes.RemoveProject)]
[ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)]
[Authorize(AuthenticationSchemes = Schemes.HeathScheme)] [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
[Permission("UserManagement.Write")] [Permission("UserManagement.Write")]
public async Task<IActionResult> RemoveProjectFromUserAsync([FromRoute] string userId, [FromRoute] string projectId) public async Task<IActionResult> RemoveProjectFromUserAsync([FromRoute] string userId, [FromRoute] string projectId, CancellationToken cancellationToken)
{ {
try var result = await service.RemoveCompanyFromUser(userId, projectId, cancellationToken).ConfigureAwait(false);
{
var result = await service.RemoveProjectFromUserService(userId, projectId);
return Ok(result); return Ok(result);
} }
catch (Exception ex)
{
logger.LogError(ex, "Error in RemoveProjectFromUserAsync");
return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}");
}
}
/// <summary> /// <summary>
/// Gets a token for the user, including roles, permissions, and modules. /// Gets a token for the user, including roles, permissions, and modules.
@@ -421,75 +315,14 @@ namespace LSA.Core.Kerberos.API.Controllers
[HttpGet] [HttpGet]
[Route("{email}/GetTokenAdapter")] [Route("{email}/GetTokenAdapter")]
[ProducesResponseType(typeof(TokenAdapter), StatusCodes.Status200OK)] [ProducesResponseType(typeof(TokenAdapter), StatusCodes.Status200OK)]
[Authorize(AuthenticationSchemes = $"{Schemes.HeathScheme}, {Schemes.AzureScheme}")] [Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.AzureScheme}")]
public async Task<IActionResult> GetTokenAdapter([FromRoute] string email) public async Task<IActionResult> GetTokenAdapter([FromRoute] string email, CancellationToken cancellationToken)
{ {
try var tokenAdapter = await service.GetToken(email, cancellationToken).ConfigureAwait(false);
{
var tokenAdapter = await service.GetTokenAdapter(email);
if (tokenAdapter == null) return NotFound($"User with email: {email} not found"); if (tokenAdapter == null) return NotFound($"User with email: {email} not found");
return Ok(tokenAdapter); return Ok(tokenAdapter);
} }
catch (Exception ex)
{
logger.LogError(ex, "Error in GetTokenAdapter");
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}");
}
}
} }
} }

View File

@@ -0,0 +1,6 @@
@Core.Thalos.DAL.API_HostAddress = http://localhost:5211
GET {{Core.Thalos.DAL.API_HostAddress}}/weatherforecast/
Accept: application/json
###

View File

@@ -15,12 +15,12 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="8.0.0" /> <PackageReference Include="Blueprint.Logging" Version="0.0.1" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Core.Cerberos.Domain\Core.Cerberos.Domain.csproj" /> <ProjectReference Include="..\Core.Thalos.Domain\Core.Thalos.Domain.csproj" />
<ProjectReference Include="..\Core.Cerberos.Provider\Core.Cerberos.Provider.csproj" /> <ProjectReference Include="..\Core.Thalos.Provider\Core.Thalos.Provider.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -1,6 +1,7 @@
using Core.Cerberos.Adapters.Extensions; using Core.Blueprint.Logging.Configuration;
using Core.Cerberos.Adapters.Helpers; using Core.Thalos.Adapters.Extensions;
using Core.Cerberos.Provider; using Core.Thalos.Adapters.Helpers;
using Core.Thalos.Provider;
using Microsoft.AspNetCore.RateLimiting; using Microsoft.AspNetCore.RateLimiting;
using Microsoft.AspNetCore.ResponseCompression; using Microsoft.AspNetCore.ResponseCompression;
using System.IO.Compression; using System.IO.Compression;
@@ -9,7 +10,7 @@ using System.Threading.RateLimiting;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
var authSettings = AuthHelper.GetAuthSettings(builder, "cerberos_dal"); var authSettings = AuthHelper.GetAuthSettings(builder, "thalos_dal");
builder.Services.ConfigureAuthentication(builder.Configuration, authSettings); builder.Services.ConfigureAuthentication(builder.Configuration, authSettings);
@@ -21,6 +22,8 @@ builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer(); builder.Services.AddEndpointsApiExplorer();
builder.Services.AddLogs(builder);
builder.Services.AddCors(options => builder.Services.AddCors(options =>
{ {
options.AddPolicy("AllowAll", policyBuilder => options.AddPolicy("AllowAll", policyBuilder =>
@@ -67,7 +70,7 @@ builder.Services.AddRateLimiter(_ => _
builder.Services.AddResponseCaching(); builder.Services.AddResponseCaching();
builder.Services.AddControllers(); builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer(); builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwagger(builder.Configuration, "Core.Cerberos.DAL.API.xml", authSettings); builder.Services.AddSwagger(builder.Configuration, "Core.Thalos.DAL.API.xml", authSettings);
builder.Services.AddVersioning(builder.Configuration); builder.Services.AddVersioning(builder.Configuration);
builder.Services.AddLogging(); builder.Services.AddLogging();
builder.Services.AddProblemDetails(); builder.Services.AddProblemDetails();
@@ -79,6 +82,7 @@ var app = builder.Build();
app.UseSwaggerUI(builder.Configuration, authSettings); app.UseSwaggerUI(builder.Configuration, authSettings);
app.ConfigureSwagger(builder.Configuration); app.ConfigureSwagger(builder.Configuration);
app.UseLogging(builder.Configuration);
app.UseHttpsRedirection(); app.UseHttpsRedirection();
app.UseAuthorization(); app.UseAuthorization();
app.MapControllers(); app.MapControllers();

View File

@@ -5,7 +5,7 @@
"KeyVault": "" //KeyVault Uri "KeyVault": "" //KeyVault Uri
}, },
"MongoDb": { "MongoDb": {
"DatabaseName": "Cerberos" "DatabaseName": "Thalos"
}, },
"CacheSettings": { "CacheSettings": {
"DefaultCacheDurationInMinutes": 3 // Default cache duration set to 3 minutes "DefaultCacheDurationInMinutes": 3 // Default cache duration set to 3 minutes
@@ -22,7 +22,7 @@
"CallbackPath": "", // Path for redirect after authentication "CallbackPath": "", // Path for redirect after authentication
"Scopes": "" // Access scopes for user permissions "Scopes": "" // Access scopes for user permissions
}, },
"HeathCerberosApp": { "ThalosApp": {
"AuthorizationUrl": "", // URL for authorization endpoint (STORED IN KEY VAULT) "AuthorizationUrl": "", // URL for authorization endpoint (STORED IN KEY VAULT)
"TokenUrl": "", // URL for token endpoint (STORED IN KEY VAULT) "TokenUrl": "", // URL for token endpoint (STORED IN KEY VAULT)
"Scope": "", // Scope for application permissions (STORED IN KEY VAULT) "Scope": "", // Scope for application permissions (STORED IN KEY VAULT)

View File

@@ -1,14 +1,14 @@
// *********************************************************************** // ***********************************************************************
// <copyright file="ModuleMapper.cs"> // <copyright file="ModuleMapper.cs">
// HEATH // AgileWebs
// </copyright> // </copyright>
// *********************************************************************** // ***********************************************************************
using Core.Cerberos.Adapters; using Core.Thalos.Adapters;
using Core.Cerberos.Domain.Contexts.Onboarding.Request; using Core.Thalos.Domain.Contexts.Onboarding.Request;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using MongoDB.Bson; using MongoDB.Bson;
using System.Security.Claims; using System.Security.Claims;
namespace Core.Cerberos.Domain.Contexts.Onboarding.Mappers namespace Core.Thalos.Domain.Contexts.Onboarding.Mappers
{ {
/// <summary> /// <summary>
/// Handles mappings between /// Handles mappings between

View File

@@ -1,14 +1,14 @@
// *********************************************************************** // ***********************************************************************
// <copyright file="PermissionMapper.cs"> // <copyright file="PermissionMapper.cs">
// HEATH // AgileWebs
// </copyright> // </copyright>
// *********************************************************************** // ***********************************************************************
using Core.Cerberos.Adapters; using Core.Thalos.Adapters;
using Core.Cerberos.Domain.Contexts.Onboarding.Request; using Core.Thalos.Domain.Contexts.Onboarding.Request;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using MongoDB.Bson; using MongoDB.Bson;
using System.Security.Claims; using System.Security.Claims;
namespace Core.Cerberos.Domain.Contexts.Onboarding.Mappers namespace Core.Thalos.Domain.Contexts.Onboarding.Mappers
{ {
/// <summary> /// <summary>
/// Handles mappings between /// Handles mappings between

View File

@@ -1,15 +1,15 @@
// *********************************************************************** // ***********************************************************************
// <copyright file="RoleMapper.cs"> // <copyright file="RoleMapper.cs">
// HEATH // AgileWebs
// </copyright> // </copyright>
// *********************************************************************** // ***********************************************************************
using Core.Cerberos.Adapters; using Core.Thalos.Adapters;
using Core.Cerberos.Domain.Contexts.Onboarding.Request; using Core.Thalos.Domain.Contexts.Onboarding.Request;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using MongoDB.Bson; using MongoDB.Bson;
using System.Security.Claims; using System.Security.Claims;
namespace Core.Cerberos.Domain.Contexts.Onboarding.Mappers namespace Core.Thalos.Domain.Contexts.Onboarding.Mappers
{ {
/// <summary> /// <summary>
/// Handles mappings between /// Handles mappings between

View File

@@ -1,15 +1,15 @@
// *********************************************************************** // ***********************************************************************
// <copyright file="UserMapper.cs"> // <copyright file="UserMapper.cs">
// HEATH // AgileWebs
// </copyright> // </copyright>
// *********************************************************************** // ***********************************************************************
using Core.Cerberos.Adapters; using Core.Thalos.Adapters;
using Core.Cerberos.Domain.Contexts.Onboarding.Request; using Core.Thalos.Domain.Contexts.Onboarding.Request;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using MongoDB.Bson; using MongoDB.Bson;
using System.Security.Claims; using System.Security.Claims;
namespace Core.Cerberos.Domain.Contexts.Onboarding.Mappers namespace Core.Thalos.Domain.Contexts.Onboarding.Mappers
{ {
/// <summary> /// <summary>
/// Handles mappings between /// Handles mappings between

View File

@@ -1,15 +1,15 @@
// *********************************************************************** // ***********************************************************************
// <copyright file="ModuleRequest.cs"> // <copyright file="ModuleRequest.cs">
// Heath // AgileWebs
// </copyright> // </copyright>
// *********************************************************************** // ***********************************************************************
using Core.Cerberos.Adapters.Common.Enums; using Core.Thalos.Adapters.Common.Enums;
using MongoDB.Bson; using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes; using MongoDB.Bson.Serialization.Attributes;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
namespace Core.Cerberos.Domain.Contexts.Onboarding.Request namespace Core.Thalos.Domain.Contexts.Onboarding.Request
{ {
/// <summary> /// <summary>
/// Data transfer object (DTO) for adding modules. /// Data transfer object (DTO) for adding modules.

View File

@@ -1,15 +1,15 @@
// *********************************************************************** // ***********************************************************************
// <copyright file="PermissionRequest.cs"> // <copyright file="PermissionRequest.cs">
// Heath // AgileWebs
// </copyright> // </copyright>
// *********************************************************************** // ***********************************************************************
using Core.Cerberos.Adapters.Common.Constants; using Core.Thalos.Adapters.Common.Constants;
using MongoDB.Bson; using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes; using MongoDB.Bson.Serialization.Attributes;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
namespace Core.Cerberos.Domain.Contexts.Onboarding.Request namespace Core.Thalos.Domain.Contexts.Onboarding.Request
{ {
/// <summary> /// <summary>
/// Data transfer object (DTO) for adding permissions. /// Data transfer object (DTO) for adding permissions.

View File

@@ -1,15 +1,15 @@
// *********************************************************************** // ***********************************************************************
// <copyright file="RoleRequest.cs"> // <copyright file="RoleRequest.cs">
// Heath // AgileWebs
// </copyright> // </copyright>
// *********************************************************************** // ***********************************************************************
using Core.Cerberos.Adapters.Common.Enums; using Core.Thalos.Adapters.Common.Enums;
using MongoDB.Bson; using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes; using MongoDB.Bson.Serialization.Attributes;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
namespace Core.Cerberos.Domain.Contexts.Onboarding.Request namespace Core.Thalos.Domain.Contexts.Onboarding.Request
{ {
/// <summary> /// <summary>
/// Data transfer object (DTO) for adding a role. /// Data transfer object (DTO) for adding a role.

View File

@@ -1,6 +1,6 @@
// *********************************************************************** // ***********************************************************************
// <copyright file="UserAddDto.cs"> // <copyright file="UserAddDto.cs">
// Heath // AgileWebs
// </copyright> // </copyright>
// *********************************************************************** // ***********************************************************************
@@ -8,7 +8,7 @@ using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes; using MongoDB.Bson.Serialization.Attributes;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
namespace Core.Cerberos.Domain.Contexts.Onboarding.Request namespace Core.Thalos.Domain.Contexts.Onboarding.Request
{ {
/// <summary> /// <summary>
/// Data transfer object (DTO) for adding a user. /// Data transfer object (DTO) for adding a user.

View File

@@ -7,7 +7,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Core.Cerberos.Adapters" Version="0.3.0-alpha0042" /> <PackageReference Include="Thalos.Building.Blocks" Version="0.0.2" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -1,4 +1,4 @@
using Core.Cerberos.Infraestructure.Caching.Configs; using Core.Thalos.Infraestructure.Caching.Configs;
namespace LSA.Core.Dapper.Service.Caching namespace LSA.Core.Dapper.Service.Caching
{ {

View File

@@ -1,5 +1,5 @@
using Azure.Identity; using Azure.Identity;
using Core.Cerberos.Infraestructure.Caching.Contracts; using Core.Thalos.Infraestructure.Caching.Contracts;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using StackExchange.Redis; using StackExchange.Redis;
using System.Text.Json; using System.Text.Json;

View File

@@ -1,4 +1,4 @@
namespace Core.Cerberos.Infraestructure.Caching.Configs namespace Core.Thalos.Infraestructure.Caching.Configs
{ {
public class CacheSettings public class CacheSettings
{ {

View File

@@ -1,4 +1,4 @@
namespace Core.Cerberos.Infraestructure.Caching.Contracts namespace Core.Thalos.Infraestructure.Caching.Contracts
{ {
public interface ICacheService public interface ICacheService
{ {

View File

@@ -1,6 +1,6 @@
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
namespace Core.Cerberos.Infraestructure.Contexts.Mongo namespace Core.Thalos.Infraestructure.Contexts.Mongo
{ {
public class ConnectionStringProvider(IConfiguration configuration) : IConnectionStringProvider public class ConnectionStringProvider(IConfiguration configuration) : IConnectionStringProvider
{ {

View File

@@ -1,4 +1,4 @@
namespace Core.Cerberos.Infraestructure.Contexts.Mongo; namespace Core.Thalos.Infraestructure.Contexts.Mongo;
public interface IMongoConnSettings public interface IMongoConnSettings
{ {

View File

@@ -7,7 +7,6 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Core.Cerberos.Adapters" Version="0.3.0-alpha0042" />
<PackageReference Include="Microsoft.Azure.StackExchangeRedis" Version="3.1.0" /> <PackageReference Include="Microsoft.Azure.StackExchangeRedis" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />

View File

@@ -1,4 +1,4 @@
namespace Core.Cerberos.Infraestructure.PerformanceCacheService namespace Core.Thalos.Infraestructure.PerformanceCacheService
{ {
[AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = false)] [AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
public class CacheAttribute : Attribute public class CacheAttribute : Attribute

View File

@@ -1,13 +1,13 @@
// *********************************************************************** // ***********************************************************************
// <copyright file="IModuleService.cs"> // <copyright file="IModuleService.cs">
// Heath // AgileWebs
// </copyright> // </copyright>
// *********************************************************************** // ***********************************************************************
using Core.Cerberos.Adapters; using Core.Thalos.Adapters;
using Core.Cerberos.Adapters.Common.Enums; using Core.Thalos.Adapters.Common.Enums;
using Core.Cerberos.Domain.Contexts.Onboarding.Request; using Core.Thalos.Domain.Contexts.Onboarding.Request;
namespace Core.Cerberos.Provider.Contracts namespace Core.Thalos.Provider.Contracts
{ {
public interface IModuleService public interface IModuleService
{ {

View File

@@ -1,13 +1,13 @@
// *********************************************************************** // ***********************************************************************
// <copyright file="IPermissionService.cs"> // <copyright file="IPermissionService.cs">
// Heath // AgileWebs
// </copyright> // </copyright>
// *********************************************************************** // ***********************************************************************
using Core.Cerberos.Adapters; using Core.Thalos.Adapters;
using Core.Cerberos.Adapters.Common.Enums; using Core.Thalos.Adapters.Common.Enums;
using Core.Cerberos.Domain.Contexts.Onboarding.Request; using Core.Thalos.Domain.Contexts.Onboarding.Request;
namespace Core.Cerberos.Provider.Contracts namespace Core.Thalos.Provider.Contracts
{ {
public interface IPermissionService public interface IPermissionService
{ {

View File

@@ -1,13 +1,13 @@
// *********************************************************************** // ***********************************************************************
// <copyright file="IRoleService.cs"> // <copyright file="IRoleService.cs">
// Heath // AgileWebs
// </copyright> // </copyright>
// *********************************************************************** // ***********************************************************************
using Core.Cerberos.Adapters; using Core.Thalos.Adapters;
using Core.Cerberos.Adapters.Common.Enums; using Core.Thalos.Adapters.Common.Enums;
using Core.Cerberos.Domain.Contexts.Onboarding.Request; using Core.Thalos.Domain.Contexts.Onboarding.Request;
namespace Core.Cerberos.Provider.Contracts namespace Core.Thalos.Provider.Contracts
{ {
public interface IRoleService public interface IRoleService
{ {

View File

@@ -1,16 +1,15 @@
// *********************************************************************** // ***********************************************************************
// <copyright file="IUserService.cs"> // <copyright file="IUserService.cs">
// Heath // AgileWebs
// </copyright> // </copyright>
// *********************************************************************** // ***********************************************************************
using Core.Blueprint.Storage.Adapters; using Core.Blueprint.Mongo;
using Core.Cerberos.Adapters; using Core.Thalos.Adapters;
using Core.Cerberos.Adapters.Common.Enums; using Core.Thalos.Domain.Contexts.Onboarding.Request;
using Core.Cerberos.Domain.Contexts.Onboarding.Request;
namespace Core.Cerberos.Provider.Contracts namespace Core.Thalos.Provider.Contracts
{ {
public interface IUserService public interface IUserProvider
{ {
/// <summary> /// <summary>
/// Creates a new User. /// Creates a new User.
@@ -18,7 +17,7 @@ namespace Core.Cerberos.Provider.Contracts
/// <param name="entity">The User to be created.</param> /// <param name="entity">The User to be created.</param>
/// <returns>A <see cref="{Task{UserAdapter}}"/> representing /// <returns>A <see cref="{Task{UserAdapter}}"/> representing
/// the asynchronous execution of the service.</returns> /// the asynchronous execution of the service.</returns>
Task<UserAdapter> CreateUserService(UserRequest newUser); ValueTask<UserAdapter> CreateUser(UserRequest newUser, CancellationToken cancellationToken);
/// <summary> /// <summary>
/// Gets an User by identifier. /// Gets an User by identifier.
@@ -26,7 +25,7 @@ namespace Core.Cerberos.Provider.Contracts
/// <param name="id">The User identifier.</param> /// <param name="id">The User identifier.</param>
/// <returns>A <see cref="{Task{UserAdapter}}"/> representing /// <returns>A <see cref="{Task{UserAdapter}}"/> representing
/// the asynchronous execution of the service.</returns> /// the asynchronous execution of the service.</returns>
Task<UserAdapter> GetUserByIdService(string id); ValueTask<UserAdapter> GetUserById(string _id, CancellationToken cancellationToken);
/// <summary> /// <summary>
@@ -34,7 +33,7 @@ namespace Core.Cerberos.Provider.Contracts
/// </summary> /// </summary>
/// <returns>A <see cref="{Task{IEnumerable{UserAdapter}}}"/> representing /// <returns>A <see cref="{Task{IEnumerable{UserAdapter}}}"/> representing
/// the asynchronous execution of the service.</returns> /// the asynchronous execution of the service.</returns>
Task<IEnumerable<UserAdapter>> GetAllUsersService(); ValueTask<IEnumerable<UserAdapter>> GetAllUsers(CancellationToken cancellationToken);
/// <summary> /// <summary>
/// Gets an User by email. /// Gets an User by email.
@@ -42,7 +41,7 @@ namespace Core.Cerberos.Provider.Contracts
/// <param name="email">The User email.</param> /// <param name="email">The User email.</param>
/// <returns>A <see cref="{Task{UserAdapter}}"/> representing /// <returns>A <see cref="{Task{UserAdapter}}"/> representing
/// the asynchronous execution of the service.</returns> /// the asynchronous execution of the service.</returns>
Task<UserAdapter> GetUserByEmailService(string? email); ValueTask<UserAdapter> GetUserByEmail(string? email, CancellationToken cancellationToken);
/// <summary> /// <summary>
/// Validates if a users exists by email. /// Validates if a users exists by email.
@@ -50,7 +49,7 @@ namespace Core.Cerberos.Provider.Contracts
/// <param name="eamil">The User email.</param> /// <param name="eamil">The User email.</param>
/// <returns>A <see cref="{Task{UserAdapter}}"/> representing /// <returns>A <see cref="{Task{UserAdapter}}"/> representing
/// the asynchronous execution of the service.</returns> /// the asynchronous execution of the service.</returns>
Task<UserAdapter> ValidateUserExistenceService(string? email); ValueTask<UserAdapter> ValidateUserExistence(string? email, CancellationToken cancellationToken);
/// <summary> /// <summary>
/// Changes the status of the user. /// Changes the status of the user.
@@ -59,7 +58,7 @@ namespace Core.Cerberos.Provider.Contracts
/// <param name="newStatus">The new status of the user.</param> /// <param name="newStatus">The new status of the user.</param>
/// <returns>A <see cref="{Task{UserAdapter}}"/> representing /// <returns>A <see cref="{Task{UserAdapter}}"/> representing
/// the asynchronous execution of the service.</returns> /// the asynchronous execution of the service.</returns>
Task<UserAdapter> ChangeUserStatusService(string id, StatusEnum newStatus); ValueTask<UserAdapter> ChangeUserStatus(string id, StatusEnum newStatus, CancellationToken cancellationToken);
/// <summary> /// <summary>
/// Updates a User by id. /// Updates a User by id.
@@ -68,7 +67,7 @@ namespace Core.Cerberos.Provider.Contracts
/// <param name="id">The User identifier.</param> /// <param name="id">The User identifier.</param>
/// <returns>A <see cref="{Task{UserAdapter}}"/> representing /// <returns>A <see cref="{Task{UserAdapter}}"/> representing
/// the asynchronous execution of the service.</returns> /// the asynchronous execution of the service.</returns>
Task<UserAdapter> UpdateUserService(UserAdapter entity, string id); ValueTask<UserAdapter> UpdateUser(UserAdapter entity, CancellationToken cancellationToken);
/// <summary> /// <summary>
/// Logs in the user. /// Logs in the user.
@@ -76,7 +75,7 @@ namespace Core.Cerberos.Provider.Contracts
/// <param name="email">The User's email.</param> /// <param name="email">The User's email.</param>
/// <returns>A <see cref="{Task{UserAdapter}}"/> representing /// <returns>A <see cref="{Task{UserAdapter}}"/> representing
/// the asynchronous execution of the service.</returns> /// the asynchronous execution of the service.</returns>
Task<UserAdapter?> LogInUserService(string email); ValueTask<UserAdapter?> LogInUser(string email, CancellationToken cancellationToken);
/// <summary> /// <summary>
/// Logs out the user's session. /// Logs out the user's session.
@@ -84,7 +83,7 @@ namespace Core.Cerberos.Provider.Contracts
/// <param name="email">The User's email.</param> /// <param name="email">The User's email.</param>
/// <returns>A <see cref="{Task{UserAdapter}}"/> representing /// <returns>A <see cref="{Task{UserAdapter}}"/> representing
/// the asynchronous execution of the service.</returns> /// the asynchronous execution of the service.</returns>
Task<UserAdapter> LogOutUserSessionService(string email); ValueTask<UserAdapter?> LogOutUserSession(string email, CancellationToken cancellationToken);
/// <summary> /// <summary>
/// Adds a company to the user's list of companies. /// Adds a company to the user's list of companies.
@@ -92,7 +91,7 @@ namespace Core.Cerberos.Provider.Contracts
/// <param name="userId">The identifier of the user to whom the company will be added.</param> /// <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> /// <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> /// <returns>A <see cref="Task{UserAdapter}"/> representing the asynchronous operation, with the updated user object.</returns>
Task<UserAdapter> AddCompanyToUserService(string userId, string companyId); ValueTask<UserAdapter> AddCompanyToUser(string userId, string companyId, CancellationToken cancellationToken);
/// <summary> /// <summary>
/// Removes a company from the user's list of companies. /// Removes a company from the user's list of companies.
@@ -100,7 +99,7 @@ namespace Core.Cerberos.Provider.Contracts
/// <param name="userId">The identifier of the user from whom the company will be removed.</param> /// <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> /// <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> /// <returns>A <see cref="Task{UserAdapter}"/> representing the asynchronous operation, with the updated user object.</returns>
Task<UserAdapter> RemoveCompanyFromUserService(string userId, string companyId); ValueTask<UserAdapter> RemoveCompanyFromUser(string userId, string companyId, CancellationToken cancellationToken);
/// <summary> /// <summary>
/// Adds a project to the user's list of projects. /// Adds a project to the user's list of projects.
@@ -108,7 +107,7 @@ namespace Core.Cerberos.Provider.Contracts
/// <param name="userId">The identifier of the user to whom the project will be added.</param> /// <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> /// <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> /// <returns>A <see cref="Task{UserAdapter}"/> representing the asynchronous operation, with the updated user object.</returns>
Task<UserAdapter> AddProjectToUserService(string userId, string projectId); ValueTask<UserAdapter> AddProjectToUser(string userId, string projectId, CancellationToken cancellationToken);
/// <summary> /// <summary>
@@ -117,27 +116,21 @@ namespace Core.Cerberos.Provider.Contracts
/// <param name="userId">The identifier of the user from whom the project will be removed.</param> /// <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> /// <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> /// <returns>A <see cref="Task{UserAdapter}"/> representing the asynchronous operation, with the updated user object.</returns>
Task<UserAdapter> RemoveProjectFromUserService(string userId, string projectId); ValueTask<UserAdapter> RemoveProjectFromUser(string userId, string projectId, CancellationToken cancellationToken);
/// <summary> /// <summary>
/// Gets the token adapter for a user. /// Gets the token adapter for a user.
/// </summary> /// </summary>
/// <param name="email">The user's email.</param> /// <param name="email">The user's email.</param>
/// <returns>A <see cref="{Task{TokenAdapter}}"/> representing the asynchronous execution of the service.</returns> /// <returns>A <see cref="{Task{TokenAdapter}}"/> representing the asynchronous execution of the service.</returns>
Task<TokenAdapter?> GetTokenAdapter(string email); ValueTask<TokenAdapter?> GetToken(string email, CancellationToken cancellationToken);
/// <summary> /// <summary>
/// Get Consent Form PDF. /// Delete an User by identifier.
/// </summary>
/// <returns>A <see cref="{Task{BlobDownloadUriAdapter}}"/> representing
/// the asynchronous execution of the service.</returns>
Task<BlobDownloadUriAdapter> GetConsentFormPDFService();
/// <summary>
/// Accept user consent form.
/// </summary> /// </summary>
/// <param name="id">The User identifier.</param>
/// <returns>A <see cref="{Task{UserAdapter}}"/> representing /// <returns>A <see cref="{Task{UserAdapter}}"/> representing
/// the asynchronous execution of the service.</returns> /// the asynchronous execution of the service.</returns>
Task<UserAdapter?> AcceptUserConsentFormService(); ValueTask<UserAdapter> DeleteUser(string _id, CancellationToken cancellationToken);
} }
} }

View File

@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Providers\Onboarding\UserService - Copy.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Blueprint.Mongo" Version="0.0.3" />
<PackageReference Include="Blueprint.Redis" Version="0.0.1" />
<PackageReference Include="BuildingBlocks.Library" Version="0.0.1" />
<PackageReference Include="Mapster" Version="7.4.2-pre02" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Core.Thalos.Domain\Core.Thalos.Domain.csproj" />
<ProjectReference Include="..\Core.Thalos.Infraestructure\Core.Thalos.Infrastructure.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,6 +1,6 @@
using MongoDB.Driver; using MongoDB.Driver;
namespace Core.Cerberos.Provider.Providers namespace Core.Thalos.Provider.Providers
{ {
public class BaseProvider public class BaseProvider
{ {

View File

@@ -1,9 +1,9 @@
using Azure.Core; using Azure.Core;
using Azure.Identity; using Azure.Identity;
using Core.Cerberos.Adapters.Common.Constants; using Core.Thalos.Adapters.Common.Constants;
using MongoDB.Driver.Authentication.Oidc; using MongoDB.Driver.Authentication.Oidc;
namespace Core.Cerberos.Provider.Providers namespace Core.Thalos.Provider.Providers
{ {
public class HeathOidcCallback : IOidcCallback public class HeathOidcCallback : IOidcCallback
{ {

View File

@@ -1,13 +1,13 @@
// *********************************************************************** // ***********************************************************************
// <copyright file="Helper.cs"> // <copyright file="Helper.cs">
// Heath // AgileWebs
// </copyright> // </copyright>
// *********************************************************************** // ***********************************************************************
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using System.Security.Claims; using System.Security.Claims;
namespace Core.Cerberos.Provider.Providers namespace Core.Thalos.Provider.Providers
{ {
/// <summary> /// <summary>
/// Provides helper methods for common operations. /// Provides helper methods for common operations.

View File

@@ -1,16 +1,16 @@
// *********************************************************************** // ***********************************************************************
// <copyright file="ModuleService.cs"> // <copyright file="ModuleService.cs">
// Heath // AgileWebs
// </copyright> // </copyright>
// *********************************************************************** // ***********************************************************************
using Core.Cerberos.Adapters; using Core.Thalos.Adapters;
using Core.Cerberos.Adapters.Common.Constants; using Core.Thalos.Adapters.Common.Constants;
using Core.Cerberos.Adapters.Common.Enums; using Core.Thalos.Adapters.Common.Enums;
using Core.Cerberos.Domain.Contexts.Onboarding.Mappers; using Core.Thalos.Domain.Contexts.Onboarding.Mappers;
using Core.Cerberos.Domain.Contexts.Onboarding.Request; using Core.Thalos.Domain.Contexts.Onboarding.Request;
using Core.Cerberos.Infraestructure.Caching.Configs; using Core.Thalos.Infraestructure.Caching.Configs;
using Core.Cerberos.Infraestructure.Caching.Contracts; using Core.Thalos.Infraestructure.Caching.Contracts;
using Core.Cerberos.Provider.Contracts; using Core.Thalos.Provider.Contracts;
using LSA.Core.Dapper.Service.Caching; using LSA.Core.Dapper.Service.Caching;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@@ -18,7 +18,7 @@ using Microsoft.Extensions.Options;
using MongoDB.Bson; using MongoDB.Bson;
using MongoDB.Driver; using MongoDB.Driver;
namespace Core.Cerberos.Provider.Providers.Onboarding namespace Core.Thalos.Provider.Providers.Onboarding
{ {
/// <summary> /// <summary>
/// Handles all services and business rules related to <see cref="ModuleAdapter"/>. /// Handles all services and business rules related to <see cref="ModuleAdapter"/>.
@@ -180,7 +180,7 @@ namespace Core.Cerberos.Provider.Providers.Onboarding
.Eq("_id", ObjectId.Parse(id)); .Eq("_id", ObjectId.Parse(id));
var update = Builders<ModuleAdapter>.Update var update = Builders<ModuleAdapter>.Update
.Set(v => v.Status, newStatus) //.Set(v => v.Status, newStatus)
.Set(v => v.UpdatedBy, Helper.GetEmail(httpContextAccessor)) .Set(v => v.UpdatedBy, Helper.GetEmail(httpContextAccessor))
.Set(v => v.UpdatedAt, DateTime.UtcNow); .Set(v => v.UpdatedAt, DateTime.UtcNow);

View File

@@ -1,16 +1,16 @@
// *********************************************************************** // ***********************************************************************
// <copyright file="PermissionService.cs"> // <copyright file="PermissionService.cs">
// Heath // AgileWebs
// </copyright> // </copyright>
// *********************************************************************** // ***********************************************************************
using Core.Cerberos.Adapters; using Core.Thalos.Adapters;
using Core.Cerberos.Adapters.Common.Constants; using Core.Thalos.Adapters.Common.Constants;
using Core.Cerberos.Adapters.Common.Enums; using Core.Thalos.Adapters.Common.Enums;
using Core.Cerberos.Domain.Contexts.Onboarding.Mappers; using Core.Thalos.Domain.Contexts.Onboarding.Mappers;
using Core.Cerberos.Domain.Contexts.Onboarding.Request; using Core.Thalos.Domain.Contexts.Onboarding.Request;
using Core.Cerberos.Infraestructure.Caching.Configs; using Core.Thalos.Infraestructure.Caching.Configs;
using Core.Cerberos.Infraestructure.Caching.Contracts; using Core.Thalos.Infraestructure.Caching.Contracts;
using Core.Cerberos.Provider.Contracts; using Core.Thalos.Provider.Contracts;
using LSA.Core.Dapper.Service.Caching; using LSA.Core.Dapper.Service.Caching;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@@ -18,7 +18,7 @@ using Microsoft.Extensions.Options;
using MongoDB.Bson; using MongoDB.Bson;
using MongoDB.Driver; using MongoDB.Driver;
namespace Core.Cerberos.Provider.Providers.Onboarding namespace Core.Thalos.Provider.Providers.Onboarding
{ {
/// <summary> /// <summary>
/// Handles all services and business rules related to <see cref="PermissionAdapter"/>. /// Handles all services and business rules related to <see cref="PermissionAdapter"/>.
@@ -175,7 +175,7 @@ namespace Core.Cerberos.Provider.Providers.Onboarding
.Eq("_id", ObjectId.Parse(id)); .Eq("_id", ObjectId.Parse(id));
var update = Builders<PermissionAdapter>.Update var update = Builders<PermissionAdapter>.Update
.Set(v => v.Status, newStatus) //.Set(v => v.Status, newStatus)
.Set(v => v.UpdatedBy, Helper.GetEmail(httpContextAccessor)) .Set(v => v.UpdatedBy, Helper.GetEmail(httpContextAccessor))
.Set(v => v.UpdatedAt, DateTime.UtcNow); .Set(v => v.UpdatedAt, DateTime.UtcNow);

View File

@@ -1,16 +1,16 @@
// *********************************************************************** // ***********************************************************************
// <copyright file="RoleService.cs"> // <copyright file="RoleService.cs">
// Heath // AgileWebs
// </copyright> // </copyright>
// *********************************************************************** // ***********************************************************************
using Core.Cerberos.Adapters; using Core.Thalos.Adapters;
using Core.Cerberos.Adapters.Common.Constants; using Core.Thalos.Adapters.Common.Constants;
using Core.Cerberos.Adapters.Common.Enums; using Core.Thalos.Adapters.Common.Enums;
using Core.Cerberos.Domain.Contexts.Onboarding.Mappers; using Core.Thalos.Domain.Contexts.Onboarding.Mappers;
using Core.Cerberos.Domain.Contexts.Onboarding.Request; using Core.Thalos.Domain.Contexts.Onboarding.Request;
using Core.Cerberos.Infraestructure.Caching.Configs; using Core.Thalos.Infraestructure.Caching.Configs;
using Core.Cerberos.Infraestructure.Caching.Contracts; using Core.Thalos.Infraestructure.Caching.Contracts;
using Core.Cerberos.Provider.Contracts; using Core.Thalos.Provider.Contracts;
using LSA.Core.Dapper.Service.Caching; using LSA.Core.Dapper.Service.Caching;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@@ -18,7 +18,7 @@ using Microsoft.Extensions.Options;
using MongoDB.Bson; using MongoDB.Bson;
using MongoDB.Driver; using MongoDB.Driver;
namespace Core.Cerberos.Provider.Providers.Onboarding namespace Core.Thalos.Provider.Providers.Onboarding
{ {
/// <summary> /// <summary>
/// Handles all services and business rules related to <see cref="RoleAdapter"/>. /// Handles all services and business rules related to <see cref="RoleAdapter"/>.
@@ -134,7 +134,7 @@ namespace Core.Cerberos.Provider.Providers.Onboarding
.Eq("_id", ObjectId.Parse(id)); .Eq("_id", ObjectId.Parse(id));
var update = Builders<RoleAdapter>.Update var update = Builders<RoleAdapter>.Update
.Set(v => v.Status, newStatus) //.Set(v => v.Status, newStatus)
.Set(v => v.UpdatedBy, Helper.GetEmail(httpContextAccessor)) .Set(v => v.UpdatedBy, Helper.GetEmail(httpContextAccessor))
.Set(v => v.UpdatedAt, DateTime.UtcNow); .Set(v => v.UpdatedAt, DateTime.UtcNow);

View File

@@ -0,0 +1,471 @@
// ***********************************************************************
// <copyright file="UserService.cs">
// AgileWebs
// </copyright>
// ***********************************************************************
using Core.Thalos.Adapters;
using Core.Thalos.Adapters.Common.Enums;
using Core.Blueprint.Mongo;
using Core.Blueprint.Redis;
using Core.Blueprint.Redis.Helpers;
using Mapster;
using Microsoft.Extensions.Options;
using MongoDB.Driver;
using Core.Thalos.Provider.Contracts;
using MongoDB.Bson;
using System.Text.RegularExpressions;
using MongoDB.Bson.Serialization;
namespace Core.Thalos.Provider.Providers.Onboarding
{
/// <summary>
/// Handles all services and business rules related to <see cref="UserAdapter"/>.
/// </summary>
public class UserProvider : IUserProvider
{
private readonly CollectionRepository<UserAdapter> repository;
private readonly CacheSettings cacheSettings;
private readonly IRedisCacheProvider cacheProvider;
public UserProvider(CollectionRepository<UserAdapter> repository,
IRedisCacheProvider cacheProvider, IOptions<CacheSettings> cacheSettings)
{
this.repository = repository;
this.repository.CollectionInitialization();
this.cacheSettings = cacheSettings.Value;
this.cacheProvider = cacheProvider;
}
/// <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 ValueTask<UserAdapter> CreateUser(Core.Thalos.Domain.Contexts.Onboarding.Request.UserRequest newUser, CancellationToken cancellationToken)
{
var userCollection = newUser.Adapt<UserAdapter>();
await repository.InsertOneAsync(userCollection);
return userCollection;
}
/// <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 ValueTask<UserAdapter> GetUserById(string _id, CancellationToken cancellationToken)
{
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserById", _id);
var cachedData = await cacheProvider.GetAsync<UserAdapter>(cacheKey);
if (cachedData is not null) { return cachedData; }
var user = await repository.FindByIdAsync(_id);
await cacheProvider.SetAsync(cacheKey, user);
return user;
}
/// <summary>
/// Gets all the users.
/// </summary>
/// <returns>A <see cref="{Task{IEnumerable{UserAdapter}}}"/> representing
/// the asynchronous execution of the service.</returns>
public async ValueTask<IEnumerable<UserAdapter>> GetAllUsers(CancellationToken cancellationToken)
{
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllUsers");
var cachedData = await cacheProvider.GetAsync<IEnumerable<UserAdapter>>(cacheKey) ?? [];
if (cachedData.Any()) return cachedData;
var users = await repository.AsQueryable();
await cacheProvider.SetAsync(cacheKey, users);
return users;
}
/// <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 ValueTask<UserAdapter> GetUserByEmail(string? email, CancellationToken cancellationToken)
{
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserByEmail", email);
var cachedData = await cacheProvider.GetAsync<UserAdapter>(cacheKey);
if (cachedData is not null) { return cachedData; }
var user = await repository.FindOneAsync(
u => u.Email == email &&
u.Status == Core.Blueprint.Mongo.StatusEnum.Active);
await cacheProvider.SetAsync(cacheKey, user);
return user;
}
/// <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 ValueTask<UserAdapter> ValidateUserExistence(string? email, CancellationToken cancellationToken)
{
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserByEmail", email);
var cachedData = await cacheProvider.GetAsync<UserAdapter>(cacheKey);
if (cachedData is not null) { return cachedData; }
var user = await repository.FindOneAsync(
u => u.Email == email &&
u.Status == Core.Blueprint.Mongo.StatusEnum.Active);
await cacheProvider.SetAsync(cacheKey, user);
return user;
}
/// <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 ValueTask<UserAdapter> ChangeUserStatus(string id, Core.Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken)
{
var entity = await repository.FindByIdAsync(id);
entity.Status = newStatus;
await repository.ReplaceOneAsync(entity);
return entity;
}
/// <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 ValueTask<UserAdapter> UpdateUser(UserAdapter entity, CancellationToken cancellationToken)
{
await repository.ReplaceOneAsync(entity);
return entity;
}
/// <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 ValueTask<UserAdapter?> LogInUser(string email, CancellationToken cancellationToken)
{
var user = await repository.FindOneAsync(
u => u.Email == email &&
u.Status == Core.Blueprint.Mongo.StatusEnum.Active);
user.LastLogIn = DateTime.UtcNow;
await repository.ReplaceOneAsync(user);
return user;
}
/// <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 ValueTask<UserAdapter?> LogOutUserSession(string email, CancellationToken cancellationToken)
{
var user = await repository.FindOneAsync(
u => u.Email == email &&
u.Status == Core.Blueprint.Mongo.StatusEnum.Active);
user.LastLogOut = DateTime.UtcNow;
await repository.ReplaceOneAsync(user);
return user;
}
/// <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 ValueTask<UserAdapter> AddCompanyToUser(string userId, string companyId, CancellationToken cancellationToken)
{
var user = await repository.FindOneAsync(
u => u.Id == userId &&
u.Status == Core.Blueprint.Mongo.StatusEnum.Active);
var updatedCompanies = user.Companies.Append(companyId).Distinct().ToArray();
user.Companies = updatedCompanies;
await repository.ReplaceOneAsync(user);
return user;
}
/// <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 ValueTask<UserAdapter> RemoveCompanyFromUser(string userId, string companyId, CancellationToken cancellationToken)
{
var user = await repository.FindOneAsync(
u => u.Id == userId &&
u.Status == Core.Blueprint.Mongo.StatusEnum.Active);
var updatedCompanies = user.Companies
?.Where(c => c != companyId)
.ToArray();
user.Companies = updatedCompanies;
await repository.ReplaceOneAsync(user);
return user;
}
/// <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 ValueTask<UserAdapter> AddProjectToUser(string userId, string projectId, CancellationToken cancellationToken)
{
var user = await repository.FindOneAsync(
u => u.Id == userId &&
u.Status == Core.Blueprint.Mongo.StatusEnum.Active);
var updatedProjects = user.Projects.Append(projectId).Distinct().ToArray();
user.Companies = updatedProjects;
await repository.ReplaceOneAsync(user);
return user;
}
/// <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 ValueTask<UserAdapter> RemoveProjectFromUser(string userId, string projectId, CancellationToken cancellationToken)
{
var user = await repository.FindOneAsync(
u => u.Id == userId &&
u.Status == Core.Blueprint.Mongo.StatusEnum.Active);
var updatedProjects = user.Projects
?.Where(c => c != projectId)
.ToArray();
user.Companies = updatedProjects;
await repository.ReplaceOneAsync(user);
return user;
}
/// <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 ValueTask<TokenAdapter?> GetToken(string email, CancellationToken cancellationToken)
{
try
{
var pipeline = new[]
{
new BsonDocument("$match", new BsonDocument
{
{ "email", new BsonDocument
{
{ "$regex", $"^{Regex.Escape(email)}$" },
{ "$options", "i" }
}
},
{ "status", Core.Blueprint.Mongo.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", Core.Blueprint.Mongo.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 repository.FindOnePipelineAsync<BsonDocument>(pipeline);
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 = (Core.Blueprint.Mongo.StatusEnum)Enum.Parse(typeof(Core.Blueprint.Mongo.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 = (Core.Blueprint.Mongo.StatusEnum)Enum.Parse(typeof(Core.Blueprint.Mongo.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 == Core.Blueprint.Mongo.StatusEnum.Active)
.ToList()
};
return tokenAdapter;
}
catch (Exception ex)
{
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 ValueTask<UserAdapter> DeleteUser(string _id, CancellationToken cancellationToken)
{
var entity = await repository.DeleteOneAsync(doc => doc.Id == _id);
return entity;
}
}
}

View File

@@ -1,9 +1,8 @@
using Core.Blueprint.Storage.Configuration; using Core.Thalos.Infraestructure.Caching.Contracts;
using Core.Cerberos.Infraestructure.Caching.Contracts; using Core.Thalos.Infraestructure.Contexts.Mongo;
using Core.Cerberos.Infraestructure.Contexts.Mongo; using Core.Thalos.Provider.Contracts;
using Core.Cerberos.Provider.Contracts; using Core.Thalos.Provider.Providers;
using Core.Cerberos.Provider.Providers; using Core.Thalos.Provider.Providers.Onboarding;
using Core.Cerberos.Provider.Providers.Onboarding;
using LSA.Core.Dapper.Service.Caching; using LSA.Core.Dapper.Service.Caching;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
@@ -11,7 +10,7 @@ using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using MongoDB.Driver; using MongoDB.Driver;
namespace Core.Cerberos.Provider namespace Core.Thalos.Provider
{ {
public static class ServiceCollectionExtensions public static class ServiceCollectionExtensions
{ {
@@ -55,7 +54,6 @@ namespace Core.Cerberos.Provider
services.AddDALConfigurationLayer(); services.AddDALConfigurationLayer();
services.AddLogs(); services.AddLogs();
services.AddRedisCacheService(configuration); services.AddRedisCacheService(configuration);
services.AddBlobStorage(configuration);
return services; return services;
} }
@@ -65,7 +63,7 @@ namespace Core.Cerberos.Provider
{ {
services.AddHttpContextAccessor(); services.AddHttpContextAccessor();
services.AddScoped<IUserService, UserService>(); services.AddScoped<IUserProvider, UserProvider>();
services.AddScoped<IRoleService, RoleService>(); services.AddScoped<IRoleService, RoleService>();
services.AddScoped<IPermissionService, PermissionService>(); services.AddScoped<IPermissionService, PermissionService>();
services.AddScoped<IPermissionService, PermissionService>(); services.AddScoped<IPermissionService, PermissionService>();