woodpecker/plugins/sender/builtin.go

53 lines
1.5 KiB
Go
Raw Normal View History

package sender
import (
2019-04-04 18:51:20 +00:00
"github.com/laszlocph/drone-oss-08/model"
)
type builtin struct {
store model.SenderStore
2017-05-05 18:05:42 +00:00
conf model.ConfigStore
}
// New returns a new local gating service.
2017-05-05 18:05:42 +00:00
func New(store model.SenderStore, conf model.ConfigStore) model.SenderService {
return &builtin{store, conf}
}
2017-05-05 17:13:40 +00:00
func (b *builtin) SenderAllowed(user *model.User, repo *model.Repo, build *model.Build, conf *model.Config) (bool, error) {
2017-05-05 18:05:42 +00:00
if build.Event == model.EventPull && build.Sender != user.Login {
// check to see if the configuration has already been used in an
// existing build. If yes it is considered approved.
if ok, _ := b.conf.ConfigFindApproved(conf); ok {
return true, nil
}
// else check to see if the configuration is sent from a user
// account that is a repositroy approver themselves.
sender, err := b.store.SenderFind(repo, build.Sender)
if err != nil || sender.Block {
return false, nil
}
}
return true, nil
}
func (b *builtin) SenderCreate(repo *model.Repo, sender *model.Sender) error {
return b.store.SenderCreate(sender)
}
func (b *builtin) SenderUpdate(repo *model.Repo, sender *model.Sender) error {
return b.store.SenderUpdate(sender)
}
func (b *builtin) SenderDelete(repo *model.Repo, login string) error {
sender, err := b.store.SenderFind(repo, login)
if err != nil {
return err
}
return b.store.SenderDelete(sender)
}
func (b *builtin) SenderList(repo *model.Repo) ([]*model.Sender, error) {
return b.store.SenderList(repo)
}