Identity: Add read-only identity apiserver (#90418)
This commit is contained in:
@@ -90,6 +90,13 @@ type SearchTeamsQuery struct {
|
||||
HiddenUsers map[string]struct{}
|
||||
}
|
||||
|
||||
type ListTeamsCommand struct {
|
||||
Limit int
|
||||
Start int
|
||||
OrgID int64
|
||||
UID string
|
||||
}
|
||||
|
||||
type TeamDTO struct {
|
||||
ID int64 `json:"id" xorm:"id"`
|
||||
UID string `json:"uid" xorm:"uid"`
|
||||
|
||||
@@ -8,6 +8,7 @@ type Service interface {
|
||||
CreateTeam(ctx context.Context, name, email string, orgID int64) (Team, error)
|
||||
UpdateTeam(ctx context.Context, cmd *UpdateTeamCommand) error
|
||||
DeleteTeam(ctx context.Context, cmd *DeleteTeamCommand) error
|
||||
ListTeams(ctx context.Context, query *ListTeamsCommand) ([]*Team, error)
|
||||
SearchTeams(ctx context.Context, query *SearchTeamsQuery) (SearchTeamQueryResult, error)
|
||||
GetTeamByID(ctx context.Context, query *GetTeamByIDQuery) (*TeamDTO, error)
|
||||
GetTeamsByUser(ctx context.Context, query *GetTeamsByUserQuery) ([]*TeamDTO, error)
|
||||
|
||||
@@ -20,6 +20,7 @@ type store interface {
|
||||
Create(name, email string, orgID int64) (team.Team, error)
|
||||
Update(ctx context.Context, cmd *team.UpdateTeamCommand) error
|
||||
Delete(ctx context.Context, cmd *team.DeleteTeamCommand) error
|
||||
ListTeams(ctx context.Context, query *team.ListTeamsCommand) ([]*team.Team, error)
|
||||
Search(ctx context.Context, query *team.SearchTeamsQuery) (team.SearchTeamQueryResult, error)
|
||||
GetByID(ctx context.Context, query *team.GetTeamByIDQuery) (*team.TeamDTO, error)
|
||||
GetByUser(ctx context.Context, query *team.GetTeamsByUserQuery) ([]*team.TeamDTO, error)
|
||||
@@ -267,6 +268,21 @@ func (ss *xormStore) Search(ctx context.Context, query *team.SearchTeamsQuery) (
|
||||
return queryResult, nil
|
||||
}
|
||||
|
||||
func (ss *xormStore) ListTeams(ctx context.Context, query *team.ListTeamsCommand) ([]*team.Team, error) {
|
||||
results := make([]*team.Team, 0)
|
||||
err := ss.db.WithDbSession(ctx, func(sess *db.Session) error {
|
||||
q := sess.Table("team")
|
||||
q.Where("team.org_id=?", query.OrgID)
|
||||
if query.UID != "" {
|
||||
q.Where("team.uid=?", query.UID)
|
||||
}
|
||||
q.Limit(query.Limit, query.Start)
|
||||
|
||||
return q.Find(&results)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (ss *xormStore) GetByID(ctx context.Context, query *team.GetTeamByIDQuery) (*team.TeamDTO, error) {
|
||||
var queryResult *team.TeamDTO
|
||||
err := ss.db.WithDbSession(ctx, func(sess *db.Session) error {
|
||||
|
||||
@@ -51,6 +51,14 @@ func (s *Service) DeleteTeam(ctx context.Context, cmd *team.DeleteTeamCommand) e
|
||||
return s.store.Delete(ctx, cmd)
|
||||
}
|
||||
|
||||
func (s *Service) ListTeams(ctx context.Context, query *team.ListTeamsCommand) ([]*team.Team, error) {
|
||||
ctx, span := s.tracer.Start(ctx, "team.ListTeams", trace.WithAttributes(
|
||||
attribute.Int64("orgID", query.OrgID),
|
||||
))
|
||||
defer span.End()
|
||||
return s.store.ListTeams(ctx, query)
|
||||
}
|
||||
|
||||
func (s *Service) SearchTeams(ctx context.Context, query *team.SearchTeamsQuery) (team.SearchTeamQueryResult, error) {
|
||||
ctx, span := s.tracer.Start(ctx, "team.SearchTeams", trace.WithAttributes(
|
||||
attribute.Int64("orgID", query.OrgID),
|
||||
|
||||
@@ -36,6 +36,10 @@ func (s *FakeService) SearchTeams(ctx context.Context, query *team.SearchTeamsQu
|
||||
return team.SearchTeamQueryResult{}, s.ExpectedError
|
||||
}
|
||||
|
||||
func (s *FakeService) ListTeams(ctx context.Context, query *team.ListTeamsCommand) ([]*team.Team, error) {
|
||||
return nil, s.ExpectedError
|
||||
}
|
||||
|
||||
func (s *FakeService) GetTeamByID(ctx context.Context, query *team.GetTeamByIDQuery) (*team.TeamDTO, error) {
|
||||
return s.ExpectedTeamDTO, s.ExpectedError
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user