model

package
v0.0.0-...-eb9f531 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRelatedUserGroupIDs

func GetRelatedUserGroupIDs(userGroups []*pbUser.RelatedUserGroup, db *pg.Tx) ([]uuid.UUID, error)

Select user groups in db with given ids in 'userGroups' Return ids slice Used in CreateUserGroup/UpdateUserGroup to add/update ids slice to recommended Artists

func GetRelatedUserGroups

func GetRelatedUserGroups(ids []uuid.UUID, db orm.DB) ([]*pbUser.RelatedUserGroup, error)

Select user groups in db with given 'ids' Return slice of UserGroup response

func GetTagIDs

func GetTagIDs(t []*pbUser.Tag, db *pg.Tx) ([]uuid.UUID, error)

GetTagIDs accepts a slice tags

func GetTags

func GetTags(tagIds []uuid.UUID, db *pg.DB) ([]*pbUser.Tag, twirp.Error)

GetTags given tag UUID returns a Tag

func SearchUserGroups

func SearchUserGroups(query string, db *pg.DB) (*pbUser.SearchResults, twirp.Error)

Types

type AccessRole

type AccessRole int8

AccessRole represents access role type

const (
	// SuperAdminRole has all permissions and can assign admins
	SuperAdminRole AccessRole = iota + 1 // 1

	// AdminRole has admin permissions across all tenants, except the ability to assign other Admins
	AdminRole // 2

	// TenantAdminRole has admin permissions over other users in their tenant.
	TenantAdminRole // 3

	// ArtistRole is a like a standard user, but can have multiple personas and the ability to upload
	ArtistRole // 4

	// UserRole is a standard user
	UserRole // 5
)

type AuthUser

type AuthUser struct {
	ID       uuid.UUID
	TenantID int32
	Username string
	Email    string
	Role     AccessRole
}

AuthUser represents data stored in session/context for a user

type GroupTaxonomy

type GroupTaxonomy struct {
	ID   uuid.UUID `sql:"type:uuid,default:uuid_generate_v4()"`
	Type string    `sql:",notnull"`
	Name string    `sql:",notnull"`
}
type Link struct {
	ID           uuid.UUID `sql:"type:uuid,default:uuid_generate_v4()"`
	URI          string    `sql:",notnull"`
	Type         string
	Platform     string `sql:",notnull"`
	PersonalData bool   `sql:",notnull"`
}

Link is an internet hyperlink

type Logger

type Logger interface {
	// source, msg, error, params
	Log(context.Context, string, string, error, map[string]interface{})
}

Logger represents logging interface

type RBACService

type RBACService interface {
	EnforceRole(context.Context, AccessRole) bool
	EnforceUser(context.Context, uuid.UUID) bool
	EnforceTenant(context.Context, uuid.UUID) bool
	EnforceTenantAdmin(context.Context, int32) bool
	EnforceTenantAndRole(context.Context, AccessRole, int32) bool
	IsLowerRole(context.Context, AccessRole) bool
}

RBACService represents role-based access control service interface

type Role

type Role struct {
	Id   int    `json:"id"`
	Name string `json:"name"`
}

Role entity

type StreetAddress

type StreetAddress struct {
	ID           uuid.UUID         `sql:"type:uuid,default:uuid_generate_v4()"`
	PersonalData bool              `sql:",notnull"`
	Data         map[string]string `pg:",hstore"`
}

StreetAddress holds geographical data and marks if private

type Tag

type Tag struct {
	ID   uuid.UUID `sql:"type:uuid,default:uuid_generate_v4()"`
	Type string    `sql:",notnull"`
	Name string    `sql:",notnull"`
}

Tag provides basic tag structure

func SearchTags

func SearchTags(query string, tagType string, db *pg.DB) ([]*Tag, twirp.Error)

SearchTags find a tag by query string on Name

type Tenant

type Tenant struct {
	Id     uuid.UUID `sql:"type:uuid,default:uuid_generate_v4()"`
	Name   string    `json:"name"`
	Active bool      `json:"active"`
}

Tenant table

type User

type User struct {
	ID                     uuid.UUID `sql:"type:uuid,default:uuid_generate_v4()"`
	CreatedAt              time.Time `sql:"default:now()"`
	UpdatedAt              time.Time
	Username               string `sql:",notnull,unique"`
	FullName               string `sql:",notnull"`
	FirstName              string
	LastName               string
	Email                  string `sql:",unique,notnull"`
	Member                 bool   `sql:",notnull"`
	NewsletterNotification bool
	FollowedGroups         []uuid.UUID `sql:",type:uuid[]" pg:",array"`
	OwnerOfGroups          []UserGroup `pg:"fk:owner_id"`
	TenantID               int32
	RoleID                 int32
	LastLogin              *time.Time
	LastPasswordChange     *time.Time
	Password               string
	Token                  string
}

