Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions bitwarden_license/src/Scim/Controllers/v2/GroupsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
}

[HttpGet("{id}")]
public async Task<IActionResult> Get(Guid organizationId, Guid id)

Check warning on line 51 in bitwarden_license/src/Scim/Controllers/v2/GroupsController.cs

View workflow job for this annotation

GitHub Actions / Sonar / Quality scan

ModelState.IsValid should be checked in controller actions. (https://rules.sonarsource.com/csharp/RSPEC-6967)
{
var group = await _groupRepository.GetByIdAsync(id);
if (group == null || group.OrganizationId != organizationId)
Expand All @@ -59,25 +59,23 @@
}

[HttpGet("")]
public async Task<IActionResult> Get(

Check warning on line 62 in bitwarden_license/src/Scim/Controllers/v2/GroupsController.cs

View workflow job for this annotation

GitHub Actions / Sonar / Quality scan

ModelState.IsValid should be checked in controller actions. (https://rules.sonarsource.com/csharp/RSPEC-6967)
Guid organizationId,
[FromQuery] string filter,
[FromQuery] int? count,
[FromQuery] int? startIndex)
[FromQuery] GetGroupsQueryParamModel model)
{
var groupsListQueryResult = await _getGroupsListQuery.GetGroupsListAsync(organizationId, filter, count, startIndex);
var groupsListQueryResult = await _getGroupsListQuery.GetGroupsListAsync(organizationId, model);
var scimListResponseModel = new ScimListResponseModel<ScimGroupResponseModel>
{
Resources = groupsListQueryResult.groupList.Select(g => new ScimGroupResponseModel(g)).ToList(),
ItemsPerPage = count.GetValueOrDefault(groupsListQueryResult.groupList.Count()),
ItemsPerPage = model.Count,
TotalResults = groupsListQueryResult.totalResults,
StartIndex = startIndex.GetValueOrDefault(1),
StartIndex = model.StartIndex,
};
return Ok(scimListResponseModel);
}

[HttpPost("")]
public async Task<IActionResult> Post(Guid organizationId, [FromBody] ScimGroupRequestModel model)

Check warning on line 78 in bitwarden_license/src/Scim/Controllers/v2/GroupsController.cs

View workflow job for this annotation

GitHub Actions / Sonar / Quality scan

ModelState.IsValid should be checked in controller actions. (https://rules.sonarsource.com/csharp/RSPEC-6967)
{
var organization = await _organizationRepository.GetByIdAsync(organizationId);
var group = await _postGroupCommand.PostGroupAsync(organization, model);
Expand All @@ -86,7 +84,7 @@
}

[HttpPut("{id}")]
public async Task<IActionResult> Put(Guid organizationId, Guid id, [FromBody] ScimGroupRequestModel model)

Check warning on line 87 in bitwarden_license/src/Scim/Controllers/v2/GroupsController.cs

View workflow job for this annotation

GitHub Actions / Sonar / Quality scan

ModelState.IsValid should be checked in controller actions. (https://rules.sonarsource.com/csharp/RSPEC-6967)
{
var organization = await _organizationRepository.GetByIdAsync(organizationId);
var group = await _putGroupCommand.PutGroupAsync(organization, id, model);
Expand All @@ -96,7 +94,7 @@
}

[HttpPatch("{id}")]
public async Task<IActionResult> Patch(Guid organizationId, Guid id, [FromBody] ScimPatchModel model)

Check warning on line 97 in bitwarden_license/src/Scim/Controllers/v2/GroupsController.cs

View workflow job for this annotation

GitHub Actions / Sonar / Quality scan

ModelState.IsValid should be checked in controller actions. (https://rules.sonarsource.com/csharp/RSPEC-6967)
{
var group = await _groupRepository.GetByIdAsync(id);
if (group == null || group.OrganizationId != organizationId)
Expand All @@ -109,7 +107,7 @@
}

[HttpDelete("{id}")]
public async Task<IActionResult> Delete(Guid organizationId, Guid id)

Check warning on line 110 in bitwarden_license/src/Scim/Controllers/v2/GroupsController.cs

View workflow job for this annotation

GitHub Actions / Sonar / Quality scan

ModelState.IsValid should be checked in controller actions. (https://rules.sonarsource.com/csharp/RSPEC-6967)
{
await _deleteGroupCommand.DeleteGroupAsync(organizationId, id, EventSystemUser.SCIM);
return new NoContentResult();
Expand Down
15 changes: 11 additions & 4 deletions bitwarden_license/src/Scim/Groups/GetGroupsListQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Bit.Core.AdminConsole.Entities;
using Bit.Core.AdminConsole.Repositories;
using Bit.Scim.Groups.Interfaces;
using Bit.Scim.Models;

namespace Bit.Scim.Groups;

Expand All @@ -16,10 +17,16 @@ public GetGroupsListQuery(IGroupRepository groupRepository)
_groupRepository = groupRepository;
}

public async Task<(IEnumerable<Group> groupList, int totalResults)> GetGroupsListAsync(Guid organizationId, string filter, int? count, int? startIndex)
public async Task<(IEnumerable<Group> groupList, int totalResults)> GetGroupsListAsync(
Guid organizationId, GetGroupsQueryParamModel groupQueryParams)
{
string nameFilter = null;
string externalIdFilter = null;

int count = groupQueryParams.Count;
int startIndex = groupQueryParams.StartIndex;
string filter = groupQueryParams.Filter;

if (!string.IsNullOrWhiteSpace(filter))
{
if (filter.StartsWith("displayName eq "))
Expand Down Expand Up @@ -53,11 +60,11 @@ public GetGroupsListQuery(IGroupRepository groupRepository)
}
totalResults = groupList.Count;
}
else if (string.IsNullOrWhiteSpace(filter) && startIndex.HasValue && count.HasValue)
else if (string.IsNullOrWhiteSpace(filter))
{
groupList = groups.OrderBy(g => g.Name)
.Skip(startIndex.Value - 1)
.Take(count.Value)
.Skip(startIndex - 1)
.Take(count)
.ToList();
totalResults = groups.Count;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Bit.Core.AdminConsole.Entities;
using Bit.Scim.Models;

namespace Bit.Scim.Groups.Interfaces;

public interface IGetGroupsListQuery
{
Task<(IEnumerable<Group> groupList, int totalResults)> GetGroupsListAsync(Guid organizationId, string filter, int? count, int? startIndex);
Task<(IEnumerable<Group> groupList, int totalResults)> GetGroupsListAsync(Guid organizationId, GetGroupsQueryParamModel model);
}
14 changes: 14 additions & 0 deletions bitwarden_license/src/Scim/Models/GetGroupsQueryParamModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.ComponentModel.DataAnnotations;

namespace Bit.Scim.Models;

public class GetGroupsQueryParamModel
{
public string Filter { get; init; } = string.Empty;

[Range(1, int.MaxValue)]
public int Count { get; init; } = 50;

[Range(1, int.MaxValue)]
public int StartIndex { get; init; } = 1;
}
2 changes: 2 additions & 0 deletions bitwarden_license/src/Scim/Models/GetUserQueryParamModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.ComponentModel.DataAnnotations;

namespace Bit.Scim.Models;

public class GetUsersQueryParamModel
{
public string Filter { get; init; } = string.Empty;
Expand Down
1 change: 1 addition & 0 deletions bitwarden_license/src/Scim/Users/GetUsersListQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using Bit.Core.Models.Data.Organizations.OrganizationUsers;
using Bit.Core.Repositories;
using Bit.Scim.Models;
using Bit.Scim.Users.Interfaces;

namespace Bit.Scim.Users;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Bit.Core.Models.Data.Organizations.OrganizationUsers;
using Bit.Scim.Models;

namespace Bit.Scim.Users.Interfaces;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Bit.Core.AdminConsole.Entities;
using Bit.Core.AdminConsole.Repositories;
using Bit.Scim.Groups;
using Bit.Scim.Models;
using Bit.Test.Common.AutoFixture;
using Bit.Test.Common.AutoFixture.Attributes;
using Bit.Test.Common.Helpers;
Expand All @@ -24,7 +25,7 @@ public async Task GetGroupsList_Success(int count, int startIndex, SutProvider<G
.GetManyByOrganizationIdAsync(organizationId)
.Returns(groups);

var result = await sutProvider.Sut.GetGroupsListAsync(organizationId, null, count, startIndex);
var result = await sutProvider.Sut.GetGroupsListAsync(organizationId, new GetGroupsQueryParamModel { Count = count, StartIndex = startIndex });

AssertHelper.AssertPropertyEqual(groups.Skip(startIndex - 1).Take(count).ToList(), result.groupList);
AssertHelper.AssertPropertyEqual(groups.Count, result.totalResults);
Expand All @@ -47,7 +48,7 @@ public async Task GetGroupsList_FilterDisplayName_Success(SutProvider<GetGroupsL
.GetManyByOrganizationIdAsync(organizationId)
.Returns(groups);

var result = await sutProvider.Sut.GetGroupsListAsync(organizationId, filter, null, null);
var result = await sutProvider.Sut.GetGroupsListAsync(organizationId, new GetGroupsQueryParamModel { Filter = filter });

AssertHelper.AssertPropertyEqual(expectedGroupList, result.groupList);
AssertHelper.AssertPropertyEqual(expectedTotalResults, result.totalResults);
Expand All @@ -67,7 +68,7 @@ public async Task GetGroupsList_FilterDisplayName_Empty(string name, SutProvider
.GetManyByOrganizationIdAsync(organizationId)
.Returns(groups);

var result = await sutProvider.Sut.GetGroupsListAsync(organizationId, filter, null, null);
var result = await sutProvider.Sut.GetGroupsListAsync(organizationId, new GetGroupsQueryParamModel { Filter = filter });

AssertHelper.AssertPropertyEqual(expectedGroupList, result.groupList);
AssertHelper.AssertPropertyEqual(expectedTotalResults, result.totalResults);
Expand All @@ -90,7 +91,7 @@ public async Task GetGroupsList_FilterExternalId_Success(SutProvider<GetGroupsLi
.GetManyByOrganizationIdAsync(organizationId)
.Returns(groups);

var result = await sutProvider.Sut.GetGroupsListAsync(organizationId, filter, null, null);
var result = await sutProvider.Sut.GetGroupsListAsync(organizationId, new GetGroupsQueryParamModel { Filter = filter });

AssertHelper.AssertPropertyEqual(expectedGroupList, result.groupList);
AssertHelper.AssertPropertyEqual(expectedTotalResults, result.totalResults);
Expand All @@ -112,7 +113,7 @@ public async Task GetGroupsList_FilterExternalId_Empty(string externalId, SutPro
.GetManyByOrganizationIdAsync(organizationId)
.Returns(groups);

var result = await sutProvider.Sut.GetGroupsListAsync(organizationId, filter, null, null);
var result = await sutProvider.Sut.GetGroupsListAsync(organizationId, new GetGroupsQueryParamModel { Filter = filter });

AssertHelper.AssertPropertyEqual(expectedGroupList, result.groupList);
AssertHelper.AssertPropertyEqual(expectedTotalResults, result.totalResults);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Bit.Core.Models.Data.Organizations.OrganizationUsers;
using Bit.Core.Repositories;
using Bit.Scim.Models;
using Bit.Scim.Users;
using Bit.Test.Common.AutoFixture;
using Bit.Test.Common.AutoFixture.Attributes;
Expand Down
Loading