From 5cfbf66397749e24c926f2a4593597d1f79e19f5 Mon Sep 17 00:00:00 2001 From: Jonas Hungershausen Date: Thu, 12 Sep 2024 10:43:54 +0200 Subject: [PATCH] feat: allow listing identities by organization ID --- identity/handler.go | 7 +++++++ identity/pool.go | 1 + internal/client-go/api_identity.go | 8 ++++++++ internal/httpclient/api_identity.go | 8 ++++++++ persistence/sql/identity/persister_identity.go | 5 +++++ spec/api.json | 8 ++++++++ spec/swagger.json | 6 ++++++ 7 files changed, 43 insertions(+) diff --git a/identity/handler.go b/identity/handler.go index cf85dc792c43..2a089e9b578e 100644 --- a/identity/handler.go +++ b/identity/handler.go @@ -171,6 +171,12 @@ type listIdentitiesParameters struct { // in: query DeclassifyCredentials []string `json:"include_credential"` + // OrganizationID is the organization id to filter identities by. + // + // If `ids` is set, this parameter is ignored. + // required: false + OrganizationID string `json:"organization_id"` + crdbx.ConsistencyRequestParameters } @@ -211,6 +217,7 @@ func (h *Handler) list(w http.ResponseWriter, r *http.Request, _ httprouter.Para IdsFilter: r.URL.Query()["ids"], CredentialsIdentifier: r.URL.Query().Get("credentials_identifier"), CredentialsIdentifierSimilar: r.URL.Query().Get("preview_credentials_identifier_similar"), + OrganizationID: x.ParseUUID(r.URL.Query().Get("organization_id")), ConsistencyLevel: crdbx.ConsistencyLevelFromRequest(r), DeclassifyCredentials: declassify, } diff --git a/identity/pool.go b/identity/pool.go index 8a94aad3e075..5e65ba6aac6b 100644 --- a/identity/pool.go +++ b/identity/pool.go @@ -23,6 +23,7 @@ type ( CredentialsIdentifierSimilar string DeclassifyCredentials []CredentialsType KeySetPagination []keysetpagination.Option + OrganizationID uuid.UUID // DEPRECATED PagePagination *x.Page ConsistencyLevel crdbx.ConsistencyLevel diff --git a/internal/client-go/api_identity.go b/internal/client-go/api_identity.go index 47c2eb6cbfc4..9e4aec1b6c58 100644 --- a/internal/client-go/api_identity.go +++ b/internal/client-go/api_identity.go @@ -2087,6 +2087,7 @@ type IdentityAPIApiListIdentitiesRequest struct { credentialsIdentifier *string previewCredentialsIdentifierSimilar *string includeCredential *[]string + organizationId *string } func (r IdentityAPIApiListIdentitiesRequest) PerPage(perPage int64) IdentityAPIApiListIdentitiesRequest { @@ -2125,6 +2126,10 @@ func (r IdentityAPIApiListIdentitiesRequest) IncludeCredential(includeCredential r.includeCredential = &includeCredential return r } +func (r IdentityAPIApiListIdentitiesRequest) OrganizationId(organizationId string) IdentityAPIApiListIdentitiesRequest { + r.organizationId = &organizationId + return r +} func (r IdentityAPIApiListIdentitiesRequest) Execute() ([]Identity, *http.Response, error) { return r.ApiService.ListIdentitiesExecute(r) @@ -2211,6 +2216,9 @@ func (a *IdentityAPIService) ListIdentitiesExecute(r IdentityAPIApiListIdentitie localVarQueryParams.Add("include_credential", parameterToString(t, "multi")) } } + if r.organizationId != nil { + localVarQueryParams.Add("organization_id", parameterToString(*r.organizationId, "")) + } // to determine the Content-Type header localVarHTTPContentTypes := []string{} diff --git a/internal/httpclient/api_identity.go b/internal/httpclient/api_identity.go index 47c2eb6cbfc4..9e4aec1b6c58 100644 --- a/internal/httpclient/api_identity.go +++ b/internal/httpclient/api_identity.go @@ -2087,6 +2087,7 @@ type IdentityAPIApiListIdentitiesRequest struct { credentialsIdentifier *string previewCredentialsIdentifierSimilar *string includeCredential *[]string + organizationId *string } func (r IdentityAPIApiListIdentitiesRequest) PerPage(perPage int64) IdentityAPIApiListIdentitiesRequest { @@ -2125,6 +2126,10 @@ func (r IdentityAPIApiListIdentitiesRequest) IncludeCredential(includeCredential r.includeCredential = &includeCredential return r } +func (r IdentityAPIApiListIdentitiesRequest) OrganizationId(organizationId string) IdentityAPIApiListIdentitiesRequest { + r.organizationId = &organizationId + return r +} func (r IdentityAPIApiListIdentitiesRequest) Execute() ([]Identity, *http.Response, error) { return r.ApiService.ListIdentitiesExecute(r) @@ -2211,6 +2216,9 @@ func (a *IdentityAPIService) ListIdentitiesExecute(r IdentityAPIApiListIdentitie localVarQueryParams.Add("include_credential", parameterToString(t, "multi")) } } + if r.organizationId != nil { + localVarQueryParams.Add("organization_id", parameterToString(*r.organizationId, "")) + } // to determine the Content-Type header localVarHTTPContentTypes := []string{} diff --git a/persistence/sql/identity/persister_identity.go b/persistence/sql/identity/persister_identity.go index 807d3d67779d..3084393816ae 100644 --- a/persistence/sql/identity/persister_identity.go +++ b/persistence/sql/identity/persister_identity.go @@ -859,6 +859,11 @@ func (p *IdentityPersister) ListIdentities(ctx context.Context, params identity. AND identities.id in (?) ` args = append(args, params.IdsFilter) + } else if !params.OrganizationID.IsNil() { + wheres += ` + AND identities.organization_id = ? + ` + args = append(args, params.OrganizationID.String()) } query := fmt.Sprintf(` diff --git a/spec/api.json b/spec/api.json index c8f296913fa0..d2b4b09047e8 100644 --- a/spec/api.json +++ b/spec/api.json @@ -4032,6 +4032,14 @@ }, "type": "array" } + }, + { + "description": "OrganizationID is the organization id to filter identities by.\n\nIf `ids` is set, this parameter is ignored.", + "in": "query", + "name": "organization_id", + "schema": { + "type": "string" + } } ], "responses": { diff --git a/spec/swagger.json b/spec/swagger.json index 2952837d4c09..1e40703227fd 100755 --- a/spec/swagger.json +++ b/spec/swagger.json @@ -261,6 +261,12 @@ "description": "Include Credentials in Response\n\nInclude any credential, for example `password` or `oidc`, in the response. When set to `oidc`, This will return\nthe initial OAuth 2.0 Access Token, OAuth 2.0 Refresh Token and the OpenID Connect ID Token if available.", "name": "include_credential", "in": "query" + }, + { + "type": "string", + "description": "OrganizationID is the organization id to filter identities by.\n\nIf `ids` is set, this parameter is ignored.", + "name": "organization_id", + "in": "query" } ], "responses": {