mirror of
https://github.com/stashapp/stash.git
synced 2026-04-26 17:05:25 +02:00
25 lines
635 B
Go
25 lines
635 B
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/99designs/gqlgen/graphql"
|
|
"github.com/stashapp/stash/pkg/session"
|
|
"github.com/stashapp/stash/pkg/user"
|
|
)
|
|
|
|
func HasRoleDirective(ctx context.Context, obj interface{}, next graphql.Resolver, role user.RoleEnum) (interface{}, error) {
|
|
currentUser := session.GetCurrentUser(ctx)
|
|
|
|
// if there is no current user, this is an anonymous request
|
|
// we should not end up here unless there are no credentials required
|
|
if currentUser == nil {
|
|
return next(ctx)
|
|
}
|
|
|
|
if currentUser != nil && !user.IsRole(currentUser.Roles, role) {
|
|
return nil, session.ErrUnauthorized
|
|
}
|
|
|
|
return next(ctx)
|
|
}
|