summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorUnknwon <joe2010xtmf@163.com>2014-10-09 19:01:22 -0400
committerUnknwon <joe2010xtmf@163.com>2014-10-09 19:01:22 -0400
commit79262173a6e0a5734ebfc1565e45353677008302 (patch)
tree279574f1398259d1a875dacd0817e77c9117ccc0 /models
parent7b03b1df0efab201b48001200b17ed3390fa83da (diff)
downloadgitea-79262173a6e0a5734ebfc1565e45353677008302.tar.gz
gitea-79262173a6e0a5734ebfc1565e45353677008302.zip
Webhook delivery locking & Hide repo for org members if they don't have access
Diffstat (limited to 'models')
-rw-r--r--models/repo.go12
-rw-r--r--models/webhook.go16
2 files changed, 26 insertions, 2 deletions
diff --git a/models/repo.go b/models/repo.go
index 3a26c88f03..c332995198 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -166,7 +166,9 @@ type Repository struct {
}
func (repo *Repository) GetOwner() (err error) {
- repo.Owner, err = GetUserById(repo.OwnerId)
+ if repo.Owner == nil {
+ repo.Owner, err = GetUserById(repo.OwnerId)
+ }
return err
}
@@ -175,6 +177,14 @@ func (repo *Repository) GetMirror() (err error) {
return err
}
+func (repo *Repository) HasAccess(uname string) bool {
+ if err := repo.GetOwner(); err != nil {
+ return false
+ }
+ has, _ := HasAccess(uname, path.Join(repo.Owner.Name, repo.Name), READABLE)
+ return has
+}
+
// DescriptionHtml does special handles to description and return HTML string.
func (repo *Repository) DescriptionHtml() template.HTML {
sanitize := func(s string) string {
diff --git a/models/webhook.go b/models/webhook.go
index 9508c98a5e..ac0c240977 100644
--- a/models/webhook.go
+++ b/models/webhook.go
@@ -235,8 +235,22 @@ func UpdateHookTask(t *HookTask) error {
return err
}
+var (
+ // Prevent duplicate deliveries.
+ // This happens with massive hook tasks cannot finish delivering
+ // before next shooting starts.
+ isShooting = false
+)
+
// DeliverHooks checks and delivers undelivered hooks.
+// FIXME: maybe can use goroutine to shoot a number of them at same time?
func DeliverHooks() {
+ if isShooting {
+ return
+ }
+ isShooting = true
+ defer func() { isShooting = false }()
+
tasks := make([]*HookTask, 0, 10)
timeout := time.Duration(setting.WebhookDeliverTimeout) * time.Second
x.Where("is_delivered=?", false).Iterate(new(HookTask),
@@ -255,7 +269,7 @@ func DeliverHooks() {
t.IsDelivered = true
- // TODO: record response.
+ // FIXME: record response.
switch t.Type {
case GOGS:
{