Changeset 0.29.0 (#195)
This commit is contained in:
@@ -203,3 +203,64 @@ func scanProviders(rows *sql.Rows) ([]models.ProviderConfig, error) {
|
||||
}
|
||||
return result, rows.Err()
|
||||
}
|
||||
|
||||
// ── CS4 additions (v0.29.0) ─────────────────────────────────────────────
|
||||
|
||||
func (s *ProviderStore) DeletePersonalByOwner(ctx context.Context, ownerID string) (int64, error) {
|
||||
result, err := DB.ExecContext(ctx,
|
||||
`DELETE FROM provider_configs WHERE scope = 'personal' AND owner_id = ?`, ownerID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected()
|
||||
}
|
||||
|
||||
// ── CS6 additions (v0.29.0) ─────────────────────────────────────────────
|
||||
|
||||
func (s *ProviderStore) ListAllForTeam(ctx context.Context, teamID string) ([]models.ProviderConfig, error) {
|
||||
rows, err := DB.QueryContext(ctx,
|
||||
fmt.Sprintf("SELECT %s FROM provider_configs WHERE scope = 'team' AND owner_id = ? ORDER BY name", providerCols),
|
||||
teamID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
return scanProviders(rows)
|
||||
}
|
||||
|
||||
func (s *ProviderStore) DeleteByIDAndTeam(ctx context.Context, id, teamID string) (int64, error) {
|
||||
res, err := DB.ExecContext(ctx,
|
||||
`DELETE FROM provider_configs WHERE id = ? AND scope = 'team' AND owner_id = ?`,
|
||||
id, teamID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return res.RowsAffected()
|
||||
}
|
||||
|
||||
// ── CS7a additions (v0.29.0) ────────────────────────────────────────────
|
||||
|
||||
func (s *ProviderStore) FindFirstForUser(ctx context.Context, userID string) (string, error) {
|
||||
var configID string
|
||||
err := DB.QueryRowContext(ctx, `
|
||||
SELECT id FROM provider_configs
|
||||
WHERE is_active = 1 AND (
|
||||
(scope = 'personal' AND owner_id = ?)
|
||||
OR scope = 'global'
|
||||
)
|
||||
ORDER BY scope ASC, created_at ASC
|
||||
LIMIT 1
|
||||
`, userID).Scan(&configID)
|
||||
return configID, err
|
||||
}
|
||||
|
||||
func (s *ProviderStore) LoadAccessible(ctx context.Context, configID, userID string) (*models.ProviderConfig, error) {
|
||||
row := DB.QueryRowContext(ctx, fmt.Sprintf(`
|
||||
SELECT %s FROM provider_configs
|
||||
WHERE id = ? AND is_active = 1
|
||||
AND (scope = 'global'
|
||||
OR (scope = 'personal' AND owner_id = ?)
|
||||
OR (scope = 'team' AND owner_id IN (SELECT team_id FROM team_members WHERE user_id = ?)))
|
||||
`, providerCols), configID, userID, userID)
|
||||
return scanProvider(row)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user