Auth: Move Team service to SignedInUserInterface (#72674)

* move SignedInUser to specific file

* add primitive interface for signedInUser
This commit is contained in:
Jo
2023-08-02 10:43:56 +02:00
committed by GitHub
parent 2c26a02b82
commit 30274a4f88
7 changed files with 146 additions and 105 deletions
+6 -4
View File
@@ -4,10 +4,12 @@ import (
"errors"
"time"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/grafana/grafana/pkg/kinds/team"
"github.com/grafana/grafana/pkg/services/auth/identity"
"github.com/grafana/grafana/pkg/services/dashboards"
"github.com/grafana/grafana/pkg/services/user"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// Typed errors
@@ -70,7 +72,7 @@ type DeleteTeamCommand struct {
type GetTeamByIDQuery struct {
OrgID int64
ID int64
SignedInUser *user.SignedInUser
SignedInUser identity.Requester
HiddenUsers map[string]struct{}
}
@@ -80,7 +82,7 @@ const FilterIgnoreUser int64 = 0
type GetTeamsByUserQuery struct {
OrgID int64
UserID int64 `json:"userId"`
SignedInUser *user.SignedInUser
SignedInUser identity.Requester
}
type SearchTeamsQuery struct {
@@ -89,7 +91,7 @@ type SearchTeamsQuery struct {
Limit int
Page int
OrgID int64 `xorm:"org_id"`
SignedInUser *user.SignedInUser
SignedInUser identity.Requester
HiddenUsers map[string]struct{}
}
+4 -4
View File
@@ -9,9 +9,9 @@ import (
"github.com/grafana/grafana/pkg/infra/db"
ac "github.com/grafana/grafana/pkg/services/accesscontrol"
"github.com/grafana/grafana/pkg/services/auth/identity"
"github.com/grafana/grafana/pkg/services/dashboards"
"github.com/grafana/grafana/pkg/services/team"
"github.com/grafana/grafana/pkg/services/user"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/util"
)
@@ -37,14 +37,14 @@ type xormStore struct {
cfg *setting.Cfg
}
func getFilteredUsers(signedInUser *user.SignedInUser, hiddenUsers map[string]struct{}) []string {
func getFilteredUsers(signedInUser identity.Requester, hiddenUsers map[string]struct{}) []string {
filteredUsers := make([]string, 0, len(hiddenUsers))
if signedInUser == nil || signedInUser.IsGrafanaAdmin {
if signedInUser == nil || signedInUser.IsNil() || signedInUser.GetIsGrafanaAdmin() {
return filteredUsers
}
for u := range hiddenUsers {
if u == signedInUser.Login {
if u == signedInUser.GetLogin() {
continue
}
filteredUsers = append(filteredUsers, u)
+3 -2
View File
@@ -461,9 +461,10 @@ func TestIntegrationSQLStore_SearchTeams(t *testing.T) {
assert.Len(t, queryResult.Teams, tt.expectedTeamCount)
assert.Equal(t, queryResult.TotalCount, int64(tt.expectedTeamCount))
if !hasWildcardScope(tt.query.SignedInUser, ac.ActionTeamsRead) {
castSignedInUser := tt.query.SignedInUser.(*user.SignedInUser)
if !hasWildcardScope(castSignedInUser, ac.ActionTeamsRead) {
for _, team := range queryResult.Teams {
assert.Contains(t, tt.query.SignedInUser.Permissions[tt.query.SignedInUser.OrgID][ac.ActionTeamsRead], fmt.Sprintf("teams:id:%d", team.ID))
assert.Contains(t, castSignedInUser.Permissions[castSignedInUser.OrgID][ac.ActionTeamsRead], fmt.Sprintf("teams:id:%d", team.ID))
}
}
})