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

feat: Support include_has_members_with_elevated_permissions for Backend API list organization endpoint #343

Merged
merged 2 commits into from
Oct 31, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Next release

- Add `EmailAddressQuery`, `PhoneNumberQuery` and `UsernameQuery` to `user.ListParams`.
- Add support for `missing_member_with_elevated_permissions` checks to the `organization.List` method.

## 2.1.0

Expand Down
31 changes: 16 additions & 15 deletions organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@ import "encoding/json"

type Organization struct {
APIResource
Object string `json:"object"`
ID string `json:"id"`
Name string `json:"name"`
Slug string `json:"slug"`
ImageURL *string `json:"image_url"`
HasImage bool `json:"has_image"`
MembersCount *int64 `json:"members_count,omitempty"`
PendingInvitationsCount *int64 `json:"pending_invitations_count,omitempty"`
MaxAllowedMemberships int64 `json:"max_allowed_memberships"`
AdminDeleteEnabled bool `json:"admin_delete_enabled"`
PublicMetadata json.RawMessage `json:"public_metadata"`
PrivateMetadata json.RawMessage `json:"private_metadata"`
CreatedBy string `json:"created_by"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
Object string `json:"object"`
ID string `json:"id"`
Name string `json:"name"`
Slug string `json:"slug"`
ImageURL *string `json:"image_url"`
HasImage bool `json:"has_image"`
MembersCount *int64 `json:"members_count,omitempty"`
MissingMemberWithElevatedPermissions *bool `json:"missing_member_with_elevated_permissions,omitempty"`
PendingInvitationsCount *int64 `json:"pending_invitations_count,omitempty"`
MaxAllowedMemberships int64 `json:"max_allowed_memberships"`
AdminDeleteEnabled bool `json:"admin_delete_enabled"`
PublicMetadata json.RawMessage `json:"public_metadata"`
PrivateMetadata json.RawMessage `json:"private_metadata"`
CreatedBy string `json:"created_by"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
}

type OrganizationList struct {
Expand Down
19 changes: 15 additions & 4 deletions organization/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,12 @@ func (c *Client) DeleteLogo(ctx context.Context, id string) (*clerk.Organization
type ListParams struct {
clerk.APIParams
clerk.ListParams
IncludeMembersCount *bool `json:"include_members_count,omitempty"`
OrderBy *string `json:"order_by,omitempty"`
Query *string `json:"query,omitempty"`
UserIDs []string `json:"user_id,omitempty"`
IncludeMembersCount *bool `json:"include_members_count,omitempty"`
IncludeMissingMemberWithElevatedPermissions *bool `json:"include_missing_member_with_elevated_permissions,omitempty"`
OrderBy *string `json:"order_by,omitempty"`
Query *string `json:"query,omitempty"`
UserIDs []string `json:"user_id,omitempty"`
FilterBy []string `json:"filter_by,omitempty"`
}

// ToQuery returns query string values from the params.
Expand All @@ -197,6 +199,9 @@ func (params *ListParams) ToQuery() url.Values {
if params.IncludeMembersCount != nil {
q.Set("include_members_count", strconv.FormatBool(*params.IncludeMembersCount))
}
if params.IncludeMissingMemberWithElevatedPermissions != nil {
q.Set("include_missing_member_with_elevated_permissions", strconv.FormatBool(*params.IncludeMissingMemberWithElevatedPermissions))
}
if params.OrderBy != nil {
q.Set("order_by", *params.OrderBy)
}
Expand All @@ -206,6 +211,12 @@ func (params *ListParams) ToQuery() url.Values {
if params.UserIDs != nil {
q["user_id"] = params.UserIDs
}
if params.UserIDs != nil {
q["user_id"] = params.UserIDs
}
if params.FilterBy != nil {
q["filter_by"] = params.FilterBy
}
return q
}

Expand Down
28 changes: 19 additions & 9 deletions organization/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,25 +156,31 @@ func TestOrganizationClientList(t *testing.T) {
Transport: &clerktest.RoundTripper{
T: t,
Out: json.RawMessage(`{
"data": [{"id":"org_123","name":"Acme Inc"}],
"data": [{"id":"org_123","name":"Acme Inc","members_count":1,"missing_member_with_elevated_permissions":true}],
"total_count": 1
}`),
Method: http.MethodGet,
Path: "/v1/organizations",
Query: &url.Values{
"limit": []string{"1"},
"offset": []string{"2"},
"order_by": []string{"-created_at"},
"query": []string{"Acme"},
"user_id": []string{"user_123", "user_456"},
"limit": []string{"1"},
"offset": []string{"2"},
"order_by": []string{"-created_at"},
"query": []string{"Acme"},
"user_id": []string{"user_123", "user_456"},
"filter_by": []string{"missing_member_with_elevated_permissions"},
"include_members_count": []string{"true"},
"include_missing_member_with_elevated_permissions": []string{"true"},
},
},
}
client := NewClient(config)
params := &ListParams{
OrderBy: clerk.String("-created_at"),
Query: clerk.String("Acme"),
UserIDs: []string{"user_123", "user_456"},
OrderBy: clerk.String("-created_at"),
Query: clerk.String("Acme"),
UserIDs: []string{"user_123", "user_456"},
FilterBy: []string{"missing_member_with_elevated_permissions"},
IncludeMembersCount: clerk.Bool(true),
IncludeMissingMemberWithElevatedPermissions: clerk.Bool(true),
}
params.Limit = clerk.Int64(1)
params.Offset = clerk.Int64(2)
Expand All @@ -184,6 +190,10 @@ func TestOrganizationClientList(t *testing.T) {
require.Equal(t, 1, len(list.Organizations))
require.Equal(t, "org_123", list.Organizations[0].ID)
require.Equal(t, "Acme Inc", list.Organizations[0].Name)
require.NotNil(t, list.Organizations[0].MembersCount)
require.Equal(t, int64(1), *list.Organizations[0].MembersCount)
require.NotNil(t, *list.Organizations[0].MissingMemberWithElevatedPermissions)
require.Equal(t, true, *list.Organizations[0].MissingMemberWithElevatedPermissions)
}

type testFile struct {
Expand Down
Loading