Changeset 0.29.0 (#195)
This commit is contained in:
@@ -233,3 +233,100 @@ func (s *TeamStore) IsMember(ctx context.Context, teamID, userID string) (bool,
|
||||
|
||||
// unused but keeping for reference
|
||||
var _ = fmt.Sprintf
|
||||
|
||||
// ── CS1 additions (v0.29.0) ─────────────────────────────────────────────
|
||||
|
||||
func (s *TeamStore) Exists(ctx context.Context, teamID string) (bool, error) {
|
||||
var count int
|
||||
err := DB.QueryRowContext(ctx,
|
||||
`SELECT COUNT(*) FROM teams WHERE id = ?`, teamID).Scan(&count)
|
||||
return count > 0, err
|
||||
}
|
||||
|
||||
func (s *TeamStore) UpdateMemberRoleByID(ctx context.Context, memberID, teamID, role string) (int64, error) {
|
||||
res, err := DB.ExecContext(ctx,
|
||||
`UPDATE team_members SET role = ? WHERE id = ? AND team_id = ?`,
|
||||
role, memberID, teamID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return res.RowsAffected()
|
||||
}
|
||||
|
||||
func (s *TeamStore) DeleteMemberByID(ctx context.Context, memberID, teamID string) (int64, error) {
|
||||
res, err := DB.ExecContext(ctx,
|
||||
`DELETE FROM team_members WHERE id = ? AND team_id = ?`,
|
||||
memberID, teamID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return res.RowsAffected()
|
||||
}
|
||||
|
||||
func (s *TeamStore) ListTeamAuditActions(ctx context.Context, teamID string) ([]string, error) {
|
||||
rows, err := DB.QueryContext(ctx, `
|
||||
SELECT DISTINCT al.action
|
||||
FROM audit_log al
|
||||
WHERE al.actor_id IN (SELECT user_id FROM team_members WHERE team_id = ?)
|
||||
ORDER BY al.action
|
||||
`, teamID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var actions []string
|
||||
for rows.Next() {
|
||||
var a string
|
||||
if err := rows.Scan(&a); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
actions = append(actions, a)
|
||||
}
|
||||
if actions == nil {
|
||||
actions = []string{}
|
||||
}
|
||||
return actions, rows.Err()
|
||||
}
|
||||
|
||||
// ── CS5b additions (v0.29.0) ────────────────────────────────────────────
|
||||
|
||||
func (s *TeamStore) GetFirstTeamIDForUser(ctx context.Context, userID string) (string, error) {
|
||||
var teamID string
|
||||
err := DB.QueryRowContext(ctx,
|
||||
`SELECT team_id FROM team_members WHERE user_id = ? LIMIT 1`, userID).Scan(&teamID)
|
||||
if err != nil {
|
||||
return "", nil
|
||||
}
|
||||
return teamID, nil
|
||||
}
|
||||
|
||||
// ── CS6 additions (v0.29.0) ────────────────────────────────────────────
|
||||
|
||||
func (s *TeamStore) AddMemberReturningID(ctx context.Context, teamID, userID, role string) (string, error) {
|
||||
id := store.NewID()
|
||||
_, err := DB.ExecContext(ctx, `
|
||||
INSERT INTO team_members (id, team_id, user_id, role)
|
||||
VALUES (?, ?, ?, ?)`, id, teamID, userID, role)
|
||||
return id, err
|
||||
}
|
||||
|
||||
func (s *TeamStore) HasPrivateProviderRequirement(ctx context.Context, userID string) (bool, error) {
|
||||
var has bool
|
||||
err := DB.QueryRowContext(ctx, `
|
||||
SELECT EXISTS(
|
||||
SELECT 1 FROM team_members tm
|
||||
JOIN teams t ON t.id = tm.team_id
|
||||
WHERE tm.user_id = ?
|
||||
AND t.is_active = 1
|
||||
AND json_extract(t.settings, '$.require_private_providers') = 'true'
|
||||
)`, userID).Scan(&has)
|
||||
return has, err
|
||||
}
|
||||
|
||||
func (s *TeamStore) MergeSettings(ctx context.Context, teamID, settingsJSON string) error {
|
||||
_, err := DB.ExecContext(ctx,
|
||||
`UPDATE teams SET settings = json_patch(COALESCE(settings, '{}'), ?) WHERE id = ?`,
|
||||
settingsJSON, teamID)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user