Changeset 0.28.0.3 (#175)
This commit is contained in:
@@ -150,7 +150,7 @@ func (s *GroupStore) Delete(ctx context.Context, id string) error {
|
||||
return err
|
||||
}
|
||||
if source == "system" {
|
||||
return fmt.Errorf("system groups cannot be deleted")
|
||||
return store.ErrSystemGroup
|
||||
}
|
||||
res, err := DB.ExecContext(ctx, "DELETE FROM groups WHERE id = ?", id)
|
||||
if err != nil {
|
||||
|
||||
@@ -94,6 +94,36 @@ func (s *TeamStore) List(ctx context.Context) ([]models.Team, error) {
|
||||
return result, rows.Err()
|
||||
}
|
||||
|
||||
func (s *TeamStore) ListForUser(ctx context.Context, userID string) ([]models.Team, error) {
|
||||
rows, err := DB.QueryContext(ctx, `
|
||||
SELECT t.id, t.name, t.description, t.created_by, t.is_active,
|
||||
COALESCE(t.settings, '{}'), t.created_at, t.updated_at,
|
||||
tm.role AS my_role,
|
||||
(SELECT COUNT(*) FROM team_members WHERE team_id = t.id) AS member_count
|
||||
FROM teams t
|
||||
JOIN team_members tm ON tm.team_id = t.id AND tm.user_id = ?
|
||||
WHERE t.is_active = 1
|
||||
ORDER BY t.name ASC`, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var result []models.Team
|
||||
for rows.Next() {
|
||||
var t models.Team
|
||||
var settingsJSON []byte
|
||||
err := rows.Scan(&t.ID, &t.Name, &t.Description, &t.CreatedBy, &t.IsActive,
|
||||
&settingsJSON, st(&t.CreatedAt), st(&t.UpdatedAt), &t.MyRole, &t.MemberCount)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
json.Unmarshal(settingsJSON, &t.Settings)
|
||||
result = append(result, t)
|
||||
}
|
||||
return result, rows.Err()
|
||||
}
|
||||
|
||||
// ── Members ─────────────────────────────────
|
||||
|
||||
func (s *TeamStore) AddMember(ctx context.Context, teamID, userID, role string) error {
|
||||
|
||||
Reference in New Issue
Block a user