diff --git a/Core.Thalos.DAL.API/Controllers/UserController.cs b/Core.Thalos.DAL.API/Controllers/UserController.cs index f5ddb8e..0eaaee7 100644 --- a/Core.Thalos.DAL.API/Controllers/UserController.cs +++ b/Core.Thalos.DAL.API/Controllers/UserController.cs @@ -222,86 +222,6 @@ namespace LSA.Core.Thalos.API.Controllers return Ok(result); } - /// - /// Adds a company to the user's list of companies. - /// - /// The user identifier. - /// The company identifier to add. - /// The updated entity. - /// The user with the updated companies. - /// The user or company not found. - /// The service internal error. - [HttpPost] - [Route(Routes.AddCompany)] - [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] - [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] - [Permission("UserManagement.Write")] - public async Task AddCompanyToUserAsync([FromRoute] string userId, [FromRoute] string companyId, CancellationToken cancellationToken) - { - var result = await service.AddCompanyToUser(userId, companyId, cancellationToken).ConfigureAwait(false); - return Ok(result); - } - - /// - /// Removes a company from the user's list of companies. - /// - /// The user identifier. - /// The company identifier to remove. - /// The updated entity. - /// The user with the updated companies. - /// The user or company not found. - /// The service internal error. - [HttpDelete] - [Route(Routes.RemoveCompany)] - [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] - [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] - [Permission("UserManagement.Write")] - public async Task RemoveCompanyFromUserAsync([FromRoute] string userId, [FromRoute] string companyId, CancellationToken cancellationToken) - { - var result = await service.RemoveCompanyFromUser(userId, companyId, cancellationToken).ConfigureAwait(false); ; - return Ok(result); - } - - /// - /// Adds a project to the user's list of projects. - /// - /// The user identifier. - /// The project identifier to add. - /// The updated entity. - /// The user with the updated projects. - /// The user or project not found. - /// The service internal error. - [HttpPost] - [Route(Routes.AddProject)] - [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] - [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] - [Permission("UserManagement.Write")] - public async Task AddProjectToUserAsync([FromRoute] string userId, [FromRoute] string projectId, CancellationToken cancellationToken) - { - var result = await service.AddProjectToUser(userId, projectId, cancellationToken).ConfigureAwait(false); - return Ok(result); - } - - /// - /// Removes a project from the user's list of projects. - /// - /// The user identifier. - /// The project identifier to remove. - /// The updated entity. - /// The user with the updated projects. - /// The user or project not found. - /// The service internal error. - [HttpDelete] - [Route(Routes.RemoveProject)] - [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] - [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] - [Permission("UserManagement.Write")] - public async Task RemoveProjectFromUserAsync([FromRoute] string userId, [FromRoute] string projectId, CancellationToken cancellationToken) - { - var result = await service.RemoveProjectFromUser(userId, projectId, cancellationToken).ConfigureAwait(false); - return Ok(result); - } - /// /// Gets a token for the user, including roles, permissions, and modules. /// diff --git a/Core.Thalos.Domain/Contexts/Onboarding/Request/UserRequest.cs b/Core.Thalos.Domain/Contexts/Onboarding/Request/UserRequest.cs index bcbcd79..8af4687 100644 --- a/Core.Thalos.Domain/Contexts/Onboarding/Request/UserRequest.cs +++ b/Core.Thalos.Domain/Contexts/Onboarding/Request/UserRequest.cs @@ -54,19 +54,5 @@ namespace Core.Thalos.Domain.Contexts.Onboarding.Request [BsonRepresentation(BsonType.ObjectId)] [JsonPropertyName("roleId")] public string RoleId { get; set; } = null!; - - /// - /// Gets or sets the array of companies associated with the user. - /// - [BsonElement("companies")] - [JsonPropertyName("companies")] - public string[] Companies { get; set; } = null!; - - /// - /// Gets or sets the array of projects associated with the user. - /// - [BsonElement("projects")] - [JsonPropertyName("projects")] - public string[]? Projects { get; set; } } } diff --git a/Core.Thalos.Domain/Core.Thalos.Domain.csproj b/Core.Thalos.Domain/Core.Thalos.Domain.csproj index 5fa5c3c..d09f8c0 100644 --- a/Core.Thalos.Domain/Core.Thalos.Domain.csproj +++ b/Core.Thalos.Domain/Core.Thalos.Domain.csproj @@ -8,7 +8,7 @@ - + diff --git a/Core.Thalos.Provider/Contracts/IUserProvider.cs b/Core.Thalos.Provider/Contracts/IUserProvider.cs index a670c9c..2af9487 100644 --- a/Core.Thalos.Provider/Contracts/IUserProvider.cs +++ b/Core.Thalos.Provider/Contracts/IUserProvider.cs @@ -84,39 +84,6 @@ namespace Core.Thalos.Provider.Contracts /// the asynchronous execution of the service. ValueTask LogOutUserSession(string email, CancellationToken cancellationToken); - /// - /// Adds a company to the user's list of companies. - /// - /// The identifier of the user to whom the company will be added. - /// The identifier of the company to add. - /// A representing the asynchronous operation, with the updated user object. - ValueTask AddCompanyToUser(string userId, string companyId, CancellationToken cancellationToken); - - /// - /// Removes a company from the user's list of companies. - /// - /// The identifier of the user from whom the company will be removed. - /// The identifier of the company to remove. - /// A representing the asynchronous operation, with the updated user object. - ValueTask RemoveCompanyFromUser(string userId, string companyId, CancellationToken cancellationToken); - - /// - /// Adds a project to the user's list of projects. - /// - /// The identifier of the user to whom the project will be added. - /// The identifier of the project to add. - /// A representing the asynchronous operation, with the updated user object. - ValueTask AddProjectToUser(string userId, string projectId, CancellationToken cancellationToken); - - - /// - /// Removes a project from the user's list of projects. - /// - /// The identifier of the user from whom the project will be removed. - /// The identifier of the project to remove. - /// A representing the asynchronous operation, with the updated user object. - ValueTask RemoveProjectFromUser(string userId, string projectId, CancellationToken cancellationToken); - /// /// Gets the token adapter for a user. /// diff --git a/Core.Thalos.Provider/Providers/Onboarding/UserProvider.cs b/Core.Thalos.Provider/Providers/Onboarding/UserProvider.cs index 0b8a570..9d9888b 100644 --- a/Core.Thalos.Provider/Providers/Onboarding/UserProvider.cs +++ b/Core.Thalos.Provider/Providers/Onboarding/UserProvider.cs @@ -209,92 +209,6 @@ namespace Core.Thalos.Provider.Providers.Onboarding return user; } - /// - /// Adds a company to the user's list of companies. - /// - /// The identifier of the user to whom the company will be added. - /// The identifier of the company to add. - /// A representing the asynchronous operation, with the updated user object. - public async ValueTask 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; - } - - /// - /// Removes a company from the user's list of companies. - /// - /// The identifier of the user from whom the company will be removed. - /// The identifier of the company to remove. - /// A representing the asynchronous operation, with the updated user object. - public async ValueTask 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; - } - - /// - /// Adds a project to the user's list of projects. - /// - /// The identifier of the user to whom the project will be added. - /// The identifier of the project to add. - /// A representing the asynchronous operation, with the updated user object. - public async ValueTask 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; - } - - /// - /// Removes a project from the user's list of projects. - /// - /// The identifier of the user from whom the project will be removed. - /// The identifier of the project to remove. - /// A representing the asynchronous operation, with the updated user object. - public async ValueTask 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; - } - /// /// Gets the token adapter for a user. /// @@ -411,18 +325,6 @@ namespace Core.Thalos.Provider.Providers.Onboarding LastName = result.Contains("lastName") && !result["lastName"].IsBsonNull ? result["lastName"].AsString : "", DisplayName = result.Contains("displayName") && !result["displayName"].IsBsonNull ? result["displayName"].AsString : "", 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(), - Projects = result.Contains("projects") && result["projects"].IsBsonArray - ? result["projects"].AsBsonArray - .Where(p => p != null && !p.IsBsonNull) - .Select(p => p.AsString) - .ToArray() - : Array.Empty(), LastLogIn = result.Contains("lastLogIn") && !result["lastLogIn"].IsBsonNull ? result["lastLogIn"].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,