user

package
v0.62.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const CSVContentType = "text/csv"

Variables

View Source
var (
	ErrNotExist         = errors.New("user doesn't exist")
	ErrInvalidID        = errors.New("user id is invalid")
	ErrInvalidEmail     = errors.New("user email is invalid")
	ErrConflict         = errors.New("user already exist")
	ErrInvalidDetails   = errors.New("invalid user details (name|email)")
	ErrMissingName      = errors.New("user name is missing")
	ErrEmptyKey         = errors.New("empty key")
	ErrKeyAlreadyExists = errors.New("key already exist")
	ErrKeyDoesNotExists = errors.New("key does not exist")
	ErrMissingEmail     = errors.New("user email is missing")
	ErrInvalidUUID      = errors.New("invalid syntax of uuid")
	ErrDisabled         = errors.New("user is disabled")
	ErrNoUsersFound     = errors.New("no users found")
)

Functions

func IsValidEmail added in v0.60.0

func IsValidEmail(str string) bool

IsValidEmail checks if the string is a valid email address

Types

type AccessPair added in v0.7.5

type AccessPair struct {
	User User
	On   string
	Can  []string
}

type CSVExport added in v0.57.0

type CSVExport struct {
	UserID    string `csv:"User ID"`
	Name      string `csv:"Name"`
	Title     string `csv:"Title"`
	Email     string `csv:"Email"`
	State     string `csv:"State"`
	CreatedAt string `csv:"Joined At"`
}

func NewCSVExport added in v0.57.0

func NewCSVExport(user User) CSVExport

NewCSVExport converts User to CSVExport

func (CSVExport) GetHeaders added in v0.57.0

func (c CSVExport) GetHeaders() []string

GetHeaders returns the CSV headers based on struct tags

func (CSVExport) ToRow added in v0.57.0

func (c CSVExport) ToRow() []string

ToRow converts the struct to a string slice for CSV writing

type Filter

type Filter struct {
	Limit int32
	Page  int32

	Keyword string
	OrgID   string
	GroupID string
	State   State
}

type Group added in v0.57.0

type Group struct {
	Name string      `json:"name"`
	Data []GroupData `json:"data"`
}

type GroupData added in v0.57.0

type GroupData struct {
	Name  string `json:"name"`
	Count int    `json:"count"`
}

type Page added in v0.57.0

type Page struct {
	Limit  int `json:"limit"`
	Offset int `json:"offset"`
}

type PolicyService added in v0.7.19

type PolicyService interface {
	List(ctx context.Context, f policy.Filter) ([]policy.Policy, error)
}

type RelationService

type RelationService interface {
	Create(ctx context.Context, rel relation.Relation) (relation.Relation, error)
	BatchCheckPermission(ctx context.Context, relations []relation.Relation) ([]relation.CheckPair, error)
	Delete(ctx context.Context, rel relation.Relation) error
	LookupSubjects(ctx context.Context, rel relation.Relation) ([]string, error)
	LookupResources(ctx context.Context, rel relation.Relation) ([]string, error)
}

type Repository

type Repository interface {
	GetByID(ctx context.Context, id string) (User, error)
	GetByEmail(ctx context.Context, email string) (User, error)
	GetByIDs(ctx context.Context, userIds []string) ([]User, error)
	GetByName(ctx context.Context, name string) (User, error)
	Create(ctx context.Context, user User) (User, error)
	List(ctx context.Context, flt Filter) ([]User, error)
	UpdateByID(ctx context.Context, toUpdate User) (User, error)
	UpdateByName(ctx context.Context, toUpdate User) (User, error)
	UpdateByEmail(ctx context.Context, toUpdate User) (User, error)
	Delete(ctx context.Context, id string) error
	SetState(ctx context.Context, id string, state State) error
	Search(ctx context.Context, query *rql.Query) (SearchUserResponse, error)
}

type RoleService added in v0.8.0

type RoleService interface {
	List(ctx context.Context, f role.Filter) ([]role.Role, error)
}

type SearchUserResponse added in v0.57.0

type SearchUserResponse struct {
	Users      []User `json:"users"`
	Group      Group  `json:"group"`
	Pagination Page   `json:"pagination"`
}

type Service

type Service struct {
	Now func() time.Time
	// contains filtered or unexported fields
}

func NewService

func NewService(repository Repository, relationRepo RelationService,
	policyService PolicyService, roleService RoleService) *Service

func (Service) Create

func (s Service) Create(ctx context.Context, user User) (User, error)

func (Service) Delete

func (s Service) Delete(ctx context.Context, id string) error

Delete by user uuid don't call this directly, use cascade deleter

func (Service) Disable

func (s Service) Disable(ctx context.Context, id string) error

func (Service) Enable

func (s Service) Enable(ctx context.Context, id string) error

func (Service) Export added in v0.57.0

func (s Service) Export(ctx context.Context) ([]byte, string, error)

func (Service) GetByEmail

func (s Service) GetByEmail(ctx context.Context, email string) (User, error)

func (Service) GetByID

func (s Service) GetByID(ctx context.Context, id string) (User, error)

GetByID email or slug

func (Service) GetByIDs

func (s Service) GetByIDs(ctx context.Context, userIDs []string) ([]User, error)

func (Service) IsSudo

func (s Service) IsSudo(ctx context.Context, id string, permissionName string) (bool, error)

IsSudo checks platform permissions. Platform permissions are: - superuser - check

func (Service) IsSudos added in v0.7.6

func (s Service) IsSudos(ctx context.Context, ids []string, permissionName string) ([]relation.Relation, error)

func (Service) List

func (s Service) List(ctx context.Context, flt Filter) ([]User, error)

func (Service) ListByGroup

func (s Service) ListByGroup(ctx context.Context, groupID string, roleFilter string) ([]User, error)

func (Service) ListByOrg

func (s Service) ListByOrg(ctx context.Context, orgID string, roleFilter string) ([]User, error)

func (Service) Search added in v0.57.0

func (s Service) Search(ctx context.Context, rql *rql.Query) (SearchUserResponse, error)

func (Service) Sudo

func (s Service) Sudo(ctx context.Context, id string, relationName string) error

Sudo add platform permissions to user

func (Service) UnSudo added in v0.14.0

func (s Service) UnSudo(ctx context.Context, id string) error

UnSudo remove platform permissions to user only remove the 'member' relation if it exists

func (Service) Update

func (s Service) Update(ctx context.Context, toUpdate User) (User, error)

Update by user uuid, email or slug Note(kushsharma): we don't actually update email field of the user, if we want to support it one security concern is that we need to ensure users can't misuse it to takeover invitations created for other users.

func (Service) UpdateByEmail

func (s Service) UpdateByEmail(ctx context.Context, toUpdate User) (User, error)

type State

type State string
const (
	Enabled  State = "enabled"
	Disabled State = "disabled"
)

func (State) String

func (s State) String() string

type User

type User struct {
	ID        string `rql:"name=id,type=string"`
	Name      string `rql:"name=name,type=string"`
	Email     string `rql:"name=email,type=string"`
	State     State  `rql:"name=state,type=string"`
	Avatar    string `rql:"name=avatar,type=string"`
	Title     string `rql:"name=title,type=string"`
	Metadata  metadata.Metadata
	CreatedAt time.Time `rql:"name=created_at,type=datetime"`
	UpdatedAt time.Time `rql:"name=updated_at,type=datetime"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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