User basic definition of a User and its meta

func (*User) Delete

func (u *User) Delete(tx *pg.Tx) (error, string)

Delete deletes a provided User

func (*User) FollowGroup

func (u *User) FollowGroup(db *pg.DB, userGroupID uuid.UUID) (error, string)

FollowGroup causes a User to follow a UserGroup

func (*User) UnfollowGroup

func (u *User) UnfollowGroup(db *pg.DB, userGroupID uuid.UUID) (error, string)

UnfollowGroup removes the follow state of the supplied User from the supplied userGroup via the supplied userGroupID

func (*User) UpdateLoginDetails

func (u *User) UpdateLoginDetails(token string)

UpdateLoginDetails updates login related fields

type UserGroup

type UserGroup struct {
	ID                 uuid.UUID `sql:"type:uuid,default:uuid_generate_v4()"`
	CreatedAt          time.Time `sql:"default:now()"`
	UpdatedAt          time.Time
	DisplayName        string `sql:",unique,notnull"`
	Description        string
	ShortBio           string
	Avatar             []byte `sql:",notnull"`
	Banner             []byte
	GroupEmailAddress  string
	PrivacyID          uuid.UUID `sql:"type:uuid,notnull"`
	Privacy            *UserGroupPrivacy
	AddressID          uuid.UUID `sql:"type:uuid,notnull"`
	Address            *StreetAddress
	TypeID             uuid.UUID `sql:"type:uuid,notnull"`
	Type               *GroupTaxonomy
	OwnerID            uuid.UUID `sql:"type:uuid,notnull"`
	Owner              *User
	Links              []uuid.UUID       `sql:",type:uuid[]" pg:",array"`
	Tags               []uuid.UUID       `sql:",type:uuid[]" pg:",array"`
	RecommendedArtists []uuid.UUID       `sql:",type:uuid[]" pg:",array"`
	RecommendedBy      []uuid.UUID       `sql:",type:uuid[]" pg:",array"`
	Followers          []uuid.UUID       `sql:",type:uuid[]" pg:",array"`
	AdminUsers         []uuid.UUID       `sql:",type:uuid[]" pg:",array"`
	Members            []UserGroup       `pg:"many2many:user_group_members,fk:user_group_id,joinFK:member_id"`
	MemberOfGroups     []UserGroup       `pg:"many2many:user_group_members,fk:member_id,joinFK:user_group_id"`
	Kvstore            map[string]string `pg:",hstore"`
	Publisher          map[string]string `pg:",hstore"`
	Pro                map[string]string `pg:",hstore"`
}

UserGroup represents a group of Users and maintains a set of metadata

func (*UserGroup) AddRecommended

func (u *UserGroup) AddRecommended(db *pg.DB, recommendedID uuid.UUID) (error, string)

func (*UserGroup) BeforeInsert

func (u *UserGroup) BeforeInsert(c context.Context, db orm.DB) error

func (*UserGroup) Create

func (u *UserGroup) Create(db *pg.DB, userGroup *pbUser.UserGroup) (error, string)

Create creates a new UserGroup

func (*UserGroup) Delete

func (u *UserGroup) Delete(tx *pg.Tx) (error, string)

func (*UserGroup) RemoveRecommended

func (u *UserGroup) RemoveRecommended(db *pg.DB, recommendedID uuid.UUID) (error, string)

func (*UserGroup) Update

func (u *UserGroup) Update(db *pg.DB, userGroup *pbUser.UserGroup) (error, string)

type UserGroupMember

type UserGroupMember struct {
	CreatedAt   time.Time `sql:"default:now()"`
	UpdatedAt   time.Time
	UserGroupID uuid.UUID `sql:",pk,type:uuid,notnull"`
	MemberID    uuid.UUID `sql:",pk,type:uuid,notnull"`
	DisplayName string
	Tags        []uuid.UUID `sql:",type:uuid[]" pg:",array"`
}

type UserGroupPrivacy

type UserGroupPrivacy struct {
	ID               uuid.UUID `sql:"type:uuid,default:uuid_generate_v4()"`
	Private          bool      `sql:",notnull"`
	OwnedTracks      bool      `sql:",notnull"`
	SupportedArtists bool      `sql:",notnull"`
}

UserGroupPrivacy describes meta data for User Group private data

Jump to

Keyboard shortcuts

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