mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-30 08:06:52 +02:00
45 lines
994 B
Go
45 lines
994 B
Go
package datastore
|
|
|
|
import (
|
|
"github.com/drone/drone/model"
|
|
"github.com/drone/drone/store/datastore/sql"
|
|
|
|
"github.com/russross/meddler"
|
|
)
|
|
|
|
func (db *datastore) PermFind(user *model.User, repo *model.Repo) (*model.Perm, error) {
|
|
stmt := sql.Lookup(db.driver, "perms-find-user-repo")
|
|
data := new(model.Perm)
|
|
err := meddler.QueryRow(db, data, stmt, user.ID, repo.ID)
|
|
return data, err
|
|
}
|
|
|
|
func (db *datastore) PermUpsert(perm *model.Perm) error {
|
|
stmt := sql.Lookup(db.driver, "perms-insert-replace-lookup")
|
|
_, err := db.Exec(stmt,
|
|
perm.UserID,
|
|
perm.Repo,
|
|
perm.Pull,
|
|
perm.Push,
|
|
perm.Admin,
|
|
perm.Synced,
|
|
)
|
|
return err
|
|
}
|
|
|
|
func (db *datastore) PermBatch(perms []*model.Perm) (err error) {
|
|
for _, perm := range perms {
|
|
err = db.PermUpsert(perm)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (db *datastore) PermDelete(perm *model.Perm) error {
|
|
stmt := sql.Lookup(db.driver, "perms-delete-user-repo")
|
|
_, err := db.Exec(stmt, perm.UserID, perm.RepoID)
|
|
return err
|
|
}
|