Add CountByConnectorID helper on access sources
Helper for callers that need to know whether a given connector row is still referenced by any access_sources. Used by the SCIM disconnect flow, which would otherwise fail with a foreign-key violation when the connector is shared with an access source. Mirrors the shape of CountByOrganizationID. Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com>
This commit is contained in:
committed by
Sacha Al Himdani
parent
0a5dfc652f
commit
2ea5f56ad6
@@ -307,6 +307,32 @@ WHERE
|
|||||||
return count, nil
|
return count, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (sources *AccessSources) CountByConnectorID(
|
||||||
|
ctx context.Context,
|
||||||
|
conn pg.Querier,
|
||||||
|
scope Scoper,
|
||||||
|
connectorID gid.GID,
|
||||||
|
) (int, error) {
|
||||||
|
q := `
|
||||||
|
SELECT COUNT(id)
|
||||||
|
FROM access_sources
|
||||||
|
WHERE
|
||||||
|
%s
|
||||||
|
AND connector_id = @connector_id;
|
||||||
|
`
|
||||||
|
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||||
|
|
||||||
|
args := pgx.StrictNamedArgs{"connector_id": connectorID}
|
||||||
|
maps.Copy(args, scope.SQLArguments())
|
||||||
|
|
||||||
|
var count int
|
||||||
|
if err := conn.QueryRow(ctx, q, args).Scan(&count); err != nil {
|
||||||
|
return 0, fmt.Errorf("cannot count access_sources by connector ID: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return count, nil
|
||||||
|
}
|
||||||
|
|
||||||
// LoadScopeSourcesByCampaignID loads the campaign scope sources in deterministic
|
// LoadScopeSourcesByCampaignID loads the campaign scope sources in deterministic
|
||||||
// name order. Only explicitly scoped sources are returned.
|
// name order. Only explicitly scoped sources are returned.
|
||||||
func (sources *AccessSources) LoadScopeSourcesByCampaignID(
|
func (sources *AccessSources) LoadScopeSourcesByCampaignID(
|
||||||
|
|||||||
Reference in New Issue
Block a user