mirror of
https://github.com/grafana/grafana.git
synced 2025-01-09 23:53:25 -06:00
Chore: delete team related entries for an org after the org gets deleted (#76706)
* delete team related entries for an org after the org gets deleted * fix tests * one more test fix
This commit is contained in:
parent
42f5e42b54
commit
1fc375855c
@ -22,4 +22,5 @@ type Service interface {
|
||||
RemoveOrgUser(context.Context, *RemoveOrgUserCommand) error
|
||||
GetOrgUsers(context.Context, *GetOrgUsersQuery) ([]*OrgUserDTO, error)
|
||||
SearchOrgUsers(context.Context, *SearchOrgUsersQuery) (*SearchOrgUsersQueryResult, error)
|
||||
RegisterDelete(query string)
|
||||
}
|
||||
|
@ -241,3 +241,7 @@ func readQuotaConfig(cfg *setting.Cfg) (*quota.Map, error) {
|
||||
limits.Set(userTag, cfg.Quota.User.Org)
|
||||
return limits, nil
|
||||
}
|
||||
|
||||
func (s *Service) RegisterDelete(query string) {
|
||||
s.store.RegisterDelete(query)
|
||||
}
|
||||
|
@ -154,3 +154,6 @@ func (f *FakeOrgStore) RemoveOrgUser(ctx context.Context, cmd *org.RemoveOrgUser
|
||||
func (f *FakeOrgStore) Count(ctx context.Context, _ *quota.ScopeParameters) (*quota.Map, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (f *FakeOrgStore) RegisterDelete(query string) {
|
||||
}
|
||||
|
@ -46,14 +46,16 @@ type store interface {
|
||||
RemoveOrgUser(context.Context, *org.RemoveOrgUserCommand) error
|
||||
|
||||
Count(context.Context, *quota.ScopeParameters) (*quota.Map, error)
|
||||
RegisterDelete(query string)
|
||||
}
|
||||
|
||||
type sqlStore struct {
|
||||
db db.DB
|
||||
dialect migrator.Dialect
|
||||
//TODO: moved to service
|
||||
log log.Logger
|
||||
cfg *setting.Cfg
|
||||
log log.Logger
|
||||
cfg *setting.Cfg
|
||||
deletes []string
|
||||
}
|
||||
|
||||
func (ss *sqlStore) Get(ctx context.Context, orgID int64) (*org.Org, error) {
|
||||
@ -239,8 +241,16 @@ func (ss *sqlStore) Delete(ctx context.Context, cmd *org.DeleteOrgCommand) error
|
||||
"DELETE FROM alert WHERE org_id = ?",
|
||||
"DELETE FROM annotation WHERE org_id = ?",
|
||||
"DELETE FROM kv_store WHERE org_id = ?",
|
||||
"DELETE FROM team WHERE org_id = ?",
|
||||
"DELETE FROM team_member WHERE org_id = ?",
|
||||
"DELETE FROM team_role WHERE org_id = ?",
|
||||
"DELETE FROM user_role WHERE org_id = ?",
|
||||
"DELETE FROM builtin_role WHERE org_id = ?",
|
||||
}
|
||||
|
||||
// Add registered deletes
|
||||
deletes = append(deletes, ss.deletes...)
|
||||
|
||||
for _, sql := range deletes {
|
||||
_, err := sess.Exec(sql, cmd.ID)
|
||||
if err != nil {
|
||||
@ -822,3 +832,8 @@ func removeUserOrg(sess *db.Session, userID int64) error {
|
||||
_, err := sess.ID(userID).MustCols("org_id").Update(&user)
|
||||
return err
|
||||
}
|
||||
|
||||
// RegisterDelete registers a delete query to be executed when an org is deleted, used to delete enterprise data.
|
||||
func (ss *sqlStore) RegisterDelete(query string) {
|
||||
ss.deletes = append(ss.deletes, query)
|
||||
}
|
||||
|
@ -99,3 +99,6 @@ func (f *FakeOrgService) RemoveOrgUser(ctx context.Context, cmd *org.RemoveOrgUs
|
||||
func (f *FakeOrgService) SearchOrgUsers(ctx context.Context, query *org.SearchOrgUsersQuery) (*org.SearchOrgUsersQueryResult, error) {
|
||||
return f.ExpectedSearchOrgUsersResult, f.ExpectedError
|
||||
}
|
||||
|
||||
func (f *FakeOrgService) RegisterDelete(query string) {
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user