Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fields to Organizations Get All Members #660

Merged
merged 3 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 20 additions & 0 deletions src/Auth0.ManagementApi/Clients/IOrganizationsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ public interface IOrganizationsClient
/// <returns>An <see cref="IPagedList{OrganizationMember}"/> containing the organization members.</returns>
Task<IPagedList<OrganizationMember>> GetAllMembersAsync(string organizationId, PaginationInfo pagination, CancellationToken cancellationToken = default);

/// <summary>
/// Retrieves a list of all organization members.
/// </summary>
/// <param name="organizationId">The ID of the organization for which you want to retrieve the members.</param>
/// <param name="request">Specifies criteria to use when querying organization members.</param>
/// <param name="pagination">Specifies pagination info to use when requesting paged results.</param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>An <see cref="IPagedList{OrganizationMember}"/> containing the organization members.</returns>
Task<IPagedList<OrganizationMember>> GetAllMembersAsync(string organizationId, OrganizationGetAllMembersRequest request, PaginationInfo pagination, CancellationToken cancellationToken = default);

/// <summary>
/// Retrieves a list of all organization members using checkpoint <paramref name="pagination"/>.
/// </summary>
Expand All @@ -137,6 +147,16 @@ public interface IOrganizationsClient
/// <returns>An <see cref="ICheckpointPagedList{OrganizationMember}"/> containing the organization members.</returns>
Task<ICheckpointPagedList<OrganizationMember>> GetAllMembersAsync(string organizationId, CheckpointPaginationInfo pagination, CancellationToken cancellationToken = default);

/// <summary>
/// Retrieves a list of all organization members using checkpoint <paramref name="pagination"/>.
/// </summary>
/// <param name="organizationId">The ID of the organization for which you want to retrieve the members.</param>
/// <param name="request">Specifies criteria to use when querying organization members.</param>
/// <param name="pagination">Specifies <see cref="CheckpointPaginationInfo"/> to use in requesting checkpoint-paginated results.</param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>An <see cref="ICheckpointPagedList{OrganizationMember}"/> containing the organization members.</returns>
Task<ICheckpointPagedList<OrganizationMember>> GetAllMembersAsync(string organizationId, OrganizationGetAllMembersRequest request, CheckpointPaginationInfo pagination, CancellationToken cancellationToken = default);

