mirror of https://github.com/grafana/grafana.git
AUTHZ: add option to bypass team membership cache (#111968)
add option to bypass team membership cache
This commit is contained in:
parent
43be84076c
commit
02fb28a478
|
@ -19,7 +19,7 @@ type Service interface {
|
||||||
GetTeamIDsByUser(ctx context.Context, query *GetTeamIDsByUserQuery) ([]int64, error)
|
GetTeamIDsByUser(ctx context.Context, query *GetTeamIDsByUserQuery) ([]int64, error)
|
||||||
IsTeamMember(ctx context.Context, orgId int64, teamId int64, userId int64) (bool, error)
|
IsTeamMember(ctx context.Context, orgId int64, teamId int64, userId int64) (bool, error)
|
||||||
RemoveUsersMemberships(tx context.Context, userID int64) error
|
RemoveUsersMemberships(tx context.Context, userID int64) error
|
||||||
GetUserTeamMemberships(ctx context.Context, orgID, userID int64, external bool) ([]*TeamMemberDTO, error)
|
GetUserTeamMemberships(ctx context.Context, orgID, userID int64, external bool, bypassCache bool) ([]*TeamMemberDTO, error)
|
||||||
GetTeamMembers(ctx context.Context, query *GetTeamMembersQuery) ([]*TeamMemberDTO, error)
|
GetTeamMembers(ctx context.Context, query *GetTeamMembersQuery) ([]*TeamMemberDTO, error)
|
||||||
RegisterDelete(query string)
|
RegisterDelete(query string)
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,19 +114,21 @@ func (s *Service) RemoveUsersMemberships(ctx context.Context, userID int64) erro
|
||||||
return s.store.RemoveUsersMemberships(ctx, userID)
|
return s.store.RemoveUsersMemberships(ctx, userID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) GetUserTeamMemberships(ctx context.Context, orgID, userID int64, external bool) ([]*team.TeamMemberDTO, error) {
|
func (s *Service) GetUserTeamMemberships(ctx context.Context, orgID, userID int64, external bool, bypassCache bool) ([]*team.TeamMemberDTO, error) {
|
||||||
ctx, span := s.tracer.Start(ctx, "team.GetUserTeamMemberships", trace.WithAttributes(
|
ctx, span := s.tracer.Start(ctx, "team.GetUserTeamMemberships", trace.WithAttributes(
|
||||||
attribute.Int64("orgID", orgID),
|
attribute.Int64("orgID", orgID),
|
||||||
attribute.Int64("userID", userID),
|
attribute.Int64("userID", userID),
|
||||||
))
|
))
|
||||||
defer span.End()
|
defer span.End()
|
||||||
cacheKey := fmt.Sprintf("teams:%d:%d:%t", orgID, userID, external)
|
cacheKey := fmt.Sprintf("teams:%d:%d:%t", orgID, userID, external)
|
||||||
|
if !bypassCache {
|
||||||
if cached, found := s.cache.Get(cacheKey); found {
|
if cached, found := s.cache.Get(cacheKey); found {
|
||||||
if teams, ok := cached.([]*team.TeamMemberDTO); ok {
|
if teams, ok := cached.([]*team.TeamMemberDTO); ok {
|
||||||
return teams, nil
|
return teams, nil
|
||||||
}
|
}
|
||||||
s.cache.Delete(cacheKey)
|
s.cache.Delete(cacheKey)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
teams, err := s.store.GetMemberships(ctx, orgID, userID, external)
|
teams, err := s.store.GetMemberships(ctx, orgID, userID, external)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -137,7 +139,9 @@ func (s *Service) GetUserTeamMemberships(ctx context.Context, orgID, userID int6
|
||||||
return []*team.TeamMemberDTO{}, nil
|
return []*team.TeamMemberDTO{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !bypassCache {
|
||||||
s.cache.Set(cacheKey, teams, defaultCacheDuration)
|
s.cache.Set(cacheKey, teams, defaultCacheDuration)
|
||||||
|
}
|
||||||
return teams, nil
|
return teams, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ func (s *FakeService) RemoveUsersMemberships(ctx context.Context, userID int64)
|
||||||
return s.ExpectedError
|
return s.ExpectedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *FakeService) GetUserTeamMemberships(ctx context.Context, orgID, userID int64, external bool) ([]*team.TeamMemberDTO, error) {
|
func (s *FakeService) GetUserTeamMemberships(ctx context.Context, orgID, userID int64, external bool, bypassCache bool) ([]*team.TeamMemberDTO, error) {
|
||||||
return s.ExpectedMembers, s.ExpectedError
|
return s.ExpectedMembers, s.ExpectedError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue