models

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2023 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SettingDisableSignup    = "disable-signup"
	SettingRequireLogin     = "require-login"
	SettingDisableLoginForm = "disable-login-form"
	SettingDisableGravatar  = "disable-gravatar"
)

Variables

This section is empty.

Functions

func ApplyMigrations

func ApplyMigrations(db *gorm.DB) error

func CountAll

func CountAll(table interface{}) (int64, error)

func CountAllGistsForkedByUser added in v1.4.0

func CountAllGistsForkedByUser(fromUserId uint, currentUserId uint) (int64, error)

func CountAllGistsFromUser added in v1.4.0

func CountAllGistsFromUser(fromUserId uint, currentUserId uint) (int64, error)

func CountAllGistsLikedByUser added in v1.4.0

func CountAllGistsLikedByUser(fromUserId uint, currentUserId uint) (int64, error)

func GetSetting

func GetSetting(key string) (string, error)

func GetSettings

func GetSettings() (map[string]string, error)

func GetUsersFromEmails

func GetUsersFromEmails(emailsSet map[string]struct{}) (map[string]*User, error)

func IsUniqueConstraintViolation

func IsUniqueConstraintViolation(err error) bool

func SSHKeyLastUsedNow

func SSHKeyLastUsedNow(sshKeyContent string) error

func Setup

func Setup(dbPath string) error

func UpdateSetting

func UpdateSetting(key string, value string) error

func UserExists

func UserExists(username string) (bool, error)

Types

type AdminSetting

type AdminSetting struct {
	Key   string `gorm:"uniqueIndex"`
	Value string
}

type FileDTO

type FileDTO struct {
	Filename string `validate:"excludes=\x2f,excludes=\x5c,max=50"`
	Content  string `validate:"required"`
}

type Gist

