grafana/pkg/services/store/static_auth.go
idafurjes 6afad51761
Move SignedInUser to user service and RoleType and Roles to org (#53445)
* Move SignedInUser to user service and RoleType and Roles to org

* Use go naming convention for roles

* Fix some imports and leftovers

* Fix ldap debug test

* Fix lint

* Fix lint 2

* Fix lint 3

* Fix type and not needed conversion

* Clean up messages in api tests

* Clean up api tests 2
2022-08-10 11:56:48 +02:00

42 lines
1.2 KiB
Go

package store
import (
"context"
"github.com/grafana/grafana/pkg/infra/filestorage"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/services/user"
)
type createPathFilterByAction func(ctx context.Context, user *user.SignedInUser, storageName string) map[string]filestorage.PathFilter
func newStaticStorageAuthService(createPathFilterByAction createPathFilterByAction) storageAuthService {
return &staticStorageAuth{
denyAllFileGuardian: &denyAllFileGuardian{},
createPathFilterByAction: createPathFilterByAction,
log: log.New("staticStorageAuthService"),
}
}
type staticStorageAuth struct {
log log.Logger
denyAllFileGuardian fileGuardian
createPathFilterByAction createPathFilterByAction
}
func (a *staticStorageAuth) newGuardian(ctx context.Context, user *user.SignedInUser, storageName string) fileGuardian {
pathFilter := a.createPathFilterByAction(ctx, user, storageName)
if pathFilter == nil {
return a.denyAllFileGuardian
}
return &pathFilterFileGuardian{
ctx: ctx,
user: user,
log: a.log,
prefix: storageName,
pathFilterByAction: pathFilter,
}
}