Compare commits
	
		
			2 Commits
		
	
	
		
			7c92a7e791
			...
			feature/pi
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| de418a123e | |||
| 179e94979c | 
							
								
								
									
										19
									
								
								.gitea/workflows/pipeline.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								.gitea/workflows/pipeline.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | |||||||
|  | name: Core Thalos DAL - Deploy | ||||||
|  | run-name: ${{ gitea.actor }} is testing out Gitea Actions | ||||||
|  | on: [push] | ||||||
|  |  | ||||||
|  | jobs: | ||||||
|  |   Explore-Gitea-Actions: | ||||||
|  |     runs-on: ubuntu-latest | ||||||
|  |     steps: | ||||||
|  |       - run: echo "The job was automatically triggered by a ${{ gitea.event_name }} event." | ||||||
|  |       - run: echo "This job is now running on a ${{ runner.os }} server hosted by Gitea!" | ||||||
|  |       - run: echo "The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}." | ||||||
|  |       - name: Check out repository code | ||||||
|  |         uses: actions/checkout@v4 | ||||||
|  |       - run: echo "The ${{ gitea.repository }} repository has been cloned to the runner." | ||||||
|  |       - run: echo "The workflow is now ready to test your code on the runner." | ||||||
|  |       - name: List files in the repository | ||||||
|  |         run: | | ||||||
|  |           ls ${{ gitea.workspace }} | ||||||
|  |       - run: echo "This job's status is ${{ job.status }}." | ||||||
| @@ -5,13 +5,15 @@ | |||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
|  |  | ||||||
| using Asp.Versioning; | using Asp.Versioning; | ||||||
| using Core.Thalos.BuildingBlocks; | using Core.Blueprint.Mongo; | ||||||
|  | using Core.Thalos.Adapters; | ||||||
|  | using Core.Thalos.Adapters.Attributes; | ||||||
|  | using Core.Thalos.Adapters.Common.Constants; | ||||||
| using Core.Thalos.Provider.Contracts; | using Core.Thalos.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 ModuleRequest = Core.Thalos.Domain.Contexts.Onboarding.Request.ModuleRequest; | using ModuleRequest = Core.Thalos.Domain.Contexts.Onboarding.Request.ModuleRequest; | ||||||
| using StatusEnum = Core.Blueprint.Mongo.StatusEnum; |  | ||||||
|  |  | ||||||
| namespace LSA.Core.Thalos.API.Controllers | namespace LSA.Core.Thalos.API.Controllers | ||||||
| { | { | ||||||
| @@ -23,7 +25,7 @@ namespace LSA.Core.Thalos.API.Controllers | |||||||
|     [Produces(MimeTypes.ApplicationJson)] |     [Produces(MimeTypes.ApplicationJson)] | ||||||
|     [Consumes(MimeTypes.ApplicationJson)] |     [Consumes(MimeTypes.ApplicationJson)] | ||||||
|     [ApiController] |     [ApiController] | ||||||
|     [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |     [AllowAnonymous] | ||||||
|     public class ModuleController(IModuleProvider service) : ControllerBase |     public class ModuleController(IModuleProvider service) : ControllerBase | ||||||
|     { |     { | ||||||
|         /// <summary> |         /// <summary> | ||||||
| @@ -37,7 +39,8 @@ namespace LSA.Core.Thalos.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)] | ||||||
|         [Permission("ModuleManagement.Read, RoleManagement.Read")] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         //[Permission("ModuleManagement.Read, RoleManagement.Read")] | ||||||
|         public async Task<IActionResult> GetAllModulesAsync(CancellationToken cancellationToken) |         public async Task<IActionResult> GetAllModulesAsync(CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.GetAllModules(cancellationToken).ConfigureAwait(false); |             var result = await service.GetAllModules(cancellationToken).ConfigureAwait(false); | ||||||
| @@ -57,7 +60,8 @@ namespace LSA.Core.Thalos.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)] | ||||||
|         [Permission("ModuleManagement.Read")] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         //[Permission("ModuleManagement.Read")] | ||||||
|         public async Task<IActionResult> GetAllModulesByList([FromBody] string[] modules, CancellationToken cancellationToken) |         public async Task<IActionResult> GetAllModulesByList([FromBody] string[] modules, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             if (modules == null || !modules.Any()) |             if (modules == null || !modules.Any()) | ||||||
| @@ -83,7 +87,8 @@ namespace LSA.Core.Thalos.API.Controllers | |||||||
|         [Consumes(MimeTypes.ApplicationJson)] |         [Consumes(MimeTypes.ApplicationJson)] | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |         [Produces(MimeTypes.ApplicationJson)] | ||||||
|         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] | ||||||
|         [Permission("ModuleManagement.Read")] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         //[Permission("ModuleManagement.Read")] | ||||||
|         public async Task<IActionResult> GetModuleByIdAsync([FromRoute] string id, CancellationToken cancellationToken) |         public async Task<IActionResult> GetModuleByIdAsync([FromRoute] string id, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.GetModuleById(id, cancellationToken).ConfigureAwait(false); |             var result = await service.GetModuleById(id, cancellationToken).ConfigureAwait(false); | ||||||
| @@ -106,7 +111,8 @@ namespace LSA.Core.Thalos.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)] | ||||||
|         [Permission("ModuleManagement.Write")] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         //[Permission("ModuleManagement.Write")] | ||||||
|         public async Task<IActionResult> CreateModuleAsync([FromBody] ModuleRequest newModule, CancellationToken cancellationToken) |         public async Task<IActionResult> CreateModuleAsync([FromBody] ModuleRequest newModule, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.CreateModule(newModule, cancellationToken).ConfigureAwait(false); |             var result = await service.CreateModule(newModule, cancellationToken).ConfigureAwait(false); | ||||||
| @@ -128,7 +134,8 @@ namespace LSA.Core.Thalos.API.Controllers | |||||||
|         [Consumes(MimeTypes.ApplicationJson)] |         [Consumes(MimeTypes.ApplicationJson)] | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |         [Produces(MimeTypes.ApplicationJson)] | ||||||
|         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] | ||||||
|         [Permission("ModuleManagement.Write")] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         //[Permission("ModuleManagement.Write")] | ||||||
|         public async Task<IActionResult> UpdateModuleAsync([FromRoute] string id, ModuleAdapter entity, CancellationToken cancellationToken) |         public async Task<IActionResult> UpdateModuleAsync([FromRoute] string id, ModuleAdapter entity, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             if (id != entity.Id?.ToString()) |             if (id != entity.Id?.ToString()) | ||||||
| @@ -156,7 +163,8 @@ namespace LSA.Core.Thalos.API.Controllers | |||||||
|         [Consumes(MimeTypes.ApplicationJson)] |         [Consumes(MimeTypes.ApplicationJson)] | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |         [Produces(MimeTypes.ApplicationJson)] | ||||||
|         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] | ||||||
|         [Permission("ModuleManagement.Write")] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         //[Permission("ModuleManagement.Write")] | ||||||
|         public async Task<IActionResult> ChangeModuleStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) |         public async Task<IActionResult> ChangeModuleStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.ChangeModuleStatus(id, newStatus, cancellationToken).ConfigureAwait(false); |             var result = await service.ChangeModuleStatus(id, newStatus, cancellationToken).ConfigureAwait(false); | ||||||
|   | |||||||
| @@ -5,13 +5,15 @@ | |||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
|  |  | ||||||
| using Asp.Versioning; | using Asp.Versioning; | ||||||
| using Core.Thalos.BuildingBlocks; | using Core.Blueprint.Mongo; | ||||||
|  | using Core.Thalos.Adapters; | ||||||
|  | using Core.Thalos.Adapters.Attributes; | ||||||
|  | using Core.Thalos.Adapters.Common.Constants; | ||||||
| using Core.Thalos.Provider.Contracts; | using Core.Thalos.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 PermissionRequest = Core.Thalos.Domain.Contexts.Onboarding.Request.PermissionRequest; | using PermissionRequest = Core.Thalos.Domain.Contexts.Onboarding.Request.PermissionRequest; | ||||||
| using StatusEnum = Core.Blueprint.Mongo.StatusEnum; |  | ||||||
|  |  | ||||||
| namespace LSA.Core.Thalos.API.Controllers | namespace LSA.Core.Thalos.API.Controllers | ||||||
| { | { | ||||||
| @@ -23,7 +25,6 @@ namespace LSA.Core.Thalos.API.Controllers | |||||||
|     [Produces(MimeTypes.ApplicationJson)] |     [Produces(MimeTypes.ApplicationJson)] | ||||||
|     [Consumes(MimeTypes.ApplicationJson)] |     [Consumes(MimeTypes.ApplicationJson)] | ||||||
|     [ApiController] |     [ApiController] | ||||||
|     [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |  | ||||||
|     public class PermissionController(IPermissionProvider service) : ControllerBase |     public class PermissionController(IPermissionProvider service) : ControllerBase | ||||||
|     { |     { | ||||||
|         /// <summary> |         /// <summary> | ||||||
| @@ -37,7 +38,8 @@ namespace LSA.Core.Thalos.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)] | ||||||
|         [Permission("PermissionManagement.Read, RoleManagement.Read")] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         //[Permission("PermissionManagement.Read, RoleManagement.Read")] | ||||||
|         public async Task<IActionResult> GetAllPermissionsAsync(CancellationToken cancellationToken) |         public async Task<IActionResult> GetAllPermissionsAsync(CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.GetAllPermissions(cancellationToken).ConfigureAwait(false); |             var result = await service.GetAllPermissions(cancellationToken).ConfigureAwait(false); | ||||||
| @@ -57,7 +59,8 @@ namespace LSA.Core.Thalos.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)] | ||||||
|         [Permission("PermissionManagement.Read")] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         //[Permission("PermissionManagement.Read")] | ||||||
|         public async Task<IActionResult> GetAllPermissionsByList([FromBody] string[] permissions, CancellationToken cancellationToken) |         public async Task<IActionResult> GetAllPermissionsByList([FromBody] string[] permissions, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             if (permissions == null || !permissions.Any()) |             if (permissions == null || !permissions.Any()) | ||||||
| @@ -82,7 +85,8 @@ namespace LSA.Core.Thalos.API.Controllers | |||||||
|         [Consumes(MimeTypes.ApplicationJson)] |         [Consumes(MimeTypes.ApplicationJson)] | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |         [Produces(MimeTypes.ApplicationJson)] | ||||||
|         [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)] | ||||||
|         [Permission("PermissionManagement.Read")] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         //[Permission("PermissionManagement.Read")] | ||||||
|         public async Task<IActionResult> GetPermissionByIdAsync([FromRoute] string id, CancellationToken cancellationToken) |         public async Task<IActionResult> GetPermissionByIdAsync([FromRoute] string id, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.GetPermissionById(id, cancellationToken).ConfigureAwait(false); |             var result = await service.GetPermissionById(id, cancellationToken).ConfigureAwait(false); | ||||||
| @@ -105,7 +109,8 @@ namespace LSA.Core.Thalos.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)] | ||||||
|         [Permission("PermissionManagement.Write")] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         //[Permission("PermissionManagement.Write")] | ||||||
|         public async Task<IActionResult> CreatePermissionAsync([FromBody] PermissionRequest newPermission, CancellationToken cancellationToken) |         public async Task<IActionResult> CreatePermissionAsync([FromBody] PermissionRequest newPermission, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.CreatePermission(newPermission, cancellationToken).ConfigureAwait(false); |             var result = await service.CreatePermission(newPermission, cancellationToken).ConfigureAwait(false); | ||||||
| @@ -127,7 +132,8 @@ namespace LSA.Core.Thalos.API.Controllers | |||||||
|         [Consumes(MimeTypes.ApplicationJson)] |         [Consumes(MimeTypes.ApplicationJson)] | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |         [Produces(MimeTypes.ApplicationJson)] | ||||||
|         [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)] | ||||||
|         [Permission("PermissionManagement.Write")] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         //[Permission("PermissionManagement.Write")] | ||||||
|         public async Task<IActionResult> UpdatePermissionAsync([FromRoute] string id, PermissionAdapter entity, CancellationToken cancellationToken) |         public async Task<IActionResult> UpdatePermissionAsync([FromRoute] string id, PermissionAdapter entity, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             if (id != entity.Id?.ToString()) |             if (id != entity.Id?.ToString()) | ||||||
| @@ -155,7 +161,8 @@ namespace LSA.Core.Thalos.API.Controllers | |||||||
|         [Consumes(MimeTypes.ApplicationJson)] |         [Consumes(MimeTypes.ApplicationJson)] | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |         [Produces(MimeTypes.ApplicationJson)] | ||||||
|         [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)] | ||||||
|         [Permission("PermissionManagement.Write")] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         //[Permission("PermissionManagement.Write")] | ||||||
|         public async Task<IActionResult> ChangePermissionStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) |         public async Task<IActionResult> ChangePermissionStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.ChangePermissionStatus(id, newStatus, cancellationToken).ConfigureAwait(false); |             var result = await service.ChangePermissionStatus(id, newStatus, cancellationToken).ConfigureAwait(false); | ||||||
|   | |||||||
| @@ -4,7 +4,10 @@ | |||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| using Asp.Versioning; | using Asp.Versioning; | ||||||
| using Core.Thalos.BuildingBlocks; | using Core.Thalos.Adapters; | ||||||
|  | using Core.Thalos.Adapters.Attributes; | ||||||
|  | using Core.Thalos.Adapters.Common.Constants; | ||||||
|  | using Core.Thalos.Adapters.Common.Enums; | ||||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
| using Core.Thalos.Provider.Contracts; | using Core.Thalos.Provider.Contracts; | ||||||
| using Microsoft.AspNetCore.Authorization; | using Microsoft.AspNetCore.Authorization; | ||||||
| @@ -21,7 +24,6 @@ namespace LSA.Core.Thalos.API.Controllers | |||||||
|     [Produces(MimeTypes.ApplicationJson)] |     [Produces(MimeTypes.ApplicationJson)] | ||||||
|     [Consumes(MimeTypes.ApplicationJson)] |     [Consumes(MimeTypes.ApplicationJson)] | ||||||
|     [ApiController] |     [ApiController] | ||||||
|     [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |  | ||||||
|     public class RoleController(IRoleProvider service) : ControllerBase |     public class RoleController(IRoleProvider service) : ControllerBase | ||||||
|     { |     { | ||||||
|         /// <summary> |         /// <summary> | ||||||
| @@ -33,7 +35,8 @@ namespace LSA.Core.Thalos.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)] | ||||||
|         [Permission("RoleManagement.Read")] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         //[Permission("RoleManagement.Read")] | ||||||
|         public async Task<IActionResult> GetAllRolesAsync(CancellationToken cancellationToken) |         public async Task<IActionResult> GetAllRolesAsync(CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.GetAllRoles(cancellationToken).ConfigureAwait(false); |             var result = await service.GetAllRoles(cancellationToken).ConfigureAwait(false); | ||||||
| @@ -51,7 +54,8 @@ namespace LSA.Core.Thalos.API.Controllers | |||||||
|         [HttpGet] |         [HttpGet] | ||||||
|         [Route(Routes.Id)] |         [Route(Routes.Id)] | ||||||
|         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] | ||||||
|         [Permission("RoleManagement.Read")] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         //[Permission("RoleManagement.Read")] | ||||||
|         public async Task<IActionResult> GetRoleByIdAsync([FromRoute] string id, CancellationToken cancellationToken) |         public async Task<IActionResult> GetRoleByIdAsync([FromRoute] string id, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.GetRoleById(id, cancellationToken).ConfigureAwait(false); |             var result = await service.GetRoleById(id, cancellationToken).ConfigureAwait(false); | ||||||
| @@ -74,7 +78,8 @@ namespace LSA.Core.Thalos.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)] | ||||||
|         [Permission("RoleManagement.Write")] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         //[Permission("RoleManagement.Write")] | ||||||
|         public async Task<IActionResult> CreateRoleAsync([FromBody] RoleRequest newRole, CancellationToken cancellationToken) |         public async Task<IActionResult> CreateRoleAsync([FromBody] RoleRequest newRole, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.CreateRole(newRole, cancellationToken).ConfigureAwait(false); |             var result = await service.CreateRole(newRole, cancellationToken).ConfigureAwait(false); | ||||||
| @@ -94,7 +99,8 @@ namespace LSA.Core.Thalos.API.Controllers | |||||||
|         [HttpPut] |         [HttpPut] | ||||||
|         [Route(Routes.Id)] |         [Route(Routes.Id)] | ||||||
|         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] | ||||||
|         [Permission("RoleManagement.Write")] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         //[Permission("RoleManagement.Write")] | ||||||
|         public async Task<IActionResult> UpdateRoleAsync([FromRoute] string id, [FromBody] RoleAdapter entity, CancellationToken cancellationToken) |         public async Task<IActionResult> UpdateRoleAsync([FromRoute] string id, [FromBody] RoleAdapter entity, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             if (id != entity.Id?.ToString()) |             if (id != entity.Id?.ToString()) | ||||||
| @@ -120,7 +126,8 @@ namespace LSA.Core.Thalos.API.Controllers | |||||||
|         [HttpPatch] |         [HttpPatch] | ||||||
|         [Route(Routes.ChangeStatus)] |         [Route(Routes.ChangeStatus)] | ||||||
|         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] | ||||||
|         [Permission("RoleManagement.Write")] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         //[Permission("RoleManagement.Write")] | ||||||
|         public async Task<IActionResult> ChangeRoleStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) |         public async Task<IActionResult> ChangeRoleStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.ChangeRoleStatus(id, newStatus, cancellationToken).ConfigureAwait(false); |             var result = await service.ChangeRoleStatus(id, newStatus, cancellationToken).ConfigureAwait(false); | ||||||
| @@ -139,7 +146,8 @@ namespace LSA.Core.Thalos.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)] | ||||||
|         [Permission("RoleManagement.Write")] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         //[Permission("RoleManagement.Write")] | ||||||
|         public async Task<IActionResult> AddApplicationToRoleAsync([FromRoute] string roleId, [FromRoute] ApplicationsEnum application, CancellationToken cancellationToken) |         public async Task<IActionResult> AddApplicationToRoleAsync([FromRoute] string roleId, [FromRoute] ApplicationsEnum application, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.AddApplicationToRole(roleId, application, cancellationToken).ConfigureAwait(false); |             var result = await service.AddApplicationToRole(roleId, application, cancellationToken).ConfigureAwait(false); | ||||||
| @@ -158,7 +166,8 @@ namespace LSA.Core.Thalos.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)] | ||||||
|         [Permission("RoleManagement.Write")] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         //[Permission("RoleManagement.Write")] | ||||||
|         public async Task<IActionResult> RemoveApplicationFromRoleAsync([FromRoute] string roleId, [FromRoute] ApplicationsEnum application, CancellationToken cancellationToken) |         public async Task<IActionResult> RemoveApplicationFromRoleAsync([FromRoute] string roleId, [FromRoute] ApplicationsEnum application, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.RemoveApplicationFromRole(roleId, application, cancellationToken).ConfigureAwait(false); |             var result = await service.RemoveApplicationFromRole(roleId, application, cancellationToken).ConfigureAwait(false); | ||||||
|   | |||||||
| @@ -4,12 +4,14 @@ | |||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| using Asp.Versioning; | using Asp.Versioning; | ||||||
| using Core.Thalos.BuildingBlocks; | using Core.Blueprint.Mongo; | ||||||
|  | using Core.Thalos.Adapters; | ||||||
|  | using Core.Thalos.Adapters.Attributes; | ||||||
|  | using Core.Thalos.Adapters.Common.Constants; | ||||||
| using Core.Thalos.Provider.Contracts; | using Core.Thalos.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 StatusEnum = Core.Blueprint.Mongo.StatusEnum; |  | ||||||
| using UserRequest = Core.Thalos.Domain.Contexts.Onboarding.Request.UserRequest; | using UserRequest = Core.Thalos.Domain.Contexts.Onboarding.Request.UserRequest; | ||||||
|  |  | ||||||
| namespace LSA.Core.Thalos.API.Controllers | namespace LSA.Core.Thalos.API.Controllers | ||||||
| @@ -33,8 +35,8 @@ namespace LSA.Core.Thalos.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.DefaultScheme)] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|         [Permission("UserManagement.Read")] |         //[Permission("UserManagement.Read")] | ||||||
|         public async Task<IActionResult> GetAllUsers(CancellationToken cancellationToken) |         public async Task<IActionResult> GetAllUsers(CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.GetAllUsers(cancellationToken).ConfigureAwait(false); |             var result = await service.GetAllUsers(cancellationToken).ConfigureAwait(false); | ||||||
| @@ -52,8 +54,8 @@ namespace LSA.Core.Thalos.API.Controllers | |||||||
|         [HttpGet] |         [HttpGet] | ||||||
|         [Route(Routes.Id)] |         [Route(Routes.Id)] | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|         [Permission("UserManagement.Read")] |         //[Permission("UserManagement.Read")] | ||||||
|         public async Task<IActionResult> GetUserById([FromRoute] string id, CancellationToken cancellationToken) |         public async Task<IActionResult> GetUserById([FromRoute] string id, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.GetUserById(id, cancellationToken).ConfigureAwait(false); |             var result = await service.GetUserById(id, cancellationToken).ConfigureAwait(false); | ||||||
| @@ -77,7 +79,7 @@ namespace LSA.Core.Thalos.API.Controllers | |||||||
|         [HttpGet] |         [HttpGet] | ||||||
|         [Route(Routes.Email)] |         [Route(Routes.Email)] | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.GoogleScheme}")] |         //[Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.AzureScheme}")] | ||||||
|         public async Task<IActionResult> GetUserByEmail([FromRoute] string email, CancellationToken cancellationToken) |         public async Task<IActionResult> GetUserByEmail([FromRoute] string email, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.GetUserByEmail(email, cancellationToken).ConfigureAwait(false); |             var result = await service.GetUserByEmail(email, cancellationToken).ConfigureAwait(false); | ||||||
| @@ -125,8 +127,8 @@ namespace LSA.Core.Thalos.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.DefaultScheme)] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|         [Permission("UserManagement.Write")] |         //[Permission("UserManagement.Write")] | ||||||
|         public async Task<IActionResult> CreateUserAsync([FromBody] UserRequest newUser, CancellationToken cancellationToken) |         public async Task<IActionResult> CreateUserAsync([FromBody] UserRequest newUser, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.CreateUser(newUser, cancellationToken).ConfigureAwait(false); |             var result = await service.CreateUser(newUser, cancellationToken).ConfigureAwait(false); | ||||||
| @@ -146,8 +148,8 @@ namespace LSA.Core.Thalos.API.Controllers | |||||||
|         [HttpPut] |         [HttpPut] | ||||||
|         [Route(Routes.Id)] |         [Route(Routes.Id)] | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|         [Permission("UserManagement.Write")] |         //[Permission("UserManagement.Write")] | ||||||
|         public async Task<IActionResult> UpdateUserAsync([FromRoute] string id, [FromBody] UserAdapter entity, CancellationToken cancellationToken) |         public async Task<IActionResult> UpdateUserAsync([FromRoute] string id, [FromBody] UserAdapter entity, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             if (id != entity.Id?.ToString()) |             if (id != entity.Id?.ToString()) | ||||||
| @@ -171,7 +173,7 @@ namespace LSA.Core.Thalos.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.DefaultScheme}, {Schemes.GoogleScheme}")] |         //[Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.AzureScheme}")] | ||||||
|         public async Task<IActionResult> LoginUserAsync([FromRoute] string email, CancellationToken cancellationToken) |         public async Task<IActionResult> LoginUserAsync([FromRoute] string email, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.LogInUser(email, cancellationToken).ConfigureAwait(false); |             var result = await service.LogInUser(email, cancellationToken).ConfigureAwait(false); | ||||||
| @@ -192,7 +194,7 @@ namespace LSA.Core.Thalos.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.DefaultScheme}, {Schemes.GoogleScheme}")] |         //[Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.AzureScheme}")] | ||||||
|         public async Task<IActionResult> LogOutUserSessionAsync([FromRoute] string email, CancellationToken cancellationToken) |         public async Task<IActionResult> LogOutUserSessionAsync([FromRoute] string email, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.LogOutUserSession(email, cancellationToken).ConfigureAwait(false); |             var result = await service.LogOutUserSession(email, cancellationToken).ConfigureAwait(false); | ||||||
| @@ -214,14 +216,94 @@ namespace LSA.Core.Thalos.API.Controllers | |||||||
|         [HttpPatch] |         [HttpPatch] | ||||||
|         [Route(Routes.ChangeStatus)] |         [Route(Routes.ChangeStatus)] | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|         [Permission("UserManagement.Write")] |         //[Permission("UserManagement.Write")] | ||||||
|         public async Task<IActionResult> ChangeUserStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) |         public async Task<IActionResult> ChangeUserStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.ChangeUserStatus(id, newStatus, cancellationToken).ConfigureAwait(false); |             var result = await service.ChangeUserStatus(id, newStatus, cancellationToken).ConfigureAwait(false); | ||||||
|             return Ok(result); |             return Ok(result); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Adds a company to the user's list of companies. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="userId">The user identifier.</param> | ||||||
|  |         /// <param name="companyId">The company identifier to add.</param> | ||||||
|  |         /// <returns>The updated <see cref="UserAdapter"/> entity.</returns> | ||||||
|  |         /// <response code="200">The user with the updated companies.</response> | ||||||
|  |         /// <response code="404">The user or company not found.</response> | ||||||
|  |         /// <response code="500">The service internal error.</response> | ||||||
|  |         [HttpPost] | ||||||
|  |         [Route(Routes.AddCompany)] | ||||||
|  |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|  |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         //[Permission("UserManagement.Write")] | ||||||
|  |         public async Task<IActionResult> AddCompanyToUserAsync([FromRoute] string userId, [FromRoute] string companyId, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.AddCompanyToUser(userId, companyId, cancellationToken).ConfigureAwait(false); | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Removes a company from the user's list of companies. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="userId">The user identifier.</param> | ||||||
|  |         /// <param name="companyId">The company identifier to remove.</param> | ||||||
|  |         /// <returns>The updated <see cref="UserAdapter"/> entity.</returns> | ||||||
|  |         /// <response code="200">The user with the updated companies.</response> | ||||||
|  |         /// <response code="404">The user or company not found.</response> | ||||||
|  |         /// <response code="500">The service internal error.</response> | ||||||
|  |         [HttpDelete] | ||||||
|  |         [Route(Routes.RemoveCompany)] | ||||||
|  |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|  |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         //[Permission("UserManagement.Write")] | ||||||
|  |         public async Task<IActionResult> RemoveCompanyFromUserAsync([FromRoute] string userId, [FromRoute] string companyId, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.RemoveCompanyFromUser(userId, companyId, cancellationToken).ConfigureAwait(false); ; | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Adds a project to the user's list of projects. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="userId">The user identifier.</param> | ||||||
|  |         /// <param name="projectId">The project identifier to add.</param> | ||||||
|  |         /// <returns>The updated <see cref="UserAdapter"/> entity.</returns> | ||||||
|  |         /// <response code="200">The user with the updated projects.</response> | ||||||
|  |         /// <response code="404">The user or project not found.</response> | ||||||
|  |         /// <response code="500">The service internal error.</response> | ||||||
|  |         [HttpPost] | ||||||
|  |         [Route(Routes.AddProject)] | ||||||
|  |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|  |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         //[Permission("UserManagement.Write")] | ||||||
|  |         public async Task<IActionResult> AddProjectToUserAsync([FromRoute] string userId, [FromRoute] string projectId, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.AddProjectToUser(userId, projectId, cancellationToken).ConfigureAwait(false); | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Removes a project from the user's list of projects. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="userId">The user identifier.</param> | ||||||
|  |         /// <param name="projectId">The project identifier to remove.</param> | ||||||
|  |         /// <returns>The updated <see cref="UserAdapter"/> entity.</returns> | ||||||
|  |         /// <response code="200">The user with the updated projects.</response> | ||||||
|  |         /// <response code="404">The user or project not found.</response> | ||||||
|  |         /// <response code="500">The service internal error.</response> | ||||||
|  |         [HttpDelete] | ||||||
|  |         [Route(Routes.RemoveProject)] | ||||||
|  |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|  |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         //[Permission("UserManagement.Write")] | ||||||
|  |         public async Task<IActionResult> RemoveProjectFromUserAsync([FromRoute] string userId, [FromRoute] string projectId, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.RemoveProjectFromUser(userId, projectId, cancellationToken).ConfigureAwait(false); | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets a token for the user, including roles, permissions, and modules. |         /// Gets a token for the user, including roles, permissions, and modules. | ||||||
|         /// </summary> |         /// </summary> | ||||||
| @@ -233,7 +315,7 @@ namespace LSA.Core.Thalos.API.Controllers | |||||||
|         [HttpGet] |         [HttpGet] | ||||||
|         [Route("{email}/GetTokenAdapter")] |         [Route("{email}/GetTokenAdapter")] | ||||||
|         [ProducesResponseType(typeof(TokenAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(TokenAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.GoogleScheme}")] |         //[Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.AzureScheme}")] | ||||||
|         public async Task<IActionResult> GetTokenAdapter([FromRoute] string email, CancellationToken cancellationToken) |         public async Task<IActionResult> GetTokenAdapter([FromRoute] string email, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var tokenAdapter = await service.GetToken(email, cancellationToken).ConfigureAwait(false); |             var tokenAdapter = await service.GetToken(email, cancellationToken).ConfigureAwait(false); | ||||||
|   | |||||||
							
								
								
									
										71
									
								
								Core.Thalos.DAL.API/Extensions/SwaggerExtensions.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								Core.Thalos.DAL.API/Extensions/SwaggerExtensions.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,71 @@ | |||||||
|  | using Asp.Versioning.ApiExplorer; | ||||||
|  | using Microsoft.Extensions.Options; | ||||||
|  | using Microsoft.OpenApi.Any; | ||||||
|  | using Swashbuckle.AspNetCore.SwaggerGen; | ||||||
|  | using Swashbuckle.AspNetCore.SwaggerUI; | ||||||
|  |  | ||||||
|  | namespace Core.Thalos.DAL.API.Extensions | ||||||
|  | { | ||||||
|  |     public static class SwaggerExtensions | ||||||
|  |     { | ||||||
|  |         public static void AddSwagger(this IServiceCollection services) | ||||||
|  |         { | ||||||
|  |             services.AddEndpointsApiExplorer(); | ||||||
|  |             services.AddSwaggerGen(); | ||||||
|  |             services.AddTransient<IConfigureOptions<SwaggerGenOptions>, ConfigureSwaggerOptions>(); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         public static void ConfigureSwagger(this WebApplication app) | ||||||
|  |         { | ||||||
|  |             app.UseSwagger(); | ||||||
|  |             app.UseSwaggerUI(options => | ||||||
|  |             { | ||||||
|  |                 foreach (var version in app.DescribeApiVersions().Select(version => version.GroupName)) | ||||||
|  |                     options.SwaggerEndpoint($"/swagger/{version}/swagger.json", version); | ||||||
|  |  | ||||||
|  |                 options.DisplayRequestDuration(); | ||||||
|  |                 options.EnableTryItOutByDefault(); | ||||||
|  |                 options.DocExpansion(DocExpansion.None); | ||||||
|  |             }); | ||||||
|  |         } | ||||||
|  |         public static IServiceCollection AddVersioning(this IServiceCollection services) | ||||||
|  |         { | ||||||
|  |             services.AddApiVersioning(options => options.ReportApiVersions = true) | ||||||
|  |                    .AddApiExplorer(options => | ||||||
|  |                    { | ||||||
|  |                        options.GroupNameFormat = "'v'VVV"; | ||||||
|  |                        options.SubstituteApiVersionInUrl = true; | ||||||
|  |                    }); | ||||||
|  |  | ||||||
|  |             return services; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     public class ConfigureSwaggerOptions : IConfigureOptions<SwaggerGenOptions> | ||||||
|  |     { | ||||||
|  |         private readonly IApiVersionDescriptionProvider _provider; | ||||||
|  |  | ||||||
|  |         public ConfigureSwaggerOptions(IApiVersionDescriptionProvider provider) | ||||||
|  |         { | ||||||
|  |             _provider = provider; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         public void Configure(SwaggerGenOptions options) | ||||||
|  |         { | ||||||
|  |             foreach (var description in _provider.ApiVersionDescriptions) | ||||||
|  |                 options.SwaggerDoc(description.GroupName, new() | ||||||
|  |                 { | ||||||
|  |                     Title = AppDomain.CurrentDomain.FriendlyName, | ||||||
|  |                     Version = description.ApiVersion.ToString() | ||||||
|  |                 }); | ||||||
|  |  | ||||||
|  |             //Map ALL Values Format TODO | ||||||
|  |             options.MapType<DateOnly>(() => new() | ||||||
|  |             { | ||||||
|  |                 Format = "date", | ||||||
|  |                 Example = new OpenApiString(DateOnly.MinValue.ToString()) | ||||||
|  |             }); | ||||||
|  |  | ||||||
|  |             options.CustomSchemaIds(type => type.ToString().Replace("+", ".")); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -1,9 +1,8 @@ | |||||||
| using Core.Blueprint.DAL.Mongo.Configuration; | using Core.Blueprint.DAL.Mongo.Configuration; | ||||||
| using Core.Blueprint.KeyVault.Configuration; |  | ||||||
| using Core.Blueprint.Logging.Configuration; | using Core.Blueprint.Logging.Configuration; | ||||||
| using Core.Blueprint.Redis.Configuration; | using Core.Blueprint.Redis.Configuration; | ||||||
| using Core.Thalos.BuildingBlocks; | using Core.Thalos.Adapters.Extensions; | ||||||
| using Core.Thalos.BuildingBlocks.Configuration; | using Core.Thalos.DAL.API.Extensions; | ||||||
| using Core.Thalos.Provider; | using Core.Thalos.Provider; | ||||||
| using Microsoft.AspNetCore.HttpLogging; | using Microsoft.AspNetCore.HttpLogging; | ||||||
| using System.Reflection; | using System.Reflection; | ||||||
| @@ -11,19 +10,12 @@ using System.Text.Json.Serialization; | |||||||
|  |  | ||||||
| var builder = WebApplication.CreateBuilder(args); | var builder = WebApplication.CreateBuilder(args); | ||||||
|  |  | ||||||
|  | builder.Services.AddEndpointsApiExplorer(); | ||||||
|  | builder.Services.AddSwaggerGen(); | ||||||
| builder.Configuration | builder.Configuration | ||||||
|     .AddUserSecrets(Assembly.GetExecutingAssembly()) |     .AddUserSecrets(Assembly.GetExecutingAssembly()) | ||||||
|     .AddEnvironmentVariables(); |     .AddEnvironmentVariables(); | ||||||
|  |  | ||||||
| var services = builder.Services.AddKeyVault(builder.Configuration); |  | ||||||
|  |  | ||||||
| var authSettings = await AuthHelper.GetAuthSettings(builder.Services, builder, "thalos_common"); |  | ||||||
|  |  | ||||||
| builder.Services.ConfigureAuthentication(builder.Configuration, authSettings); |  | ||||||
|  |  | ||||||
| builder.Services.AddEndpointsApiExplorer(); |  | ||||||
| builder.Services.AddSwaggerGen(builder.Configuration, "Core.Thalos.DAL.API.xml", authSettings); |  | ||||||
| builder.Services.AddVersioning(builder.Configuration); |  | ||||||
| builder.Services.AddResponseCompression(); | builder.Services.AddResponseCompression(); | ||||||
| builder.Services.AddProblemDetails(); | builder.Services.AddProblemDetails(); | ||||||
| builder.Services.AddMemoryCache(); | builder.Services.AddMemoryCache(); | ||||||
| @@ -50,6 +42,11 @@ builder.Host.ConfigureServices((context, services) => | |||||||
|         options.SerializerOptions.Converters.Add(new JsonStringEnumConverter()); |         options.SerializerOptions.Converters.Add(new JsonStringEnumConverter()); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|  |     services | ||||||
|  |         .AddEndpointsApiExplorer() | ||||||
|  |         .AddVersioning() | ||||||
|  |         .AddSwagger(); | ||||||
|  |  | ||||||
|     services.AddHealthChecks(); |     services.AddHealthChecks(); | ||||||
|     services.AddHttpLogging(options => options.LoggingFields = HttpLoggingFields.All); |     services.AddHttpLogging(options => options.LoggingFields = HttpLoggingFields.All); | ||||||
|  |  | ||||||
| @@ -66,22 +63,20 @@ builder.Host.ConfigureServices((context, services) => | |||||||
|  |  | ||||||
| var app = builder.Build(); | var app = builder.Build(); | ||||||
|  |  | ||||||
| app.UseLogging(builder.Configuration); | app.UseSwagger(); | ||||||
| app.UseSwaggerUI(builder.Configuration, authSettings); | app.UseSwaggerUI(); | ||||||
| app.ConfigureSwagger(builder.Configuration); | app.UseAuthentication(); | ||||||
|  | app.UseAuthorization(); | ||||||
| app.UseRouting(); | app.MapControllers(); | ||||||
| app.UseCors(); | app.UseCors(); | ||||||
|  | app.ConfigureSwagger(); | ||||||
| app.UseHttpsRedirection(); | app.UseHttpsRedirection(); | ||||||
| app.UseStaticFiles(); | app.UseStaticFiles(); | ||||||
|  | app.UseRouting(); | ||||||
| app.UseResponseCompression(); | app.UseResponseCompression(); | ||||||
| app.UseOutputCache(); | app.UseOutputCache(); | ||||||
| app.UseResponseCaching(); | app.UseResponseCaching(); | ||||||
|  | app.UseLogging(builder.Configuration); | ||||||
| app.UseAuthentication(); |  | ||||||
| app.UseAuthorization(); |  | ||||||
|  |  | ||||||
| app.MapControllers(); |  | ||||||
| app.MapHealthChecks("/health"); | app.MapHealthChecks("/health"); | ||||||
|  |  | ||||||
| app.Run(); | app.Run(); | ||||||
| @@ -22,14 +22,5 @@ | |||||||
|   "ServiceSettings": { |   "ServiceSettings": { | ||||||
|     "ApplicationName": "thalos", |     "ApplicationName": "thalos", | ||||||
|     "LayerName": "dal" |     "LayerName": "dal" | ||||||
|   }, |  | ||||||
|   "Vault": { |  | ||||||
|     "Address": "http://100.123.31.103:8200", |  | ||||||
|     "Token": "hvs.e37LQvLuPhTd5ALS5QQ03Cwm", |  | ||||||
|     "SecretMount": "secret" |  | ||||||
|   }, |  | ||||||
|   "IdentityProviders": { |  | ||||||
|     "Google": true, |  | ||||||
|     "Azure":  true |  | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -4,5 +4,19 @@ | |||||||
|       "Default": "Information", |       "Default": "Information", | ||||||
|       "Microsoft.AspNetCore": "Warning" |       "Microsoft.AspNetCore": "Warning" | ||||||
|     } |     } | ||||||
|  |   }, | ||||||
|  |   "AllowedHosts": "*", | ||||||
|  |   "ConnectionStrings": { | ||||||
|  |     "MongoDB": "mongodb://admin_agile:Admin%40agileWebs@portainer.white-enciso.pro:27017/?authMechanism=SCRAM-SHA-256", | ||||||
|  |     "Redis": "localhost:6379" | ||||||
|  |   }, | ||||||
|  |   "MongoDb": { | ||||||
|  |     "DatabaseName": "Thalos", | ||||||
|  |     "LocalAudience": "" | ||||||
|  |   }, | ||||||
|  |   "DetailedErrors": true, | ||||||
|  |   "UseRedisCache": true, | ||||||
|  |   "CacheSettings": { | ||||||
|  |     "DefaultCacheDurationInMinutes": 3 | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -4,7 +4,7 @@ | |||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
|  |  | ||||||
| using Core.Thalos.BuildingBlocks; | 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; | ||||||
|   | |||||||
| @@ -4,7 +4,7 @@ | |||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
|  |  | ||||||
| using Core.Thalos.BuildingBlocks; | 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; | ||||||
|   | |||||||
| @@ -4,7 +4,7 @@ | |||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
|  |  | ||||||
| using Core.Thalos.BuildingBlocks; | 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; | ||||||
|   | |||||||
| @@ -54,5 +54,19 @@ namespace Core.Thalos.Domain.Contexts.Onboarding.Request | |||||||
|         [BsonRepresentation(BsonType.ObjectId)] |         [BsonRepresentation(BsonType.ObjectId)] | ||||||
|         [JsonPropertyName("roleId")] |         [JsonPropertyName("roleId")] | ||||||
|         public string RoleId { get; set; } = null!; |         public string RoleId { get; set; } = null!; | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets or sets the array of companies associated with the user. | ||||||
|  |         /// </summary> | ||||||
|  |         [BsonElement("companies")] | ||||||
|  |         [JsonPropertyName("companies")] | ||||||
|  |         public string[] Companies { get; set; } = null!; | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets or sets the array of projects associated with the user. | ||||||
|  |         /// </summary> | ||||||
|  |         [BsonElement("projects")] | ||||||
|  |         [JsonPropertyName("projects")] | ||||||
|  |         public string[]? Projects { get; set; } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -7,8 +7,7 @@ | |||||||
|   </PropertyGroup> |   </PropertyGroup> | ||||||
|  |  | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <PackageReference Include="Core.Blueprint.KeyVault" Version="1.0.3" /> |     <PackageReference Include="Core.Thalos.BuildingBlocks" Version="1.0.3" /> | ||||||
|     <PackageReference Include="Core.Thalos.BuildingBlocks" Version="1.0.8" /> |  | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|  |  | ||||||
| </Project> | </Project> | ||||||
|   | |||||||
| @@ -3,7 +3,8 @@ | |||||||
| //     AgileWebs | //     AgileWebs | ||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| using Core.Thalos.BuildingBlocks; | using Core.Blueprint.Mongo; | ||||||
|  | using Core.Thalos.Adapters; | ||||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
|  |  | ||||||
| namespace Core.Thalos.Provider.Contracts | namespace Core.Thalos.Provider.Contracts | ||||||
| @@ -49,7 +50,7 @@ namespace Core.Thalos.Provider.Contracts | |||||||
|         /// <returns>The <see cref="ModuleAdapter"/> updated entity.</returns> |         /// <returns>The <see cref="ModuleAdapter"/> updated entity.</returns> | ||||||
|         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing |         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         ValueTask<ModuleAdapter> ChangeModuleStatus(string id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken); |         ValueTask<ModuleAdapter> ChangeModuleStatus(string id, StatusEnum newStatus, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Updates a Module by id. |         /// Updates a Module by id. | ||||||
|   | |||||||
| @@ -3,7 +3,8 @@ | |||||||
| //     AgileWebs | //     AgileWebs | ||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| using Core.Thalos.BuildingBlocks; | using Core.Blueprint.Mongo; | ||||||
|  | using Core.Thalos.Adapters; | ||||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
|  |  | ||||||
| namespace Core.Thalos.Provider.Contracts | namespace Core.Thalos.Provider.Contracts | ||||||
| @@ -49,7 +50,7 @@ namespace Core.Thalos.Provider.Contracts | |||||||
|         /// <returns>The <see cref="PermissionAdapter"/> updated entity.</returns> |         /// <returns>The <see cref="PermissionAdapter"/> updated entity.</returns> | ||||||
|         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing |         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         ValueTask<PermissionAdapter> ChangePermissionStatus(string id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken); |         ValueTask<PermissionAdapter> ChangePermissionStatus(string id, StatusEnum newStatus, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Updates a Permission by id. |         /// Updates a Permission by id. | ||||||
|   | |||||||
| @@ -3,7 +3,8 @@ | |||||||
| //     AgileWebs | //     AgileWebs | ||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| using Core.Thalos.BuildingBlocks; | using Core.Thalos.Adapters; | ||||||
|  | using Core.Thalos.Adapters.Common.Enums; | ||||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
|  |  | ||||||
| namespace Core.Thalos.Provider.Contracts | namespace Core.Thalos.Provider.Contracts | ||||||
|   | |||||||
| @@ -3,7 +3,8 @@ | |||||||
| //     AgileWebs | //     AgileWebs | ||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| using Core.Thalos.BuildingBlocks; | using Core.Blueprint.Mongo; | ||||||
|  | using Core.Thalos.Adapters; | ||||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
|  |  | ||||||
| namespace Core.Thalos.Provider.Contracts | namespace Core.Thalos.Provider.Contracts | ||||||
| @@ -57,7 +58,7 @@ namespace Core.Thalos.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> | ||||||
|         ValueTask<UserAdapter> ChangeUserStatus(string id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken); |         ValueTask<UserAdapter> ChangeUserStatus(string id, StatusEnum newStatus, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Updates a User by id. |         /// Updates a User by id. | ||||||
| @@ -84,6 +85,39 @@ namespace Core.Thalos.Provider.Contracts | |||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         ValueTask<UserAdapter?> LogOutUserSession(string email, CancellationToken cancellationToken); |         ValueTask<UserAdapter?> LogOutUserSession(string email, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <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> | ||||||
|  |         ValueTask<UserAdapter> AddCompanyToUser(string userId, string companyId, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <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> | ||||||
|  |         ValueTask<UserAdapter> RemoveCompanyFromUser(string userId, string companyId, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |         /// <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> | ||||||
|  |         ValueTask<UserAdapter> AddProjectToUser(string userId, string projectId, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |  | ||||||
|  |         /// <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> | ||||||
|  |         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> | ||||||
|   | |||||||
| @@ -3,15 +3,15 @@ | |||||||
| //     AgileWebs | //     AgileWebs | ||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
|  | using Core.Thalos.Adapters; | ||||||
| using Core.Blueprint.Mongo; | using Core.Blueprint.Mongo; | ||||||
| using Core.Blueprint.Redis; |  | ||||||
| using Core.Blueprint.Redis.Helpers; |  | ||||||
| using Core.Thalos.BuildingBlocks; |  | ||||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; |  | ||||||
| using Core.Thalos.Provider.Contracts; |  | ||||||
| using Mapster; | using Mapster; | ||||||
| using Microsoft.Extensions.Options; | using Microsoft.Extensions.Options; | ||||||
| using MongoDB.Driver; | using MongoDB.Driver; | ||||||
|  | using Core.Thalos.Provider.Contracts; | ||||||
|  | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
|  | using Core.Blueprint.Redis; | ||||||
|  | using Core.Blueprint.Redis.Helpers; | ||||||
|  |  | ||||||
| namespace Core.Thalos.Provider.Providers.Onboarding | namespace Core.Thalos.Provider.Providers.Onboarding | ||||||
| { | { | ||||||
|   | |||||||
| @@ -6,7 +6,7 @@ | |||||||
| using Core.Blueprint.Mongo; | using Core.Blueprint.Mongo; | ||||||
| using Core.Blueprint.Redis; | using Core.Blueprint.Redis; | ||||||
| using Core.Blueprint.Redis.Helpers; | using Core.Blueprint.Redis.Helpers; | ||||||
| using Core.Thalos.BuildingBlocks; | using Core.Thalos.Adapters; | ||||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
| using Core.Thalos.Provider.Contracts; | using Core.Thalos.Provider.Contracts; | ||||||
| using Mapster; | using Mapster; | ||||||
| @@ -128,7 +128,7 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|         /// <param name="newStatus">The new status of the permission.</param> |         /// <param name="newStatus">The new status of the permission.</param> | ||||||
|         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing |         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         public async ValueTask<PermissionAdapter> ChangePermissionStatus(string id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken) |         public async ValueTask<PermissionAdapter> ChangePermissionStatus(string id, StatusEnum newStatus, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var entity = await repository.FindByIdAsync(id); |             var entity = await repository.FindByIdAsync(id); | ||||||
|             entity.Status = newStatus; |             entity.Status = newStatus; | ||||||
|   | |||||||
| @@ -6,12 +6,18 @@ | |||||||
| using Core.Blueprint.Mongo; | using Core.Blueprint.Mongo; | ||||||
| using Core.Blueprint.Redis; | using Core.Blueprint.Redis; | ||||||
| using Core.Blueprint.Redis.Helpers; | using Core.Blueprint.Redis.Helpers; | ||||||
| using Core.Thalos.BuildingBlocks; | using Core.Thalos.Adapters; | ||||||
|  | using Core.Thalos.Adapters.Common.Enums; | ||||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
| using Core.Thalos.Provider.Contracts; | using Core.Thalos.Provider.Contracts; | ||||||
| using Mapster; | using Mapster; | ||||||
| using Microsoft.Extensions.Options; | using Microsoft.Extensions.Options; | ||||||
|  | using Microsoft.Graph; | ||||||
|  | using MongoDB.Bson; | ||||||
|  | using MongoDB.Bson.Serialization; | ||||||
| using MongoDB.Driver; | using MongoDB.Driver; | ||||||
|  | using System.ComponentModel.Design; | ||||||
|  | using System.Text.RegularExpressions; | ||||||
|  |  | ||||||
| namespace Core.Thalos.Provider.Providers.Onboarding | namespace Core.Thalos.Provider.Providers.Onboarding | ||||||
| { | { | ||||||
| @@ -21,19 +27,19 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|     public class RoleProvider : IRoleProvider |     public class RoleProvider : IRoleProvider | ||||||
|     { |     { | ||||||
|         private readonly CollectionRepository<RoleAdapter> repository; |         private readonly CollectionRepository<RoleAdapter> repository; | ||||||
|         private readonly CacheSettings cacheSettings; | 		private readonly CacheSettings cacheSettings; | ||||||
|         private readonly IRedisCacheProvider cacheProvider; | 		private readonly IRedisCacheProvider cacheProvider; | ||||||
|  |  | ||||||
|         public RoleProvider(CollectionRepository<RoleAdapter> repository, | 		public RoleProvider(CollectionRepository<RoleAdapter> repository, | ||||||
|             IRedisCacheProvider cacheProvider, | 		    IRedisCacheProvider cacheProvider, | ||||||
|             IOptions<CacheSettings> cacheSettings | 			IOptions<CacheSettings> cacheSettings | ||||||
|             ) | 			) | ||||||
|         { |         { | ||||||
|             this.repository = repository; |             this.repository = repository; | ||||||
|             this.repository.CollectionInitialization(); |             this.repository.CollectionInitialization(); | ||||||
|             this.cacheSettings = cacheSettings.Value; | 			this.cacheSettings = cacheSettings.Value; | ||||||
|             this.cacheProvider = cacheProvider; | 			this.cacheProvider = cacheProvider; | ||||||
|         } | 		} | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Creates a new Role. |         /// Creates a new Role. | ||||||
|   | |||||||
| @@ -7,13 +7,15 @@ | |||||||
| using Core.Blueprint.Mongo; | using Core.Blueprint.Mongo; | ||||||
| using Core.Blueprint.Redis; | using Core.Blueprint.Redis; | ||||||
| using Core.Blueprint.Redis.Helpers; | using Core.Blueprint.Redis.Helpers; | ||||||
| using Core.Thalos.BuildingBlocks; | using Core.Thalos.Adapters; | ||||||
|  | using Core.Thalos.Adapters.Common.Enums; | ||||||
| using Core.Thalos.Provider.Contracts; | using Core.Thalos.Provider.Contracts; | ||||||
| using Mapster; | using Mapster; | ||||||
| using Microsoft.Extensions.Options; | using Microsoft.Extensions.Options; | ||||||
| using MongoDB.Bson; | using MongoDB.Bson; | ||||||
| using MongoDB.Bson.Serialization; | using MongoDB.Bson.Serialization; | ||||||
| using MongoDB.Driver; | using MongoDB.Driver; | ||||||
|  | using System.Reflection; | ||||||
| using System.Text.RegularExpressions; | using System.Text.RegularExpressions; | ||||||
|  |  | ||||||
| namespace Core.Thalos.Provider.Providers.Onboarding | namespace Core.Thalos.Provider.Providers.Onboarding | ||||||
| @@ -25,18 +27,18 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|     { |     { | ||||||
|         private readonly CollectionRepository<UserAdapter> repository; |         private readonly CollectionRepository<UserAdapter> repository; | ||||||
|         private readonly CacheSettings cacheSettings; |         private readonly CacheSettings cacheSettings; | ||||||
|         private readonly IRedisCacheProvider cacheProvider; | 		private readonly IRedisCacheProvider cacheProvider; | ||||||
|  |  | ||||||
|         public UserProvider(CollectionRepository<UserAdapter> repository, | 		public UserProvider(CollectionRepository<UserAdapter> repository, | ||||||
|             IRedisCacheProvider cacheProvider, |             IRedisCacheProvider cacheProvider, | ||||||
|             IOptions<CacheSettings> cacheSettings | 			IOptions<CacheSettings> cacheSettings | ||||||
|             ) |             ) | ||||||
|         { |         { | ||||||
|             this.repository = repository; |             this.repository = repository; | ||||||
|             this.repository.CollectionInitialization(); |             this.repository.CollectionInitialization(); | ||||||
|             this.cacheSettings = cacheSettings.Value; | 			this.cacheSettings = cacheSettings.Value; | ||||||
|             this.cacheProvider = cacheProvider; | 			this.cacheProvider = cacheProvider; | ||||||
|         } | 		} | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Creates a new User. |         /// Creates a new User. | ||||||
| @@ -106,7 +108,7 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|             //if (cachedData is not null) { return cachedData; } |             //if (cachedData is not null) { return cachedData; } | ||||||
|  |  | ||||||
|             var user = await repository.FindOneAsync( |             var user = await repository.FindOneAsync( | ||||||
|                 u => u.Email == email && |                 u => u.Email == email &&  | ||||||
|                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); |                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); | ||||||
|  |  | ||||||
|             await cacheProvider.SetAsync(cacheKey, user); |             await cacheProvider.SetAsync(cacheKey, user); | ||||||
| @@ -209,6 +211,92 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|             return 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.Projects = 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.Projects = updatedProjects; | ||||||
|  |  | ||||||
|  |             await repository.ReplaceOneAsync(user); | ||||||
|  |  | ||||||
|  |             return user; | ||||||
|  |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets the token adapter for a user. |         /// Gets the token adapter for a user. | ||||||
|         /// </summary> |         /// </summary> | ||||||
| @@ -325,6 +413,18 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|                         LastName = result.Contains("lastName") && !result["lastName"].IsBsonNull ? result["lastName"].AsString : "", |                         LastName = result.Contains("lastName") && !result["lastName"].IsBsonNull ? result["lastName"].AsString : "", | ||||||
|                         DisplayName = result.Contains("displayName") && !result["displayName"].IsBsonNull ? result["displayName"].AsString : "", |                         DisplayName = result.Contains("displayName") && !result["displayName"].IsBsonNull ? result["displayName"].AsString : "", | ||||||
|                         RoleId = result.Contains("roleId") && !result["roleId"].IsBsonNull ? result["roleId"].ToString() : "", |                         RoleId = result.Contains("roleId") && !result["roleId"].IsBsonNull ? result["roleId"].ToString() : "", | ||||||
|  |                         Companies = result.Contains("companies") && result["companies"].IsBsonArray | ||||||
|  |                             ? result["companies"].AsBsonArray | ||||||
|  |                                 .Where(c => c != null && !c.IsBsonNull) | ||||||
|  |                                 .Select(c => c.AsString) | ||||||
|  |                                 .ToArray() | ||||||
|  |                             : Array.Empty<string>(), | ||||||
|  |                                         Projects = result.Contains("projects") && result["projects"].IsBsonArray | ||||||
|  |                             ? result["projects"].AsBsonArray | ||||||
|  |                                 .Where(p => p != null && !p.IsBsonNull) | ||||||
|  |                                 .Select(p => p.AsString) | ||||||
|  |                                 .ToArray() | ||||||
|  |                             : Array.Empty<string>(), | ||||||
|                         LastLogIn = result.Contains("lastLogIn") && !result["lastLogIn"].IsBsonNull ? result["lastLogIn"].ToUniversalTime() : DateTime.MinValue, |                         LastLogIn = result.Contains("lastLogIn") && !result["lastLogIn"].IsBsonNull ? result["lastLogIn"].ToUniversalTime() : DateTime.MinValue, | ||||||
|                         LastLogOut = result.Contains("lastLogOut") && !result["lastLogOut"].IsBsonNull ? result["lastLogOut"].ToUniversalTime() : DateTime.MinValue, |                         LastLogOut = result.Contains("lastLogOut") && !result["lastLogOut"].IsBsonNull ? result["lastLogOut"].ToUniversalTime() : DateTime.MinValue, | ||||||
|                         CreatedAt = result.Contains("createdAt") && !result["createdAt"].IsBsonNull ? result["createdAt"].ToUniversalTime() : DateTime.MinValue, |                         CreatedAt = result.Contains("createdAt") && !result["createdAt"].IsBsonNull ? result["createdAt"].ToUniversalTime() : DateTime.MinValue, | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| using Core.Blueprint.Mongo; | using Core.Blueprint.Mongo; | ||||||
| using Core.Thalos.BuildingBlocks; | using Core.Thalos.Adapters; | ||||||
| using Core.Thalos.Provider.Contracts; | using Core.Thalos.Provider.Contracts; | ||||||
| using Core.Thalos.Provider.Providers.Onboarding; | using Core.Thalos.Provider.Providers.Onboarding; | ||||||
| using Microsoft.Extensions.Configuration; | using Microsoft.Extensions.Configuration; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user