mirror of
https://github.com/grafana/grafana.git
synced 2024-11-23 09:26:43 -06:00
Teams: Allow Services to register deletes (#76325)
* add team RegisterDelete * fix-docs
This commit is contained in:
parent
72a1de855c
commit
79b2974215
@ -113,7 +113,7 @@ Status Codes:
|
||||
|
||||
## Remove External Group
|
||||
|
||||
`DELETE /api/teams/:teamId/groups/:groupId`
|
||||
`DELETE /api/teams/:teamId/groups?groupId=external-group-id`
|
||||
|
||||
**Required permissions**
|
||||
|
||||
@ -126,7 +126,7 @@ See note in the [introduction]({{< ref "#external-group-synchronization-api" >}}
|
||||
**Example Request**:
|
||||
|
||||
```http
|
||||
DELETE /api/teams/1/groups/cn=editors,ou=groups,dc=grafana,dc=org HTTP/1.1
|
||||
DELETE /api/teams/1/groups?groupId=cn%3Deditors%2Cou%3Dgroups%2Cdc%3Dgrafana%2Cdc%3Dorg HTTP/1.1
|
||||
Accept: application/json
|
||||
Content-Type: application/json
|
||||
Authorization: Basic YWRtaW46YWRtaW4=
|
||||
|
@ -20,4 +20,5 @@ type Service interface {
|
||||
RemoveUsersMemberships(tx context.Context, userID int64) error
|
||||
GetUserTeamMemberships(ctx context.Context, orgID, userID int64, external bool) ([]*TeamMemberDTO, error)
|
||||
GetTeamMembers(ctx context.Context, query *GetTeamMembersQuery) ([]*TeamMemberDTO, error)
|
||||
RegisterDelete(query string)
|
||||
}
|
||||
|
@ -30,11 +30,13 @@ type store interface {
|
||||
RemoveMember(ctx context.Context, cmd *team.RemoveTeamMemberCommand) error
|
||||
GetMemberships(ctx context.Context, orgID, userID int64, external bool) ([]*team.TeamMemberDTO, error)
|
||||
GetMembers(ctx context.Context, query *team.GetTeamMembersQuery) ([]*team.TeamMemberDTO, error)
|
||||
RegisterDelete(query string)
|
||||
}
|
||||
|
||||
type xormStore struct {
|
||||
db db.DB
|
||||
cfg *setting.Cfg
|
||||
db db.DB
|
||||
cfg *setting.Cfg
|
||||
deletes []string
|
||||
}
|
||||
|
||||
func getFilteredUsers(signedInUser identity.Requester, hiddenUsers map[string]struct{}) []string {
|
||||
@ -142,6 +144,8 @@ func (ss *xormStore) Delete(ctx context.Context, cmd *team.DeleteTeamCommand) er
|
||||
"DELETE FROM team_role WHERE org_id=? and team_id = ?",
|
||||
}
|
||||
|
||||
deletes = append(deletes, ss.deletes...)
|
||||
|
||||
for _, sql := range deletes {
|
||||
_, err := sess.Exec(sql, cmd.OrgID, cmd.ID)
|
||||
if err != nil {
|
||||
@ -567,3 +571,8 @@ func (ss *xormStore) getTeamMembers(ctx context.Context, query *team.GetTeamMemb
|
||||
}
|
||||
return queryResult, nil
|
||||
}
|
||||
|
||||
// RegisterDelete registers a delete query to be executed when the transaction is committed
|
||||
func (ss *xormStore) RegisterDelete(query string) {
|
||||
ss.deletes = append(ss.deletes, query)
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ type Service struct {
|
||||
}
|
||||
|
||||
func ProvideService(db db.DB, cfg *setting.Cfg) team.Service {
|
||||
return &Service{store: &xormStore{db: db, cfg: cfg}}
|
||||
return &Service{store: &xormStore{db: db, cfg: cfg, deletes: []string{}}}
|
||||
}
|
||||
|
||||
func (s *Service) CreateTeam(name, email string, orgID int64) (team.Team, error) {
|
||||
@ -68,3 +68,7 @@ func (s *Service) GetUserTeamMemberships(ctx context.Context, orgID, userID int6
|
||||
func (s *Service) GetTeamMembers(ctx context.Context, query *team.GetTeamMembersQuery) ([]*team.TeamMemberDTO, error) {
|
||||
return s.store.GetMembers(ctx, query)
|
||||
}
|
||||
|
||||
func (s *Service) RegisterDelete(query string) {
|
||||
s.store.RegisterDelete(query)
|
||||
}
|
||||
|
@ -72,3 +72,6 @@ func (s *FakeService) GetUserTeamMemberships(ctx context.Context, orgID, userID
|
||||
func (s *FakeService) GetTeamMembers(ctx context.Context, query *team.GetTeamMembersQuery) ([]*team.TeamMemberDTO, error) {
|
||||
return s.ExpectedMembers, s.ExpectedError
|
||||
}
|
||||
|
||||
func (s *FakeService) RegisterDelete(query string) {
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user