mirror of
https://github.com/go-gitea/gitea
synced 2025-07-23 02:38:35 +00:00
add user models
This commit is contained in:
@@ -5,67 +5,42 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/lunny/xorm"
|
||||
|
||||
git "github.com/libgit2/git2go"
|
||||
)
|
||||
|
||||
const (
|
||||
UserRepo = iota
|
||||
OrgRepo
|
||||
var (
|
||||
// orm
|
||||
orm *xorm.Engine
|
||||
// repository root path
|
||||
root string
|
||||
)
|
||||
|
||||
type User struct {
|
||||
Id int64
|
||||
Name string `xorm:"unique"`
|
||||
type PublicKey struct {
|
||||
Id int64
|
||||
Name string `xorm:"unique not null"`
|
||||
Content string `xorm:"text not null"`
|
||||
Created time.Time `xorm:"created"`
|
||||
Updated time.Time `xorm:"updated"`
|
||||
}
|
||||
|
||||
type Org struct {
|
||||
type Members struct {
|
||||
Id int64
|
||||
OrgId int64 `xorm:"unique(s) index"`
|
||||
UserId int64 `xorm:"unique(s)"`
|
||||
}
|
||||
|
||||
type Issue struct {
|
||||
Id int64
|
||||
RepoId int64 `xorm:"index"`
|
||||
PosterId int64
|
||||
}
|
||||
|
||||
type PullRequest struct {
|
||||
Id int64
|
||||
}
|
||||
|
||||
type Repo struct {
|
||||
Id int64
|
||||
OwnerId int64 `xorm:"unique(s)"`
|
||||
Type int `xorm:"unique(s)"`
|
||||
Name string `xorm:"unique(s)"`
|
||||
}
|
||||
|
||||
var (
|
||||
orm *xorm.Engine
|
||||
)
|
||||
|
||||
//
|
||||
// create a repository for a user or orgnaziation
|
||||
//
|
||||
func CreateUserRepository(root string, user *User, reposName string) error {
|
||||
p := filepath.Join(root, user.Name)
|
||||
os.MkdirAll(p, os.ModePerm)
|
||||
f := filepath.Join(p, reposName)
|
||||
_, err := git.InitRepository(f, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
repo := Repo{OwnerId: user.Id, Type: UserRepo, Name: reposName}
|
||||
_, err = orm.Insert(&repo)
|
||||
if err != nil {
|
||||
os.RemoveAll(f)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
//
|
||||
// delete a repository for a user or orgnaztion
|
||||
//
|
||||
func DeleteUserRepository(root string, user *User, reposName string) error {
|
||||
err := os.RemoveAll(filepath.Join(root, user.Name, reposName))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = orm.Delete(&Repo{OwnerId: user.Id, Type: UserRepo, Name: reposName})
|
||||
return err
|
||||
type Comment struct {
|
||||
Id int64
|
||||
}
|
||||
|
Reference in New Issue
Block a user