type Gist struct {
	ID              uint `gorm:"primaryKey"`
	Uuid            string
	Title           string
	Preview         string
	PreviewFilename string
	Description     string
	Private         bool
	UserID          uint
	User            User
	NbFiles         int
	NbLikes         int
	NbForks         int
	CreatedAt       int64
	UpdatedAt       int64

	Likes    []User `gorm:"many2many:likes;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
	Forked   *Gist  `gorm:"foreignKey:ForkedID;constraint:OnUpdate:CASCADE,OnDelete:SET NULL"`
	ForkedID uint
}

func GetAllGists

func GetAllGists(offset int) ([]*Gist, error)

func GetAllGistsForCurrentUser

func GetAllGistsForCurrentUser(currentUserId uint, offset int, sort string, order string) ([]*Gist, error)

func GetAllGistsForkedByUser added in v1.4.0

func GetAllGistsForkedByUser(fromUserId uint, currentUserId uint, offset int, sort string, order string) ([]*Gist, error)

func GetAllGistsFromSearch added in v1.4.0

func GetAllGistsFromSearch(currentUserId uint, query string, offset int, sort string, order string) ([]*Gist, error)

func GetAllGistsFromUser

func GetAllGistsFromUser(fromUserId uint, currentUserId uint, offset int, sort string, order string) ([]*Gist, error)

func GetAllGistsLikedByUser added in v1.4.0

func GetAllGistsLikedByUser(fromUserId uint, currentUserId uint, offset int, sort string, order string) ([]*Gist, error)

func GetAllGistsRows

func GetAllGistsRows() ([]*Gist, error)

func GetGist

func GetGist(user string, gistUuid string) (*Gist, error)

func GetGistByID

func GetGistByID(gistId string) (*Gist, error)

func (*Gist) AddAndCommitFiles

func (gist *Gist) AddAndCommitFiles(files *[]FileDTO) error

func (*Gist) AppendUserLike

func (gist *Gist) AppendUserLike(user *User) error

func (*Gist) BeforeDelete

func (gist *Gist) BeforeDelete(tx *gorm.DB) error

func (*Gist) CanWrite

func (gist *Gist) CanWrite(user *User) bool

func (*Gist) Create

func (gist *Gist) Create() error

func (*Gist) CreateForked

func (gist *Gist) CreateForked() error

func (*Gist) Delete

func (gist *Gist) Delete() error

func (*Gist) DeleteRepository

func (gist *Gist) DeleteRepository() error

func (*Gist) File

func (gist *Gist) File(revision string, filename string, truncate bool) (*git.File, error)

func (*Gist) Files

func (gist *Gist) Files(revision string) ([]*git.File, error)

func (*Gist) ForkClone

func (gist *Gist) ForkClone(username string, uuid string) error

func (*Gist) GetForkParent

func (gist *Gist) GetForkParent(user *User) (*Gist, error)

func (*Gist) GetForks

func (gist *Gist) GetForks(currentUserId uint, offset int) ([]*Gist, error)

func (*Gist) GetUsersLikes

func (gist *Gist) GetUsersLikes(offset int) ([]*User, error)

func (*Gist) IncrementForkCount

func (gist *Gist) IncrementForkCount() error

func (*Gist) InitRepository

func (gist *Gist) InitRepository() error

func (*Gist) Log

func (gist *Gist) Log(skip int) ([]*git.Commit, error)

func (*Gist) NbCommits

func (gist *Gist) NbCommits() (string, error)

func (*Gist) RPC

func (gist *Gist) RPC(service string) ([]byte, error)

func (*Gist) RemoveUserLike

func (gist *Gist) RemoveUserLike(user *User) error

func (*Gist) SetLastActiveNow

func (gist *Gist) SetLastActiveNow() error

func (*Gist) Update

func (gist *Gist) Update() error

func (*Gist) UpdatePreviewAndCount

func (gist *Gist) UpdatePreviewAndCount() error

func (*Gist) UpdateServerInfo

func (gist *Gist) UpdateServerInfo() error

type GistDTO

type GistDTO struct {
	Title       string    `validate:"max=50" form:"title"`
	Description string    `validate:"max=150" form:"description"`
	Private     bool      `form:"private"`
	Files       []FileDTO `validate:"min=1,dive"`
}

func (*GistDTO) ToExistingGist

func (dto *GistDTO) ToExistingGist(gist *Gist) *Gist

func (*GistDTO) ToGist

func (dto *GistDTO) ToGist() *Gist

type Like added in v1.4.0

type Like struct {
	UserID    uint `gorm:"primaryKey"`
	GistID    uint `gorm:"primaryKey"`
	CreatedAt int64
}

type MigrationVersion

type MigrationVersion struct {
	ID      uint `gorm:"primaryKey"`
	Version uint
}

type SSHKey

type SSHKey struct {
	ID         uint `gorm:"primaryKey"`
	Title      string
	Content    string
	SHA        string
	CreatedAt  int64
	LastUsedAt int64
	UserID     uint
	User       User `validate:"-" `
}

func GetSSHKeyByID

func GetSSHKeyByID(sshKeyId uint) (*SSHKey, error)

func GetSSHKeysByUserID

func GetSSHKeysByUserID(userId uint) ([]*SSHKey, error)

func SSHKeyDoesExists

func SSHKeyDoesExists(sshKeyContent string) (*SSHKey, error)

func SSHKeyExistsForUser

func SSHKeyExistsForUser(sshKey string, userId uint) (*SSHKey, error)

func (*SSHKey) BeforeCreate

func (sshKey *SSHKey) BeforeCreate(tx *gorm.DB) error

func (*SSHKey) Create

func (sshKey *SSHKey) Create() error

func (*SSHKey) Delete

func (sshKey *SSHKey) Delete() error

type SSHKeyDTO

type SSHKeyDTO struct {
	Title   string `form:"title" validate:"required,max=50"`
	Content string `form:"content" validate:"required"`
}

func (*SSHKeyDTO) ToSSHKey

func (dto *SSHKeyDTO) ToSSHKey() *SSHKey

type User

type User struct {
	ID        uint   `gorm:"primaryKey"`
	Username  string `gorm:"uniqueIndex"`
	Password  string
	IsAdmin   bool
	CreatedAt int64
	Email     string
	MD5Hash   string // for gravatar, if no Email is specified, the value is random
	AvatarURL string
	GithubID  string
	GiteaID   string

	Gists   []Gist   `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;foreignKey:UserID"`
	SSHKeys []SSHKey `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;foreignKey:UserID"`
	Liked   []Gist   `gorm:"many2many:likes;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
}

func GetAllUsers

func GetAllUsers(offset int) ([]*User, error)

func GetUserById

func GetUserById(userId uint) (*User, error)

func GetUserByProvider

func GetUserByProvider(id string, provider string) (*User, error)

func GetUserByUsername

func GetUserByUsername(username string) (*User, error)

func (*User) BeforeDelete

func (user *User) BeforeDelete(tx *gorm.DB) error

func (*User) Create

func (user *User) Create() error

func (*User) Delete

func (user *User) Delete() error

func (*User) DeleteProviderID

func (user *User) DeleteProviderID(provider string) error

func (*User) HasLiked

func (user *User) HasLiked(gist *Gist) (bool, error)

func (*User) SetAdmin

func (user *User) SetAdmin() error

func (*User) Update

func (user *User) Update() error

type UserDTO

type UserDTO struct {
	Username string `form:"username" validate:"required,max=24,alphanum,notreserved"`
	Password string `form:"password" validate:"required"`
}

func (*UserDTO) ToUser

func (dto *UserDTO) ToUser() *User

Jump to

Keyboard shortcuts

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