viewer

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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.

Types

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
	Edit
	View
)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL