Feat v0.9.3 team user roles (#77)
All checks were successful
CI/CD / detect-changes (push) Successful in 4s
CI/CD / e2e-smoke (push) Has been skipped
CI/CD / test-runners (push) Has been skipped
CI/CD / test-frontend (push) Successful in 6s
CI/CD / test-go-pg (push) Successful in 2m51s
CI/CD / test-sqlite (push) Successful in 3m5s
CI/CD / build-and-deploy (push) Successful in 27s

Co-authored-by: Jeffrey Smith <jasafpro@gmail.com>
Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
This commit was merged in pull request #77.
This commit is contained in:
2026-04-03 15:51:31 +00:00
committed by xcaliber
parent 0cae963480
commit 0661e1d768
17 changed files with 852 additions and 12 deletions

View File

@@ -314,3 +314,88 @@ func (s *TeamStore) MergeSettings(ctx context.Context, teamID, settingsJSON stri
settingsJSON, teamID)
return err
}
// ── v0.9.3 — Team User Roles (many-to-many) ──────────────────
func (s *TeamStore) AddUserRole(ctx context.Context, teamID, userID, role, assignedBy string) error {
_, err := DB.ExecContext(ctx, `
INSERT INTO team_user_roles (id, team_id, user_id, role, assigned_by)
VALUES (?, ?, ?, ?, ?)
ON CONFLICT (team_id, user_id, role) DO NOTHING`,
store.NewID(), teamID, userID, role, assignedBy)
return err
}
func (s *TeamStore) RemoveUserRole(ctx context.Context, teamID, userID, role string) error {
_, err := DB.ExecContext(ctx,
`DELETE FROM team_user_roles WHERE team_id = ? AND user_id = ? AND role = ?`,
teamID, userID, role)
return err
}
func (s *TeamStore) ListUserRoles(ctx context.Context, teamID, userID string) ([]string, error) {
rows, err := DB.QueryContext(ctx,
`SELECT role FROM team_user_roles WHERE team_id = ? AND user_id = ? ORDER BY role`,
teamID, userID)
if err != nil {
return nil, err
}
defer rows.Close()
var roles []string
for rows.Next() {
var r string
if err := rows.Scan(&r); err != nil {
return nil, err
}
roles = append(roles, r)
}
if roles == nil {
roles = []string{}
}
return roles, rows.Err()
}
func (s *TeamStore) GetMemberRoles(ctx context.Context, teamID, userID string) ([]string, error) {
rows, err := DB.QueryContext(ctx, `
SELECT role FROM team_members WHERE team_id = ? AND user_id = ?
UNION
SELECT role FROM team_user_roles WHERE team_id = ? AND user_id = ?
ORDER BY role`,
teamID, userID, teamID, userID)
if err != nil {
return nil, err
}
defer rows.Close()
var roles []string
for rows.Next() {
var r string
if err := rows.Scan(&r); err != nil {
return nil, err
}
roles = append(roles, r)
}
if roles == nil {
roles = []string{}
}
return roles, rows.Err()
}
func (s *TeamStore) HasRole(ctx context.Context, teamID, userID, role string) (bool, error) {
var count int
err := DB.QueryRowContext(ctx, `
SELECT COUNT(*) FROM (
SELECT 1 FROM team_members WHERE team_id = ? AND user_id = ? AND role = ?
UNION ALL
SELECT 1 FROM team_user_roles WHERE team_id = ? AND user_id = ? AND role = ?
)`, teamID, userID, role, teamID, userID, role).Scan(&count)
return count > 0, err
}
func (s *TeamStore) RemoveAllUserRoles(ctx context.Context, teamID, userID string) error {
_, err := DB.ExecContext(ctx,
`DELETE FROM team_user_roles WHERE team_id = ? AND user_id = ?`,
teamID, userID)
return err
}