mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-10 20:59:31 +01:00
29 lines
569 B
Go
29 lines
569 B
Go
package models
|
|
|
|
import (
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
Readable = iota + 1
|
|
Writable
|
|
)
|
|
|
|
type Access struct {
|
|
Id int64
|
|
UserName string `xorm:"unique(s)"`
|
|
RepoName string `xorm:"unique(s)"`
|
|
Mode int `xorm:"unique(s)"`
|
|
Created time.Time `xorm:"created"`
|
|
}
|
|
|
|
func AddAccess(access *Access) error {
|
|
_, err := orm.Insert(access)
|
|
return err
|
|
}
|
|
|
|
// if one user can read or write one repository
|
|
func HasAccess(userName, repoName, mode string) (bool, error) {
|
|
return orm.Get(&Access{0, strings.ToLower(userName), strings.ToLower(repoName), mode})
|
|
}
|