This section is empty.


This section is empty.


func NewContext

func NewContext(parent context.Context, v Viewer) context.Context

NewContext returns a copy of parent context with the given Viewer attached with it.


type AppViewer

type AppViewer struct {
	Role Role // Attached roles.

AppViewer describes an app-viewer.

func (AppViewer) Admin

func (v AppViewer) Admin() bool

func (AppViewer) Can

func (v AppViewer) Can(r Role) bool

func (AppViewer) Teams

func (v AppViewer) Teams(context.Context) ([]string, error)

type Role

type Role int

Role for viewer actions.

const (
	Admin Role

List of roles.

type UserViewer

type UserViewer struct {
	User *ent.User // Actual user.
	Role Role      // Attached roles.

UserViewer describes a user-viewer.

func (UserViewer) Admin

func (v UserViewer) Admin() bool

func (UserViewer) Can

func (v UserViewer) Can(r Role) bool

func (UserViewer) Teams

func (v UserViewer) Teams(ctx context.Context) ([]string, error)

type Viewer

type Viewer interface {
	Teams(context.Context) ([]string, error) // Team to query (tenant == team).
	Admin() bool                             // If viewer is admin.
	Can(Role) bool                           // If viewer is able to apply role action.

Viewer describes the query/mutation viewer-context.

func FromContext

func FromContext(ctx context.Context) Viewer

FromContext returns the Viewer stored in a context.

Source Files