Skip to content

Commit

Permalink
re-use gated logic
Browse files Browse the repository at this point in the history
  • Loading branch information
bradrydzewski committed May 5, 2017
1 parent 4569b60 commit 4aac0bc
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 18 deletions.
1 change: 0 additions & 1 deletion model/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ type Repo struct {
IsTrusted bool `json:"trusted" meddler:"repo_trusted"`
IsStarred bool `json:"starred,omitempty" meddler:"-"`
IsGated bool `json:"gated" meddler:"repo_gated"`
IsGatedConf bool `json:"gated_conf" meddler:"repo_gated_conf"`
AllowPull bool `json:"allow_pr" meddler:"repo_allow_pr"`
AllowPush bool `json:"allow_push" meddler:"repo_allow_push"`
AllowDeploy bool `json:"allow_deploys" meddler:"repo_allow_deploys"`
Expand Down
2 changes: 1 addition & 1 deletion model/sender.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package model

type SenderService interface {
SenderAllowed(*User, *Repo, *Build) (bool, error)
SenderAllowed(*User, *Repo, *Build, *Config) (bool, error)
SenderCreate(*Repo, *Sender) error
SenderUpdate(*Repo, *Sender) error
SenderDelete(*Repo, string) error
Expand Down
4 changes: 2 additions & 2 deletions plugins/sender/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ func New(store model.SenderStore) model.SenderService {
return &builtin{store}
}

func (b *builtin) SenderAllowed(user *model.User, repo *model.Repo, build *model.Build) (bool, error) {
if repo.IsPrivate == false && build.Event == model.EventPull && build.Sender != user.Login {
func (b *builtin) SenderAllowed(user *model.User, repo *model.Repo, build *model.Build, conf *model.Config) (bool, error) {
if !conf.Approved {
sender, err := b.store.SenderFind(repo, build.Sender)
if err != nil || sender.Block {
return false, nil
Expand Down
2 changes: 1 addition & 1 deletion plugins/sender/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func NewRemote(endpoint string) model.SenderService {
return &plugin{endpoint}
}

func (p *plugin) SenderAllowed(user *model.User, repo *model.Repo, build *model.Build) (bool, error) {
func (p *plugin) SenderAllowed(user *model.User, repo *model.Repo, build *model.Build, conf *model.Config) (bool, error) {
path := fmt.Sprintf("%s/senders/%s/%s/%s/verify", p.endpoint, repo.Owner, repo.Name, build.Sender)
err := internal.Send("POST", path, build, nil)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions server/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func PostHook(c *gin.Context) {
Hash: sha,
Approved: false,
}
if user.Login == repo.Owner || build.Event != model.EventPull {
if user.Login == repo.Owner || build.Event != model.EventPull || repo.IsGated == false {
conf.Approved = true
}
err = Config.Storage.Config.ConfigInsert(conf)
Expand All @@ -158,7 +158,7 @@ func PostHook(c *gin.Context) {
}
}
if !conf.Approved {
if user.Login == repo.Owner || build.Event != model.EventPull || !repo.IsGatedConf {
if user.Login == repo.Owner || build.Event != model.EventPull || repo.IsGated == false {
conf.Approved = true
Config.Storage.Config.ConfigUpdate(conf)
}
Expand Down Expand Up @@ -195,8 +195,8 @@ func PostHook(c *gin.Context) {
build.Verified = true
build.Status = model.StatusPending

if repo.IsGated || repo.IsGatedConf {
allowed, _ := Config.Services.Senders.SenderAllowed(user, repo, build)
if repo.IsGated {
allowed, _ := Config.Services.Senders.SenderAllowed(user, repo, build, conf)
if !allowed {
build.Status = model.StatusBlocked
}
Expand Down
3 changes: 0 additions & 3 deletions store/datastore/ddl/mysql/16.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ CREATE TABLE config (
ALTER TABLE builds ADD COLUMN build_config_id INTEGER;
UPDATE builds set build_config_id = 0;

ALTER TABLE repos ADD COLUMN repo_gated_conf BOOLEAN;
UPDATE repos SET repo_gated_conf = 0;

-- +migrate Down

DROP TABLE config;
3 changes: 0 additions & 3 deletions store/datastore/ddl/postgres/16.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ CREATE TABLE config (
ALTER TABLE builds ADD COLUMN build_config_id INTEGER;
UPDATE builds set build_config_id = 0;

ALTER TABLE repos ADD COLUMN repo_gated_conf BOOLEAN;
UPDATE repos SET repo_gated_conf = 0;

-- +migrate Down

DROP TABLE config;
3 changes: 0 additions & 3 deletions store/datastore/ddl/sqlite3/16.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ CREATE TABLE config (
ALTER TABLE builds ADD COLUMN build_config_id INTEGER;
UPDATE builds set build_config_id = 0;

ALTER TABLE repos ADD COLUMN repo_gated_conf BOOLEAN;
UPDATE repos SET repo_gated_conf = 0;

-- +migrate Down

DROP TABLE config;

0 comments on commit 4aac0bc

Please sign in to comment.