/// <summary>
/// Deletes members from an organization.
/// </summary>
Expand Down
38 changes: 38 additions & 0 deletions src/Auth0.ManagementApi/Clients/OrganizationsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,19 @@ public Task AddMembersAsync(string organizationId, OrganizationAddMembersRequest
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>An <see cref="IPagedList{OrganizationMember}"/> containing the organization members.</returns>
public Task<IPagedList<OrganizationMember>> GetAllMembersAsync(string organizationId, PaginationInfo pagination, CancellationToken cancellationToken = default)
{
return GetAllMembersAsync(organizationId, null, pagination, cancellationToken);
}

/// <summary>
/// Retrieves a list of all organization members.
/// </summary>
/// <param name="organizationId">The ID of the organization for which you want to retrieve the members.</param>
/// <param name="request">Specifies criteria to use when querying organization members.</param>
/// <param name="pagination">Specifies pagination info to use when requesting paged results.</param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>An <see cref="IPagedList{OrganizationMember}"/> containing the organization members.</returns>
public Task<IPagedList<OrganizationMember>> GetAllMembersAsync(string organizationId, OrganizationGetAllMembersRequest request, PaginationInfo pagination, CancellationToken cancellationToken = default)
{
if (pagination == null)
throw new ArgumentNullException(nameof(pagination));
Expand All @@ -229,6 +242,12 @@ public Task<IPagedList<OrganizationMember>> GetAllMembersAsync(string organizati
{"include_totals", pagination.IncludeTotals.ToString().ToLower()},
};

if (request != null)
{
queryStrings.Add("fields", request.Fields);
queryStrings.Add("include_fields", request.IncludeFields?.ToString().ToLower());
}

return Connection.GetAsync<IPagedList<OrganizationMember>>(BuildUri($"organizations/{EncodePath(organizationId)}/members", queryStrings), DefaultHeaders, membersConverters, cancellationToken);
}

Expand All @@ -240,6 +259,19 @@ public Task<IPagedList<OrganizationMember>> GetAllMembersAsync(string organizati
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>An <see cref="ICheckpointPagedList{OrganizationMember}"/> containing the organization members.</returns>
public Task<ICheckpointPagedList<OrganizationMember>> GetAllMembersAsync(string organizationId, CheckpointPaginationInfo pagination, CancellationToken cancellationToken = default)
{
return GetAllMembersAsync(organizationId, null, pagination, cancellationToken);
}

/// <summary>
/// Retrieves a list of all organization members using checkpoint <paramref name="pagination"/>.
/// </summary>
/// <param name="organizationId">The ID of the organization for which you want to retrieve the members.</param>
/// <param name="request">Specifies criteria to use when querying organization members.</param>
/// <param name="pagination">Specifies <see cref="CheckpointPaginationInfo"/> to use in requesting checkpoint-paginated results.</param>
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
/// <returns>An <see cref="ICheckpointPagedList{OrganizationMember}"/> containing the organization members.</returns>
public Task<ICheckpointPagedList<OrganizationMember>> GetAllMembersAsync(string organizationId, OrganizationGetAllMembersRequest request, CheckpointPaginationInfo pagination, CancellationToken cancellationToken = default)
{
if (pagination == null)
throw new ArgumentNullException(nameof(pagination));
Expand All @@ -250,6 +282,12 @@ public Task<ICheckpointPagedList<OrganizationMember>> GetAllMembersAsync(string
{"take", pagination.Take.ToString()},
};

if (request != null)
{
queryStrings.Add("fields", request.Fields);
queryStrings.Add("include_fields", request.IncludeFields?.ToString().ToLower());
}

return Connection.GetAsync<ICheckpointPagedList<OrganizationMember>>(BuildUri($"organizations/{EncodePath(organizationId)}/members", queryStrings), DefaultHeaders, membersCheckpointConverters, cancellationToken);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Auth0.ManagementApi.Models
{
public class OrganizationGetAllMembersRequest {

/// <summary>
/// A comma separated list of fields to include or exclude (depending on <see cref="IncludeFields"/>) from the result, empty to retrieve all fields.
/// </summary>
public string Fields { get; set; } = null;

/// <summary>
/// Specifies whether the fields specified in <see cref="Fields"/> should be included or excluded in the result.
/// </summary>
public bool? IncludeFields { get; set; } = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,11 @@ public async Task Test_organization_members_crud_sequence()

try
{
var members = await RetryUtils.Retry(() => fixture.ApiClient.Organizations.GetAllMembersAsync(ExistingOrganizationId, new Paging.PaginationInfo()), members => members.Count != 2);
var members = await RetryUtils.Retry(() => fixture.ApiClient.Organizations.GetAllMembersAsync(ExistingOrganizationId, new OrganizationGetAllMembersRequest { Fields = "name", IncludeFields = false }, new Paging.PaginationInfo()), members => members.Count != 2);

members.Count.Should().Be(2);
members[0].Name.Should().BeNull();
members[1].Name.Should().BeNull();

await fixture.ApiClient.Organizations.DeleteMemberAsync(ExistingOrganizationId, new OrganizationDeleteMembersRequest
{
Expand Down Expand Up @@ -275,10 +277,12 @@ public async Task Test_organization_members_checkpoint_pagination()

await RetryUtils.Retry(() => fixture.ApiClient.Organizations.GetAllMembersAsync(ExistingOrganizationId, new Paging.CheckpointPaginationInfo(2)), response => response.Count != 2);

var firstCheckPointPaginationRequest = await fixture.ApiClient.Organizations.GetAllMembersAsync(ExistingOrganizationId, new Paging.CheckpointPaginationInfo(1));
var firstCheckPointPaginationRequest = await fixture.ApiClient.Organizations.GetAllMembersAsync(ExistingOrganizationId, new OrganizationGetAllMembersRequest { Fields = "name", IncludeFields = false }, new Paging.CheckpointPaginationInfo(1));
var secondCheckPointPaginationRequest = await fixture.ApiClient.Organizations.GetAllMembersAsync(ExistingOrganizationId, new Paging.CheckpointPaginationInfo(1, firstCheckPointPaginationRequest.Paging.Next));

firstCheckPointPaginationRequest[0].Name.Should().BeNull();
secondCheckPointPaginationRequest.Count.Should().Be(1);
secondCheckPointPaginationRequest[0].Name.Should().NotBeNull();
secondCheckPointPaginationRequest.Paging.Next.Should().NotBeNullOrEmpty();

}
Expand Down