|
|
|
|
@ -2,6 +2,8 @@
@@ -2,6 +2,8 @@
|
|
|
|
|
using Bit.Api.SecretManagerFeatures.Models.Request; |
|
|
|
|
using Bit.Api.SecretManagerFeatures.Models.Response; |
|
|
|
|
using Bit.Api.Utilities; |
|
|
|
|
using Bit.Core.Context; |
|
|
|
|
using Bit.Core.Entities; |
|
|
|
|
using Bit.Core.Exceptions; |
|
|
|
|
using Bit.Core.Repositories; |
|
|
|
|
using Bit.Core.SecretManagerFeatures.Projects.Interfaces; |
|
|
|
|
@ -18,19 +20,22 @@ public class ProjectsController : Controller
@@ -18,19 +20,22 @@ public class ProjectsController : Controller
|
|
|
|
|
private readonly ICreateProjectCommand _createProjectCommand; |
|
|
|
|
private readonly IUpdateProjectCommand _updateProjectCommand; |
|
|
|
|
private readonly IDeleteProjectCommand _deleteProjectCommand; |
|
|
|
|
private readonly ICurrentContext _currentContext; |
|
|
|
|
|
|
|
|
|
public ProjectsController( |
|
|
|
|
IUserService userService, |
|
|
|
|
IProjectRepository projectRepository, |
|
|
|
|
ICreateProjectCommand createProjectCommand, |
|
|
|
|
IUpdateProjectCommand updateProjectCommand, |
|
|
|
|
IDeleteProjectCommand deleteProjectCommand) |
|
|
|
|
IDeleteProjectCommand deleteProjectCommand, |
|
|
|
|
ICurrentContext currentContext) |
|
|
|
|
{ |
|
|
|
|
_userService = userService; |
|
|
|
|
_projectRepository = projectRepository; |
|
|
|
|
_createProjectCommand = createProjectCommand; |
|
|
|
|
_updateProjectCommand = updateProjectCommand; |
|
|
|
|
_deleteProjectCommand = deleteProjectCommand; |
|
|
|
|
_currentContext = currentContext; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[HttpPost("organizations/{organizationId}/projects")] |
|
|
|
|
@ -51,7 +56,16 @@ public class ProjectsController : Controller
@@ -51,7 +56,16 @@ public class ProjectsController : Controller
|
|
|
|
|
public async Task<ListResponseModel<ProjectResponseModel>> GetProjectsByOrganizationAsync([FromRoute] Guid organizationId) |
|
|
|
|
{ |
|
|
|
|
var userId = _userService.GetProperUserId(User).Value; |
|
|
|
|
var projects = await _projectRepository.GetManyByOrganizationIdAsync(organizationId, userId); |
|
|
|
|
IEnumerable<Project> projects; |
|
|
|
|
if (await _currentContext.OrganizationAdmin(organizationId)) |
|
|
|
|
{ |
|
|
|
|
// Fetch all projects without access checks since admins have access to all |
|
|
|
|
projects = await _projectRepository.GetAllByOrganizationIdAsync(organizationId); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
projects = await _projectRepository.GetManyByOrganizationIdAsync(organizationId, userId); |
|
|
|
|
} |
|
|
|
|
var responses = projects.Select(project => new ProjectResponseModel(project)); |
|
|
|
|
return new ListResponseModel<ProjectResponseModel>(responses); |
|
|
|
|
} |
|
|
|
|
|